@lengkapp/edge 0.0.56 → 0.0.57
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/LICENSE +27 -27
- package/dist/LICENSE +27 -27
- package/dist/edge-client.js +1 -1
- package/dist/edge-server.d.ts +27 -27
- package/dist/edge-server.js +2 -2
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
LengkApp License
|
|
2
|
-
|
|
3
|
-
Copyright (c) LengkApp — Yasir Haris
|
|
4
|
-
Contact: yh@lengk.app / yasir.haris@gmail.com
|
|
5
|
-
|
|
6
|
-
Permission is granted to any person obtaining a copy of this software
|
|
7
|
-
and associated documentation files (the "Software") to use, copy, and
|
|
8
|
-
distribute the Software free of charge, for any purpose, including
|
|
9
|
-
commercial use, subject to the following conditions:
|
|
10
|
-
|
|
11
|
-
1. The Software may not be modified, adapted, or altered in any way
|
|
12
|
-
without prior written permission from the copyright holder.
|
|
13
|
-
|
|
14
|
-
2. Redistribution of the Software, in whole or in part, must retain
|
|
15
|
-
this LICENSE file unmodified and include the copyright notice above.
|
|
16
|
-
|
|
17
|
-
3. This permission notice does not grant any right to use the
|
|
18
|
-
LengkApp name, brand, or trademarks without separate written
|
|
19
|
-
permission.
|
|
20
|
-
|
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
22
|
-
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
23
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
24
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE
|
|
25
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
27
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
LengkApp License
|
|
2
|
+
|
|
3
|
+
Copyright (c) LengkApp — Yasir Haris
|
|
4
|
+
Contact: yh@lengk.app / yasir.haris@gmail.com
|
|
5
|
+
|
|
6
|
+
Permission is granted to any person obtaining a copy of this software
|
|
7
|
+
and associated documentation files (the "Software") to use, copy, and
|
|
8
|
+
distribute the Software free of charge, for any purpose, including
|
|
9
|
+
commercial use, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
1. The Software may not be modified, adapted, or altered in any way
|
|
12
|
+
without prior written permission from the copyright holder.
|
|
13
|
+
|
|
14
|
+
2. Redistribution of the Software, in whole or in part, must retain
|
|
15
|
+
this LICENSE file unmodified and include the copyright notice above.
|
|
16
|
+
|
|
17
|
+
3. This permission notice does not grant any right to use the
|
|
18
|
+
LengkApp name, brand, or trademarks without separate written
|
|
19
|
+
permission.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
22
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
23
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
24
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE
|
|
25
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
27
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/LICENSE
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
LengkApp License
|
|
2
|
-
|
|
3
|
-
Copyright (c) LengkApp — Yasir Haris
|
|
4
|
-
Contact: yh@lengk.app / yasir.haris@gmail.com
|
|
5
|
-
|
|
6
|
-
Permission is granted to any person obtaining a copy of this software
|
|
7
|
-
and associated documentation files (the "Software") to use, copy, and
|
|
8
|
-
distribute the Software free of charge, for any purpose, including
|
|
9
|
-
commercial use, subject to the following conditions:
|
|
10
|
-
|
|
11
|
-
1. The Software may not be modified, adapted, or altered in any way
|
|
12
|
-
without prior written permission from the copyright holder.
|
|
13
|
-
|
|
14
|
-
2. Redistribution of the Software, in whole or in part, must retain
|
|
15
|
-
this LICENSE file unmodified and include the copyright notice above.
|
|
16
|
-
|
|
17
|
-
3. This permission notice does not grant any right to use the
|
|
18
|
-
LengkApp name, brand, or trademarks without separate written
|
|
19
|
-
permission.
|
|
20
|
-
|
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
22
|
-
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
23
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
24
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE
|
|
25
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
27
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
LengkApp License
|
|
2
|
+
|
|
3
|
+
Copyright (c) LengkApp — Yasir Haris
|
|
4
|
+
Contact: yh@lengk.app / yasir.haris@gmail.com
|
|
5
|
+
|
|
6
|
+
Permission is granted to any person obtaining a copy of this software
|
|
7
|
+
and associated documentation files (the "Software") to use, copy, and
|
|
8
|
+
distribute the Software free of charge, for any purpose, including
|
|
9
|
+
commercial use, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
1. The Software may not be modified, adapted, or altered in any way
|
|
12
|
+
without prior written permission from the copyright holder.
|
|
13
|
+
|
|
14
|
+
2. Redistribution of the Software, in whole or in part, must retain
|
|
15
|
+
this LICENSE file unmodified and include the copyright notice above.
|
|
16
|
+
|
|
17
|
+
3. This permission notice does not grant any right to use the
|
|
18
|
+
LengkApp name, brand, or trademarks without separate written
|
|
19
|
+
permission.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
22
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
23
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
24
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE
|
|
25
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
27
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/edge-client.js
CHANGED
package/dist/edge-server.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @lengkapp/edge v0.0.
|
|
2
|
+
* @lengkapp/edge v0.0.57
|
|
3
3
|
* MIT License
|
|
4
4
|
*
|
|
5
|
-
* LengkApp License
|
|
6
|
-
*
|
|
7
|
-
* Copyright (c) LengkApp — Yasir Haris
|
|
8
|
-
* Contact: yh@lengk.app / yasir.haris@gmail.com
|
|
9
|
-
*
|
|
10
|
-
* Permission is granted to any person obtaining a copy of this software
|
|
11
|
-
* and associated documentation files (the "Software") to use, copy, and
|
|
12
|
-
* distribute the Software free of charge, for any purpose, including
|
|
13
|
-
* commercial use, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* 1. The Software may not be modified, adapted, or altered in any way
|
|
16
|
-
* without prior written permission from the copyright holder.
|
|
17
|
-
*
|
|
18
|
-
* 2. Redistribution of the Software, in whole or in part, must retain
|
|
19
|
-
* this LICENSE file unmodified and include the copyright notice above.
|
|
20
|
-
*
|
|
21
|
-
* 3. This permission notice does not grant any right to use the
|
|
22
|
-
* LengkApp name, brand, or trademarks without separate written
|
|
23
|
-
* permission.
|
|
24
|
-
*
|
|
25
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
26
|
-
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
27
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
28
|
-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE
|
|
29
|
-
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
30
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
5
|
+
* LengkApp License
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) LengkApp — Yasir Haris
|
|
8
|
+
* Contact: yh@lengk.app / yasir.haris@gmail.com
|
|
9
|
+
*
|
|
10
|
+
* Permission is granted to any person obtaining a copy of this software
|
|
11
|
+
* and associated documentation files (the "Software") to use, copy, and
|
|
12
|
+
* distribute the Software free of charge, for any purpose, including
|
|
13
|
+
* commercial use, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* 1. The Software may not be modified, adapted, or altered in any way
|
|
16
|
+
* without prior written permission from the copyright holder.
|
|
17
|
+
*
|
|
18
|
+
* 2. Redistribution of the Software, in whole or in part, must retain
|
|
19
|
+
* this LICENSE file unmodified and include the copyright notice above.
|
|
20
|
+
*
|
|
21
|
+
* 3. This permission notice does not grant any right to use the
|
|
22
|
+
* LengkApp name, brand, or trademarks without separate written
|
|
23
|
+
* permission.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
26
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
27
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
28
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE
|
|
29
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
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
33
|
/* ------------------------------------------------------------------ *
|
package/dist/edge-server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @lengkapp/edge v0.0.
|
|
2
|
+
* @lengkapp/edge v0.0.57
|
|
3
3
|
* MIT License
|
|
4
4
|
*
|
|
5
5
|
* LengkApp 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 t(t){const e=[],n=t.length;let r=1;for(let s=1;s<=n;s++)s!==n&&47!==t.charCodeAt(s)||(s>r&&e.push(t.slice(r,s)),r=s+1);return e}function e(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 s;s=47===n?47===r?t+e.slice(1):t+e:47===r?t+e:t+"/"+e;const o=s.length;return o>1&&47===s.charCodeAt(o-1)?s.slice(0,-1):s}var n=new Set(["__proto__","constructor","prototype"]);function r(t){return"string"==typeof t&&!n.has(t)}function s(){return{s:null,h:null,p:null,w:null}}function o(t,e=[]){const n=/\/:(\w+)\?/.exec(t);return n?(o(t.replace(n[0],"/:"+n[1]),e),o(t.replace(n[0],""),e),e):(e.push(t),e)}function i(t){let e=0,n=t.length;for(;e<n&&47===t.charCodeAt(e);)e++;for(;n>e&&47===t.charCodeAt(n-1);)n--;return e>=n?"/":"/"+t.slice(e,n)}function l(t){if(t.indexOf("%")<0)return t;try{return decodeURIComponent(t)}catch{return t}}function u(t,e){return t[e]??t["*"]??("HEAD"===e?t.GET:void 0)}function c(){const t=new Map,e={s:null,h:null,p:null,w:null},n=[];function r(t,e,s,o,i){for(;s<o&&47===e.charCodeAt(s);)s++;if(s>=o)return t.h??(null!==t.w?(n[i]="",t.w.h):null);let l=e.indexOf("/",s);l<0&&(l=o);const u=t.s;if(null!==u){const t=u.get(e.slice(s,l));if(void 0!==t){const n=r(t,e,l,o,i);if(n)return n}}if(null!==t.p){const u=r(t.p,e,l,o,i+1);if(u)return n[i]=e.slice(s,l),u}return null!==t.w?(n[i]=e.slice(s),t.w.h):null}return{add:function(n,r,l){const u=o(r);for(let o=0;o<u.length;o++){const c=i(u[o]),a=c.length;let f=!1,h=1;for(;h<a;){let t=c.indexOf("/",h);if(t<0&&(t=a),t>h){const e=c.charCodeAt(h);if(42===e){if(t-h!==1||t!==a)throw new Error("Wildcard must be terminal: "+r);f=!0}else 58===e&&(f=!0)}h=t+1}if(!f){let e=t.get(c);void 0===e&&t.set(c,e=Object.create(null)),e[n]={handler:l,keys:null};continue}const p=[];let d=e,w=1;for(;w<a;){let t=c.indexOf("/",w);if(t<0&&(t=a),t>w){const e=c.charCodeAt(w);if(42===e&&t-w===1){p.push("*"),d=d.w??=s();break}if(58===e)p.push(c.slice(w+1,t)),d=d.p??=s();else{const e=c.slice(w,t),n=d.s??=new Map;let r=n.get(e);void 0===r&&(r=s(),n.set(e,r)),d=r}}w=t+1}(d.h??=Object.create(null))[n]={handler:l,keys:p}}},match:function(s,o){const i=function(t){const e=t.length;let n;if(47===t.charCodeAt(0))n=0;else{const e=115===t.charCodeAt(4)?8:7;n=47===t.charCodeAt(e-1)&&47===t.charCodeAt(e-2)?t.indexOf("/",e):t.indexOf("/",t.indexOf("://")+3)}if(n<0)return"/";const r=t.indexOf("?",n),s=r<0?e:r;let o=t.slice(n,s),i=o.length;for(;i>1&&47===o.charCodeAt(i-1);)i--;return i===o.length?o:o.slice(0,i)}(o),c=t.get(i);if(void 0!==c){const t=u(c,s);return void 0===t?null:{handler:t.handler,params:null}}const a=r(e,i,0,i.length,0);if(null===a)return null;const f=u(a,s);if(void 0===f)return null;let h=null;if(null!==f.keys){h=Object.create(null);for(let t=0;t<f.keys.length;t++)h[f.keys[t]]=l(n[t])}return{handler:f.handler,params:h}}}}function a(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),s=n;for(;n<e;n++){const e=t.charCodeAt(n);let o;if(38===e)o="&";else if(60===e)o="<";else if(62===e)o=">";else if(34===e)o=""";else{if(39!==e)continue;o="'"}n>s&&(r+=t.slice(s,n)),r+=o,s=n+1}return s<e&&(r+=t.slice(s)),r}function f(t){return t>=65&&t<=90||t>=97&&t<=122}function h(t){return t>=48&&t<=57}function p(t){const e=t.length;if(0===e)return!1;const n=t.charCodeAt(0);if(!f(n)&&95!==n&&58!==n)return!1;for(let n=1;n<e;n++){const e=t.charCodeAt(n);if(!f(e)&&!h(e)&&95!==e&&58!==e&&46!==e&&45!==e)return!1}return!0}function d(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 w=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),y=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"]),m=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"]),g=new Map;function b(t){const e=g.get(t);if(void 0!==e)return e;const n=t.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,"");return g.size>=2e3&&g.clear(),g.set(t,n),n}function S(t){if(!t||"object"!=typeof t)return"";let e="";for(const n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const r=b(n);let s=t[n];"number"!=typeof s||m.has(r)||(s+="px"),e&&(e+=";"),e+=r+":"+s}return e}var T=new Set(["href","src","xlink:href","action","formaction"]),x=[];function useCtx(){const t=x[x.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=x[x.length-1]),null==t||"boolean"==typeof t)return"";const n=typeof t;if("string"===n)return a(t);if("number"===n)return a(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 a(String(t));const{type:s,props:o,children:i}=t;if(s===Fragment){let t="";for(let n=0;n<i.length;n++)t+=await renderToString(i[n],e);return t}if("symbol"==typeof s)return"";if("function"==typeof s){let t;if(e){x.push(e);try{t=s({...o,children:i})}finally{x.pop()}}else t=s({...o,children:i});return renderToString(await t,e)}if("string"!=typeof s||!function(t){const e=t.length;if(0===e||!f(t.charCodeAt(0)))return!1;for(let n=1;n<e;n++){const e=t.charCodeAt(n);if(!f(e)&&!h(e)&&45!==e)return!1}return!0}(s))return"";const l=w.has(s);let u="";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"),r(n)&&!d(n)&&p(n)){if(T.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(y.has(n))!0===e&&(u+=" "+n);else if(!0!==e){if("style"===n&&"object"==typeof e){const t=S(e);t&&(u+=' style="'+a(t)+'"');continue}u+=" "+n+'="'+a(String(e))+'"'}else u+=" "+n+'="true"'}}let c="";const m=o.dangerouslySetInnerHTML;if(m&&null!=m.__html)c=m.__html;else for(let t=0;t<i.length;t++)c+=await renderToString(i[t],e);return l?"<"+s+u+"/>":"<"+s+u+">"+c+"</"+s+">"}var C=Object.freeze([["X-Content-Type-Options","nosniff"],["X-Frame-Options","DENY"],["Referrer-Policy","strict-origin-when-cross-origin"],["Permissions-Policy","geolocation=(), microphone=(), camera=()"]]),v=new Headers(C),R=Object.freeze(Object.create(null)),k=Symbol("edge.sealed"),O=new Headers(C.concat([["Content-Type","application/json; charset=utf-8"]])),E=new Headers(C.concat([["Content-Type","text/html; charset=utf-8"]])),j=new Headers(C.concat([["Content-Type","text/plain;charset=UTF-8"]])),H=new Map([["text/plain;charset=UTF-8",j],["application/json",new Headers(C.concat([["Content-Type","application/json"]]))],["application/json; charset=utf-8",O],["text/html; charset=utf-8",E]]),_=Object.freeze({});function P(t){if(null==t||t===_)return!1;for(const e in t)return!0;return!1}var Context=class{constructor(t,e,n=null,r=null,s=null){this.req=t,this.env=e,this.ctx=s,this.executionCtx=s,this.t=n,this.status=200,this.o=null,this.i=0,this.l=null,this.u=r||null,this.m=null}get params(){return null===this.t&&(this.t=Object.create(null)),this.t}set params(t){this.t=t}get headers(){return null===this.o&&(this.o=new Headers(C),this.i++),this.o}set headers(t){this.o=t,this.i++}get url(){return null===this.u&&(this.u=new URL(this.req.url)),this.u}set url(t){this.u=t,this.m=null}S(t){return t[k]=this.i,t}T(){if(null!==this.l)return this.l;const t=this.req.headers.get("Cookie");if(!t)return this.l=R,R;const e=Object.create(null);let n=0;const s=t.length;for(;n<s;){let o=t.indexOf(";",n);-1===o&&(o=s);let i=n,l=o;for(;i<l&&32===t.charCodeAt(i);)i++;for(;l>i&&32===t.charCodeAt(l-1);)l--;if(l>i){const n=t.indexOf("=",i);if(n>i&&n<l){const s=t.slice(i,n),o=t.slice(n+1,l);try{const t=s.indexOf("%")<0?s:decodeURIComponent(s);r(t)&&(e[t]=o.indexOf("%")<0?o:decodeURIComponent(o))}catch{}}}n=o+1}return this.l=e,e}getCookie(t){const e=this.T()[t];return void 0===e?null:e}get query(){if(null!==this.u)return this.u.searchParams;if(null===this.m){const t=this.req.url,e=t.indexOf("?");this.m=new URLSearchParams(e<0?"":t.slice(e+1))}return this.m}waitUntil(t){return this.ctx&&"function"==typeof this.ctx.waitUntil&&this.ctx.waitUntil(t),t}passThroughOnException(){this.ctx&&"function"==typeof this.ctx.passThroughOnException&&this.ctx.passThroughOnException()}setCookie(t,e,n={}){if("string"!=typeof t||!r(t)||/[\r\n;=]/.test(t))return;let s=encodeURIComponent(t)+"="+encodeURIComponent(e);n.path&&(s+="; Path="+n.path),n.domain&&(s+="; Domain="+n.domain),void 0!==n.maxAge&&(s+="; Max-Age="+n.maxAge),n.expires&&(s+="; Expires="+n.expires.toUTCString()),n.secure&&(s+="; Secure"),n.httpOnly&&(s+="; HttpOnly"),n.sameSite&&(s+="; SameSite="+n.sameSite),this.headers.append("Set-Cookie",s)}deleteCookie(t,e={}){this.setCookie(t,"",{...e,maxAge:0,expires:new Date(0)})}C(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}async v(t){return"string"==typeof t?t:t&&t.__isJSX||Array.isArray(t)?renderToString(t,this):null==t?"":String(t)}text(t,e=this.status,n){if(null===this.o&&!P(n))return this.S(new Response(t,{status:e,headers:j}));const r=this.C(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){if(null===this.o&&!P(n))return this.S(new Response(JSON.stringify(t),{status:e,headers:O}));const r=this.C(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){if(null===this.o&&!P(n)){const n=await this.v(t);return this.S(new Response(n,{status:e,headers:E}))}const r=this.C(n||_);return r.has("Content-Type")||r.set("Content-Type","text/html; charset=utf-8"),new Response(await this.v(t),{status:e,headers:r})}async page(t,e=this.status,n){let r=await this.v(t);if(/^\s*<!doctype\s/i.test(r)||(r="<!DOCTYPE html>"+r),null===this.o&&!P(n))return this.S(new Response(r,{status:e,headers:E}));const s=this.C(n||_);return s.has("Content-Type")||s.set("Content-Type","text/html; charset=utf-8"),new Response(r,{status:e,headers:s})}redirect(t,e=302){if(null===this.o)return this.S(new Response(null,{status:e,headers:C.concat([["Location",String(t)]])}));const n=new Headers(this.headers);return n.set("Location",String(t)),n.delete("Content-Type"),new Response(null,{status:e,headers:n})}},A=class{constructor(){this.children=null,this.paramChild=null,this.handler=null,this.wildcardHandler=null}},I=class{constructor(){this.root=new A}add(t,e){let n=this.root;const s=[];for(let o=0;o<t.length;o++){const i=t[o];if("*"===i)return void(n.wildcardHandler={handler:e,paramNames:s.slice()});if(58===i.charCodeAt(0)){const t=i.slice(1);s.push(r(t)?t:"_p"+o),n.paramChild||(n.paramChild=new A),n=n.paramChild}else{n.children||(n.children=new Map);let t=n.children.get(i);t||(t=new A,n.children.set(i,t)),n=t}}n.handler={handler:e,paramNames:s}}match(t){const e=[],n=this.R(this.root,t,0,e);if(!n)return null;const{handler:r,paramNames:s}=n,o=Object.create(null);for(let t=0;t<s.length;t++)o[s[t]]=e[t];return{handler:r,params:o}}R(t,e,n,r){if(n===e.length)return t.handler||t.wildcardHandler;const s=e[n],o=t.children;if(o){const t=o.get(s);if(t){const s=this.R(t,e,n+1,r);if(s)return s}}const i=t.paramChild;if(i){r.push(s);const t=this.R(i,e,n+1,r);if(t)return t;r.pop()}return t.wildcardHandler?t.wildcardHandler:null}},U=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD"];function N(t){return-1===t.indexOf(":")&&-1===t.indexOf("*")}var Edge=class n{constructor(t=""){this.prefix=t&&"/"!==t?function(t){const e=t.length;return e>1&&47===t.charCodeAt(e-1)?t.slice(0,-1):t}(t):"",this.k=c(),this.O=null,this.j=null,this.H=[],this.scheduledHandler=null,this.notFoundHandler=null,this.errorHandler=null}get staticRoutes(){if(null===this.O){const t=new Map;for(let e=0;e<U.length;e++)t.set(U[e],new Map);for(let e=0;e<this.H.length;e++){const n=this.H[e];if(!N(n.path))continue;const r=t.get(n.method);r&&r.set(n.path,n.handler)}this.O=t}return this.O}get dynamicTries(){if(null===this.j){const e={};for(let t=0;t<U.length;t++)e[U[t]]=new I;for(let n=0;n<this.H.length;n++){const r=this.H[n];if(N(r.path))continue;const s=e[r.method];s&&s.add(t(r.path),r.handler)}this.j=e}return this.j}set routes(t){const e=Array.isArray(t)?t:t?[t]:[];for(let t=0;t<e.length;t++){const r=e[t];if(!(r instanceof n))throw new Error("app.routes entries must be Edge instances");this._(r)}}_(t){const n=t.H,r=this.prefix;for(let t=0;t<n.length;t++){const s=n[t],o=e(r,s.path);this.P(s.method,o,s.handler),this.H.push({method:s.method,path:o,handler:s.handler})}this.O=null,this.j=null}A(t,n,r,s){if("function"==typeof r&&(s=r),"function"!=typeof s)throw new Error("Handler for "+t+" "+n+" must be a function");const o=e(this.prefix,n);this.P(t,o,s),this.H.push({method:t,path:o,handler:s}),this.O=null,this.j=null}P(t,e,n){this.k.add(t,e,n)}I(t,e,n){const r=new Context(t,e,null,null,n);return"OPTIONS"===t.method?this.U(r,new Response(null,{status:204})):this.notFoundHandler?this.N(this.notFoundHandler,t,e,null,null,n):this.U(r,new Response("Not Found",{status:404}))}get(t,e,n){this.A("GET",t,e,n)}post(t,e,n){this.A("POST",t,e,n)}put(t,e,n){this.A("PUT",t,e,n)}delete(t,e,n){this.A("DELETE",t,e,n)}patch(t,e,n){this.A("PATCH",t,e,n)}options(t,e,n){this.A("OPTIONS",t,e,n)}head(t,e,n){this.A("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}U(t,e){const n=e[k];if(void 0!==n&&n===t.i)return e;const r=t.o;if(null===r&&null===e.headers.get("set-cookie")){if(e.webSocket){const t=new Headers(v);return e.headers.forEach((e,n)=>t.set(n,e)),new Response(null,{status:101,webSocket:e.webSocket,headers:t})}let t=0,n=null;if(e.headers.forEach((e,r)=>{t++,"content-type"===r&&(n=e)}),0===t)return new Response(e.body,{status:e.status,statusText:e.statusText,headers:v});if(1===t){const t=H.get(n);if(void 0!==t){const n=204===e.status||304===e.status?null:e.body;return new Response(n,{status:e.status,statusText:e.statusText,headers:t})}}const r=new Headers(v);e.headers.forEach((t,e)=>r.set(e,t));const s=204===e.status||304===e.status?null:e.body;return new Response(s,{status:e.status,statusText:e.statusText,headers:r})}const s=new Headers(e.headers);if(null!==r){r.forEach((t,e)=>{"set-cookie"!==e.toLowerCase()&&(s.has(e)||s.set(e,t))});const t="function"==typeof r.getSetCookie?r.getSetCookie():r.get("Set-Cookie")?[r.get("Set-Cookie")]:[];if(t.length){const e="function"==typeof s.getSetCookie?s.getSetCookie():s.get("Set-Cookie")?[s.get("Set-Cookie")]:[],n=new Set(e);for(let e=0;e<t.length;e++){const r=t[e];n.has(r)||(s.append("Set-Cookie",r),n.add(r))}}}for(let t=0;t<C.length;t++){const e=C[t];s.has(e[0])||s.set(e[0],e[1])}if(e.webSocket)return new Response(null,{status:101,webSocket:e.webSocket,headers:s});const o=204===e.status||304===e.status?null:e.body;return new Response(o,{status:e.status,statusText:e.statusText,headers:s})}fetch(t,e,n){const r=this.k.match(t.method,t.url);return null===r?this.I(t,e,n):this.N(r.handler,t,e,r.params,null,n)}async M(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.U(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)}}N(t,e,n,r,s,o){const i=new Context(e,n,r,s,o);let l;try{l=t(i)}catch(t){return this.M(i,t)}return l&&"function"==typeof l.then?l.then(t=>this.D(i,t),t=>this.M(i,t)):this.D(i,l)}D(t,e){return e instanceof Response?this.U(t,e):e&&e.__isJSX?t.html(e):t.text("OK")}},M=Edge;export{Context,Edge,Fragment,M as default,jsx,renderToString,useCtx};
|
|
33
|
+
function t(t){const e=[],n=t.length;let r=1;for(let s=1;s<=n;s++)s!==n&&47!==t.charCodeAt(s)||(s>r&&e.push(t.slice(r,s)),r=s+1);return e}function e(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 s;s=47===n?47===r?t+e.slice(1):t+e:47===r?t+e:t+"/"+e;const o=s.length;return o>1&&47===s.charCodeAt(o-1)?s.slice(0,-1):s}var n=new Set(["__proto__","constructor","prototype"]);function r(t){return"string"==typeof t&&!n.has(t)}function s(){return{s:null,h:null,p:null,w:null}}function o(t,e=[]){const n=/\/:(\w+)\?/.exec(t);return n?(o(t.replace(n[0],"/:"+n[1]),e),o(t.replace(n[0],""),e),e):(e.push(t),e)}function i(t){let e=0,n=t.length;for(;e<n&&47===t.charCodeAt(e);)e++;for(;n>e&&47===t.charCodeAt(n-1);)n--;return e>=n?"/":"/"+t.slice(e,n)}function l(t){if(t.indexOf("%")<0)return t;try{return decodeURIComponent(t)}catch{return t}}function u(t,e){return t[e]??t["*"]??("HEAD"===e?t.GET:void 0)}function c(){const t=new Map,e={s:null,h:null,p:null,w:null},n=[];function r(t,e,s,o,i){for(;s<o&&47===e.charCodeAt(s);)s++;if(s>=o)return t.h??(null!==t.w?(n[i]="",t.w.h):null);let l=e.indexOf("/",s);l<0&&(l=o);const u=t.s;if(null!==u){const t=u.get(e.slice(s,l));if(void 0!==t){const n=r(t,e,l,o,i);if(n)return n}}if(null!==t.p){const u=r(t.p,e,l,o,i+1);if(u)return n[i]=e.slice(s,l),u}return null!==t.w?(n[i]=e.slice(s),t.w.h):null}return{add:function(n,r,l){const u=o(r);for(let o=0;o<u.length;o++){const c=i(u[o]),a=c.length;let f=!1,h=1;for(;h<a;){let t=c.indexOf("/",h);if(t<0&&(t=a),t>h){const e=c.charCodeAt(h);if(42===e){if(t-h!==1||t!==a)throw new Error("Wildcard must be terminal: "+r);f=!0}else 58===e&&(f=!0)}h=t+1}if(!f){let e=t.get(c);void 0===e&&t.set(c,e=Object.create(null)),e[n]={handler:l,keys:null};continue}const p=[];let d=e,w=1;for(;w<a;){let t=c.indexOf("/",w);if(t<0&&(t=a),t>w){const e=c.charCodeAt(w);if(42===e&&t-w===1){p.push("*"),d=d.w??=s();break}if(58===e)p.push(c.slice(w+1,t)),d=d.p??=s();else{const e=c.slice(w,t),n=d.s??=new Map;let r=n.get(e);void 0===r&&(r=s(),n.set(e,r)),d=r}}w=t+1}(d.h??=Object.create(null))[n]={handler:l,keys:p}}},match:function(s,o){const i=function(t){const e=t.length;let n;if(47===t.charCodeAt(0))n=0;else{const e=115===t.charCodeAt(4)?8:7;n=47===t.charCodeAt(e-1)&&47===t.charCodeAt(e-2)?t.indexOf("/",e):t.indexOf("/",t.indexOf("://")+3)}if(n<0)return"/";const r=t.indexOf("?",n),s=r<0?e:r;let o=t.slice(n,s),i=o.length;for(;i>1&&47===o.charCodeAt(i-1);)i--;return i===o.length?o:o.slice(0,i)}(o),c=t.get(i);if(void 0!==c){const t=u(c,s);return void 0===t?null:{handler:t.handler,params:null}}const a=r(e,i,0,i.length,0);if(null===a)return null;const f=u(a,s);if(void 0===f)return null;let h=null;if(null!==f.keys){h=Object.create(null);for(let t=0;t<f.keys.length;t++)h[f.keys[t]]=l(n[t])}return{handler:f.handler,params:h}}}}function a(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),s=n;for(;n<e;n++){const e=t.charCodeAt(n);let o;if(38===e)o="&";else if(60===e)o="<";else if(62===e)o=">";else if(34===e)o=""";else{if(39!==e)continue;o="'"}n>s&&(r+=t.slice(s,n)),r+=o,s=n+1}return s<e&&(r+=t.slice(s)),r}function f(t){return t>=65&&t<=90||t>=97&&t<=122}function h(t){return t>=48&&t<=57}function p(t){const e=t.length;if(0===e)return!1;const n=t.charCodeAt(0);if(!f(n)&&95!==n&&58!==n)return!1;for(let n=1;n<e;n++){const e=t.charCodeAt(n);if(!f(e)&&!h(e)&&95!==e&&58!==e&&46!==e&&45!==e)return!1}return!0}function d(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 w=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),y=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"]),m=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"]),g=new Map;function b(t){const e=g.get(t);if(void 0!==e)return e;const n=t.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,"");return g.size>=2e3&&g.clear(),g.set(t,n),n}function S(t){if(!t||"object"!=typeof t)return"";let e="";for(const n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const r=b(n);let s=t[n];"number"!=typeof s||m.has(r)||(s+="px"),e&&(e+=";"),e+=r+":"+s}return e}var T=new Set(["href","src","xlink:href","action","formaction"]),x=[];function useCtx(){const t=x[x.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=x[x.length-1]),null==t||"boolean"==typeof t)return"";const n=typeof t;if("string"===n)return a(t);if("number"===n)return a(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 a(String(t));const{type:s,props:o,children:i}=t;if(s===Fragment){let t="";for(let n=0;n<i.length;n++)t+=await renderToString(i[n],e);return t}if("symbol"==typeof s)return"";if("function"==typeof s){let t;if(e){x.push(e);try{t=s({...o,children:i})}finally{x.pop()}}else t=s({...o,children:i});return renderToString(await t,e)}if("string"!=typeof s||!function(t){const e=t.length;if(0===e||!f(t.charCodeAt(0)))return!1;for(let n=1;n<e;n++){const e=t.charCodeAt(n);if(!f(e)&&!h(e)&&45!==e)return!1}return!0}(s))return"";const l=w.has(s);let u="";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"),r(n)&&!d(n)&&p(n)){if(T.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(y.has(n))!0===e&&(u+=" "+n);else if(!0!==e){if("style"===n&&"object"==typeof e){const t=S(e);t&&(u+=' style="'+a(t)+'"');continue}u+=" "+n+'="'+a(String(e))+'"'}else u+=" "+n+'="true"'}}let c="";const m=o.dangerouslySetInnerHTML;if(m&&null!=m.__html)c=m.__html;else for(let t=0;t<i.length;t++)c+=await renderToString(i[t],e);return l?"<"+s+u+"/>":"<"+s+u+">"+c+"</"+s+">"}var C=Object.freeze([["X-Content-Type-Options","nosniff"],["X-Frame-Options","DENY"],["Referrer-Policy","strict-origin-when-cross-origin"],["Permissions-Policy","geolocation=(), microphone=(), camera=()"]]),v=new Headers(C),R=Object.freeze(Object.create(null)),k=Symbol("edge.sealed"),O=new Headers(C.concat([["Content-Type","application/json; charset=utf-8"]])),E=new Headers(C.concat([["Content-Type","text/html; charset=utf-8"]])),j=new Headers(C.concat([["Content-Type","text/plain;charset=UTF-8"]])),H=new Map([["text/plain;charset=UTF-8",j],["application/json",new Headers(C.concat([["Content-Type","application/json"]]))],["application/json; charset=utf-8",O],["text/html; charset=utf-8",E]]),_=Object.freeze({});function P(t){if(null==t||t===_)return!1;for(const e in t)return!0;return!1}var Context=class{constructor(t,e,n=null,r=null,s=null){this.req=t,this.env=e,this.ctx=s,this.executionCtx=s,this.t=n,this.status=200,this.o=null,this.i=0,this.l=null,this.u=r||null,this.m=null}get params(){return null===this.t&&(this.t=Object.create(null)),this.t}set params(t){this.t=t}get headers(){return null===this.o&&(this.o=new Headers(C),this.i++),this.o}set headers(t){this.o=t,this.i++}get url(){return null===this.u&&(this.u=new URL(this.req.url)),this.u}set url(t){this.u=t,this.m=null}S(t){return t[k]=this.i,t}T(){if(null!==this.l)return this.l;const t=this.req.headers.get("Cookie");if(!t)return this.l=R,R;const e=Object.create(null);let n=0;const s=t.length;for(;n<s;){let o=t.indexOf(";",n);-1===o&&(o=s);let i=n,l=o;for(;i<l&&32===t.charCodeAt(i);)i++;for(;l>i&&32===t.charCodeAt(l-1);)l--;if(l>i){const n=t.indexOf("=",i);if(n>i&&n<l){const s=t.slice(i,n),o=t.slice(n+1,l);try{const t=s.indexOf("%")<0?s:decodeURIComponent(s);r(t)&&(e[t]=o.indexOf("%")<0?o:decodeURIComponent(o))}catch{}}}n=o+1}return this.l=e,e}getCookie(t){const e=this.T()[t];return void 0===e?null:e}get query(){if(null!==this.u)return this.u.searchParams;if(null===this.m){const t=this.req.url,e=t.indexOf("?");this.m=new URLSearchParams(e<0?"":t.slice(e+1))}return this.m}waitUntil(t){return this.ctx&&"function"==typeof this.ctx.waitUntil&&this.ctx.waitUntil(t),t}passThroughOnException(){this.ctx&&"function"==typeof this.ctx.passThroughOnException&&this.ctx.passThroughOnException()}setCookie(t,e,n={}){if("string"!=typeof t||!r(t)||/[\r\n;=]/.test(t))return;let s=encodeURIComponent(t)+"="+encodeURIComponent(e);n.path&&(s+="; Path="+n.path),n.domain&&(s+="; Domain="+n.domain),void 0!==n.maxAge&&(s+="; Max-Age="+n.maxAge),n.expires&&(s+="; Expires="+n.expires.toUTCString()),n.secure&&(s+="; Secure"),n.httpOnly&&(s+="; HttpOnly"),n.sameSite&&(s+="; SameSite="+n.sameSite),this.headers.append("Set-Cookie",s)}deleteCookie(t,e={}){this.setCookie(t,"",{...e,maxAge:0,expires:new Date(0)})}C(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}async v(t){return"string"==typeof t?t:t&&t.__isJSX||Array.isArray(t)?renderToString(t,this):null==t?"":String(t)}text(t,e=this.status,n){if(null===this.o&&!P(n))return this.S(new Response(t,{status:e,headers:j}));const r=this.C(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){if(null===this.o&&!P(n))return this.S(new Response(JSON.stringify(t),{status:e,headers:O}));const r=this.C(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=await this.v(t);if(null===this.o&&!P(n))return this.S(new Response(r,{status:e,headers:E}));const s=this.C(n||_);return s.has("Content-Type")||s.set("Content-Type","text/html; charset=utf-8"),new Response(r,{status:e,headers:s})}async page(t,e=this.status,n){let r=await this.v(t);if(/^\s*<!doctype\s/i.test(r)||(r="<!DOCTYPE html>"+r),null===this.o&&!P(n))return this.S(new Response(r,{status:e,headers:E}));const s=this.C(n||_);return s.has("Content-Type")||s.set("Content-Type","text/html; charset=utf-8"),new Response(r,{status:e,headers:s})}redirect(t,e=302){if(null===this.o)return this.S(new Response(null,{status:e,headers:C.concat([["Location",String(t)]])}));const n=new Headers(this.headers);return n.set("Location",String(t)),n.delete("Content-Type"),new Response(null,{status:e,headers:n})}},A=class{constructor(){this.children=null,this.paramChild=null,this.handler=null,this.wildcardHandler=null}},I=class{constructor(){this.root=new A}add(t,e){let n=this.root;const s=[];for(let o=0;o<t.length;o++){const i=t[o];if("*"===i)return void(n.wildcardHandler={handler:e,paramNames:s.slice()});if(58===i.charCodeAt(0)){const t=i.slice(1);s.push(r(t)?t:"_p"+o),n.paramChild||(n.paramChild=new A),n=n.paramChild}else{n.children||(n.children=new Map);let t=n.children.get(i);t||(t=new A,n.children.set(i,t)),n=t}}n.handler={handler:e,paramNames:s}}match(t){const e=[],n=this.R(this.root,t,0,e);if(!n)return null;const{handler:r,paramNames:s}=n,o=Object.create(null);for(let t=0;t<s.length;t++)o[s[t]]=e[t];return{handler:r,params:o}}R(t,e,n,r){if(n===e.length)return t.handler||t.wildcardHandler;const s=e[n],o=t.children;if(o){const t=o.get(s);if(t){const s=this.R(t,e,n+1,r);if(s)return s}}const i=t.paramChild;if(i){r.push(s);const t=this.R(i,e,n+1,r);if(t)return t;r.pop()}return t.wildcardHandler?t.wildcardHandler:null}},U=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD"];function N(t){return-1===t.indexOf(":")&&-1===t.indexOf("*")}var Edge=class n{constructor(t=""){this.prefix=t&&"/"!==t?function(t){const e=t.length;return e>1&&47===t.charCodeAt(e-1)?t.slice(0,-1):t}(t):"",this.k=c(),this.O=null,this.j=null,this.H=[],this.scheduledHandler=null,this.notFoundHandler=null,this.errorHandler=null}get staticRoutes(){if(null===this.O){const t=new Map;for(let e=0;e<U.length;e++)t.set(U[e],new Map);for(let e=0;e<this.H.length;e++){const n=this.H[e];if(!N(n.path))continue;const r=t.get(n.method);r&&r.set(n.path,n.handler)}this.O=t}return this.O}get dynamicTries(){if(null===this.j){const e={};for(let t=0;t<U.length;t++)e[U[t]]=new I;for(let n=0;n<this.H.length;n++){const r=this.H[n];if(N(r.path))continue;const s=e[r.method];s&&s.add(t(r.path),r.handler)}this.j=e}return this.j}set routes(t){const e=Array.isArray(t)?t:t?[t]:[];for(let t=0;t<e.length;t++){const r=e[t];if(!(r instanceof n))throw new Error("app.routes entries must be Edge instances");this._(r)}}_(t){const n=t.H,r=this.prefix;for(let t=0;t<n.length;t++){const s=n[t],o=e(r,s.path);this.P(s.method,o,s.handler),this.H.push({method:s.method,path:o,handler:s.handler})}this.O=null,this.j=null}A(t,n,r,s){if("function"==typeof r&&(s=r),"function"!=typeof s)throw new Error("Handler for "+t+" "+n+" must be a function");const o=e(this.prefix,n);this.P(t,o,s),this.H.push({method:t,path:o,handler:s}),this.O=null,this.j=null}P(t,e,n){this.k.add(t,e,n)}I(t,e,n){const r=new Context(t,e,null,null,n);return"OPTIONS"===t.method?this.U(r,new Response(null,{status:204})):this.notFoundHandler?this.N(this.notFoundHandler,t,e,null,null,n):this.U(r,new Response("Not Found",{status:404}))}get(t,e,n){this.A("GET",t,e,n)}post(t,e,n){this.A("POST",t,e,n)}put(t,e,n){this.A("PUT",t,e,n)}delete(t,e,n){this.A("DELETE",t,e,n)}patch(t,e,n){this.A("PATCH",t,e,n)}options(t,e,n){this.A("OPTIONS",t,e,n)}head(t,e,n){this.A("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}U(t,e){const n=e[k];if(void 0!==n&&n===t.i)return e;const r=t.o;if(null===r&&null===e.headers.get("set-cookie")){if(e.webSocket){const t=new Headers(v);return e.headers.forEach((e,n)=>t.set(n,e)),new Response(null,{status:101,webSocket:e.webSocket,headers:t})}let t=0,n=null;if(e.headers.forEach((e,r)=>{t++,"content-type"===r&&(n=e)}),0===t)return new Response(e.body,{status:e.status,statusText:e.statusText,headers:v});if(1===t){const t=H.get(n);if(void 0!==t){const n=204===e.status||304===e.status?null:e.body;return new Response(n,{status:e.status,statusText:e.statusText,headers:t})}}const r=new Headers(v);e.headers.forEach((t,e)=>r.set(e,t));const s=204===e.status||304===e.status?null:e.body;return new Response(s,{status:e.status,statusText:e.statusText,headers:r})}const s=new Headers(e.headers);if(null!==r){r.forEach((t,e)=>{"set-cookie"!==e.toLowerCase()&&(s.has(e)||s.set(e,t))});const t="function"==typeof r.getSetCookie?r.getSetCookie():r.get("Set-Cookie")?[r.get("Set-Cookie")]:[];if(t.length){const e="function"==typeof s.getSetCookie?s.getSetCookie():s.get("Set-Cookie")?[s.get("Set-Cookie")]:[],n=new Set(e);for(let e=0;e<t.length;e++){const r=t[e];n.has(r)||(s.append("Set-Cookie",r),n.add(r))}}}for(let t=0;t<C.length;t++){const e=C[t];s.has(e[0])||s.set(e[0],e[1])}if(e.webSocket)return new Response(null,{status:101,webSocket:e.webSocket,headers:s});const o=204===e.status||304===e.status?null:e.body;return new Response(o,{status:e.status,statusText:e.statusText,headers:s})}fetch(t,e,n){const r=this.k.match(t.method,t.url);return null===r?this.I(t,e,n):this.N(r.handler,t,e,r.params,null,n)}async M(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.U(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)}}N(t,e,n,r,s,o){const i=new Context(e,n,r,s,o);let l;try{l=t(i)}catch(t){return this.M(i,t)}return l&&"function"==typeof l.then?l.then(t=>this.D(i,t),t=>this.M(i,t)):this.D(i,l)}D(t,e){return e instanceof Response?this.U(t,e):e&&e.__isJSX?t.html(e):t.text("OK")}},M=Edge;export{Context,Edge,Fragment,M as default,jsx,renderToString,useCtx};
|