@lengkapp/edge 0.0.50 → 0.0.52

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/README.md CHANGED
@@ -202,6 +202,11 @@ c.redirect('https://example.com', 301);
202
202
 
203
203
  Both are `async` because component trees may contain async components.
204
204
 
205
+ default fallback handlers:
206
+ `app.notFound` — runs with a full Context; can return a Response or JSX. OPTIONS requests are short-circuited to 204 before this handler runs.
207
+
208
+ `app.onError` — returning a Response uses it verbatim; returning JSX renders as a 500 HTML response. Errors thrown by the error handler itself are swallowed and replaced with plain-text 500.
209
+
205
210
  ### Headers
206
211
 
207
212
  `c.headers` is a `Headers` instance already containing the base security headers. Mutate it directly before returning a response:
@@ -415,6 +420,7 @@ Serve it as a static asset:
415
420
  | `_post` | URL | Perform a `POST` request to this URL. |
416
421
  | `_trigger` | `load`, `visible`, `click`, `submit`, `change`, `input`, `keyup`, `dblclick` | When to fire. Default: `submit` on a `<form>`, `click` on anything else. |
417
422
  | `_in` | CSS selector | Element whose `innerHTML` receives the response. Default: the element itself. |
423
+ | `_out` | CSS selector | Replaces the target element itself (outerHTML) with the response. Overrides _in. Default: the element itself. |
418
424
  | `_form` | CSS selector | A `<form>` whose `FormData` becomes the URL-encoded POST body. |
419
425
  | `_json` | CSS selector | A `<form>` or input whose values become a JSON POST body. |
420
426
  | `_error` | CSS selector | Element that receives the response body when the status is not 2xx. |
@@ -496,6 +502,7 @@ Every request automatically includes:
496
502
  |---|---|
497
503
  | `x-csrf-token` | `<meta name="_csrf" content="…">` |
498
504
  | `x-auth-token` | `<meta name="_auth" content="…">` |
505
+ | `x-edge` | `1` |
499
506
 
500
507
  ```html
501
508
  <meta name="_csrf" content="<%= csrfToken %>" />
package/dist/README.md CHANGED
@@ -202,6 +202,11 @@ c.redirect('https://example.com', 301);
202
202
 
203
203
  Both are `async` because component trees may contain async components.
204
204
 
205
+ default fallback handlers:
206
+ `app.notFound` — runs with a full Context; can return a Response or JSX. OPTIONS requests are short-circuited to 204 before this handler runs.
207
+
208
+ `app.onError` — returning a Response uses it verbatim; returning JSX renders as a 500 HTML response. Errors thrown by the error handler itself are swallowed and replaced with plain-text 500.
209
+
205
210
  ### Headers
206
211
 
207
212
  `c.headers` is a `Headers` instance already containing the base security headers. Mutate it directly before returning a response:
@@ -415,6 +420,7 @@ Serve it as a static asset:
415
420
  | `_post` | URL | Perform a `POST` request to this URL. |
416
421
  | `_trigger` | `load`, `visible`, `click`, `submit`, `change`, `input`, `keyup`, `dblclick` | When to fire. Default: `submit` on a `<form>`, `click` on anything else. |
417
422
  | `_in` | CSS selector | Element whose `innerHTML` receives the response. Default: the element itself. |
423
+ | `_out` | CSS selector | Replaces the target element itself (outerHTML) with the response. Overrides _in. Default: the element itself. |
418
424
  | `_form` | CSS selector | A `<form>` whose `FormData` becomes the URL-encoded POST body. |
419
425
  | `_json` | CSS selector | A `<form>` or input whose values become a JSON POST body. |
420
426
  | `_error` | CSS selector | Element that receives the response body when the status is not 2xx. |
@@ -496,6 +502,7 @@ Every request automatically includes:
496
502
  |---|---|
497
503
  | `x-csrf-token` | `<meta name="_csrf" content="…">` |
498
504
  | `x-auth-token` | `<meta name="_auth" content="…">` |
505
+ | `x-edge` | `1` |
499
506
 
500
507
  ```html
501
508
  <meta name="_csrf" content="<%= csrfToken %>" />
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @lengkapp/edge v0.0.50
2
+ * @lengkapp/edge v0.0.52
3
3
  * MIT License
4
4
  *
5
5
  * LengkApp Edge License
@@ -30,4 +30,4 @@
30
30
  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
31
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
32
  */
33
- !function(){if(!window.__ec){window.__ec=1;for(var n=document,r=window,i=0,t=n.currentScript,o=n.querySelector.bind(n),e=n.createElement.bind(n),a=n.addEventListener.bind(n),f=["click","submit","change","input","keyup","dblclick"],c=new WeakSet,u=new WeakSet,v=new WeakMap,l={},s=r.IntersectionObserver?new IntersectionObserver(function(n){for(var r=0;r<n.length;r++){var i=n[r];i.isIntersecting&&(s.unobserve(i.target),u.delete(i.target),b(i.target,"visible"))}}):null,w=0;w<f.length;w++)(function(n){a(n,function(r){var i=h(r.target,n);i&&(r.cancelable&&r.preventDefault(),l={},b(i,n))},!0)})(f[w]);new MutationObserver(function(n){for(var r=0;r<n.length;r++){var i,t=n[r].addedNodes,o=n[r].removedNodes;for(i=0;i<t.length;i++)1===t[i].nodeType&&g(t[i]);if(s)for(i=0;i<o.length;i++){var e=o[i];1===e.nodeType&&u.has(e)&&(s.unobserve(e),u.delete(e))}}}).observe(n.documentElement,{childList:!0,subtree:!0}),"loading"===n.readyState?a("DOMContentLoaded",function(){g(n.body)}):g(n.body)}function _(n){return n.hasAttribute("_get")||n.hasAttribute("_post")}function d(n){if(!c.has(n)){c.add(n),!_(n)||n.getAttribute("_in")&&"this"!==n.getAttribute("_in")||n.id||(n.id="_g"+ ++i);var r=n.getAttribute("_trigger");"load"===r?b(n,"load"):"visible"===r&&s&&(u.add(n),s.observe(n))}}function g(n){if(n&&1===n.nodeType){_(n)&&d(n);for(var r=n.querySelectorAll("[_get],[_post]"),i=0;i<r.length;i++)d(r[i])}}function m(n,r){var t=n.getAttribute(r);return t&&"this"!==t?t:(n.id||(n.id="_g"+ ++i),"#"+n.id)}function b(n,r){var i=n.getAttribute("_get"),t=n.getAttribute("_post");if(i||t){var e=i||t,a=i?"GET":"POST";if("load"!==r&&"visible"!==r||!((l[e]=(l[e]||0)+1)>8)){var f=v.get(n);f&&f.abort(),f=new AbortController,v.set(n,f);var c=null,u={"x-edge":"1"},s=(o('meta[name="_csrf"]')||{}).content,w=(o('meta[name="_auth"]')||{}).content;if(s&&(u["x-csrf-token"]=s),w&&(u["x-auth-token"]=w),"POST"===a){var _=n.getAttribute("_form"),d=n.getAttribute("_json");if(_){var g=o(_);g&&(c=new URLSearchParams(new FormData(g)).toString(),u["Content-Type"]="application/x-www-form-urlencoded")}else if(d){var b=o(d),h={};b&&("FORM"===b.tagName?new FormData(b).forEach(function(n,r){h[r]=n}):h[b.name||b.id]=b.value),c=JSON.stringify(h),u["Content-Type"]="application/json"}}var O=m(n,"_in"),k=n.hasAttribute("_error");fetch(e,{method:a,headers:u,body:c,signal:f.signal}).then(function(r){return r.text().then(function(i){r.ok?p(O,i):k&&p(m(n,"_error"),i)})}).catch(function(n){if(!n||"AbortError"!==n.name)throw n})}}}function p(n,r){var i=o(n);i&&(i.innerHTML=r,function(n){for(var r=n.querySelectorAll("script,style"),i=0;i<r.length;i++){var o=r[i];if(!(o===t||t&&t.src&&o.src===t.src)){for(var a=e(o.tagName),f=0;f<o.attributes.length;f++)a.setAttribute(o.attributes[f].name,o.attributes[f].value);a.textContent=o.textContent,o.parentNode.replaceChild(a,o)}}}(i),g(i))}function h(n,r){for(;n&&1===n.nodeType;){if(_(n)&&(n.getAttribute("_trigger")||("FORM"===n.tagName?"submit":"click"))===r)return n;n=n.parentNode}return null}}();
33
+ !function(){if(!window.__ec){window.__ec=1;for(var r=document,n=window,t=0,o=r.currentScript,i=r.querySelector.bind(r),e=r.createElement.bind(r),a=r.addEventListener.bind(r),f=["click","submit","change","input","keyup","dblclick"],u=new WeakSet,c=new WeakSet,v=new WeakMap,l={},s=n.IntersectionObserver?new IntersectionObserver(function(r){for(var n=0;n<r.length;n++){var t=r[n];t.isIntersecting&&(s.unobserve(t.target),c.delete(t.target),p(t.target,"visible"))}}):null,_=0;_<f.length;_++)(function(r){a(r,function(n){var t=O(n.target,r);t&&(n.cancelable&&n.preventDefault(),l={},p(t,r))},!0)})(f[_]);new MutationObserver(function(r){for(var n=0;n<r.length;n++){var t,o=r[n].addedNodes,i=r[n].removedNodes;for(t=0;t<o.length;t++)1===o[t].nodeType&&m(o[t]);for(t=0;t<i.length;t++)k(i[t])}}).observe(r.documentElement,{childList:!0,subtree:!0}),"loading"===r.readyState?a("DOMContentLoaded",function(){m(r.body)}):m(r.body)}function w(r){return r.hasAttribute("_get")||r.hasAttribute("_post")}function d(r){if(!u.has(r)){u.add(r);var n=r.getAttribute("_in"),o=r.getAttribute("_out"),i=r.hasAttribute("_out")?!o||"this"===o:!n||"this"===n;w(r)&&!r.id&&i&&(r.id="_g"+ ++t);var e=r.getAttribute("_trigger");"load"===e?p(r,"load"):"visible"===e&&s&&(c.add(r),s.observe(r))}}function m(r){if(r&&1===r.nodeType){w(r)&&d(r);for(var n=r.querySelectorAll("[_get],[_post]"),t=0;t<n.length;t++)d(n[t])}}function g(r){for(var n=r.querySelectorAll("script,style"),t=0;t<n.length;t++){var i=n[t];if(!(i===o||o&&o.src&&i.src===o.src)){for(var a=e(i.tagName),f=0;f<i.attributes.length;f++)a.setAttribute(i.attributes[f].name,i.attributes[f].value);a.textContent=i.textContent,i.parentNode.replaceChild(a,i)}}}function b(r,n){var o=r.getAttribute(n);return o&&"this"!==o?o:(r.id||(r.id="_g"+ ++t),"#"+r.id)}function p(r,n){var t=r.getAttribute("_get"),o=r.getAttribute("_post");if(t||o){var e=t||o,a=t?"GET":"POST";if("load"!==n&&"visible"!==n||!((l[e]=(l[e]||0)+1)>8)){var f=v.get(r);f&&f.abort(),f=new AbortController,v.set(r,f);var u=null,c={"x-edge":"1"},s=(i('meta[name="_csrf"]')||{}).content,_=(i('meta[name="_auth"]')||{}).content;if(s&&(c["x-csrf-token"]=s),_&&(c["x-auth-token"]=_),"POST"===a){var w=r.getAttribute("_form"),d=r.getAttribute("_json");if(w){var m=i(w);m&&(u=new URLSearchParams(new FormData(m)).toString(),c["Content-Type"]="application/x-www-form-urlencoded")}else if(d){var g=i(d),p={};g&&("FORM"===g.tagName?new FormData(g).forEach(function(r,n){p[n]=r}):p[g.name||g.id]=g.value),u=JSON.stringify(p),c["Content-Type"]="application/json"}}var O=r.hasAttribute("_out"),k=b(r,O?"_out":"_in"),S=r.hasAttribute("_error");fetch(e,{method:a,headers:c,body:u,signal:f.signal}).then(function(n){return n.text().then(function(t){n.ok?h(k,t,O):S&&h(b(r,"_error"),t,!1)})}).catch(function(r){if(!r||"AbortError"!==r.name)throw r})}}}function h(r,n,t){var o=i(r);if(o)if(t){var a=o.parentNode;if(!a)return;var f=e("template");f.innerHTML=n,g(f.content);for(var u=[],c=f.content.firstChild;c;c=c.nextSibling)u.push(c);a.replaceChild(f.content,o);for(var v=0;v<u.length;v++)1===u[v].nodeType&&m(u[v])}else o.innerHTML=n,g(o),m(o)}function O(r,n){for(;r&&1===r.nodeType;){if(w(r)&&(r.getAttribute("_trigger")||("FORM"===r.tagName?"submit":"click"))===n)return r;r=r.parentNode}return null}function k(r){if(r&&1===r.nodeType){c.has(r)&&(s&&s.unobserve(r),c.delete(r));var n=v.get(r);n&&(n.abort(),v.delete(r));for(var t=r.getElementsByTagName("*"),o=0;o<t.length;o++){var i=t[o];c.has(i)&&(s&&s.unobserve(i),c.delete(i));var e=v.get(i);e&&(e.abort(),v.delete(i))}}}}();
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @lengkapp/edge v0.0.50
2
+ * @lengkapp/edge v0.0.52
3
3
  * MIT License
4
4
  *
5
5
  * LengkApp Edge License
@@ -33,13 +33,6 @@
33
33
  /* ------------------------------------------------------------------ *
34
34
  * JSX runtime *
35
35
  * ------------------------------------------------------------------ */
36
-
37
- /**
38
- * Runtime value is `Symbol('Fragment')`. The function signature is a
39
- * type-level shim so `<></>` works with the automatic JSX runtime.
40
- * Never called directly — `jsx(Fragment, …)` passes it through and
41
- * `renderToString` compares by identity.
42
- */
43
36
  export const Fragment: (props: { children?: any }) => JSXNode;
44
37
 
45
38
  export interface JSXNode {
@@ -62,7 +55,10 @@ export function jsx(
62
55
  * The optional `ctx` is normally supplied by `Context.html`/`Context.page`;
63
56
  * user code never needs to pass it.
64
57
  */
65
- export function renderToString(node: any, ctx?: Context): Promise<string>;
58
+ export function renderToString<Env = any>(
59
+ node: any,
60
+ ctx?: Context<Env>
61
+ ): Promise<string>;
66
62
 
67
63
  /* ------------------------------------------------------------------ *
68
64
  * Ambient context *
@@ -72,13 +68,12 @@ export function renderToString(node: any, ctx?: Context): Promise<string>;
72
68
  * Returns the Context of the request whose render is currently executing.
73
69
  *
74
70
  * MUST be called synchronously at the top of a component — before any
75
- * `await`. After an `await`, use the captured local reference; the
76
- * ambient slot is no longer guaranteed to belong to your request.
71
+ * `await`. After an `await`, use the captured local reference.
77
72
  *
78
73
  * Throws if called outside an active render (module top-level, scheduled
79
74
  * handler, `waitUntil` callback, or after an `await`).
80
75
  */
81
- export function useCtx(): Context;
76
+ export function useCtx<Env = any>(): Context<Env>;
82
77
 
83
78
  /* ------------------------------------------------------------------ *
84
79
  * Context *
@@ -94,16 +89,16 @@ export interface CookieOptions {
94
89
  sameSite?: 'Strict' | 'Lax' | 'None' | string;
95
90
  }
96
91
 
97
- export class Context {
92
+ export class Context<Env = any> {
98
93
  constructor(
99
94
  request: Request,
100
- env: Record<string, any>,
95
+ env: Env,
101
96
  params?: Record<string, string>,
102
97
  parsedUrl?: URL | null
103
98
  );
104
99
 
105
100
  req: Request;
106
- env: Record<string, any>;
101
+ env: Env;
107
102
  params: Record<string, string>;
108
103
  status: number;
109
104
  headers: Headers;
@@ -117,14 +112,12 @@ export class Context {
117
112
  text(data: string, status?: number, headers?: Record<string, string>): Response;
118
113
  json(data: any, status?: number, headers?: Record<string, string>): Response;
119
114
 
120
- /** Async — JSX trees may contain async components. */
121
115
  html(
122
116
  data: string | JSXNode | JSXNode[] | null | undefined,
123
117
  status?: number,
124
118
  headers?: Record<string, string>
125
119
  ): Promise<Response>;
126
120
 
127
- /** Async — JSX trees may contain async components. */
128
121
  page(
129
122
  data: string | JSXNode | JSXNode[] | null | undefined,
130
123
  status?: number,
@@ -138,134 +131,52 @@ export class Context {
138
131
  * Edge router *
139
132
  * ------------------------------------------------------------------ */
140
133
 
141
- export type RouteHandler = (ctx: Context) => any | Promise<any>;
134
+ export type RouteHandler<Env = any> =
135
+ (ctx: Context<Env>) => any | Promise<any>;
142
136
 
143
- export type ScheduledHandler = (
144
- event: ScheduledEvent,
145
- env: Record<string, any>,
146
- ctx: ExecutionContext
137
+ export type ScheduledHandler<Env = any> = (
138
+ event: any,
139
+ env: Env,
140
+ ctx: any
147
141
  ) => void | Promise<void>;
148
142
 
149
- /**
150
- * Invoked when no route matches the incoming request.
151
- *
152
- * Receives a full Context (same shape as a route handler) so it can
153
- * set `c.status` and return a Response, or a JSX tree (which is
154
- * coerced to an HTML response at that status).
155
- */
156
- export type NotFoundHandler = (ctx: Context) => any | Promise<any>;
143
+ export type NotFoundHandler<Env = any> =
144
+ (ctx: Context<Env>) => any | Promise<any>;
157
145
 
158
- /**
159
- * Invoked when a route handler (or the not-found handler) throws.
160
- *
161
- * The thrown value is `unknown` because nothing enforces that handlers
162
- * throw `Error` specifically. Returning a Response uses it verbatim;
163
- * returning JSX renders it as a 500 HTML response. Errors thrown by
164
- * the error handler itself are swallowed and replaced with a
165
- * plain-text 500.
166
- */
167
- export type ErrorHandler = (
168
- ctx: Context,
146
+ export type ErrorHandler<Env = any> = (
147
+ ctx: Context<Env>,
169
148
  err: unknown
170
149
  ) => any | Promise<any>;
171
150
 
172
- export class Edge {
173
- /**
174
- * @param prefix Optional mount prefix for this Edge. `''` and `'/'`
175
- * both mean "no prefix". Joined with every registered route path at
176
- * registration time — never stripped or re-applied per request.
177
- */
151
+ export class Edge<Env = any> {
178
152
  constructor(prefix?: string);
179
153
 
180
- /**
181
- * Normalized mount prefix for this Edge. `''` means "no prefix".
182
- * Set once at construction; applied to every route registered on this
183
- * Edge (and merged from sub-apps) so lookups at request time are
184
- * plain map/trie hits with no prefix stripping.
185
- */
186
154
  prefix: string;
187
155
 
188
- readonly staticRoutes: Map<string, Map<string, RouteHandler>>;
156
+ readonly staticRoutes: Map<string, Map<string, RouteHandler<Env>>>;
189
157
  readonly dynamicTries: Record<string, any>;
190
158
 
191
- /**
192
- * Set via `.scheduled()`. `null` until `.scheduled()` is called.
193
- * Read it only from the Worker entry
194
- * (`export default { fetch, scheduled }`) if you wire that up yourself.
195
- */
196
- scheduledHandler: ScheduledHandler | null;
197
-
198
- /* ---- Fallback handlers ------------------------------------------ *
199
- * Exposed as public fields to mirror the runtime shape; normally *
200
- * set via `.notFound()` / `.onError()` rather than assigned *
201
- * directly. */
202
- notFoundHandler: NotFoundHandler | null;
203
- errorHandler: ErrorHandler | null;
204
-
205
- /* ---- Sub-app mounting ------------------------------------------- */
206
-
207
- /**
208
- * Assigning runs a one-time merge: every route on each sub-app is
209
- * copied into this Edge's own tables, prefixed with `this.prefix`
210
- * combined with the sub-app's own prefix. After the merge the hot
211
- * path is unchanged — no per-request dispatch, no path rewriting.
212
- *
213
- * const signIn = new Edge('/sign-in');
214
- * signIn.get('/login', h);
215
- * const app = new Edge();
216
- * app.routes = [signIn]; // GET /sign-in/login
217
- *
218
- * Non-`Edge` entries throw. Mount is eager and one-way: routes
219
- * registered on a sub-app *after* it was mounted do not propagate.
220
- */
221
- set routes(apps: Edge | Edge[]);
222
-
223
- /* ---- Route registration ----------------------------------------- *
224
- * Paths are joined with this Edge's `prefix` (if any) at *
225
- * registration time; the resulting full path is what the router *
226
- * matches against on each request. */
227
-
228
- get(path: string, handler: RouteHandler): void;
229
- post(path: string, handler: RouteHandler): void;
230
- put(path: string, handler: RouteHandler): void;
231
- delete(path: string, handler: RouteHandler): void;
232
- patch(path: string, handler: RouteHandler): void;
233
- options(path: string, handler: RouteHandler): void;
234
- head(path: string, handler: RouteHandler): void;
235
-
236
- /* ---- Scheduled handler ------------------------------------------ */
237
- scheduled(handler: ScheduledHandler): void;
238
-
239
- /* ---- Fallback registration -------------------------------------- */
240
-
241
- /**
242
- * Register a handler invoked when no route matches the incoming
243
- * request. The handler runs with a full Context (headers, cookies,
244
- * `c.page`, `c.html`).
245
- *
246
- * `OPTIONS` requests are short-circuited to a 204 (with base security
247
- * headers, no body) before this handler runs, so preflights never
248
- * render an HTML error page.
249
- */
250
- notFound(handler: NotFoundHandler): void;
251
-
252
- /**
253
- * Register a handler invoked when a route handler (including the
254
- * not-found handler) throws. Returning a Response uses it verbatim;
255
- * returning JSX renders it as a 500 HTML response. Errors thrown by
256
- * the error handler itself are swallowed and replaced with a
257
- * plain-text 500.
258
- */
259
- onError(handler: ErrorHandler): void;
260
-
261
- /* ---- Entry point ------------------------------------------------ *
262
- * The Workers module contract also passes an `ExecutionContext` as
263
- * the third argument; the router ignores it. Declare only what the
264
- * implementation consumes. */
265
- fetch(
266
- request: Request,
267
- env: Record<string, any>
268
- ): Promise<Response>;
159
+ scheduledHandler: ScheduledHandler<Env> | null;
160
+
161
+ notFoundHandler: NotFoundHandler<Env> | null;
162
+ errorHandler: ErrorHandler<Env> | null;
163
+
164
+ set routes(apps: Edge<Env> | Edge<Env>[]);
165
+
166
+ get(path: string, handler: RouteHandler<Env>): void;
167
+ post(path: string, handler: RouteHandler<Env>): void;
168
+ put(path: string, handler: RouteHandler<Env>): void;
169
+ delete(path: string, handler: RouteHandler<Env>): void;
170
+ patch(path: string, handler: RouteHandler<Env>): void;
171
+ options(path: string, handler: RouteHandler<Env>): void;
172
+ head(path: string, handler: RouteHandler<Env>): void;
173
+
174
+ scheduled(handler: ScheduledHandler<Env>): void;
175
+
176
+ notFound(handler: NotFoundHandler<Env>): void;
177
+ onError(handler: ErrorHandler<Env>): void;
178
+
179
+ fetch(request: Request, env: Env): Promise<Response>;
269
180
  }
270
181
 
271
182
  export default Edge;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @lengkapp/edge v0.0.50
2
+ * @lengkapp/edge v0.0.52
3
3
  * MIT License
4
4
  *
5
5
  * LengkApp Edge License
@@ -30,4 +30,4 @@
30
30
  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
31
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
32
  */
33
- var t=Object.defineProperty,e=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,o=(e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})},s=(o,s,i,c)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let a of n(s))r.call(o,a)||a===i||t(o,a,{get:()=>s[a],enumerable:!(c=e(s,a))||c.enumerable});return o},i=e=>s(t({},"__esModule",{value:!0}),e),c={};function a(t){const e=[],n=t.length;let r=1;for(let o=1;o<=n;o++)o!==n&&47!==t.charCodeAt(o)||(o>r&&e.push(t.slice(r,o)),r=o+1);return e}function l(t){const e=t.length;return e>1&&47===t.charCodeAt(e-1)?t.slice(0,-1):t}function u(t,e){if(!e)return t||"/";if(!t||"/"===t)return 47===e.charCodeAt(0)?e:"/"+e;const n=t.charCodeAt(t.length-1),r=e.charCodeAt(0);let o;o=47===n?47===r?t+e.slice(1):t+e:47===r?t+e:t+"/"+e;const s=o.length;return s>1&&47===o.charCodeAt(s-1)?o.slice(0,-1):o}o(c,{Context:()=>Context,Edge:()=>Edge,Fragment:()=>Fragment,default:()=>H,jsx:()=>jsx,renderToString:()=>renderToString,useCtx:()=>useCtx}),module.exports=i(c);var f=new Set(["__proto__","constructor","prototype"]);function h(t){return"string"==typeof t&&!f.has(t)}function p(t){const e=t.length;let n=0;for(;n<e;){const e=t.charCodeAt(n);if(38===e||60===e||62===e||34===e||39===e)break;n++}if(n===e)return t;let r=t.slice(0,n),o=n;for(;n<e;n++){const e=t.charCodeAt(n);let s;if(38===e)s="&amp;";else if(60===e)s="&lt;";else if(62===e)s="&gt;";else if(34===e)s="&quot;";else{if(39!==e)continue;s="&#039;"}n>o&&(r+=t.slice(o,n)),r+=s,o=n+1}return o<e&&(r+=t.slice(o)),r}function d(t){return t>=65&&t<=90||t>=97&&t<=122}function y(t){return t>=48&&t<=57}function w(t){const e=t.length;if(0===e||!d(t.charCodeAt(0)))return!1;for(let n=1;n<e;n++){const e=t.charCodeAt(n);if(!d(e)&&!y(e)&&45!==e)return!1}return!0}function m(t){const e=t.length;if(0===e)return!1;const n=t.charCodeAt(0);if(!d(n)&&95!==n&&58!==n)return!1;for(let n=1;n<e;n++){const e=t.charCodeAt(n);if(!d(e)&&!y(e)&&95!==e&&58!==e&&46!==e&&45!==e)return!1}return!0}function g(t){const e=t.charCodeAt(0),n=t.charCodeAt(1);return!(111!==e&&79!==e||110!==n&&78!==n)}var Fragment=Symbol("Fragment");function jsx(t,e,...n){return{type:t,props:e||{},children:n,__isJSX:!0}}var b=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),S=new Set(["allowfullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","formnovalidate","hidden","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"]),C=new Set(["animation-iteration-count","border-image-outset","border-image-slice","border-image-width","box-flex","box-flex-group","box-ordinal-group","column-count","columns","flex","flex-grow","flex-positive","flex-shrink","flex-negative","flex-order","grid-row","grid-row-end","grid-row-span","grid-row-start","grid-column","grid-column-end","grid-column-span","grid-column-start","font-weight","line-clamp","line-height","opacity","order","orphans","tab-size","widows","z-index","zoom","fill-opacity","flood-opacity","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-miterlimit","stroke-opacity","stroke-width"]),O=new Map,x=2e3;function T(t){const e=O.get(t);if(void 0!==e)return e;const n=t.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,"");return O.size>=x&&O.clear(),O.set(t,n),n}function E(t){if(!t||"object"!=typeof t)return"";let e="";for(const n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const r=T(n);let o=t[n];"number"!=typeof o||C.has(r)||(o+="px"),e&&(e+=";"),e+=r+":"+o}return e}var k=new Set(["href","src","xlink:href","action","formaction"]),j=[];function useCtx(){const t=j[j.length-1];if(!t)throw new Error("useCtx() must be called synchronously at the top of a component (before any await). It is not available after an await, nor outside a render.");return t}async function renderToString(t,e){if(void 0===e&&(e=j[j.length-1]),null==t||"boolean"==typeof t)return"";const n=typeof t;if("string"===n)return p(t);if("number"===n)return p(String(t));if("object"===n&&"function"==typeof t.then)return renderToString(await t,e);if(Array.isArray(t)){let n="";for(let r=0;r<t.length;r++)n+=await renderToString(t[r],e);return n}if(!t.__isJSX)return p(String(t));const{type:r,props:o,children:s}=t;if(r===Fragment){let t="";for(let n=0;n<s.length;n++)t+=await renderToString(s[n],e);return t}if("symbol"==typeof r)return"";if("function"==typeof r){let t;if(e){j.push(e);try{t=r({...o,children:s})}finally{j.pop()}}else t=r({...o,children:s});return renderToString(await t,e)}if("string"!=typeof r||!w(r))return"";const i=b.has(r);let c="";for(const t in o){if(!Object.prototype.hasOwnProperty.call(o,t))continue;if("children"===t||"key"===t||"ref"===t)continue;const e=o[t];if(null==e||!1===e)continue;if("dangerouslySetInnerHTML"===t)continue;let n=t;if("className"===t||"class"===t?n="class":"htmlFor"!==t&&"for"!==t||(n="for"),h(n)&&!g(n)&&m(n)){if(k.has(n)){const t=String(e).replace(/[\u0000-\u0020]/g,"").toLowerCase();if(t.startsWith("javascript:")||t.startsWith("vbscript:")||t.startsWith("data:text/html"))continue}if(S.has(n))!0===e&&(c+=" "+n);else if(!0!==e){if("style"===n&&"object"==typeof e){const t=E(e);t&&(c+=' style="'+p(t)+'"');continue}c+=" "+n+'="'+p(String(e))+'"'}else c+=" "+n+'="true"'}}let a="";const l=o.dangerouslySetInnerHTML;if(l&&null!=l.__html)a=l.__html;else for(let t=0;t<s.length;t++)a+=await renderToString(s[t],e);return i?"<"+r+c+"/>":"<"+r+c+">"+a+"</"+r+">"}var v=Object.freeze([["X-Content-Type-Options","nosniff"],["X-Frame-Options","DENY"],["Referrer-Policy","strict-origin-when-cross-origin"],["Permissions-Policy","geolocation=(), microphone=(), camera=()"]]),R=Object.freeze(Object.create(null)),Context=class{constructor(t,e,n={},r=null){this.req=t,this.env=e,this.params=n,this.status=200,this.headers=new Headers(v),this.t=null,this.url=r||new URL(t.url)}o(){if(null!==this.t)return this.t;const t=this.req.headers.get("Cookie");if(!t)return this.t=R,R;const e=Object.create(null);let n=0;const r=t.length;for(;n<r;){let o=t.indexOf(";",n);-1===o&&(o=r);let s=n,i=o;for(;s<i&&32===t.charCodeAt(s);)s++;for(;i>s&&32===t.charCodeAt(i-1);)i--;if(i>s){const n=t.indexOf("=",s);if(n>s&&n<i)try{const r=decodeURIComponent(t.slice(s,n));h(r)&&(e[r]=decodeURIComponent(t.slice(n+1,i)))}catch{}}n=o+1}return this.t=e,e}getCookie(t){const e=this.o()[t];return void 0===e?null:e}get query(){return this.url.searchParams}setCookie(t,e,n={}){if("string"!=typeof t||!h(t)||/[\r\n;=]/.test(t))return;let r=encodeURIComponent(t)+"="+encodeURIComponent(e);n.path&&(r+="; Path="+n.path),n.domain&&(r+="; Domain="+n.domain),void 0!==n.maxAge&&(r+="; Max-Age="+n.maxAge),n.expires&&(r+="; Expires="+n.expires.toUTCString()),n.secure&&(r+="; Secure"),n.httpOnly&&(r+="; HttpOnly"),n.sameSite&&(r+="; SameSite="+n.sameSite),this.headers.append("Set-Cookie",r)}deleteCookie(t,e={}){this.setCookie(t,"",{...e,maxAge:0,expires:new Date(0)})}i(t){if(!t)return this.headers;const e=Object.keys(t);if(0===e.length)return this.headers;const n=new Headers(this.headers);for(let r=0;r<e.length;r++)n.set(e[r],t[e[r]]);return n}text(t,e=this.status,n={}){const r=this.i(n);return r.has("Content-Type")||r.set("Content-Type","text/plain; charset=utf-8"),new Response(t,{status:e,headers:r})}json(t,e=this.status,n={}){const r=this.i(n);return r.has("Content-Type")||r.set("Content-Type","application/json; charset=utf-8"),new Response(JSON.stringify(t),{status:e,headers:r})}async html(t,e=this.status,n={}){const r=this.i(n);let o;return r.has("Content-Type")||r.set("Content-Type","text/html; charset=utf-8"),o="string"==typeof t?t:t&&t.__isJSX||Array.isArray(t)?await renderToString(t,this):null==t?"":String(t),new Response(o,{status:e,headers:r})}async page(t,e=this.status,n={}){const r=this.i(n);let o;return r.has("Content-Type")||r.set("Content-Type","text/html; charset=utf-8"),o="string"==typeof t?t:t&&t.__isJSX||Array.isArray(t)?await renderToString(t,this):null==t?"":String(t),/^\s*<!doctype\s/i.test(o)||(o="<!DOCTYPE html>"+o),new Response(o,{status:e,headers:r})}redirect(t,e=302){const n=new Headers(this.headers);return n.set("Location",String(t)),n.delete("Content-Type"),new Response(null,{status:e,headers:n})}},_=class{constructor(){this.children=null,this.paramChild=null,this.handler=null}},P=class{constructor(){this.root=new _}add(t,e){let n=this.root;const r=[];for(let e=0;e<t.length;e++){const o=t[e];if(58===o.charCodeAt(0)){const t=o.slice(1);r.push(h(t)?t:"_p"+e),n.paramChild||(n.paramChild=new _),n=n.paramChild}else{n.children||(n.children=new Map);let t=n.children.get(o);t||(t=new _,n.children.set(o,t)),n=t}}n.handler={handler:e,paramNames:r}}match(t){const e=[],n=this.l(this.root,t,0,e);if(!n)return null;const{handler:r,paramNames:o}=n,s=Object.create(null);for(let t=0;t<o.length;t++)s[o[t]]=e[t];return{handler:r,params:s}}l(t,e,n,r){if(n===e.length)return t.handler;const o=e[n],s=t.children;if(s){const t=s.get(o);if(t){const o=this.l(t,e,n+1,r);if(o)return o}}const i=t.paramChild;if(i){r.push(o);const t=this.l(i,e,n+1,r);if(t)return t;r.pop()}return null}},A=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD"],Edge=class t{constructor(t=""){this.prefix=t&&"/"!==t?l(t):"",this.staticRoutes=new Map;for(let t=0;t<A.length;t++)this.staticRoutes.set(A[t],new Map);this.dynamicTries={};for(let t=0;t<A.length;t++)this.dynamicTries[A[t]]=new P;this.u=[],this.scheduledHandler=null,this.notFoundHandler=null,this.errorHandler=null}set routes(e){const n=Array.isArray(e)?e:e?[e]:[];for(let e=0;e<n.length;e++){const r=n[e];if(!(r instanceof t))throw new Error("app.routes entries must be Edge instances");this.h(r)}}h(t){const e=t.u,n=this.prefix;for(let t=0;t<e.length;t++){const r=e[t],o=u(n,r.path);this.u.push({method:r.method,path:o,handler:r.handler}),this.p(r.method,o,r.handler)}}m(t,e,n,r){if("function"==typeof n&&(r=n),"function"!=typeof r)throw new Error("Handler for "+t+" "+e+" must be a function");const o=u(this.prefix,e);this.u.push({method:t,path:o,handler:r}),this.p(t,o,r)}p(t,e,n){-1===e.indexOf(":")?this.staticRoutes.get(t).set(e,n):this.dynamicTries[t].add(a(e),n)}get(t,e,n){this.m("GET",t,e,n)}post(t,e,n){this.m("POST",t,e,n)}put(t,e,n){this.m("PUT",t,e,n)}delete(t,e,n){this.m("DELETE",t,e,n)}patch(t,e,n){this.m("PATCH",t,e,n)}options(t,e,n){this.m("OPTIONS",t,e,n)}head(t,e,n){this.m("HEAD",t,e,n)}scheduled(t){this.scheduledHandler=t}notFound(t){if("function"!=typeof t)throw new Error("notFound(handler) requires a function");this.notFoundHandler=t}onError(t){if("function"!=typeof t)throw new Error("onError(handler) requires a function");this.errorHandler=t}S(t,e){const n=new Headers(e.headers);t.headers.forEach((t,e)=>{"set-cookie"!==e.toLowerCase()&&(n.has(e)||n.set(e,t))});const r="function"==typeof t.headers.getSetCookie?t.headers.getSetCookie():t.headers.get("Set-Cookie")?[t.headers.get("Set-Cookie")]:[];if(r.length){const t="function"==typeof n.getSetCookie?n.getSetCookie():n.get("Set-Cookie")?[n.get("Set-Cookie")]:[],e=new Set(t);for(let t=0;t<r.length;t++){const o=r[t];e.has(o)||(n.append("Set-Cookie",o),e.add(o))}}const o=204===e.status||304===e.status?null:e.body;return new Response(o,{status:e.status,statusText:e.statusText,headers:n})}async fetch(t,e){const n=new URL(t.url),r=l(n.pathname),o=t.method,s=this.staticRoutes.get(o);if(s){const o=s.get(r);if(o)return this.C(o,t,e,Object.create(null),n)}const i=this.dynamicTries[o];if(i){const o=i.match(a(r));if(o)return this.C(o.handler,t,e,o.params,n)}if("OPTIONS"===o){const r=new Context(t,e,Object.create(null),n);return this.S(r,new Response(null,{status:204}))}if(this.notFoundHandler)return this.C(this.notFoundHandler,t,e,Object.create(null),n);const c=new Context(t,e,Object.create(null),n);return this.S(c,new Response("Not Found",{status:404}))}async O(t,e){const n=this.errorHandler;if(!n)return t.text("Internal Server Error",500);try{const r=await n(t,e);return r instanceof Response?this.S(t,r):r&&r.__isJSX||Array.isArray(r)?t.html(r,500):t.text("Internal Server Error",500)}catch{return t.text("Internal Server Error",500)}}async C(t,e,n,r,o){const s=new Context(e,n,r,o);let i;try{const e=await t(s);i=e instanceof Response?this.S(s,e):e&&e.__isJSX?await s.html(e):s.text("OK")}catch(t){i=await this.O(s,t)}return i}},H=Edge;
33
+ function t(t){const e=[],n=t.length;let r=1;for(let o=1;o<=n;o++)o!==n&&47!==t.charCodeAt(o)||(o>r&&e.push(t.slice(r,o)),r=o+1);return e}function e(t){const e=t.length;return e>1&&47===t.charCodeAt(e-1)?t.slice(0,-1):t}function n(t,e){if(!e)return t||"/";if(!t||"/"===t)return 47===e.charCodeAt(0)?e:"/"+e;const n=t.charCodeAt(t.length-1),r=e.charCodeAt(0);let o;o=47===n?47===r?t+e.slice(1):t+e:47===r?t+e:t+"/"+e;const s=o.length;return s>1&&47===o.charCodeAt(s-1)?o.slice(0,-1):o}var r=new Set(["__proto__","constructor","prototype"]);function o(t){return"string"==typeof t&&!r.has(t)}function s(t){const e=t.length;let n=0;for(;n<e;){const e=t.charCodeAt(n);if(38===e||60===e||62===e||34===e||39===e)break;n++}if(n===e)return t;let r=t.slice(0,n),o=n;for(;n<e;n++){const e=t.charCodeAt(n);let s;if(38===e)s="&amp;";else if(60===e)s="&lt;";else if(62===e)s="&gt;";else if(34===e)s="&quot;";else{if(39!==e)continue;s="&#039;"}n>o&&(r+=t.slice(o,n)),r+=s,o=n+1}return o<e&&(r+=t.slice(o)),r}function i(t){return t>=65&&t<=90||t>=97&&t<=122}function c(t){return t>=48&&t<=57}function a(t){const e=t.length;if(0===e)return!1;const n=t.charCodeAt(0);if(!i(n)&&95!==n&&58!==n)return!1;for(let n=1;n<e;n++){const e=t.charCodeAt(n);if(!i(e)&&!c(e)&&95!==e&&58!==e&&46!==e&&45!==e)return!1}return!0}function l(t){const e=t.charCodeAt(0),n=t.charCodeAt(1);return!(111!==e&&79!==e||110!==n&&78!==n)}var Fragment=Symbol("Fragment");function jsx(t,e,...n){return{type:t,props:e||{},children:n,__isJSX:!0}}var u=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),f=new Set(["allowfullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","formnovalidate","hidden","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"]),h=new Set(["animation-iteration-count","border-image-outset","border-image-slice","border-image-width","box-flex","box-flex-group","box-ordinal-group","column-count","columns","flex","flex-grow","flex-positive","flex-shrink","flex-negative","flex-order","grid-row","grid-row-end","grid-row-span","grid-row-start","grid-column","grid-column-end","grid-column-span","grid-column-start","font-weight","line-clamp","line-height","opacity","order","orphans","tab-size","widows","z-index","zoom","fill-opacity","flood-opacity","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-miterlimit","stroke-opacity","stroke-width"]),p=new Map;function d(t){const e=p.get(t);if(void 0!==e)return e;const n=t.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,"");return p.size>=2e3&&p.clear(),p.set(t,n),n}function y(t){if(!t||"object"!=typeof t)return"";let e="";for(const n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const r=d(n);let o=t[n];"number"!=typeof o||h.has(r)||(o+="px"),e&&(e+=";"),e+=r+":"+o}return e}var w=new Set(["href","src","xlink:href","action","formaction"]),m=[];function useCtx(){const t=m[m.length-1];if(!t)throw new Error("useCtx() must be called synchronously at the top of a component (before any await). It is not available after an await, nor outside a render.");return t}async function renderToString(t,e){if(void 0===e&&(e=m[m.length-1]),null==t||"boolean"==typeof t)return"";const n=typeof t;if("string"===n)return s(t);if("number"===n)return s(String(t));if("object"===n&&"function"==typeof t.then)return renderToString(await t,e);if(Array.isArray(t)){let n="";for(let r=0;r<t.length;r++)n+=await renderToString(t[r],e);return n}if(!t.__isJSX)return s(String(t));const{type:r,props:h,children:p}=t;if(r===Fragment){let t="";for(let n=0;n<p.length;n++)t+=await renderToString(p[n],e);return t}if("symbol"==typeof r)return"";if("function"==typeof r){let t;if(e){m.push(e);try{t=r({...h,children:p})}finally{m.pop()}}else t=r({...h,children:p});return renderToString(await t,e)}if("string"!=typeof r||!function(t){const e=t.length;if(0===e||!i(t.charCodeAt(0)))return!1;for(let n=1;n<e;n++){const e=t.charCodeAt(n);if(!i(e)&&!c(e)&&45!==e)return!1}return!0}(r))return"";const d=u.has(r);let g="";for(const t in h){if(!Object.prototype.hasOwnProperty.call(h,t))continue;if("children"===t||"key"===t||"ref"===t)continue;const e=h[t];if(null==e||!1===e)continue;if("dangerouslySetInnerHTML"===t)continue;let n=t;if("className"===t||"class"===t?n="class":"htmlFor"!==t&&"for"!==t||(n="for"),o(n)&&!l(n)&&a(n)){if(w.has(n)){const t=String(e).replace(/[\u0000-\u0020]/g,"").toLowerCase();if(t.startsWith("javascript:")||t.startsWith("vbscript:")||t.startsWith("data:text/html"))continue}if(f.has(n))!0===e&&(g+=" "+n);else if(!0!==e){if("style"===n&&"object"==typeof e){const t=y(e);t&&(g+=' style="'+s(t)+'"');continue}g+=" "+n+'="'+s(String(e))+'"'}else g+=" "+n+'="true"'}}let b="";const S=h.dangerouslySetInnerHTML;if(S&&null!=S.__html)b=S.__html;else for(let t=0;t<p.length;t++)b+=await renderToString(p[t],e);return d?"<"+r+g+"/>":"<"+r+g+">"+b+"</"+r+">"}var g=Object.freeze([["X-Content-Type-Options","nosniff"],["X-Frame-Options","DENY"],["Referrer-Policy","strict-origin-when-cross-origin"],["Permissions-Policy","geolocation=(), microphone=(), camera=()"]]),b=Object.freeze(Object.create(null)),Context=class{constructor(t,e,n={},r=null){this.req=t,this.env=e,this.params=n,this.status=200,this.headers=new Headers(g),this.t=null,this.url=r||new URL(t.url)}o(){if(null!==this.t)return this.t;const t=this.req.headers.get("Cookie");if(!t)return this.t=b,b;const e=Object.create(null);let n=0;const r=t.length;for(;n<r;){let s=t.indexOf(";",n);-1===s&&(s=r);let i=n,c=s;for(;i<c&&32===t.charCodeAt(i);)i++;for(;c>i&&32===t.charCodeAt(c-1);)c--;if(c>i){const n=t.indexOf("=",i);if(n>i&&n<c)try{const r=decodeURIComponent(t.slice(i,n));o(r)&&(e[r]=decodeURIComponent(t.slice(n+1,c)))}catch{}}n=s+1}return this.t=e,e}getCookie(t){const e=this.o()[t];return void 0===e?null:e}get query(){return this.url.searchParams}setCookie(t,e,n={}){if("string"!=typeof t||!o(t)||/[\r\n;=]/.test(t))return;let r=encodeURIComponent(t)+"="+encodeURIComponent(e);n.path&&(r+="; Path="+n.path),n.domain&&(r+="; Domain="+n.domain),void 0!==n.maxAge&&(r+="; Max-Age="+n.maxAge),n.expires&&(r+="; Expires="+n.expires.toUTCString()),n.secure&&(r+="; Secure"),n.httpOnly&&(r+="; HttpOnly"),n.sameSite&&(r+="; SameSite="+n.sameSite),this.headers.append("Set-Cookie",r)}deleteCookie(t,e={}){this.setCookie(t,"",{...e,maxAge:0,expires:new Date(0)})}i(t){if(!t)return this.headers;const e=Object.keys(t);if(0===e.length)return this.headers;const n=new Headers(this.headers);for(let r=0;r<e.length;r++)n.set(e[r],t[e[r]]);return n}text(t,e=this.status,n={}){const r=this.i(n);return r.has("Content-Type")||r.set("Content-Type","text/plain; charset=utf-8"),new Response(t,{status:e,headers:r})}json(t,e=this.status,n={}){const r=this.i(n);return r.has("Content-Type")||r.set("Content-Type","application/json; charset=utf-8"),new Response(JSON.stringify(t),{status:e,headers:r})}async html(t,e=this.status,n={}){const r=this.i(n);let o;return r.has("Content-Type")||r.set("Content-Type","text/html; charset=utf-8"),o="string"==typeof t?t:t&&t.__isJSX||Array.isArray(t)?await renderToString(t,this):null==t?"":String(t),new Response(o,{status:e,headers:r})}async page(t,e=this.status,n={}){const r=this.i(n);let o;return r.has("Content-Type")||r.set("Content-Type","text/html; charset=utf-8"),o="string"==typeof t?t:t&&t.__isJSX||Array.isArray(t)?await renderToString(t,this):null==t?"":String(t),/^\s*<!doctype\s/i.test(o)||(o="<!DOCTYPE html>"+o),new Response(o,{status:e,headers:r})}redirect(t,e=302){const n=new Headers(this.headers);return n.set("Location",String(t)),n.delete("Content-Type"),new Response(null,{status:e,headers:n})}},S=class{constructor(){this.children=null,this.paramChild=null,this.handler=null}},C=class{constructor(){this.root=new S}add(t,e){let n=this.root;const r=[];for(let e=0;e<t.length;e++){const s=t[e];if(58===s.charCodeAt(0)){const t=s.slice(1);r.push(o(t)?t:"_p"+e),n.paramChild||(n.paramChild=new S),n=n.paramChild}else{n.children||(n.children=new Map);let t=n.children.get(s);t||(t=new S,n.children.set(s,t)),n=t}}n.handler={handler:e,paramNames:r}}match(t){const e=[],n=this.l(this.root,t,0,e);if(!n)return null;const{handler:r,paramNames:o}=n,s=Object.create(null);for(let t=0;t<o.length;t++)s[o[t]]=e[t];return{handler:r,params:s}}l(t,e,n,r){if(n===e.length)return t.handler;const o=e[n],s=t.children;if(s){const t=s.get(o);if(t){const o=this.l(t,e,n+1,r);if(o)return o}}const i=t.paramChild;if(i){r.push(o);const t=this.l(i,e,n+1,r);if(t)return t;r.pop()}return null}},x=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD"],Edge=class r{constructor(t=""){this.prefix=t&&"/"!==t?e(t):"",this.staticRoutes=new Map;for(let t=0;t<x.length;t++)this.staticRoutes.set(x[t],new Map);this.dynamicTries={};for(let t=0;t<x.length;t++)this.dynamicTries[x[t]]=new C;this.u=[],this.scheduledHandler=null,this.notFoundHandler=null,this.errorHandler=null}set routes(t){const e=Array.isArray(t)?t:t?[t]:[];for(let t=0;t<e.length;t++){const n=e[t];if(!(n instanceof r))throw new Error("app.routes entries must be Edge instances");this.h(n)}}h(t){const e=t.u,r=this.prefix;for(let t=0;t<e.length;t++){const o=e[t],s=n(r,o.path);this.u.push({method:o.method,path:s,handler:o.handler}),this.p(o.method,s,o.handler)}}m(t,e,r,o){if("function"==typeof r&&(o=r),"function"!=typeof o)throw new Error("Handler for "+t+" "+e+" must be a function");const s=n(this.prefix,e);this.u.push({method:t,path:s,handler:o}),this.p(t,s,o)}p(e,n,r){-1===n.indexOf(":")?this.staticRoutes.get(e).set(n,r):this.dynamicTries[e].add(t(n),r)}get(t,e,n){this.m("GET",t,e,n)}post(t,e,n){this.m("POST",t,e,n)}put(t,e,n){this.m("PUT",t,e,n)}delete(t,e,n){this.m("DELETE",t,e,n)}patch(t,e,n){this.m("PATCH",t,e,n)}options(t,e,n){this.m("OPTIONS",t,e,n)}head(t,e,n){this.m("HEAD",t,e,n)}scheduled(t){this.scheduledHandler=t}notFound(t){if("function"!=typeof t)throw new Error("notFound(handler) requires a function");this.notFoundHandler=t}onError(t){if("function"!=typeof t)throw new Error("onError(handler) requires a function");this.errorHandler=t}S(t,e){const n=new Headers(e.headers);t.headers.forEach((t,e)=>{"set-cookie"!==e.toLowerCase()&&(n.has(e)||n.set(e,t))});const r="function"==typeof t.headers.getSetCookie?t.headers.getSetCookie():t.headers.get("Set-Cookie")?[t.headers.get("Set-Cookie")]:[];if(r.length){const t="function"==typeof n.getSetCookie?n.getSetCookie():n.get("Set-Cookie")?[n.get("Set-Cookie")]:[],e=new Set(t);for(let t=0;t<r.length;t++){const o=r[t];e.has(o)||(n.append("Set-Cookie",o),e.add(o))}}const o=204===e.status||304===e.status?null:e.body;return new Response(o,{status:e.status,statusText:e.statusText,headers:n})}async fetch(n,r){const o=new URL(n.url),s=e(o.pathname),i=n.method,c=this.staticRoutes.get(i);if(c){const t=c.get(s);if(t)return this.C(t,n,r,Object.create(null),o)}const a=this.dynamicTries[i];if(a){const e=a.match(t(s));if(e)return this.C(e.handler,n,r,e.params,o)}if("OPTIONS"===i){const t=new Context(n,r,Object.create(null),o);return this.S(t,new Response(null,{status:204}))}if(this.notFoundHandler)return this.C(this.notFoundHandler,n,r,Object.create(null),o);const l=new Context(n,r,Object.create(null),o);return this.S(l,new Response("Not Found",{status:404}))}async O(t,e){const n=this.errorHandler;if(!n)return t.text("Internal Server Error",500);try{const r=await n(t,e);return r instanceof Response?this.S(t,r):r&&r.__isJSX||Array.isArray(r)?t.html(r,500):t.text("Internal Server Error",500)}catch{return t.text("Internal Server Error",500)}}async C(t,e,n,r,o){const s=new Context(e,n,r,o);let i;try{const e=await t(s);i=e instanceof Response?this.S(s,e):e&&e.__isJSX?await s.html(e):s.text("OK")}catch(t){i=await this.O(s,t)}return i}},O=Edge;export{Context,Edge,Fragment,O as default,jsx,renderToString,useCtx};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lengkapp/edge",
3
- "version": "0.0.50",
3
+ "version": "0.0.52",
4
4
  "description": "Edge framework used by Lengkapp",
5
5
  "main": "dist/edge-server.js",
6
6
  "types": "dist/edge-server.d.ts",