itty-router 4.1.0-next.3 → 4.1.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.
Files changed (78) hide show
  1. package/README.md +107 -28
  2. package/Router.d.ts +10 -4
  3. package/Router.js +2 -1
  4. package/Router.js.map +1 -0
  5. package/Router.mjs +2 -1
  6. package/Router.mjs.map +1 -0
  7. package/StatusError.js +1 -0
  8. package/StatusError.js.map +1 -0
  9. package/StatusError.mjs +1 -0
  10. package/StatusError.mjs.map +1 -0
  11. package/createCors.d.ts +3 -3
  12. package/createCors.js +2 -1
  13. package/createCors.js.map +1 -0
  14. package/createCors.mjs +2 -1
  15. package/createCors.mjs.map +1 -0
  16. package/createResponse.js +2 -1
  17. package/createResponse.js.map +1 -0
  18. package/createResponse.mjs +2 -1
  19. package/createResponse.mjs.map +1 -0
  20. package/error.js +2 -1
  21. package/error.js.map +1 -0
  22. package/error.mjs +2 -1
  23. package/error.mjs.map +1 -0
  24. package/html.js +2 -1
  25. package/html.js.map +1 -0
  26. package/html.mjs +2 -1
  27. package/html.mjs.map +1 -0
  28. package/index.d.ts +0 -1
  29. package/index.js +2 -1
  30. package/index.js.map +1 -0
  31. package/index.mjs +2 -1
  32. package/index.mjs.map +1 -0
  33. package/jpeg.js +2 -1
  34. package/jpeg.js.map +1 -0
  35. package/jpeg.mjs +2 -1
  36. package/jpeg.mjs.map +1 -0
  37. package/json.js +2 -1
  38. package/json.js.map +1 -0
  39. package/json.mjs +2 -1
  40. package/json.mjs.map +1 -0
  41. package/package.json +3 -10
  42. package/png.js +2 -1
  43. package/png.js.map +1 -0
  44. package/png.mjs +2 -1
  45. package/png.mjs.map +1 -0
  46. package/status.js +1 -0
  47. package/status.js.map +1 -0
  48. package/status.mjs +1 -0
  49. package/status.mjs.map +1 -0
  50. package/text.d.ts +1 -1
  51. package/text.js +2 -1
  52. package/text.js.map +1 -0
  53. package/text.mjs +2 -1
  54. package/text.mjs.map +1 -0
  55. package/webp.js +2 -1
  56. package/webp.js.map +1 -0
  57. package/webp.mjs +2 -1
  58. package/webp.mjs.map +1 -0
  59. package/websocket.js +2 -1
  60. package/websocket.js.map +1 -0
  61. package/websocket.mjs +2 -1
  62. package/websocket.mjs.map +1 -0
  63. package/withContent.d.ts +4 -1
  64. package/withContent.js +2 -1
  65. package/withContent.js.map +1 -0
  66. package/withContent.mjs +2 -1
  67. package/withContent.mjs.map +1 -0
  68. package/withCookies.js +1 -0
  69. package/withCookies.js.map +1 -0
  70. package/withCookies.mjs +1 -0
  71. package/withCookies.mjs.map +1 -0
  72. package/withParams.js +2 -1
  73. package/withParams.js.map +1 -0
  74. package/withParams.mjs +2 -1
  75. package/withParams.mjs.map +1 -0
  76. package/flow.d.ts +0 -9
  77. package/flow.js +0 -1
  78. package/flow.mjs +0 -1
package/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  <p align="center">
2
2
  <a href="https://itty.dev/itty-router">
3
- <img src="https://github.com/kwhitley/itty-router/assets/865416/7751dac0-2dc8-4754-8b39-d08fc2144b4f" alt="Itty Router" />
3
+ <img src="https://github.com/kwhitley/itty-router/assets/865416/15a90b05-344d-4135-a3f8-52a4d117250e" alt="Itty Router" />
4
4
  </a>
5
5
  <p>
6
-
7
- ---
6
+
8
7
  <h2 align="center"><a href="https://itty.dev/itty-router">v4.x Documentation @ itty.dev</a>
9
8
  <br /></h2>
10
9
 
@@ -33,8 +32,8 @@
33
32
  </p>
34
33
 
35
34
  <p align="center">
36
- <a href="https://discord.com/channels/832353585802903572" target="_blank">
37
- <img src="https://img.shields.io/discord/832353585802903572?style=flat-square" alt="join us on discord" />
35
+ <a href="https://discord.gg/53vyrZAu9u" target="_blank">
36
+ <img src="https://img.shields.io/discord/832353585802903572?label=Discord&logo=Discord&style=flat-square&logoColor=fff" alt="join us on discord" />
38
37
  </a>
39
38
  <a href="https://github.com/kwhitley/itty-router" target="_blank">
40
39
  <img src="https://img.shields.io/github/stars/kwhitley/itty-router?style=social" alt="repo stars" />
@@ -49,38 +48,29 @@
49
48
 
50
49
  ---
51
50
 
52
- Itty aims to be the world's smallest (~440 bytes), feature-rich JavaScript router, enabling beautiful API code with a near-zero bundlesize. Designed originally for [Cloudflare Workers](https://itty.dev/itty-router/runtimes#Cloudflare%20Workers), itty can be used in browsers, Service Workers, edge functions, or standalone runtimes like [Node](https://itty.dev/itty-router/runtimes#Node), [Bun](https://itty.dev/itty-router/runtimes#Bun), etc.!
51
+ Itty is arguably the smallest (~450 bytes) feature-rich JavaScript router available, while enabling dead-simple API code.
52
+
53
+ Designed originally for [Cloudflare Workers](https://itty.dev/itty-router/runtimes#Cloudflare%20Workers), itty can be used in browsers, service workers, edge functions, or runtimes like [Node](https://itty.dev/itty-router/runtimes#Node), [Bun](https://itty.dev/itty-router/runtimes#Bun), etc.!
53
54
 
54
55
  ## Features
55
56
 
56
- - Tiny. The Router itself is ~440 bytes gzipped, and the **entire** library is under 1.6k!
57
- - Easy to use. We believe route code should be self-evident, obvious, and read more like poetry than code.
58
- - Agnostic. We leave **you** with full control over response types, matching order, upstream/downstream effects, etc.
59
- - Works [anywhere, in any environment](https://itty.dev/itty-router/runtimes).
60
- - [Fully typed/TypeScript support](https://itty.dev/itty-router/typescript), including hinting.
57
+ - Tiny. [~450](https://deno.bundlejs.com/?q=itty-router/Router) bytes for the Router itself, or [~1.6k](https://bundlephobia.com/package/itty-router) for the entire library (>100x smaller than [express.js](https://www.npmjs.com/package/express)).
58
+ - [Fully-Typed](https://itty.dev/itty-router/typescript).
59
+ - Shorter, simpler route code than most modern routers.
60
+ - Dead-simple [middleware](https://itty.dev/itty-router/middleware) - use ours or write your own.
61
+ - Supports [nested APIs](https://itty.dev/itty-router/nesting).
62
+ - Platform agnostic (based on [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)) - use it [anywhere, in any environment](https://itty.dev/itty-router/runtimes).
61
63
  - Parses [route params](https://itty.dev/itty-router/route-patterns#params),
62
64
  [optional params](https://itty.dev/itty-router/route-patterns#optional),
63
65
  [wildcards](https://itty.dev/itty-router/route-patterns#wildcards),
64
66
  [greedy params](https://itty.dev/itty-router/route-patterns#greedy),
65
- and [file formats](https://itty.dev/itty-router/route-patterns#file-formats).
66
- - Automatic [query parsing](https://itty.dev/itty-router/route-patterns#query).
67
- - Easy [error handling](https://itty.dev/itty-router/errors), including throwing errors with HTTP status codes!
68
- - Easy [Response](https://itty.dev/itty-router/responses) creation, with helpers for major formats (e.g.
69
- [json](https://itty.dev/itty-router/api#json),
70
- [html](https://itty.dev/itty-router/api#html),
71
- [png](https://itty.dev/itty-router/api#png),
72
- [jpeg](https://itty.dev/itty-router/api#jpeg), etc.)
73
- - Deep APIs via [router nesting](https://itty.dev/itty-router/nesting).
74
- - Full [middleware](https://itty.dev/itty-router/middleware) support. Includes the following by default:
75
- - [withParams](https://itty.dev/itty-router/api#withParams) - access the params directly off the `Request` (instead of `request.params`).
76
- - [withCookies](https://itty.dev/itty-router/api#withCookies) - access cookies in a convenient Object format.
77
- - [withContent](https://itty.dev/itty-router/api#withContent) - auto-parse Request bodies as `request.content`.
78
- - [CORS](https://itty.dev/itty-router/cors) - because we love you.
79
- - Fully readable regex... yeah right! 😆
67
+ [file formats](https://itty.dev/itty-router/route-patterns#file-formats)
68
+ and [query strings](https://itty.dev/itty-router/route-patterns#query).
69
+ - Extremely extendable/flexible. We leave you in complete control.
80
70
 
81
71
  ## [Full Documentation](https://itty.dev/itty-router)
82
72
 
83
- Complete documentation/API is available at [itty.dev](https://itty.dev/itty-router), or join our [Discord](https://discord.com/channels/832353585802903572) channel to chat with community members for quick help!
73
+ Complete API documentation is available at [itty.dev/itty-router](https://itty.dev/itty-router), or join our [Discord](https://discord.gg/53vyrZAu9u) channel to chat with community members for quick help!
84
74
 
85
75
  ## Installation
86
76
 
@@ -128,11 +118,100 @@ export default {
128
118
  }
129
119
  ```
130
120
 
121
+ # What's different about itty? <a name="a-different-kind-of-router"></a>
122
+ Itty does a few things very differently from other routers. This allows itty route code to be shorter and more intuitive than most!
123
+
124
+ ### 1. Simpler handler/middleware flow.
125
+ In itty, you simply return (anything) to exit the flow. If any handler ever returns a thing, that's what the `router.handle` returns. If it doesn't, it's considered middleware, and the next handler is called.
126
+
127
+ That's it!
128
+
129
+ ```ts
130
+ // not middleware: any handler that returns (anything at all)
131
+ (request) => [1, 4, 5, 1]
132
+
133
+ // middleware: simply doesn't return
134
+ const withUser = (request) => {
135
+ request.user = 'Halsey'
136
+ }
137
+
138
+ // a middleware that *might* return
139
+ const onlyHalsey = (request) => {
140
+ if (request.user !== 'Halsey') {
141
+ return error(403, 'Only Halsey is allowed to see this!')
142
+ }
143
+ }
144
+
145
+ // uses middleware, then returns something
146
+ route.get('/secure', withUser, onlyHalsey,
147
+ ({ user }) => `Hey, ${user} - welcome back!`
148
+ )
149
+ ```
150
+
151
+ ### 2. You don't have to build a response in each route handler.
152
+ We've been stuck in this pattern for over a decade. Almost every router still expects you to build and return a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)... in every single route.
153
+
154
+ We think you should be able to do that once, at the end. In most modern APIs for instance, we're serving JSON in the majority of our routes. So why handle that more than once?
155
+ ```ts
156
+ router
157
+ // we can still do it the manual way
158
+ .get('/traditional', (request) => json([1, 2, 3]))
159
+
160
+ // or defer to later
161
+ .get('/easy-mode', (request) => [1, 2, 3])
162
+
163
+ // later, when handling a request
164
+ router
165
+ .handle(request)
166
+ .then(json) // we can turn any non-Response into valid JSON.
167
+ ```
168
+
169
+ ### 3. It's all Promises.
170
+ itty `await`s every handler, looking for a return value. If it gets one, it breaks the flow and returns the value. If it doesn't, it continues processing handlers/routes until it does. This means that every handler can either be synchronous or async - it's all the same.
171
+
172
+ When paired with the fact that we can simply return raw data and transform it later, this is AWESOME for working with async APIs, database layers, etc. We don't need to transform anything at the route, we can simply return the Promise (to data) itself!
173
+
174
+ Check this out:
175
+ ```ts
176
+ import { myDatabase } from './somewhere'
177
+
178
+ router
179
+ // assumes getItems() returns a Promise to some data
180
+ .get('/items', () => myDatabase.getItems())
181
+
182
+ // later, when handling a request
183
+ router
184
+ .handle(request)
185
+ .then(json) // we can turn any non-Response into valid JSON.
186
+ ```
187
+
188
+ ### 4. Only one required argument. The rest is up to you.
189
+ itty only requires one argument - a Request-like object with the following shape: `{ url, method }` (usually a native [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request)). Because itty is not opinionated about [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) creation, there is not "response" argument built in. Every other argument you pass to `route.handle` is given to each handler, in the same order.
190
+
191
+ > ### This makes itty one of the most platform-agnostic routers, *period*, as it's able to match up to any platform's signature.
192
+
193
+ Here's an example using [Cloudflare Worker](https://workers.cloudflare.com/) arguments:
194
+ ```ts
195
+ router
196
+ .get('/my-route', (request, environment, context) => {
197
+ // we can access anything here that was passed to `router.handle`.
198
+ })
199
+
200
+ // Cloudflare gives us 3 arguments: request, environment, and context.
201
+ // Passing them to `route.handle` gives every route handler (above) access to each.
202
+ export default {
203
+ fetch: (request, env, ctx) => router
204
+ .handle(request, env, ctx)
205
+ .then(json)
206
+ .catch(error)
207
+ }
208
+ ```
209
+
131
210
  ## Join the Discussion!
132
211
 
133
212
  Have a question? Suggestion? Complaint? Want to send a gift basket?
134
213
 
135
- Join us on [Discord](https://discord.com/channels/832353585802903572)!
214
+ Join us on [Discord](https://discord.gg/53vyrZAu9u)!
136
215
 
137
216
  ## Testing and Contributing
138
217
 
package/Router.d.ts CHANGED
@@ -21,11 +21,16 @@ export type IRequest = IRequestStrict & GenericTraps;
21
21
  export type RouterOptions = {
22
22
  base?: string;
23
23
  routes?: RouteEntry[];
24
- };
24
+ } & Record<string, any>;
25
25
  export type RouteHandler<I = IRequest, A extends any[] = any[]> = {
26
26
  (request: I, ...args: A): any;
27
27
  };
28
- export type RouteEntry = [string, RegExp, RouteHandler[], string];
28
+ export type RouteEntry = [
29
+ httpMethod: string,
30
+ match: RegExp,
31
+ handlers: RouteHandler[],
32
+ path?: string
33
+ ];
29
34
  export type Route = <RequestType = IRequest, Args extends any[] = any[], RT = RouterType>(path: string, ...handlers: RouteHandler<RequestType, Args>[]) => RT;
30
35
  export type UniversalRoute<RequestType = IRequest, Args extends any[] = any[]> = (path: string, ...handlers: RouteHandler<RequestType, Args>[]) => RouterType<UniversalRoute<RequestType, Args>, Args>;
31
36
  type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
@@ -35,6 +40,7 @@ export type CustomRoutes<R = Route> = {
35
40
  export type RouterType<R = Route, Args extends any[] = any[]> = {
36
41
  __proto__: RouterType<R>;
37
42
  routes: RouteEntry[];
43
+ fetch: <A extends any[] = Args>(request: RequestLike, ...extra: Equal<R, Args> extends true ? A : Args) => Promise<any>;
38
44
  handle: <A extends any[] = Args>(request: RequestLike, ...extra: Equal<R, Args> extends true ? A : Args) => Promise<any>;
39
45
  all: R;
40
46
  delete: R;
@@ -44,6 +50,6 @@ export type RouterType<R = Route, Args extends any[] = any[]> = {
44
50
  patch: R;
45
51
  post: R;
46
52
  put: R;
47
- } & CustomRoutes<R>;
48
- export declare const Router: <RequestType = IRequest, Args extends any[] = any[], RouteType = Equal<RequestType, IRequest> extends true ? Route : UniversalRoute<RequestType, Args>>({ base, routes }?: RouterOptions) => RouterType<RouteType, Args>;
53
+ } & CustomRoutes<R> & Record<string, any>;
54
+ export declare const Router: <RequestType = IRequest, Args extends any[] = any[], RouteType = Equal<RequestType, IRequest> extends true ? Route : UniversalRoute<RequestType, Args>>({ base, routes, ...other }?: RouterOptions) => RouterType<RouteType, Args>;
49
55
  export {};
package/Router.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";exports.Router=({base:e="",routes:r=[]}={})=>({__proto__:new Proxy({},{get:(o,t,a,p)=>(o,...l)=>r.push([t.toUpperCase(),RegExp(`^${(p=(e+o).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),l,p])&&a}),routes:r,async handle(e,...o){let t,a,p=new URL(e.url),l=e.query={__proto__:null};for(let[e,r]of p.searchParams)l[e]=void 0===l[e]?r:[l[e],r].flat();for(let[l,s,u,$]of r)if((l===e.method||"ALL"===l)&&(a=p.pathname.match(s))){e.params=a.groups||{},e.route=$;for(let r of u)if(void 0!==(t=await r(e.proxy||e,...o)))return t}}});
1
+ "use strict";exports.Router=({base:e="",routes:r=[],...t}={})=>({__proto__:new Proxy({},{get:(t,o,a,p)=>"handle"==o?a.fetch:(t,...l)=>r.push([o.toUpperCase?.(),RegExp(`^${(p=(e+t).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),l,p])&&a}),routes:r,...t,async fetch(e,...t){let o,a,p=new URL(e.url),l=e.query={__proto__:null};for(let[e,r]of p.searchParams)l[e]=l[e]?[].concat(l[e],r):r;for(let[l,c,s,u]of r)if((l==e.method||"ALL"==l)&&(a=p.pathname.match(c))){e.params=a.groups||{},e.route=u;for(let r of s)if(null!=(o=await r(e.proxy??e,...t)))return o}}});
2
+ //# sourceMappingURL=Router.js.map
package/Router.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Router.js","sources":["../src/src/Router.ts"],"sourcesContent":[null],"names":["base","routes","other","__proto__","Proxy","get","target","prop","receiver","path","fetch","route","handlers","push","toUpperCase","RegExp","replace","async","request","args","response","match","url","URL","query","k","v","searchParams","concat","method","regex","pathname","params","groups","handler","proxy"],"mappings":"4BA2EsB,EAIlBA,OAAO,GAAIC,SAAS,MAAOC,GAAyB,CAAE,KAExD,CACEC,UAAW,IAAIC,MAAM,GAAI,CAEvBC,IAAK,CAACC,EAAaC,EAAcC,EAAsBC,IAC7C,UAARF,EAAmBC,EAASE,MAE5B,CAACC,KAAkBC,IACjBX,EAAOY,KACL,CACEN,EAAKO,gBACLC,OAAO,KAAKN,GAAQT,EAAOW,GACxBK,QAAQ,aAAc,OACtBA,QAAQ,oBAAqB,gBAC7BA,QAAQ,kBAAmB,uBAC3BA,QAAQ,MAAO,OACfA,QAAQ,WAAY,iBAEvBJ,EACAH,KAECD,IAEXP,YACGC,EACHe,YAAaC,KAAyBC,GACpC,IAAIC,EAAUC,EAAOC,EAAM,IAAIC,IAAIL,EAAQI,KAAME,EAA6BN,EAAQM,MAAQ,CAAErB,UAAW,MAG3G,IAAK,IAAKsB,EAAGC,KAAMJ,EAAIK,aACrBH,EAAMC,GAAKD,EAAMC,GAAM,GAAgBG,OAAOJ,EAAMC,GAAIC,GAAKA,EAG/D,IAAK,IAAKG,EAAQC,EAAOlB,EAAUH,KAASR,EAC1C,IAAK4B,GAAUX,EAAQW,QAAoB,OAAVA,KAAqBR,EAAQC,EAAIS,SAASV,MAAMS,IAAS,CACxFZ,EAAQc,OAASX,EAAMY,QAAU,CAAA,EACjCf,EAAQP,MAAQF,EAChB,IAAK,IAAIyB,KAAWtB,EAClB,GAAqE,OAAhEQ,QAAiBc,EAAQhB,EAAQiB,OAASjB,KAAYC,IAAgB,OAAOC,CACrF,CACJ"}
package/Router.mjs CHANGED
@@ -1 +1,2 @@
1
- const e=({base:e="",routes:r=[]}={})=>({__proto__:new Proxy({},{get:(o,a,t,p)=>(o,...l)=>r.push([a.toUpperCase(),RegExp(`^${(p=(e+o).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),l,p])&&t}),routes:r,async handle(e,...o){let a,t,p=new URL(e.url),l=e.query={__proto__:null};for(let[e,r]of p.searchParams)l[e]=void 0===l[e]?r:[l[e],r].flat();for(let[l,s,$,c]of r)if((l===e.method||"ALL"===l)&&(t=p.pathname.match(s))){e.params=t.groups||{},e.route=c;for(let r of $)if(void 0!==(a=await r(e.proxy||e,...o)))return a}}});export{e as Router};
1
+ const e=({base:e="",routes:r=[],...o}={})=>({__proto__:new Proxy({},{get:(o,t,a,p)=>"handle"==t?a.fetch:(o,...l)=>r.push([t.toUpperCase?.(),RegExp(`^${(p=(e+o).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),l,p])&&a}),routes:r,...o,async fetch(e,...o){let t,a,p=new URL(e.url),l=e.query={__proto__:null};for(let[e,r]of p.searchParams)l[e]=l[e]?[].concat(l[e],r):r;for(let[l,c,s,f]of r)if((l==e.method||"ALL"==l)&&(a=p.pathname.match(c))){e.params=a.groups||{},e.route=f;for(let r of s)if(null!=(t=await r(e.proxy??e,...o)))return t}}});export{e as Router};
2
+ //# sourceMappingURL=Router.mjs.map
package/Router.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Router.mjs","sources":["../src/src/Router.ts"],"sourcesContent":[null],"names":["Router","base","routes","other","__proto__","Proxy","get","target","prop","receiver","path","fetch","route","handlers","push","toUpperCase","RegExp","replace","async","request","args","response","match","url","URL","query","k","v","searchParams","concat","method","regex","pathname","params","groups","handler","proxy"],"mappings":"AA2Ea,MAAAA,EAAS,EAIlBC,OAAO,GAAIC,SAAS,MAAOC,GAAyB,CAAE,KAExD,CACEC,UAAW,IAAIC,MAAM,GAAI,CAEvBC,IAAK,CAACC,EAAaC,EAAcC,EAAsBC,IAC7C,UAARF,EAAmBC,EAASE,MAE5B,CAACC,KAAkBC,IACjBX,EAAOY,KACL,CACEN,EAAKO,gBACLC,OAAO,KAAKN,GAAQT,EAAOW,GACxBK,QAAQ,aAAc,OACtBA,QAAQ,oBAAqB,gBAC7BA,QAAQ,kBAAmB,uBAC3BA,QAAQ,MAAO,OACfA,QAAQ,WAAY,iBAEvBJ,EACAH,KAECD,IAEXP,YACGC,EACHe,YAAaC,KAAyBC,GACpC,IAAIC,EAAUC,EAAOC,EAAM,IAAIC,IAAIL,EAAQI,KAAME,EAA6BN,EAAQM,MAAQ,CAAErB,UAAW,MAG3G,IAAK,IAAKsB,EAAGC,KAAMJ,EAAIK,aACrBH,EAAMC,GAAKD,EAAMC,GAAM,GAAgBG,OAAOJ,EAAMC,GAAIC,GAAKA,EAG/D,IAAK,IAAKG,EAAQC,EAAOlB,EAAUH,KAASR,EAC1C,IAAK4B,GAAUX,EAAQW,QAAoB,OAAVA,KAAqBR,EAAQC,EAAIS,SAASV,MAAMS,IAAS,CACxFZ,EAAQc,OAASX,EAAMY,QAAU,CAAA,EACjCf,EAAQP,MAAQF,EAChB,IAAK,IAAIyB,KAAWtB,EAClB,GAAqE,OAAhEQ,QAAiBc,EAAQhB,EAAQiB,OAASjB,KAAYC,IAAgB,OAAOC,CACrF,CACJ"}
package/StatusError.js CHANGED
@@ -1 +1,2 @@
1
1
  "use strict";class t extends Error{status;constructor(t=500,s){super("object"==typeof s?s.error:s),"object"==typeof s&&Object.assign(this,s),this.status=t}}exports.StatusError=t;
2
+ //# sourceMappingURL=StatusError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StatusError.js","sources":["../src/src/StatusError.ts"],"sourcesContent":[null],"names":["StatusError","Error","status","constructor","body","super","error","Object","assign","this"],"mappings":"aAKM,MAAOA,UAAoBC,MAC/BC,OAGAC,YAAYD,EAAS,IAAKE,GACxBC,MAAsB,iBAATD,EAAoBA,EAAKE,MAAQF,GAC9B,iBAATA,GAAqBG,OAAOC,OAAOC,KAAML,GAChDK,KAAKP,OAASA,CACf"}
package/StatusError.mjs CHANGED
@@ -1 +1,2 @@
1
1
  class t extends Error{status;constructor(t=500,s){super("object"==typeof s?s.error:s),"object"==typeof s&&Object.assign(this,s),this.status=t}}export{t as StatusError};
2
+ //# sourceMappingURL=StatusError.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StatusError.mjs","sources":["../src/src/StatusError.ts"],"sourcesContent":[null],"names":["StatusError","Error","status","constructor","body","super","error","Object","assign","this"],"mappings":"AAKM,MAAOA,UAAoBC,MAC/BC,OAGAC,YAAYD,EAAS,IAAKE,GACxBC,MAAsB,iBAATD,EAAoBA,EAAKE,MAAQF,GAC9B,iBAATA,GAAqBG,OAAOC,OAAOC,KAAML,GAChDK,KAAKP,OAASA,CACf"}
package/createCors.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { IRequest } from './Router';
2
- export interface CorsOptions {
3
- origins?: string[];
2
+ export type CorsOptions = {
3
+ origins?: string[] | ((origin: string) => boolean);
4
4
  maxAge?: number;
5
5
  methods?: string[];
6
6
  headers?: any;
7
- }
7
+ };
8
8
  export declare const createCors: (options?: CorsOptions) => {
9
9
  corsify: (response: Response) => Response;
10
10
  preflight: (r: IRequest) => Response | undefined;
package/createCors.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";exports.createCors=(e={})=>{const{origins:s=["*"],maxAge:o,methods:t=["GET"],headers:n={}}=e;let r;const c={"content-type":"application/json","Access-Control-Allow-Methods":t.join(", "),...n};o&&(c["Access-Control-Max-Age"]=o);return{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:s,status:o,body:t}=e;return[101,301,302,308].includes(o)||s.get("access-control-allow-origin")?e:new Response(t,{status:o,headers:{...Object.fromEntries(s),...c,...r,"content-type":s.get("content-type")}})},preflight:e=>{const o=[...new Set(["OPTIONS",...t])],n=e.headers.get("origin")||"";if(r=(s.includes(n)||s.includes("*"))&&{"Access-Control-Allow-Origin":n},"OPTIONS"===e.method){const s={...c,"Access-Control-Allow-Methods":o.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...r};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?s:{Allow:o.join(", ")}})}}}};
1
+ "use strict";exports.createCors=(e={})=>{const{origins:s=["*"],maxAge:o,methods:t=["GET"],headers:n={}}=e;let r;const c="function"==typeof s?s:e=>s.includes(e)||s.includes("*"),l={"content-type":"application/json","Access-Control-Allow-Methods":t.join(", "),...n};o&&(l["Access-Control-Max-Age"]=o);return{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:s,status:o,body:t}=e;return[101,301,302,308].includes(o)||s.get("access-control-allow-origin")?e:new Response(t,{status:o,headers:{...Object.fromEntries(s),...l,...r,"content-type":s.get("content-type")}})},preflight:e=>{const s=[...new Set(["OPTIONS",...t])],o=e.headers.get("origin")||"";if(r=c(o)&&{"Access-Control-Allow-Origin":o},"OPTIONS"===e.method){const o={...l,"Access-Control-Allow-Methods":s.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...r};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?o:{Allow:s.join(", ")}})}}}};
2
+ //# sourceMappingURL=createCors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCors.js","sources":["../src/src/createCors.ts"],"sourcesContent":[null],"names":["options","origins","maxAge","methods","headers","allowOrigin","isAllowOrigin","origin","includes","rHeaders","join","corsify","response","Error","status","body","get","Response","Object","fromEntries","preflight","r","useMethods","Set","method","reqHeaders","Allow"],"mappings":"gCAU0B,CAACA,EAAuB,MAEhD,MAAMC,QAAEA,EAAU,CAAC,KAAIC,OAAEA,EAAMC,QAAEA,EAAU,CAAC,OAAMC,QAAEA,EAAU,CAAE,GAAKJ,EAErE,IAAIK,EACJ,MAAMC,EAAmC,mBAAZL,EACzBA,EACCM,GAAoBN,EAAQO,SAASD,IAAWN,EAAQO,SAAS,KAGhEC,EAAW,CACf,eAAgB,mBAChB,+BAAgCN,EAAQO,KAAK,SAC1CN,GAIDF,IAAQO,EAAS,0BAA4BP,GA+DjD,MAAO,CAAES,QA5BQC,IACf,IAAKA,EACH,MAAM,IAAIC,MACR,qEAGJ,MAAMT,QAAEA,EAAOU,OAAEA,EAAMC,KAAEA,GAASH,EAGlC,MACE,CAAC,IAAK,IAAK,IAAK,KAAKJ,SAASM,IAC9BV,EAAQY,IAAI,+BAELJ,EAGF,IAAIK,SAASF,EAAM,CACxBD,SACAV,QAAS,IACJc,OAAOC,YAAYf,MACnBK,KACAJ,EACH,eAAgBD,EAAQY,IAAI,kBAE9B,EAIcI,UA5DCC,IAEjB,MAAMC,EAAa,IAAI,IAAIC,IAAI,CAAC,aAAcpB,KACxCI,EAASc,EAAEjB,QAAQY,IAAI,WAAa,GAM1C,GAHAX,EAAcC,EAAcC,IAAW,CAAE,8BAA+BA,GAGvD,YAAbc,EAAEG,OAAsB,CAC1B,MAAMC,EAAa,IACdhB,EACH,+BAAgCa,EAAWZ,KAAK,MAChD,+BAAgCW,EAAEjB,QAAQY,IACxC,qCAECX,GAIL,OAAO,IAAIY,SAAS,KAAM,CACxBb,QACEiB,EAAEjB,QAAQY,IAAI,WACdK,EAAEjB,QAAQY,IAAI,kCACdK,EAAEjB,QAAQY,IAAI,kCACVS,EACA,CAAEC,MAAOJ,EAAWZ,KAAK,QAElC,GAgC0B"}
package/createCors.mjs CHANGED
@@ -1 +1,2 @@
1
- const e=(e={})=>{const{origins:o=["*"],maxAge:s,methods:t=["GET"],headers:n={}}=e;let r;const c={"content-type":"application/json","Access-Control-Allow-Methods":t.join(", "),...n};s&&(c["Access-Control-Max-Age"]=s);return{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:o,status:s,body:t}=e;return[101,301,302,308].includes(s)||o.get("access-control-allow-origin")?e:new Response(t,{status:s,headers:{...Object.fromEntries(o),...c,...r,"content-type":o.get("content-type")}})},preflight:e=>{const s=[...new Set(["OPTIONS",...t])],n=e.headers.get("origin")||"";if(r=(o.includes(n)||o.includes("*"))&&{"Access-Control-Allow-Origin":n},"OPTIONS"===e.method){const o={...c,"Access-Control-Allow-Methods":s.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...r};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?o:{Allow:s.join(", ")}})}}}};export{e as createCors};
1
+ const e=(e={})=>{const{origins:o=["*"],maxAge:s,methods:t=["GET"],headers:n={}}=e;let r;const c="function"==typeof o?o:e=>o.includes(e)||o.includes("*"),l={"content-type":"application/json","Access-Control-Allow-Methods":t.join(", "),...n};s&&(l["Access-Control-Max-Age"]=s);return{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:o,status:s,body:t}=e;return[101,301,302,308].includes(s)||o.get("access-control-allow-origin")?e:new Response(t,{status:s,headers:{...Object.fromEntries(o),...l,...r,"content-type":o.get("content-type")}})},preflight:e=>{const o=[...new Set(["OPTIONS",...t])],s=e.headers.get("origin")||"";if(r=c(s)&&{"Access-Control-Allow-Origin":s},"OPTIONS"===e.method){const s={...l,"Access-Control-Allow-Methods":o.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...r};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?s:{Allow:o.join(", ")}})}}}};export{e as createCors};
2
+ //# sourceMappingURL=createCors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCors.mjs","sources":["../src/src/createCors.ts"],"sourcesContent":[null],"names":["createCors","options","origins","maxAge","methods","headers","allowOrigin","isAllowOrigin","origin","includes","rHeaders","join","corsify","response","Error","status","body","get","Response","Object","fromEntries","preflight","r","useMethods","Set","method","reqHeaders","Allow"],"mappings":"MAUaA,EAAa,CAACC,EAAuB,MAEhD,MAAMC,QAAEA,EAAU,CAAC,KAAIC,OAAEA,EAAMC,QAAEA,EAAU,CAAC,OAAMC,QAAEA,EAAU,CAAE,GAAKJ,EAErE,IAAIK,EACJ,MAAMC,EAAmC,mBAAZL,EACzBA,EACCM,GAAoBN,EAAQO,SAASD,IAAWN,EAAQO,SAAS,KAGhEC,EAAW,CACf,eAAgB,mBAChB,+BAAgCN,EAAQO,KAAK,SAC1CN,GAIDF,IAAQO,EAAS,0BAA4BP,GA+DjD,MAAO,CAAES,QA5BQC,IACf,IAAKA,EACH,MAAM,IAAIC,MACR,qEAGJ,MAAMT,QAAEA,EAAOU,OAAEA,EAAMC,KAAEA,GAASH,EAGlC,MACE,CAAC,IAAK,IAAK,IAAK,KAAKJ,SAASM,IAC9BV,EAAQY,IAAI,+BAELJ,EAGF,IAAIK,SAASF,EAAM,CACxBD,SACAV,QAAS,IACJc,OAAOC,YAAYf,MACnBK,KACAJ,EACH,eAAgBD,EAAQY,IAAI,kBAE9B,EAIcI,UA5DCC,IAEjB,MAAMC,EAAa,IAAI,IAAIC,IAAI,CAAC,aAAcpB,KACxCI,EAASc,EAAEjB,QAAQY,IAAI,WAAa,GAM1C,GAHAX,EAAcC,EAAcC,IAAW,CAAE,8BAA+BA,GAGvD,YAAbc,EAAEG,OAAsB,CAC1B,MAAMC,EAAa,IACdhB,EACH,+BAAgCa,EAAWZ,KAAK,MAChD,+BAAgCW,EAAEjB,QAAQY,IACxC,qCAECX,GAIL,OAAO,IAAIY,SAAS,KAAM,CACxBb,QACEiB,EAAEjB,QAAQY,IAAI,WACdK,EAAEjB,QAAQY,IAAI,kCACdK,EAAEjB,QAAQY,IAAI,kCACVS,EACA,CAAEC,MAAOJ,EAAWZ,KAAK,QAElC,GAgC0B"}
package/createResponse.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";exports.createResponse=(e="text/plain; charset=utf-8",t)=>(s,n)=>{const{headers:r={},...o}=n||{};return"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...r},...o})};
1
+ "use strict";exports.createResponse=(e="text/plain; charset=utf-8",t)=>(s,{headers:n={},...r}={})=>void 0===s||"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...n.entries?Object.fromEntries(n):n},...r});
2
+ //# sourceMappingURL=createResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createResponse.js","sources":["../src/src/createResponse.ts"],"sourcesContent":[null],"names":["format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries"],"mappings":"oCASE,CACEA,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC"}
@@ -1 +1,2 @@
1
- const e=(e="text/plain; charset=utf-8",t)=>(n,s)=>{const{headers:o={},...r}=s||{};return"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...o},...r})};export{e as createResponse};
1
+ const e=(e="text/plain; charset=utf-8",t)=>(n,{headers:s={},...o}={})=>void 0===n||"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...s.entries?Object.fromEntries(s):s},...o});export{e as createResponse};
2
+ //# sourceMappingURL=createResponse.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createResponse.mjs","sources":["../src/src/createResponse.ts"],"sourcesContent":[null],"names":["createResponse","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries"],"mappings":"AAQa,MAAAA,EACX,CACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC"}
package/error.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";const r=((r="text/plain; charset=utf-8",e)=>(t,s)=>{const{headers:n={},...o}=s||{};return"Response"===t?.constructor.name?t:new Response(e?e(t):t,{headers:{"content-type":r,...n},...o})})("application/json; charset=utf-8",JSON.stringify),e=r=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[r]||"Unknown Error");exports.error=(t=500,s)=>{if(t instanceof Error){const{message:r,...n}=t;t=t.status||500,s={error:r||e(t),...n}}return s={status:t,..."object"==typeof s?s:{error:s||e(t)}},r(s,{status:t})};
1
+ "use strict";const e=((e="text/plain; charset=utf-8",r)=>(t,{headers:s={},...n}={})=>void 0===t||"Response"===t?.constructor.name?t:new Response(r?r(t):t,{headers:{"content-type":e,...s.entries?Object.fromEntries(s):s},...n}))("application/json; charset=utf-8",JSON.stringify),r=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error");exports.error=(t=500,s)=>{if(t instanceof Error){const{message:e,...n}=t;t=t.status||500,s={error:e||r(t),...n}}return s={status:t,..."object"==typeof s?s:{error:s||r(t)}},e(s,{status:t})};
2
+ //# sourceMappingURL=error.js.map
package/error.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sources":["../src/src/createResponse.ts","../src/src/json.ts","../src/src/error.ts"],"sourcesContent":[null,null,null],"names":["json","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse","JSON","stringify","getMessage","code","a","b","Error","message","err","status","error"],"mappings":"aAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBHQ,CAClB,kCACAC,KAAKC,WCUDC,EAAcC,IAAyB,CAC3C,IAAK,cACL,IAAK,eACL,IAAK,YACL,IAAK,YACL,IAAK,yBACJA,IAAS,+BAEyB,CAACC,EAAI,IAAKC,KAE7C,GAAID,aAAaE,MAAO,CACtB,MAAMC,QAAEA,KAAYC,GAAQJ,EAC5BA,EAAIA,EAAEK,QAAU,IAChBJ,EAAI,CACFK,MAAOH,GAAWL,EAAWE,MAC1BI,EAEN,CAOD,OALAH,EAAI,CACFI,OAAQL,KACS,iBAANC,EAAiBA,EAAI,CAAEK,MAAOL,GAAKH,EAAWE,KAGpDlB,EAAKmB,EAAG,CAAEI,OAAQL,GAAI"}
package/error.mjs CHANGED
@@ -1 +1,2 @@
1
- const e=((e="text/plain; charset=utf-8",r)=>(t,n)=>{const{headers:o={},...s}=n||{};return"Response"===t?.constructor.name?t:new Response(r?r(t):t,{headers:{"content-type":e,...o},...s})})("application/json; charset=utf-8",JSON.stringify),r=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),t=(t=500,n)=>{if(t instanceof Error){const{message:e,...o}=t;t=t.status||500,n={error:e||r(t),...o}}return n={status:t,..."object"==typeof n?n:{error:n||r(t)}},e(n,{status:t})};export{t as error};
1
+ const e=((e="text/plain; charset=utf-8",r)=>(t,{headers:n={},...o}={})=>void 0===t||"Response"===t?.constructor.name?t:new Response(r?r(t):t,{headers:{"content-type":e,...n.entries?Object.fromEntries(n):n},...o}))("application/json; charset=utf-8",JSON.stringify),r=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),t=(t=500,n)=>{if(t instanceof Error){const{message:e,...o}=t;t=t.status||500,n={error:e||r(t),...o}}return n={status:t,..."object"==typeof n?n:{error:n||r(t)}},e(n,{status:t})};export{t as error};
2
+ //# sourceMappingURL=error.mjs.map
package/error.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.mjs","sources":["../src/src/createResponse.ts","../src/src/json.ts","../src/src/error.ts"],"sourcesContent":[null,null,null],"names":["json","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse","JSON","stringify","getMessage","code","error","a","b","Error","message","err","status"],"mappings":"AAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBHQ,CAClB,kCACAC,KAAKC,WCUDC,EAAcC,IAAyB,CAC3C,IAAK,cACL,IAAK,eACL,IAAK,YACL,IAAK,YACL,IAAK,yBACJA,IAAS,iBAECC,EAAwB,CAACC,EAAI,IAAKC,KAE7C,GAAID,aAAaE,MAAO,CACtB,MAAMC,QAAEA,KAAYC,GAAQJ,EAC5BA,EAAIA,EAAEK,QAAU,IAChBJ,EAAI,CACFF,MAAOI,GAAWN,EAAWG,MAC1BI,EAEN,CAOD,OALAH,EAAI,CACFI,OAAQL,KACS,iBAANC,EAAiBA,EAAI,CAAEF,MAAOE,GAAKJ,EAAWG,KAGpDnB,EAAKoB,EAAG,CAAEI,OAAQL,GAAI"}
package/html.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";const t=((t="text/plain; charset=utf-8",e)=>(s,n)=>{const{headers:r={},...o}=n||{};return"Response"===s?.constructor.name?s:new Response(e?e(s):s,{headers:{"content-type":t,...r},...o})})("text/html");exports.html=t;
1
+ "use strict";const e=((e="text/plain; charset=utf-8",t)=>(s,{headers:n={},...r}={})=>void 0===s||"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...n.entries?Object.fromEntries(n):n},...r}))("text/html");exports.html=e;
2
+ //# sourceMappingURL=html.js.map
package/html.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.js","sources":["../src/src/createResponse.ts","../src/src/html.ts"],"sourcesContent":[null,null],"names":["html","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse"],"mappings":"aAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBHQ,CAAe"}
package/html.mjs CHANGED
@@ -1 +1,2 @@
1
- const e=((e="text/plain; charset=utf-8",t)=>(n,s)=>{const{headers:o={},...r}=s||{};return"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...o},...r})})("text/html");export{e as html};
1
+ const e=((e="text/plain; charset=utf-8",t)=>(n,{headers:s={},...o}={})=>void 0===n||"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...s.entries?Object.fromEntries(s):s},...o}))("text/html");export{e as html};
2
+ //# sourceMappingURL=html.mjs.map
package/html.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.mjs","sources":["../src/src/createResponse.ts","../src/src/html.ts"],"sourcesContent":[null,null],"names":["html","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse"],"mappings":"AAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBHQ,CAAe"}
package/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './flow';
2
1
  export * from './Router';
3
2
  export * from './StatusError';
4
3
  export * from './createResponse';
package/index.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";const e=(e={})=>{const{origins:t=["*"],maxAge:o,methods:r=["GET"],headers:s={}}=e;let n;const a={"content-type":"application/json","Access-Control-Allow-Methods":r.join(", "),...s};o&&(a["Access-Control-Max-Age"]=o);return{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:t,status:o,body:r}=e;return[101,301,302,308].includes(o)||t.get("access-control-allow-origin")?e:new Response(r,{status:o,headers:{...Object.fromEntries(t),...a,...n,"content-type":t.get("content-type")}})},preflight:e=>{const o=[...new Set(["OPTIONS",...r])],s=e.headers.get("origin")||"";if(n=(t.includes(s)||t.includes("*"))&&{"Access-Control-Allow-Origin":s},"OPTIONS"===e.method){const t={...a,"Access-Control-Allow-Methods":o.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?t:{Allow:o.join(", ")}})}}}},t=(e="text/plain; charset=utf-8",t)=>(o,r)=>{const{headers:s={},...n}=r||{};return"Response"===o?.constructor.name?o:new Response(t?t(o):o,{headers:{"content-type":e,...s},...n})},o=t("application/json; charset=utf-8",JSON.stringify),r=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),s=(e=500,t)=>{if(e instanceof Error){const{message:o,...s}=e;e=e.status||500,t={error:o||r(e),...s}}return t={status:e,..."object"==typeof t?t:{error:t||r(e)}},o(t,{status:e})},n=e=>{e.proxy=new Proxy(e.proxy||e,{get:(t,o)=>{let r;return void 0!==(r=t[o])?r.bind?.(e)||r:t?.params?.[o]}})};class a extends Error{status;constructor(e=500,t){super("object"==typeof t?t.error:t),"object"==typeof t&&Object.assign(this,t),this.status=e}}const c=t("text/html"),p=t("image/jpeg"),l=t("image/png"),i=t("image/webp");exports.Router=({base:e="",routes:t=[]}={})=>({__proto__:new Proxy({},{get:(o,r,s,n)=>(o,...a)=>t.push([r.toUpperCase(),RegExp(`^${(n=(e+o).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),a,n])&&s}),routes:t,async handle(e,...o){let r,s,n=new URL(e.url),a=e.query={__proto__:null};for(let[e,t]of n.searchParams)a[e]=void 0===a[e]?t:[a[e],t].flat();for(let[a,c,p,l]of t)if((a===e.method||"ALL"===a)&&(s=n.pathname.match(c))){e.params=s.groups||{},e.route=l;for(let t of p)if(void 0!==(r=await t(e.proxy||e,...o)))return r}}}),exports.StatusError=a,exports.createCors=e,exports.createResponse=t,exports.error=s,exports.flow=(t,r={})=>{const{format:a=o,cors:c,handleErrors:p=s,handleNotFound:l=(()=>s(404))}=r;let i;return"function"==typeof l&&t.all("*",l),c&&(i=e(!0===c?void 0:c),t.routes.unshift(["ALL",/^(.*)?\/*$/,[i.preflight,n],"*"])),async(...e)=>{let o=t.handle(...e);return a&&(o=o.then(a)),p&&(o=o.catch(p)),c&&(o=o.then(i?.corsify)),o}},exports.html=c,exports.jpeg=p,exports.json=o,exports.png=l,exports.status=(e,t)=>new Response(null,{...t,status:e}),exports.text=(e,t)=>new Response(String(e),t),exports.webp=i,exports.withContent=async e=>{e.headers.get("content-type")?.includes("json")&&(e.content=await e.json())},exports.withCookies=e=>{e.cookies=(e.headers.get("Cookie")||"").split(/;\s*/).map((e=>e.split(/=(.+)/))).reduce(((e,[t,o])=>o?(e[t]=o,e):e),{})},exports.withParams=n;
1
+ "use strict";class e extends Error{status;constructor(e=500,t){super("object"==typeof t?t.error:t),"object"==typeof t&&Object.assign(this,t),this.status=e}}const t=(e="text/plain; charset=utf-8",t)=>(s,{headers:o={},...r}={})=>void 0===s||"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...o.entries?Object.fromEntries(o):o},...r}),s=t("application/json; charset=utf-8",JSON.stringify),o=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),r=t("text/plain; charset=utf-8",String),n=t("text/html"),a=t("image/jpeg"),c=t("image/png"),p=t("image/webp");exports.Router=({base:e="",routes:t=[],...s}={})=>({__proto__:new Proxy({},{get:(s,o,r,n)=>"handle"==o?r.fetch:(s,...a)=>t.push([o.toUpperCase?.(),RegExp(`^${(n=(e+s).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),a,n])&&r}),routes:t,...s,async fetch(e,...s){let o,r,n=new URL(e.url),a=e.query={__proto__:null};for(let[e,t]of n.searchParams)a[e]=a[e]?[].concat(a[e],t):t;for(let[a,c,p,i]of t)if((a==e.method||"ALL"==a)&&(r=n.pathname.match(c))){e.params=r.groups||{},e.route=i;for(let t of p)if(null!=(o=await t(e.proxy??e,...s)))return o}}}),exports.StatusError=e,exports.createCors=(e={})=>{const{origins:t=["*"],maxAge:s,methods:o=["GET"],headers:r={}}=e;let n;const a="function"==typeof t?t:e=>t.includes(e)||t.includes("*"),c={"content-type":"application/json","Access-Control-Allow-Methods":o.join(", "),...r};s&&(c["Access-Control-Max-Age"]=s);return{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:t,status:s,body:o}=e;return[101,301,302,308].includes(s)||t.get("access-control-allow-origin")?e:new Response(o,{status:s,headers:{...Object.fromEntries(t),...c,...n,"content-type":t.get("content-type")}})},preflight:e=>{const t=[...new Set(["OPTIONS",...o])],s=e.headers.get("origin")||"";if(n=a(s)&&{"Access-Control-Allow-Origin":s},"OPTIONS"===e.method){const s={...c,"Access-Control-Allow-Methods":t.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?s:{Allow:t.join(", ")}})}}}},exports.createResponse=t,exports.error=(e=500,t)=>{if(e instanceof Error){const{message:s,...r}=e;e=e.status||500,t={error:s||o(e),...r}}return t={status:e,..."object"==typeof t?t:{error:t||o(e)}},s(t,{status:e})},exports.html=n,exports.jpeg=a,exports.json=s,exports.png=c,exports.status=(e,t)=>new Response(null,{...t,status:e}),exports.text=r,exports.webp=p,exports.withContent=async t=>{if(t.headers.get("content-type")?.includes("json"))try{t.content=await t.json()}catch(t){throw new e(400,t.message)}},exports.withCookies=e=>{e.cookies=(e.headers.get("Cookie")||"").split(/;\s*/).map((e=>e.split(/=(.+)/))).reduce(((e,[t,s])=>s?(e[t]=s,e):e),{})},exports.withParams=e=>{e.proxy=new Proxy(e.proxy||e,{get:(t,s)=>void 0!==t[s]?t[s].bind?.(e)||t[s]:t?.params?.[s]})};
2
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/src/StatusError.ts","../src/src/createResponse.ts","../src/src/json.ts","../src/src/error.ts","../src/src/text.ts","../src/src/html.ts","../src/src/jpeg.ts","../src/src/png.ts","../src/src/webp.ts","../src/src/Router.ts","../src/src/createCors.ts","../src/src/status.ts","../src/src/withContent.ts","../src/src/withCookies.ts","../src/src/withParams.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"names":["StatusError","Error","status","constructor","body","super","error","Object","assign","this","createResponse","format","transform","headers","rest","undefined","name","Response","entries","fromEntries","json","JSON","stringify","getMessage","code","text","String","html","jpeg","png","webp","base","routes","other","__proto__","Proxy","get","target","prop","receiver","path","fetch","route","handlers","push","toUpperCase","RegExp","replace","async","request","args","response","match","url","URL","query","k","v","searchParams","concat","method","regex","pathname","params","groups","handler","proxy","options","origins","maxAge","methods","allowOrigin","isAllowOrigin","origin","includes","rHeaders","join","corsify","preflight","r","useMethods","Set","reqHeaders","Allow","a","b","message","err","content","e","cookies","split","map","p","reduce","obj","bind"],"mappings":"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"}
package/index.mjs CHANGED
@@ -1 +1,2 @@
1
- const e=(e={})=>{const{origins:t=["*"],maxAge:o,methods:r=["GET"],headers:s={}}=e;let n;const a={"content-type":"application/json","Access-Control-Allow-Methods":r.join(", "),...s};o&&(a["Access-Control-Max-Age"]=o);return{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:t,status:o,body:r}=e;return[101,301,302,308].includes(o)||t.get("access-control-allow-origin")?e:new Response(r,{status:o,headers:{...Object.fromEntries(t),...a,...n,"content-type":t.get("content-type")}})},preflight:e=>{const o=[...new Set(["OPTIONS",...r])],s=e.headers.get("origin")||"";if(n=(t.includes(s)||t.includes("*"))&&{"Access-Control-Allow-Origin":s},"OPTIONS"===e.method){const t={...a,"Access-Control-Allow-Methods":o.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?t:{Allow:o.join(", ")}})}}}},t=(e="text/plain; charset=utf-8",t)=>(o,r)=>{const{headers:s={},...n}=r||{};return"Response"===o?.constructor.name?o:new Response(t?t(o):o,{headers:{"content-type":e,...s},...n})},o=t("application/json; charset=utf-8",JSON.stringify),r=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),s=(e=500,t)=>{if(e instanceof Error){const{message:o,...s}=e;e=e.status||500,t={error:o||r(e),...s}}return t={status:e,..."object"==typeof t?t:{error:t||r(e)}},o(t,{status:e})},n=e=>{e.proxy=new Proxy(e.proxy||e,{get:(t,o)=>{let r;return void 0!==(r=t[o])?r.bind?.(e)||r:t?.params?.[o]}})},a=(t,r={})=>{const{format:a=o,cors:c,handleErrors:l=s,handleNotFound:i=(()=>s(404))}=r;let p;return"function"==typeof i&&t.all("*",i),c&&(p=e(!0===c?void 0:c),t.routes.unshift(["ALL",/^(.*)?\/*$/,[p.preflight,n],"*"])),async(...e)=>{let o=t.handle(...e);return a&&(o=o.then(a)),l&&(o=o.catch(l)),c&&(o=o.then(p?.corsify)),o}},c=({base:e="",routes:t=[]}={})=>({__proto__:new Proxy({},{get:(o,r,s,n)=>(o,...a)=>t.push([r.toUpperCase(),RegExp(`^${(n=(e+o).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),a,n])&&s}),routes:t,async handle(e,...o){let r,s,n=new URL(e.url),a=e.query={__proto__:null};for(let[e,t]of n.searchParams)a[e]=void 0===a[e]?t:[a[e],t].flat();for(let[a,c,l,i]of t)if((a===e.method||"ALL"===a)&&(s=n.pathname.match(c))){e.params=s.groups||{},e.route=i;for(let t of l)if(void 0!==(r=await t(e.proxy||e,...o)))return r}}});class l extends Error{status;constructor(e=500,t){super("object"==typeof t?t.error:t),"object"==typeof t&&Object.assign(this,t),this.status=e}}const i=(e,t)=>new Response(null,{...t,status:e}),p=(e,t)=>new Response(String(e),t),d=t("text/html"),u=t("image/jpeg"),h=t("image/png"),g=t("image/webp"),f=async e=>{e.headers.get("content-type")?.includes("json")&&(e.content=await e.json())},w=e=>{e.cookies=(e.headers.get("Cookie")||"").split(/;\s*/).map((e=>e.split(/=(.+)/))).reduce(((e,[t,o])=>o?(e[t]=o,e):e),{})};export{c as Router,l as StatusError,e as createCors,t as createResponse,s as error,a as flow,d as html,u as jpeg,o as json,h as png,i as status,p as text,g as webp,f as withContent,w as withCookies,n as withParams};
1
+ const e=({base:e="",routes:t=[],...o}={})=>({__proto__:new Proxy({},{get:(o,s,r,n)=>"handle"==s?r.fetch:(o,...a)=>t.push([s.toUpperCase?.(),RegExp(`^${(n=(e+o).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),a,n])&&r}),routes:t,...o,async fetch(e,...o){let s,r,n=new URL(e.url),a=e.query={__proto__:null};for(let[e,t]of n.searchParams)a[e]=a[e]?[].concat(a[e],t):t;for(let[a,c,i,l]of t)if((a==e.method||"ALL"==a)&&(r=n.pathname.match(c))){e.params=r.groups||{},e.route=l;for(let t of i)if(null!=(s=await t(e.proxy??e,...o)))return s}}});class t extends Error{status;constructor(e=500,t){super("object"==typeof t?t.error:t),"object"==typeof t&&Object.assign(this,t),this.status=e}}const o=(e="text/plain; charset=utf-8",t)=>(o,{headers:s={},...r}={})=>void 0===o||"Response"===o?.constructor.name?o:new Response(t?t(o):o,{headers:{"content-type":e,...s.entries?Object.fromEntries(s):s},...r}),s=o("application/json; charset=utf-8",JSON.stringify),r=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),n=(e=500,t)=>{if(e instanceof Error){const{message:o,...s}=e;e=e.status||500,t={error:o||r(e),...s}}return t={status:e,..."object"==typeof t?t:{error:t||r(e)}},s(t,{status:e})},a=(e,t)=>new Response(null,{...t,status:e}),c=o("text/plain; charset=utf-8",String),i=o("text/html"),l=o("image/jpeg"),p=o("image/png"),d=o("image/webp"),u=async e=>{if(e.headers.get("content-type")?.includes("json"))try{e.content=await e.json()}catch(e){throw new t(400,e.message)}},h=e=>{e.cookies=(e.headers.get("Cookie")||"").split(/;\s*/).map((e=>e.split(/=(.+)/))).reduce(((e,[t,o])=>o?(e[t]=o,e):e),{})},g=e=>{e.proxy=new Proxy(e.proxy||e,{get:(t,o)=>void 0!==t[o]?t[o].bind?.(e)||t[o]:t?.params?.[o]})},f=(e={})=>{const{origins:t=["*"],maxAge:o,methods:s=["GET"],headers:r={}}=e;let n;const a="function"==typeof t?t:e=>t.includes(e)||t.includes("*"),c={"content-type":"application/json","Access-Control-Allow-Methods":s.join(", "),...r};o&&(c["Access-Control-Max-Age"]=o);return{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:t,status:o,body:s}=e;return[101,301,302,308].includes(o)||t.get("access-control-allow-origin")?e:new Response(s,{status:o,headers:{...Object.fromEntries(t),...c,...n,"content-type":t.get("content-type")}})},preflight:e=>{const t=[...new Set(["OPTIONS",...s])],o=e.headers.get("origin")||"";if(n=a(o)&&{"Access-Control-Allow-Origin":o},"OPTIONS"===e.method){const o={...c,"Access-Control-Allow-Methods":t.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?o:{Allow:t.join(", ")}})}}}};export{e as Router,t as StatusError,f as createCors,o as createResponse,n as error,i as html,l as jpeg,s as json,p as png,a as status,c as text,d as webp,u as withContent,h as withCookies,g as withParams};
2
+ //# sourceMappingURL=index.mjs.map
package/index.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/src/Router.ts","../src/src/StatusError.ts","../src/src/createResponse.ts","../src/src/json.ts","../src/src/error.ts","../src/src/status.ts","../src/src/text.ts","../src/src/html.ts","../src/src/jpeg.ts","../src/src/png.ts","../src/src/webp.ts","../src/src/withContent.ts","../src/src/withCookies.ts","../src/src/withParams.ts","../src/src/createCors.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"names":["Router","base","routes","other","__proto__","Proxy","get","target","prop","receiver","path","fetch","route","handlers","push","toUpperCase","RegExp","replace","async","request","args","response","match","url","URL","query","k","v","searchParams","concat","method","regex","pathname","params","groups","handler","proxy","StatusError","Error","status","constructor","body","super","error","Object","assign","this","createResponse","format","transform","headers","rest","undefined","name","Response","entries","fromEntries","json","JSON","stringify","getMessage","code","a","b","message","err","options","text","String","html","jpeg","png","webp","withContent","includes","content","e","withCookies","r","cookies","split","map","p","reduce","withParams","obj","bind","createCors","origins","maxAge","methods","allowOrigin","isAllowOrigin","origin","rHeaders","join","corsify","preflight","useMethods","Set","reqHeaders","Allow"],"mappings":"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"}
package/jpeg.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";const e=((e="text/plain; charset=utf-8",t)=>(s,n)=>{const{headers:r={},...o}=n||{};return"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...r},...o})})("image/jpeg");exports.jpeg=e;
1
+ "use strict";const e=((e="text/plain; charset=utf-8",t)=>(s,{headers:n={},...r}={})=>void 0===s||"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...n.entries?Object.fromEntries(n):n},...r}))("image/jpeg");exports.jpeg=e;
2
+ //# sourceMappingURL=jpeg.js.map
package/jpeg.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jpeg.js","sources":["../src/src/createResponse.ts","../src/src/jpeg.ts"],"sourcesContent":[null,null],"names":["jpeg","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse"],"mappings":"aAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBHQ,CAAe"}
package/jpeg.mjs CHANGED
@@ -1 +1,2 @@
1
- const e=((e="text/plain; charset=utf-8",t)=>(n,s)=>{const{headers:o={},...r}=s||{};return"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...o},...r})})("image/jpeg");export{e as jpeg};
1
+ const e=((e="text/plain; charset=utf-8",t)=>(n,{headers:s={},...o}={})=>void 0===n||"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...s.entries?Object.fromEntries(s):s},...o}))("image/jpeg");export{e as jpeg};
2
+ //# sourceMappingURL=jpeg.mjs.map
package/jpeg.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jpeg.mjs","sources":["../src/src/createResponse.ts","../src/src/jpeg.ts"],"sourcesContent":[null,null],"names":["jpeg","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse"],"mappings":"AAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBHQ,CAAe"}
package/json.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";const t=((t="text/plain; charset=utf-8",e)=>(s,n)=>{const{headers:o={},...r}=n||{};return"Response"===s?.constructor.name?s:new Response(e?e(s):s,{headers:{"content-type":t,...o},...r})})("application/json; charset=utf-8",JSON.stringify);exports.json=t;
1
+ "use strict";const e=((e="text/plain; charset=utf-8",t)=>(s,{headers:n={},...o}={})=>void 0===s||"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...n.entries?Object.fromEntries(n):n},...o}))("application/json; charset=utf-8",JSON.stringify);exports.json=e;
2
+ //# sourceMappingURL=json.js.map
package/json.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sources":["../src/src/createResponse.ts","../src/src/json.ts"],"sourcesContent":[null,null],"names":["json","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse","JSON","stringify"],"mappings":"aAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBHQ,CAClB,kCACAC,KAAKC"}
package/json.mjs CHANGED
@@ -1 +1,2 @@
1
- const e=((e="text/plain; charset=utf-8",t)=>(n,s)=>{const{headers:o={},...r}=s||{};return"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...o},...r})})("application/json; charset=utf-8",JSON.stringify);export{e as json};
1
+ const e=((e="text/plain; charset=utf-8",t)=>(n,{headers:s={},...o}={})=>void 0===n||"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...s.entries?Object.fromEntries(s):s},...o}))("application/json; charset=utf-8",JSON.stringify);export{e as json};
2
+ //# sourceMappingURL=json.mjs.map
package/json.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.mjs","sources":["../src/src/createResponse.ts","../src/src/json.ts"],"sourcesContent":[null,null],"names":["json","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse","JSON","stringify"],"mappings":"AAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBHQ,CAClB,kCACAC,KAAKC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itty-router",
3
- "version": "4.1.0-next.3",
3
+ "version": "4.1.0",
4
4
  "description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -26,11 +26,6 @@
26
26
  "require": "./error.js",
27
27
  "types": "./error.d.ts"
28
28
  },
29
- "./flow": {
30
- "import": "./flow.mjs",
31
- "require": "./flow.js",
32
- "types": "./flow.d.ts"
33
- },
34
29
  "./html": {
35
30
  "import": "./html.mjs",
36
31
  "require": "./html.js",
@@ -98,19 +93,17 @@
98
93
  }
99
94
  },
100
95
  "keywords": [
101
- "itty",
102
96
  "api",
103
97
  "router",
104
98
  "cloudflare",
105
99
  "workers",
106
- "bun",
100
+ "worker",
107
101
  "serverless",
108
102
  "cors",
109
103
  "middleware",
110
104
  "rest",
111
105
  "serviceworker",
112
- "http",
113
- "nodejs"
106
+ "nested"
114
107
  ],
115
108
  "scripts": {
116
109
  "dev": "yarn test",
package/png.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";const e=((e="text/plain; charset=utf-8",t)=>(n,s)=>{const{headers:r={},...o}=s||{};return"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...r},...o})})("image/png");exports.png=e;
1
+ "use strict";const e=((e="text/plain; charset=utf-8",t)=>(s,{headers:n={},...r}={})=>void 0===s||"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...n.entries?Object.fromEntries(n):n},...r}))("image/png");exports.png=e;
2
+ //# sourceMappingURL=png.js.map
package/png.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"png.js","sources":["../src/src/createResponse.ts","../src/src/png.ts"],"sourcesContent":[null,null],"names":["png","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse"],"mappings":"aAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBJQ,CAAe"}
package/png.mjs CHANGED
@@ -1 +1,2 @@
1
- const e=((e="text/plain; charset=utf-8",t)=>(n,s)=>{const{headers:o={},...r}=s||{};return"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...o},...r})})("image/png");export{e as png};
1
+ const e=((e="text/plain; charset=utf-8",t)=>(n,{headers:s={},...o}={})=>void 0===n||"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...s.entries?Object.fromEntries(s):s},...o}))("image/png");export{e as png};
2
+ //# sourceMappingURL=png.mjs.map
package/png.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"png.mjs","sources":["../src/src/createResponse.ts","../src/src/png.ts"],"sourcesContent":[null,null],"names":["png","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse"],"mappings":"AAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBJQ,CAAe"}
package/status.js CHANGED
@@ -1 +1,2 @@
1
1
  "use strict";exports.status=(s,t)=>new Response(null,{...t,status:s});
2
+ //# sourceMappingURL=status.js.map
package/status.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sources":["../src/src/status.ts"],"sourcesContent":[null],"names":["status","options","Response"],"mappings":"4BAAsB,CAACA,EAAgBC,IACrC,IAAIC,SAAS,KAAM,IAAKD,EAASD"}
package/status.mjs CHANGED
@@ -1 +1,2 @@
1
1
  const s=(s,e)=>new Response(null,{...e,status:s});export{s as status};
2
+ //# sourceMappingURL=status.mjs.map
package/status.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.mjs","sources":["../src/src/status.ts"],"sourcesContent":[null],"names":["status","options","Response"],"mappings":"MAAaA,EAAS,CAACA,EAAgBC,IACrC,IAAIC,SAAS,KAAM,IAAKD,EAASD"}
package/text.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const text: (message: any, options?: ResponseInit) => Response;
1
+ export declare const text: import("./createResponse").ResponseFormatter;
package/text.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";exports.text=(e,t)=>new Response(String(e),t);
1
+ "use strict";const e=((e="text/plain; charset=utf-8",t)=>(s,{headers:n={},...r}={})=>void 0===s||"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...n.entries?Object.fromEntries(n):n},...r}))("text/plain; charset=utf-8",String);exports.text=e;
2
+ //# sourceMappingURL=text.js.map
package/text.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sources":["../src/src/createResponse.ts","../src/src/text.ts"],"sourcesContent":[null,null],"names":["text","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse","String"],"mappings":"aAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBHQ,CAClB,4BACAC"}
package/text.mjs CHANGED
@@ -1 +1,2 @@
1
- const e=(e,n)=>new Response(String(e),n);export{e as text};
1
+ const e=((e="text/plain; charset=utf-8",t)=>(n,{headers:s={},...r}={})=>void 0===n||"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...s.entries?Object.fromEntries(s):s},...r}))("text/plain; charset=utf-8",String);export{e as text};
2
+ //# sourceMappingURL=text.mjs.map
package/text.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.mjs","sources":["../src/src/createResponse.ts","../src/src/text.ts"],"sourcesContent":[null,null],"names":["text","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse","String"],"mappings":"AAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBHQ,CAClB,4BACAC"}
package/webp.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";const e=((e="text/plain; charset=utf-8",t)=>(s,n)=>{const{headers:r={},...o}=n||{};return"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...r},...o})})("image/webp");exports.webp=e;
1
+ "use strict";const e=((e="text/plain; charset=utf-8",t)=>(s,{headers:n={},...r}={})=>void 0===s||"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...n.entries?Object.fromEntries(n):n},...r}))("image/webp");exports.webp=e;
2
+ //# sourceMappingURL=webp.js.map
package/webp.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webp.js","sources":["../src/src/createResponse.ts","../src/src/webp.ts"],"sourcesContent":[null,null],"names":["webp","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse"],"mappings":"aAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBHQ,CAAe"}
package/webp.mjs CHANGED
@@ -1 +1,2 @@
1
- const e=((e="text/plain; charset=utf-8",t)=>(n,s)=>{const{headers:o={},...r}=s||{};return"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...o},...r})})("image/webp");export{e as webp};
1
+ const e=((e="text/plain; charset=utf-8",t)=>(n,{headers:s={},...o}={})=>void 0===n||"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...s.entries?Object.fromEntries(s):s},...o}))("image/webp");export{e as webp};
2
+ //# sourceMappingURL=webp.mjs.map
package/webp.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webp.mjs","sources":["../src/src/createResponse.ts","../src/src/webp.ts"],"sourcesContent":[null,null],"names":["webp","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse"],"mappings":"AAQO,MCNMA,EDOX,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICvBHQ,CAAe"}
package/websocket.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";exports.websocket=(e,t={})=>((e="text/plain; charset=utf-8",t)=>(s,n)=>{const{headers:o={},...r}=n||{};return"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...o},...r})})()(null,{status:101,webSocket:e,...t});
1
+ "use strict";exports.websocket=(e,t={})=>((e="text/plain; charset=utf-8",t)=>(s,{headers:n={},...o}={})=>void 0===s||"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...n.entries?Object.fromEntries(n):n},...o}))()(null,{status:101,webSocket:e,...t});
2
+ //# sourceMappingURL=websocket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket.js","sources":["../src/src/websocket.ts","../src/src/createResponse.ts"],"sourcesContent":[null,null],"names":["client","options","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse","status","webSocket"],"mappings":"+BAEyB,CAACA,EAAmBC,EAAkB,CAAA,ICO7D,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,IDtBrBQ,GAAiB,KAAM,CACrBC,OAAQ,IACRC,UAAWhB,KACRC"}
package/websocket.mjs CHANGED
@@ -1 +1,2 @@
1
- const e=(e,t={})=>((e="text/plain; charset=utf-8",t)=>(n,s)=>{const{headers:o={},...r}=s||{};return"Response"===n?.constructor.name?n:new Response(t?t(n):n,{headers:{"content-type":e,...o},...r})})()(null,{status:101,webSocket:e,...t});export{e as websocket};
1
+ const e=(e,t={})=>((e="text/plain; charset=utf-8",t)=>(s,{headers:n={},...o}={})=>void 0===s||"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...n.entries?Object.fromEntries(n):n},...o}))()(null,{status:101,webSocket:e,...t});export{e as websocket};
2
+ //# sourceMappingURL=websocket.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket.mjs","sources":["../src/src/createResponse.ts","../src/src/websocket.ts"],"sourcesContent":[null,null],"names":["websocket","client","options","format","transform","body","headers","rest","undefined","constructor","name","Response","entries","Object","fromEntries","createResponse","status","webSocket"],"mappings":"AAQO,MCNMA,EAAY,CAACC,EAAmBC,EAAkB,CAAA,IDO7D,EACEC,EAAS,4BACTC,IAEF,CAACC,GAAQC,UAAU,CAAA,KAAOC,GAAS,CAAA,SACxBC,IAATH,GAAiD,aAA3BA,GAAMI,YAAYC,KACtCL,EACA,IAAIM,SAASP,EAAYA,EAAUC,GAAQA,EAAM,CACnCC,QAAS,CACP,eAAgBH,KACZG,EAAQM,QAENC,OAAOC,YAAYR,GACnBA,MAGLC,ICtBrBQ,GAAiB,KAAM,CACrBC,OAAQ,IACRC,UAAWhB,KACRC"}
package/withContent.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- import { IRequest } from './Router';
1
+ import { IRequest, IRequestStrict } from './Router';
2
+ export type HasContent<ContentType> = {
3
+ content: ContentType;
4
+ } & IRequestStrict;
2
5
  export declare const withContent: (request: IRequest) => Promise<void>;
package/withContent.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";exports.withContent=async t=>{t.headers.get("content-type")?.includes("json")&&(t.content=await t.json())};
1
+ "use strict";class t extends Error{status;constructor(t=500,s){super("object"==typeof s?s.error:s),"object"==typeof s&&Object.assign(this,s),this.status=t}}exports.withContent=async s=>{if(s.headers.get("content-type")?.includes("json"))try{s.content=await s.json()}catch(s){throw new t(400,s.message)}};
2
+ //# sourceMappingURL=withContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withContent.js","sources":["../src/src/StatusError.ts","../src/src/withContent.ts"],"sourcesContent":[null,null],"names":["StatusError","Error","status","constructor","body","super","error","Object","assign","this","async","request","headers","get","includes","content","json","e","message"],"mappings":"aAKM,MAAOA,UAAoBC,MAC/BC,OAGAC,YAAYD,EAAS,IAAKE,GACxBC,MAAsB,iBAATD,EAAoBA,EAAKE,MAAQF,GAC9B,iBAATA,GAAqBG,OAAOC,OAAOC,KAAML,GAChDK,KAAKP,OAASA,CACf,sBCLwBQ,MAAOC,IAChC,GAAIA,EAAQC,QAAQC,IAAI,iBAAiBC,SAAS,QAChD,IACEH,EAAQI,cAAgBJ,EAAQK,MACjC,CAAC,MAAOC,GAEP,MAAM,IAAIjB,EAAY,IADXiB,EACmBC,QAC/B"}
package/withContent.mjs CHANGED
@@ -1 +1,2 @@
1
- const n=async n=>{n.headers.get("content-type")?.includes("json")&&(n.content=await n.json())};export{n as withContent};
1
+ class t extends Error{status;constructor(t=500,s){super("object"==typeof s?s.error:s),"object"==typeof s&&Object.assign(this,s),this.status=t}}const s=async s=>{if(s.headers.get("content-type")?.includes("json"))try{s.content=await s.json()}catch(s){throw new t(400,s.message)}};export{s as withContent};
2
+ //# sourceMappingURL=withContent.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withContent.mjs","sources":["../src/src/StatusError.ts","../src/src/withContent.ts"],"sourcesContent":[null,null],"names":["StatusError","Error","status","constructor","body","super","error","Object","assign","this","withContent","async","request","headers","get","includes","content","json","e","message"],"mappings":"AAKM,MAAOA,UAAoBC,MAC/BC,OAGAC,YAAYD,EAAS,IAAKE,GACxBC,MAAsB,iBAATD,EAAoBA,EAAKE,MAAQF,GAC9B,iBAATA,GAAqBG,OAAOC,OAAOC,KAAML,GAChDK,KAAKP,OAASA,CACf,QCLUQ,EAAcC,MAAOC,IAChC,GAAIA,EAAQC,QAAQC,IAAI,iBAAiBC,SAAS,QAChD,IACEH,EAAQI,cAAgBJ,EAAQK,MACjC,CAAC,MAAOC,GAEP,MAAM,IAAIlB,EAAY,IADXkB,EACmBC,QAC/B"}
package/withCookies.js CHANGED
@@ -1 +1,2 @@
1
1
  "use strict";exports.withCookies=e=>{e.cookies=(e.headers.get("Cookie")||"").split(/;\s*/).map((e=>e.split(/=(.+)/))).reduce(((e,[s,i])=>i?(e[s]=i,e):e),{})};
2
+ //# sourceMappingURL=withCookies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withCookies.js","sources":["../src/src/withCookies.ts"],"sourcesContent":[null],"names":["r","cookies","headers","get","split","map","p","reduce","a","k","v"],"mappings":"iCAO4BA,IAC1BA,EAAEC,SAAWD,EAAEE,QAAQC,IAAI,WAAa,IACrCC,MAAM,QACNC,KAAKC,GAAsBA,EAAEF,MAAM,WACnCG,QAAO,CAACC,GAAkBC,EAAGC,KAAgBA,GAAMF,EAAEC,GAAKC,EAAIF,GAAKA,GAAI,CAAE,EAAC"}
package/withCookies.mjs CHANGED
@@ -1 +1,2 @@
1
1
  const e=e=>{e.cookies=(e.headers.get("Cookie")||"").split(/;\s*/).map((e=>e.split(/=(.+)/))).reduce(((e,[o,s])=>s?(e[o]=s,e):e),{})};export{e as withCookies};
2
+ //# sourceMappingURL=withCookies.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withCookies.mjs","sources":["../src/src/withCookies.ts"],"sourcesContent":[null],"names":["withCookies","r","cookies","headers","get","split","map","p","reduce","a","k","v"],"mappings":"AAOa,MAAAA,EAAeC,IAC1BA,EAAEC,SAAWD,EAAEE,QAAQC,IAAI,WAAa,IACrCC,MAAM,QACNC,KAAKC,GAAsBA,EAAEF,MAAM,WACnCG,QAAO,CAACC,GAAkBC,EAAGC,KAAgBA,GAAMF,EAAEC,GAAKC,EAAIF,GAAKA,GAAI,CAAE,EAAC"}
package/withParams.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";exports.withParams=r=>{r.proxy=new Proxy(r.proxy||r,{get:(t,e)=>{let o;return void 0!==(o=t[e])?o.bind?.(r)||o:t?.params?.[e]}})};
1
+ "use strict";exports.withParams=r=>{r.proxy=new Proxy(r.proxy||r,{get:(o,s)=>void 0!==o[s]?o[s].bind?.(r)||o[s]:o?.params?.[s]})};
2
+ //# sourceMappingURL=withParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withParams.js","sources":["../src/src/withParams.ts"],"sourcesContent":[null],"names":["request","proxy","Proxy","get","obj","prop","undefined","bind","params"],"mappings":"gCAE2BA,IACzBA,EAAQC,MAAQ,IAAIC,MAAMF,EAAQC,OAASD,EAAS,CAClDG,IAAK,CAACC,EAAKC,SAAuBC,IAAdF,EAAIC,GACND,EAAIC,GAAME,OAAOP,IAAYI,EAAIC,GACjCD,GAAKI,SAASH,IAChC"}
package/withParams.mjs CHANGED
@@ -1 +1,2 @@
1
- const r=r=>{r.proxy=new Proxy(r.proxy||r,{get:(o,e)=>{let t;return void 0!==(t=o[e])?t.bind?.(r)||t:o?.params?.[e]}})};export{r as withParams};
1
+ const o=o=>{o.proxy=new Proxy(o.proxy||o,{get:(r,p)=>void 0!==r[p]?r[p].bind?.(o)||r[p]:r?.params?.[p]})};export{o as withParams};
2
+ //# sourceMappingURL=withParams.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withParams.mjs","sources":["../src/src/withParams.ts"],"sourcesContent":[null],"names":["withParams","request","proxy","Proxy","get","obj","prop","undefined","bind","params"],"mappings":"AAEa,MAAAA,EAAcC,IACzBA,EAAQC,MAAQ,IAAIC,MAAMF,EAAQC,OAASD,EAAS,CAClDG,IAAK,CAACC,EAAKC,SAAuBC,IAAdF,EAAIC,GACND,EAAIC,GAAME,OAAOP,IAAYI,EAAIC,GACjCD,GAAKI,SAASH,IAChC"}
package/flow.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { RouteHandler, RouterType } from './Router';
2
- import { CorsOptions } from './createCors';
3
- export type FlowOptions = {
4
- format?: Function | false;
5
- handleErrors?: Function | false;
6
- handleNotFound?: RouteHandler | false;
7
- cors?: CorsOptions | true;
8
- };
9
- export declare const flow: (router: RouterType, options?: FlowOptions) => (...args: any[]) => Promise<any>;
package/flow.js DELETED
@@ -1 +0,0 @@
1
- "use strict";const e=((e="text/plain; charset=utf-8",t)=>(o,r)=>{const{headers:s={},...n}=r||{};return"Response"===o?.constructor.name?o:new Response(t?t(o):o,{headers:{"content-type":e,...s},...n})})("application/json; charset=utf-8",JSON.stringify),t=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),o=(o=500,r)=>{if(o instanceof Error){const{message:e,...s}=o;o=o.status||500,r={error:e||t(o),...s}}return r={status:o,..."object"==typeof r?r:{error:r||t(o)}},e(r,{status:o})},r=e=>{e.proxy=new Proxy(e.proxy||e,{get:(t,o)=>{let r;return void 0!==(r=t[o])?r.bind?.(e)||r:t?.params?.[o]}})};exports.flow=(t,s={})=>{const{format:n=e,cors:c,handleErrors:a=o,handleNotFound:l=(()=>o(404))}=s;let i;return"function"==typeof l&&t.all("*",l),c&&(i=((e={})=>{const{origins:t=["*"],maxAge:o,methods:r=["GET"],headers:s={}}=e;let n;const c={"content-type":"application/json","Access-Control-Allow-Methods":r.join(", "),...s};return o&&(c["Access-Control-Max-Age"]=o),{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:t,status:o,body:r}=e;return[101,301,302,308].includes(o)||t.get("access-control-allow-origin")?e:new Response(r,{status:o,headers:{...Object.fromEntries(t),...c,...n,"content-type":t.get("content-type")}})},preflight:e=>{const o=[...new Set(["OPTIONS",...r])],s=e.headers.get("origin")||"";if(n=(t.includes(s)||t.includes("*"))&&{"Access-Control-Allow-Origin":s},"OPTIONS"===e.method){const t={...c,"Access-Control-Allow-Methods":o.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?t:{Allow:o.join(", ")}})}}}})(!0===c?void 0:c),t.routes.unshift(["ALL",/^(.*)?\/*$/,[i.preflight,r],"*"])),async(...e)=>{let o=t.handle(...e);return n&&(o=o.then(n)),a&&(o=o.catch(a)),c&&(o=o.then(i?.corsify)),o}};
package/flow.mjs DELETED
@@ -1 +0,0 @@
1
- const e=((e="text/plain; charset=utf-8",t)=>(o,r)=>{const{headers:s={},...n}=r||{};return"Response"===o?.constructor.name?o:new Response(t?t(o):o,{headers:{"content-type":e,...s},...n})})("application/json; charset=utf-8",JSON.stringify),t=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),o=(o=500,r)=>{if(o instanceof Error){const{message:e,...s}=o;o=o.status||500,r={error:e||t(o),...s}}return r={status:o,..."object"==typeof r?r:{error:r||t(o)}},e(r,{status:o})},r=e=>{e.proxy=new Proxy(e.proxy||e,{get:(t,o)=>{let r;return void 0!==(r=t[o])?r.bind?.(e)||r:t?.params?.[o]}})},s=(t,s={})=>{const{format:n=e,cors:c,handleErrors:a=o,handleNotFound:l=(()=>o(404))}=s;let i;return"function"==typeof l&&t.all("*",l),c&&(i=((e={})=>{const{origins:t=["*"],maxAge:o,methods:r=["GET"],headers:s={}}=e;let n;const c={"content-type":"application/json","Access-Control-Allow-Methods":r.join(", "),...s};return o&&(c["Access-Control-Max-Age"]=o),{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:t,status:o,body:r}=e;return[101,301,302,308].includes(o)||t.get("access-control-allow-origin")?e:new Response(r,{status:o,headers:{...Object.fromEntries(t),...c,...n,"content-type":t.get("content-type")}})},preflight:e=>{const o=[...new Set(["OPTIONS",...r])],s=e.headers.get("origin")||"";if(n=(t.includes(s)||t.includes("*"))&&{"Access-Control-Allow-Origin":s},"OPTIONS"===e.method){const t={...c,"Access-Control-Allow-Methods":o.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?t:{Allow:o.join(", ")}})}}}})(!0===c?void 0:c),t.routes.unshift(["ALL",/^(.*)?\/*$/,[i.preflight,r],"*"])),async(...e)=>{let o=t.handle(...e);return n&&(o=o.then(n)),a&&(o=o.catch(a)),c&&(o=o.then(i?.corsify)),o}};export{s as flow};