k99 0.2.0 → 0.3.0-beta.1
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 +1 -1
- package/README.md +8 -0
- package/README.zh.md +8 -0
- package/browser/package.json +8 -0
- package/browser/types.d.ts +20 -0
- package/cli/command/create.js +1 -2
- package/cli/command/index.js +1 -2
- package/cli/command/init.js +3 -5
- package/cli/command/start.js +9 -10
- package/cli/index.js +3 -4
- package/cli/opt/bind.js +1 -2
- package/cli/opt/index.js +1 -2
- package/cli/opt/listen.js +1 -2
- package/cli/opt/path.js +1 -2
- package/cli/opt/port.js +1 -2
- package/cli/opt/show-router.js +1 -2
- package/dist/k99.browser.js +3110 -0
- package/dist/k99.browser.min.js +6 -0
- package/dist/k99.esm.js +3082 -0
- package/dist/k99.esm.min.js +6 -0
- package/dist/k99.js +3104 -0
- package/dist/k99.mjs +3082 -0
- package/dist/k99Browser.browser.js +490 -0
- package/dist/k99Browser.browser.min.js +6 -0
- package/dist/k99Browser.esm.js +475 -0
- package/dist/k99Browser.esm.min.js +6 -0
- package/dist/k99Browser.js +484 -0
- package/dist/k99Browser.mjs +475 -0
- package/dist/k99Services.browser.js +145 -0
- package/dist/k99Services.browser.min.js +6 -0
- package/dist/k99Services.esm.js +136 -0
- package/dist/k99Services.esm.min.js +6 -0
- package/dist/k99Services.js +141 -0
- package/dist/k99Services.mjs +136 -0
- package/node/index.js +1386 -0
- package/node/index.mjs +1350 -0
- package/node/package.json +5 -0
- package/node/types.d.ts +166 -0
- package/package.json +77 -11
- package/services/package.json +8 -0
- package/services/types.d.ts +22 -0
- package/starter.js +0 -1
- package/types.d.ts +748 -0
- package/Container.d.ts +0 -92
- package/Container.js +0 -242
- package/Container.js.map +0 -1
- package/Controller/index.d.ts +0 -178
- package/Controller/index.js +0 -576
- package/Controller/index.js.map +0 -1
- package/Controller/patch/cookie.d.ts +0 -33
- package/Controller/patch/cookie.js +0 -168
- package/Controller/patch/cookie.js.map +0 -1
- package/Controller/patch/index.d.ts +0 -7
- package/Controller/patch/index.js +0 -26
- package/Controller/patch/index.js.map +0 -1
- package/Controller/patch/render.d.ts +0 -5
- package/Controller/patch/render.js +0 -24
- package/Controller/patch/render.js.map +0 -1
- package/ExitSignal.d.ts +0 -14
- package/ExitSignal.js +0 -29
- package/ExitSignal.js.map +0 -1
- package/Extension.d.ts +0 -56
- package/Extension.js +0 -93
- package/Extension.js.map +0 -1
- package/ExtensionContainer.d.ts +0 -55
- package/ExtensionContainer.js +0 -105
- package/ExtensionContainer.js.map +0 -1
- package/Plugin.d.ts +0 -52
- package/Plugin.js +0 -278
- package/Plugin.js.map +0 -1
- package/Preprocessor.d.ts +0 -86
- package/Preprocessor.js +0 -135
- package/Preprocessor.js.map +0 -1
- package/Router/assets.d.ts +0 -33
- package/Router/assets.js +0 -106
- package/Router/assets.js.map +0 -1
- package/Router/callback.d.ts +0 -9
- package/Router/callback.js +0 -152
- package/Router/callback.js.map +0 -1
- package/Router/extendsInterface.d.ts +0 -8
- package/Router/extendsInterface.js +0 -43
- package/Router/extendsInterface.js.map +0 -1
- package/Router/index.d.ts +0 -184
- package/Router/index.js +0 -615
- package/Router/index.js.map +0 -1
- package/Router/log.d.ts +0 -23
- package/Router/log.js +0 -120
- package/Router/log.js.map +0 -1
- package/Router/order.d.ts +0 -14
- package/Router/order.js +0 -71
- package/Router/order.js.map +0 -1
- package/Router/register.d.ts +0 -9
- package/Router/register.js +0 -252
- package/Router/register.js.map +0 -1
- package/Router/registerManager.d.ts +0 -22
- package/Router/registerManager.js +0 -102
- package/Router/registerManager.js.map +0 -1
- package/Router/scan.d.ts +0 -2
- package/Router/scan.js +0 -72
- package/Router/scan.js.map +0 -1
- package/Router/setHandleItem.d.ts +0 -3
- package/Router/setHandleItem.js +0 -94
- package/Router/setHandleItem.js.map +0 -1
- package/Router/settings.d.ts +0 -12
- package/Router/settings.js +0 -74
- package/Router/settings.js.map +0 -1
- package/Router/start.d.ts +0 -3
- package/Router/start.js +0 -270
- package/Router/start.js.map +0 -1
- package/Router/vars.d.ts +0 -10
- package/Router/vars.js +0 -40
- package/Router/vars.js.map +0 -1
- package/Service.d.ts +0 -12
- package/Service.js +0 -20
- package/Service.js.map +0 -1
- package/cli/command/create.d.ts +0 -7
- package/cli/command/create.js.map +0 -1
- package/cli/command/index.d.ts +0 -7
- package/cli/command/index.js.map +0 -1
- package/cli/command/init.d.ts +0 -6
- package/cli/command/init.js.map +0 -1
- package/cli/command/start.d.ts +0 -6
- package/cli/command/start.js.map +0 -1
- package/cli/index.d.ts +0 -2
- package/cli/index.js.map +0 -1
- package/cli/opt/bind.d.ts +0 -3
- package/cli/opt/bind.js.map +0 -1
- package/cli/opt/index.d.ts +0 -16
- package/cli/opt/index.js.map +0 -1
- package/cli/opt/listen.d.ts +0 -3
- package/cli/opt/listen.js.map +0 -1
- package/cli/opt/path.d.ts +0 -3
- package/cli/opt/path.js.map +0 -1
- package/cli/opt/port.d.ts +0 -3
- package/cli/opt/port.js.map +0 -1
- package/cli/opt/show-router.d.ts +0 -3
- package/cli/opt/show-router.js.map +0 -1
- package/index.d.ts +0 -354
- package/index.js +0 -155
- package/index.js.map +0 -1
- package/setOptions.d.ts +0 -12
- package/setOptions.js +0 -60
- package/setOptions.js.map +0 -1
- package/starter.d.ts +0 -2
- package/starter.js.map +0 -1
- package/symbols.d.ts +0 -13
- package/symbols.js +0 -31
- package/symbols.js.map +0 -1
- package/util/index.d.ts +0 -5
- package/util/index.js +0 -92
- package/util/index.js.map +0 -1
- package/util/stream.d.ts +0 -19
- package/util/stream.js +0 -66
- package/util/stream.js.map +0 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* k99 v0.3.0-beta.1
|
|
3
|
+
* (c) 2019-2022 Fierflame
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).k99={})}(this,(function(t){"use strict";class e{constructor(t){this.context=t,Object.defineProperties(this,Object.getOwnPropertyDescriptors(t))}async destroy(){}}e||(e={});var n=e;const r=Symbol("return"),o=Symbol("catch"),s=Symbol("finally"),i=Symbol("data"),u=Symbol("init"),c=Symbol("methods"),a=Symbol("test"),f=Symbol("options");function l(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}t.Log=void 0,t.Log||(t.Log={}),t.Settings=void 0,t.Settings||(t.Settings={}),t.Assets=void 0,t.Assets||(t.Assets={});function h(t){return"{"===t?"{":"}"===t?"}":"*"===t||"+"===t||"?"===t?7:5}function*p(t){let e=0;for(;e<t.length;){const r=e,o=t[e++];if("\\"===o){const n=t[e++];yield[6,r,n];continue}if(":"===o){for(;e<t.length&&("0"<=(n=t[e])&&n<="9"||"a"<=n&&n<="z"||"A"<=n&&n<="Z"||"_"===n);e++);if(r+1===e){yield[5,e,o];continue}yield[4,r,t.substring(r+1,e)];continue}if("("!==o){yield[h(o),r,o];continue}if("?"===t[e])throw new TypeError(`Pattern cannot start with "?" at ${e}`);let s=1;const i=["(?:"];for(;e<t.length;){const n=t[e++];if(i.push(n),"\\"!==n){if(")"!==n)if("["!==n){if("("===n&&(s++,i.push("?:"),"?"===t[e]&&(e+=2,":"!==t[e-1])))throw new TypeError("Invalid pattern group at "+(e-2))}else for(;e<t.length;){const n=t[e++];if(i.push(n),"]"===n)break;"\\"===n&&i.push(t[e++])}else if(s--,0===s)break}else i.push(t[e++])}if(s)throw new TypeError(`Unterminated pattern at ${r}`);if(!i.length)throw new TypeError(`Missing pattern at ${r}`);yield[3,r,i.join("")]}var n}function d([t,e,n]){switch(t){case"{":case"}":throw new TypeError(`Unexpected token '${t}' at ${e}`);case 3:throw new TypeError(`Unexpected pattern '(${n})' at ${e}`);case 4:throw new TypeError(`Unexpected name ':${n}' at ${e}`);case 5:throw new TypeError(`Unexpected char '${n}' at ${e}`);case 6:throw new TypeError(`Unexpected char '\\' at ${e}`);case 7:throw new TypeError(`Unexpected token '${n}' at ${e}`)}}function y(){throw new TypeError("Unexpected end of input")}function g(t){return"/"===t||"string"!=typeof t&&"/"===t.prefix}const m=/^\.+$/;function b(t){if("/"!==t[0])return!0;if(1===t.length)return!1;if(2!==t.length)return!0;const[,e]=t;return"string"!=typeof e||!m.test(e)}function*w(t){let e=["/"];for(const n of t)g(n)&&(b(e)&&(yield*e),e=[]),e.push(n);b(e)&&(yield*e)}function $(t){return[...w(function*(t){let e=0;function n(n){const r=t[e];if(!r)return;const[o,,s]=r;return o===n?(e++,s):void 0}function r(){let n="";for(let r=t[e];r;r=t[++e]){const[t,,e]=r;if(5===t)n+=e;else{if(6!==t)break;n+=e}}return n}const o=[];for(;e<t.length;){const s=n(5)||n(7)||"",i=n(4),u=n(3);if(i||u){let t="";s&&"-/.:".includes(s)?t=s:s&&o.push(s),o.length&&(yield o.join(""),o.length=0);const e=n(7)||"";yield{prefix:t,name:i||"",suffix:"",pattern:u,modifier:e};continue}const c=s||n(6)||n(7);if(c){if("/"!==c){o.push(c);continue}o.length&&(yield o.join(""),o.length=0),yield"/";continue}o.length&&(yield o.join(""),o.length=0);const a=t[e++];if(!a)break;"{"!==a[0]&&d(a);const f=r(),l=n(4)||"",h=n(3),p=r(),g=t[e++];g||y(),"}"!==g[0]&&d(g);const m=n(7)||"";yield{prefix:f,name:l||"",pattern:h,suffix:p,modifier:m,group:!0}}o.length&&(yield o.join(""))}([...p(t)]))]}function P(t){return decodeURIComponent(t).replace(/([.+*?=^!:${}()[\]|\\])/g,"\\$1")}function _(t,e){if("string"==typeof t)return P(t);const n=P(t.prefix),r=P(t.suffix),{name:o,modifier:s}=t;if(""===o)return`(?:${n}${r})${s}`;e.push(function({name:t,modifier:e,suffix:n,prefix:r}){if(!["*","+"].includes(e)||!r&&!n)return"number"==typeof t?(e,n,r)=>e[t+r]=decodeURIComponent(n):(e,n)=>e[t]=decodeURIComponent(n);const o=r+n;return"number"==typeof t?(e,n,r)=>{e[t+r]=n.split(o).map((t=>decodeURIComponent(t)))}:(e,n)=>{e[t]=n.split(o).map((t=>decodeURIComponent(t)))}}(t));const i=t.pattern||"[^/]+?";return n||r?"?"===s?`(?:${n}(${i})${r})?`:"+"===s?`${n}(${i}(?:${r}${n}${i})*)${r}`:"*"===s?`(?:${n}(${i}(?:${r}${n}${i})*)${r})?`:`${n}(${i})${r}`:`((?:${i})${s})`}function O(t,e,n,r){const o=Object.create(null);for(let r=1;r<e.length;r++){const s=e[r];if(void 0===s)continue;const i=t[r];i&&i(o,s,n)}return o.$path=r,o}function x(t,e,n){const r=e.exec(n);return r?O(t,r,0,r[0]):null}function S(t,e,n,r,o=0){const s=e.exec(n.substring(r.length));return s?O(t,s,o,`${r}${s[0]}`):null}const T=/^(\.+)\/+/;function E(t,e){if(!t||"*"===t){const t=(t,e)=>({$path:e});return t.keyLen=0,t}if("."===t){const t=(t,n)=>{"/"===n[n.length-1]&&(n=n.substring(0,n.length-1));const r=t[n.length];if(r&&("/"!==r||e&&t.length-1>n.length))return null;const o=Object.create(null);return o.$path=`${n}${r}`,o};return t.keyLen=0,t}const n="/"===t[0];let r=0;for(let e=T.exec(t);e;e=T.exec(t)){const[{length:n},{length:o}]=e;t=t.substring(n),r+=o-1}r&&(t=`/${t}`);const o=$(t),s=function(t){let e=0;for(const n of t)"string"!=typeof n&&(n.name||n.pattern&&(n.name=e++));return e}(o),i=[()=>{}],u=function(t,e,n){const r=e.map((e=>_(e,t)));return r.unshift("^"),r.push(n?"$":"(?=/|$)"),new RegExp(r.join(""),"i")}(i,o,e);if(n){const t=t=>x(i,u,t);return t.keyLen=s,t.isRoot=!0,t}if(r){const t=(...t)=>function(t,e,n,r,o,s=0){const i=o.split("/").filter(Boolean);return n>=i.length?x(t,e,r):S(t,e,r,`/${i.splice(0,i.length-n).join("/")}`,s)}(i,u,r,...t);return t.keyLen=s,t}const c=(...t)=>function(t,e,n,r,o=0){return"/"===r[r.length-1]&&(r=r.substring(0,r.length-1)),S(t,e,n,r,o)}(i,u,...t);return c.keyLen=s,c}function j(t,e,n,r={}){const o=function(t){return"string"==typeof t?[t]:Array.isArray(t)?t:["GET","POST","PUT","DELETE"]}(r.methods||n[c]);if(!o.length)return null;const{controller:s,test:i=n[a],plugin:u="",root:f="",absPath:l="",filePath:h="",name:p=n.name}=r,d={controller:s,root:f,absPath:l,filePath:h,handle:n,plugin:u,path:e.replace(/(.)\/+$/,"$1").replace(/\/+/g,"/"),methods:o,test:i,name:p,match:E(e,!0)};return t.push(d),d}const v=new Set(["GET","POST","PUT","DELETE","HEAD","OPTIONS"]);function k(t,e,n,r,o=""){n&&("object"==typeof n?function(t,e,n,r,o=""){for(const s of v){const i=n[s];"function"==typeof i&&j(t,e,i,{...r,test:i[a]||n[a],methods:[s],name:o||s})}}(t,e,n,r,o):"function"==typeof n&&function(t,e,n,r,o=""){const s={...r};delete s.test,delete s.methods;const i=j(t,e,n,{...s,name:o});if(!i)return;if(i.methods.includes("OPTIONS"))return;let{controller:u,test:c,plugin:a="",root:l="",absPath:h="",filePath:p=""}=r||{};e=e.replace(/(.)\/+$/,"$1").replace(/\/+/g,"/"),t.push({controller:u,root:l,absPath:h,filePath:p,handle:f,plugin:a,path:e,methods:["OPTIONS"],test:c,name:`${o}:OPTIONS`,match:E(e,!0)})}(t,e,n,r,o))}function A(t,e,{controller:n,plugin:r,root:o,filePath:s,absPath:i}={}){const u={controller:e.Controller||n,plugin:r,root:o,filePath:s,absPath:i};return k(t,"",e,u),u}const U={index:{methods:["GET"],path:""},create:{methods:["POST"],path:""},new:{methods:["GET"],path:"new"},show:{methods:["GET"],path:":id"},update:{methods:["PUT"],path:":id"},destroy:{methods:["DELETE"],path:":id"}};function C(t,e,n){n=A(t,e,n);for(const r in e){const o=e[r];if(o&&/^[a-z0-9][a-z0-9A-Z_-]*$/.test(r))if("function"==typeof o&&r in U){const e=U[r];j(t,e.path,o,{...n,test:o[a],methods:e.methods,name:r})}else k(t,`:id/${r}`,o,n,r)}}class R{static isControllerConstructor(t){return t===R||"function"==typeof t&&R.isPrototypeOf(t)}constructor(t){this.context=t,Object.defineProperties(this,Object.getOwnPropertyDescriptors(t))}[u](){}[i](){const t={...this.query},{body:e}=this;return e&&"object"==typeof e&&Object.assign(t,e),Object.assign(t,this.params),t}[f](){}[r](t){return this.write(t).then((e=>{if(!e&&"object"==typeof t)return this.responseType="application/json",this.write(JSON.stringify(t))})).then((()=>{}))}[o](t){return this.logs.error(t).then((()=>{}))}[s](){}}R||(R={});var I=R;function L(t,e,{plugin:n="",root:r="",absPath:o="",filePath:s=""}={}){const{prototype:i}=e;for(const u in i){if("function"!=typeof i[u])continue;if(!/^[a-z0-9][a-z0-9A-Z_-]*$/.test(u))continue;let c=u.replace(/(.)\/+$/,"$1").replace(/\/+/g,"/"),a=["GET","POST","PUT","DELETE"];if(u in U){const t=U[u];c=t.path?`${t.path}`:"",({methods:a}=t)}t.push({controller:e,root:r,absPath:o,filePath:s,handle:u,plugin:n,path:c,methods:a,name:u,match:E(c,!0)})}}class z{constructor(t=""){l(this,"disabled",!1),l(this,"__routes",[]),l(this,"guards",new Set),t=t.replace(/(.)\/+$/,"$1").replace(/\/+/g,"/"),this.path=t,this.match=E(t,!1)}route(t){const e=t instanceof z?t:new z(t);return this.__routes.push(e),e}verb(t,e,n,r){return"function"!=typeof e||("string"==typeof n?j(this.__routes,t,e,{...r,methods:[n]}):Array.isArray(n)?j(this.__routes,t,e,{...r,methods:n}):j(this.__routes,t,e,n)),this}get(t,e,n){return"function"!=typeof e||j(this.__routes,t,e,{...n,methods:["GET"]}),this}post(t,e,n){return"function"!=typeof e||j(this.__routes,t,e,{...n,methods:["POST"]}),this}put(t,e,n){return"function"!=typeof e||j(this.__routes,t,e,{...n,methods:["PUT"]}),this}delete(t,e,n){return"function"!=typeof e||j(this.__routes,t,e,{...n,methods:["DELETE"]}),this}head(t,e,n){return"function"!=typeof e||j(this.__routes,t,e,{...n,methods:["HEAD"]}),this}options(t,e,n){return"function"!=typeof e||j(this.__routes,t,e,{...n,methods:["OPTIONS"]}),this}resource(t,e){return C(this.__routes,t,e),this}register(t,e){return I.isControllerConstructor(t)?(L(this.__routes,t,e),this):I.isControllerConstructor(t.default)?(L(this.__routes,t.default,e),this):(C(this.__routes,t,e),this)}collection(t,e){e=A(this.__routes,t,e);for(const n in t)/^[a-z0-9][a-z0-9A-Z_-]*$/.test(n)&&k(this.__routes,n,t[n],e,n);return this}member(t,e){e=A(this.__routes,t,e);for(const n in t)/^[a-z0-9][a-z0-9A-Z_-]*$/.test(n)&&k(this.__routes,`:id/${n}`,t[n],e);return this}}class D extends n{decide(){return!0}static async test(t){return!0}set(t,e){return this}get(t){}delete(t){return!1}has(t){return!1}*keys(){}clear(){}get size(){return 0}static set(t,e){return this}static get(t){}static delete(t){return!1}static has(t){return!1}static*keys(){}static clear(){}static get size(){return 0}}D||(D={});var B=D;class G extends Error{static assert(t){if(t instanceof G)throw t}}function H(t,e,n){let r=e.get(n);return r||(r=new Map,e.set(n,r)),Object.defineProperties(t,{set:{configurable:!0,value(t,e){return r.set(t,e),this}},get:{configurable:!0,value:t=>r.get(t)},delete:{configurable:!0,value:t=>r.delete(t)},has:{configurable:!0,value:t=>r.has(t)},keys:{configurable:!0,value:()=>r.keys()},clear:{configurable:!0,value:()=>r.clear()},size:{configurable:!0,get:()=>r.size}}),t}async function M(t,e,n,r,o,s){if(!function(t,e){return!t.length||!!t.includes(e)}(t.methods,e))return null;const{match:i}=t,u=i(n,o,s);if(!u)return null;const c=i.isRoot?u:{...r,...u};return!1===await async function({test:t},e){if("function"!=typeof t)return!0;try{return await t(e)}catch{return!1}}(t,c)?null:c}async function q(t,e,n,r,o,s,i,u){if(t.disabled)return null;const{match:c}=t,a=c(n,i,u);if(!a)return null;const f=c.isRoot?a:{...o,...a};if(!async function(t,e,n){for(let r of t){const t=H(Object.create(r),e,r);try{if(!await t.test(n))return!1}catch{return!1}}return!0}([...t.guards],r,f))return null;const l=[...s,t],h=c.isRoot?c.keyLen:c.keyLen+u,p=a.$path;for(const o of Array.from(t.__routes)){if(o instanceof z){const t=await q(o,e,n,r,f,l,p,h);if(t)return t;continue}const t=await M(o,e,n,f,p,h);if(t)return{route:o,routers:l,params:t}}return null}function N(t){const e=new Uint8Array(t);let n=[],r=0;for(;r<e.length;){let t=0|e[r++];t>224?(t=(15&t)<<12,t|=(63&e[r++])<<6,t|=63&e[r++]):t>192&&(t=(31&t)<<12,t|=63&e[r++]),n.push(t)}return n.map((t=>String.fromCharCode(t))).join("")}function Z(t,e=t.reduce(((t,e)=>t+e.byteLength),0)){if(1===t.length)return t[0];const n=new Uint8Array(e);let r=0;for(const e of t)for(let t of new Uint8Array(e))n[r++]=t;return n.buffer}function V(t,e,n){if(!n){const n=Z(e);return t?N(n):n}let r,o=0;for(;r=e.shift();){if(o+r.byteLength>n){const t=r.slice(0,n-o);o+=t.byteLength,e.unshift(r.slice(t.byteLength));break}if(o+=r.byteLength,o===n)break}const s=Z(e,o);return t?N(s):s}function F(t){return"string"==typeof t?function(t){let e=[];for(let n of t.split("").map((t=>t.charCodeAt(0))))n<128?e.push(n):n<2048?(e.push(192|31&n>>6),e.push(128|63&n)):(e.push(224|15&n>>12),e.push(128|63&n>>6),e.push(128|63&n));return new Uint8Array(e).buffer}(t):ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t}async function*J(t){if(t){if("string"==typeof t)return yield t;if("object"==typeof t){if(function(t){if(t instanceof ArrayBuffer)return!0;if(ArrayBuffer.isView(t))return!0;try{if(t instanceof SharedArrayBuffer)return!0}catch{}return!1}(t))return yield t;if(Symbol.asyncIterator in t||Symbol.iterator in t)for await(const e of t)yield*J(e)}}}function K(t){if(!t)return()=>Promise.resolve(null);const e=[];let n=null;return async function(t,e){const n=[];let r=0,[o,s,i]=await e();for await(const u of J(t)){const t=F(u);if(n.push(t),r+=t.byteLength,o<=0)r=0,i(V(s,n)),[o,s,i]=await e();else for(r>=o&&(r-=o,i(V(s,n,o)),[o,s,i]=await e());r&&(o<=0||o<=r);){if(o<=0){r=0,i(V(s,n)),[o,s,i]=await e();break}r-=o,i(V(s,n,o)),[o,s,i]=await e()}}for(r&&(i(V(s,n)),[o,s,i]=await e()),i(null);;)[o,s,i]=await e(),i(null)}(t,(function(){return new Promise((t=>{const r=e.shift();if(r)return t(r);n=e=>{n=null,t(e)}}))})),function(t=0,r=!1){return new Promise((o=>{t=Math.max(t,0),n?n([t,r,o]):e.push([t,r,o])}))}}const Q=/^(?:(?:https?:)?\/\/(?:(?:[^/?#]*@)?)(?:\d+|(?:\[[0-9a-f:]+\])|(?:\d{1,3}\.){3}\d{1,3}|(?:(?:[a-z0-9\u0100-\uffff]+-*)+\.)+[a-z]+)(?::\d+)?)?((?:\/?[^?#]*)?)((?:\?[^#]*)?)(?:#.*)?$/i;function W(t){const e=t.indexOf("=");return e<0?[decodeURIComponent(t),""]:[decodeURIComponent(t.substring(0,e)),decodeURIComponent(t.substring(e+1))]}function X(t){const e={};for(const n of t.split("&").filter(Boolean)){const[t,r]=W(n);e[t]=t in e?[e[t],r].flat():[r]}return e}function Y(t,e,n,r={}){const[o,s]=function(t){const e=Q.exec(t);if(!e)return["/",""];let[,n,r]=e;const o=[];for(const t of n.replace(/^[\\/]+/,"").replace(/[\\/]+/g,"/").split("/"))"."!==t&&(".."!==t?o.push(t):o.pop());return[`/${o.join("/")}`,r]}(e);return{method:t,url:`${o}${s}`,headers:r,pathname:o,search:s,query:X(s.substring(1)),read:"function"==typeof n?n:K(n)}}function tt(t,e,r,o,s){if(i=o,!n.isPrototypeOf(i)){if("function"==typeof n)return o(r,...s);throw new TypeError("the object not is service class or function")}var i;let u=t.get(o);return u||(u=new o(r),t.set(o,u),B.isPrototypeOf(o)&&H(u,e,o)),u.export(...s)}async function et(t,e,n){if(!n)return!1;if(e())return!0;if("string"==typeof n)return t(n);if("object"!=typeof n)return!1;if(function(t){if(t instanceof ArrayBuffer)return!0;if(ArrayBuffer.isView(t))return!0;try{if(t instanceof SharedArrayBuffer)return!0}catch{}return!1}(n))return t(n);if(!(Symbol.asyncIterator in n)&&!(Symbol.iterator in n))return!1;for await(const r of n){if(e())return!0;if(!await et(t,e,r))return!1}return!0}function nt(t){return t.map((({name:t,value:e,expire:n,domain:r,path:o,secure:s,httpOnly:i})=>t&&[`${encodeURI(t)}=${encodeURI(e||"")}`,n&&`Expires=${n}`,r&&`Domain=${encodeURI(r)}`,o&&`Path=${encodeURI(o)}`,s&&"Secure",i&&"HttpOnly"].filter(Boolean).join("; "))).filter(Boolean)}const rt=/^(\[[^\]]+\]|^:):(\d+)$/;function ot(t,e,n,r,{method:o,url:s,pathname:i,search:u,query:c,read:a,headers:{...f}}){const[l,h,p,d]=function(){let t=[],e=!1,n=null,r=null;function o(){r&&r(t.shift()||null)}let s=null;function i(){return n}return[function(r){return new Promise((s=>{if(n||e)return s(!1);t.push([r,s]),o()}))},function(){return s||(s=new Promise((t=>{if(e)return t();n=t,o()}))),s},async function*(){try{for(;;){const e=await new Promise((e=>{const o=t.shift();return o?e(o):n?e(null):void(r=t=>{r=null,e(t)})}));if(e){const[t,n]=e;try{yield t,n(!0)}catch{n(!1)}}else if(i())break}}finally{e=!0;for(let e;e=t.shift();){const[,t]=e;t(!1)}const n=i();n&&n()}}(),()=>e]}();let y,g,m=!1,b=200,w={};function $(){m||(m=!0,g={get statusCode(){return b},get finished(){return d()},headers:Object.freeze({...w}),[Symbol.asyncIterator]:()=>p},y&&y(g))}Object.freeze(f);const P=f.host||"",_=rt.exec(P),[O,x]=_?[_[1],_[2]]:[P,""],S=[],T=function(t){let e={};for(const n of t.replace(/\s/g,"").split(";")){const t=n.split("=");e[decodeURIComponent(t.shift())]=decodeURIComponent(t.join("="))}return e}(f.cookie||""),E=new Map;let j,v,k=!1;function A(){return k||d()}const U={get body(){return j},set body(t){j=t},get data(){return v},app:t,settings:n?t.settings(n,!0):t.settings,assets:n?t.assets(n,!0):t.assets,logs:n?t.logs(n,!0):t.logs,plugin:n,params:e,url:s,method:o,pathname:i,search:u,query:c,headers:f,referer:f.referer||"",host:P,hostname:O,port:x,userAgent:f["user-agent"]||"",accept:(f.accept||"").split(/,\s*/).filter(Boolean),acceptLanguage:(f["accept-language"]||"").split(/,\s*/).filter(Boolean),cookies:T,read:a,get destroyed(){return k},get finished(){return d()},get headersSent(){return m},get status(){return b},set status(t){m||(b=t)},getCookie:t=>function*(t,e){const n=t;for(const t of n)e&&t.name!==e||(yield{...t})}(S,t),setCookie(t,e,{expire:n,domain:r,path:o,secure:s,httpOnly:i}={}){m||(S.push({name:t,value:e,expire:n,domain:r,path:o,secure:s,httpOnly:i}),w["set-cookie"]=nt(S))},clearCookie(t,e){m||(!function(t,e,n,r){let o="Fri, 31 Dec 1999 16:00:00 GMT";if("string"==typeof n){if(!n)return;const{domain:e,path:s,secure:i,httpOnly:u}=!0!==r&&r||{};t.push({name:n,value:"delete",expire:o,domain:e,path:s,secure:i,httpOnly:u})}else{const{domain:s,path:i,secure:u,httpOnly:c}=n||{};if(t.length=0,r)for(let n in e)t.push({name:n,value:"delete",expire:o,domain:s,path:i,secure:u,httpOnly:c})}}(S,T,t,e),w["set-cookie"]=nt(S))},service(t,...e){if(k)throw new Error("This controller is destroyed");return tt(E,r,U,t,e)},get requestType(){return f["content-type"]||""},get responseType(){return w["content-type"]||""},set responseType(t){m||(w["content-type"]=t)},hasHeader:t=>t in w,getHeaderNames:()=>Object.keys(w),getHeaders:()=>({...w}),getHeader:t=>w[t],removeHeader(t){m||delete w[t]},setHeader(t,e){m||(void 0===e?delete w[t]:w[t]=e)},write:async t=>!t||($(),!!A()||et(l,A,t)),exit(t){throw"number"==typeof t&&t>=100&&t<700&&(b=t),new G},transfer(t,e){throw b=e?301:302,m||(w.location=t),new G},request:(e,n,{headers:r,body:o}={})=>t.request(Y(e,n,o,r))};const C=new Promise((t=>{m&&g?t(g):y=t}));return{context:U,destroy:async function(){if(!k){k=!0;for(const e of[...E.values()])try{await e.destroy()}catch(e){t.logs.error(e)}return $(),h()}},setData:function(t){v=t},response:C,runGuards:async function(t){for(const e of t){let t=E.get(e);if(t||(t=new e(U),H(t,r,e),E.set(e,t)),!1===await t.decide())return!1}return!0}}}function st(t,e,n){if(!n.finished&&t&&n!==t&&e!==t)return e[r](t)}async function it(t,e,n,r,c,a,l,h){try{if(await n[u](),!await c(function*(t){for(const{guards:e}of[...t])yield*e}(a)))return;const o=await n[i]();h(o),await async function(t,e,n,r){if("function"==typeof t)return st(await t.call(n,r),e,n);if("string"==typeof t){const r=e[t];if("function"!=typeof r)return;return st(await r.call(e),e,n)}if(t===f)return st(await e[f](),e,n)}(e.handle,n,r,o)}catch(e){await async function(t,e,n){if(!(n instanceof G))try{await e[o](n)}catch(n){t.logs.error(n)}}(t,n,e)}finally{try{await n[s]()}catch(e){t.logs.error(e)}await l()}}function ut(t,e,n,r,o,s){const{context:i,destroy:u,setData:c,response:a,runGuards:f}=ot(t,s,r.plugin,e,o),l=function(t,{controller:e}){if(I.isControllerConstructor(e))return e;for(const{controller:e}of[...t].reverse())if(I.isControllerConstructor(e))return e;return I}(n,r);return it(t,r,new l(i),i,f,n,u,c),a}async function ct(t){const e=new Map,n=await q(this,t.method,t.pathname,e,{},[],"",0);return n?ut(this,e,n.routers,n.route,t,n.params):null}const at=/^\.+$/;function ft(...t){const e=[];for(const n of t.map((t=>t.split("/"))).flat())n&&"."!==n&&(at.test(n)?e.length=Math.max(0,e.length-n.length+1):e.push(n));return`${e.join("/")}`}function lt(t,e,n,r,o,s){return void 0===o?r:("~"===o?o=n:"~/"===o.substr(0,2)?o=`${n}/${o.substr(2)}`:"\\~"===o.substr(0,2)&&(o=o.substr(1)),ht(t,e,s?ft(o):n,s?"":o,r))}function ht(t,e,n="",r="",o=""){o=ft(o,r);const s=lt.bind(null,t,e,n,o);for(const e in t){const n=t[e];s[e]="function"==typeof n?(t,...e)=>n(ft(o,t),...e):n}if(!e)return s;for(const t in e)s[t]=e[t];return s}function pt(t){return"string"==typeof t?t:t instanceof Error?t.stack||`${t.name}:${t.message}`:String(t)}const dt=/(?:^|\/)(debug|error|warn|info)\/?$/,yt=/^\/?(debug|error|warn|info)(?:\/|$)/;async function gt(){return""}function mt(t,e){switch(console.group(`log @ ${t}`),function(t){const e=dt.exec(t);if(e)return e[1];const n=yt.exec(t);return n?n[1]:""}(t)){case"debug":console.debug(e);break;case"info":console.info(e);break;case"warn":console.warn(e);break;case"error":console.error(e);break;default:console.log(e)}console.groupEnd()}async function bt(t,e){switch(t){case"debug":console.debug(e);break;case"info":console.info(e);break;case"warn":console.warn(e);break;case"error":console.error(e);break;default:mt(t,e)}return!0}async function wt(){}function $t({read:t=gt,write:e=bt,clear:n=wt}={}){function r(t,n,r){return r&&(n=function(t,{tags:e,indent:n}){let r="";return e&&(Array.isArray(e)||(e=[e]),r=e.map((t=>`[${t}]`)).join(" ")),r=`${(new Date).toISOString()} ${r}`,t.includes("\n")?("number"==typeof n&&(n=Math.floor(n),isFinite(n)&&n>0&&(n=Array(n).fill(" ").join(""))),n&&"string"==typeof n||(n=" "),t=(t=`${r}\n${t}`).split("\n").join(`\n${n}`)):`${r} ${t}`}(n,r)),"\n"!==n[n.length-1]&&(n+="\n"),e(t,n)}return ht({read:function(e){return t(e)},write:r,clear:function(t){return n(t)}},{debug:async(t,e)=>r("debug",t,e),info:async(t,e)=>r("info",t,e),warn:async(t,e)=>r("warn",pt(t),e),error:async(t,e)=>r("error",pt(t),e)})}const Pt="[a-zA-Z][a-zA-Z0-9_-]*",_t=`${Pt}(?:.${Pt})*`,Ot=new RegExp(`^/plugins/((?:@${_t}/)?${_t})/(.+)$`);function xt(t,e){if(!e)return null;const n=Ot.exec(t);if(!n)return null;const r=e[n[1]];return r?[r,n[2]]:null}async function St(){}async function Tt(){return!1}async function Et(){return null}async function jt(){return!1}function vt(t,e,n){return void 0===n&&delete t[e],t[e]=n,t}t.App=class extends z{constructor({router:t,settingApi:e,assetApi:n,logApi:r,path:o}={},s=Object.create(null)){super(o),this.settings=function({read:t=St,write:e=Tt}={},n){return ht({read:async function(e){const r=await t(e);if(r)return r;const o=xt(e,n);if(!o)return null;const[s,i]=o;return s.readSettings(i)},write:function(t,n){return e(t,n)}},{})}(e,s),this.assets=function({read:t=Et,write:e=jt,delete:n=jt,stat:r=Et}={},o){return ht({read:async function(e,n){const r=await t(e,n);if(null!==r)return r;const s=xt(e,o);if(!s)return null;const[i,u]=s;return i.readAsset(u,n)},write:function(t,n){return e(t,n)},delete:function(t){return n(t)},stat:async function(t){return r(t)}},{})}(n,s),this.logs=$t(r),this.plugins=s;for(const t of Object.values(s))this.route(t.router);t instanceof z&&this.route(t),this.request=ct.bind(this)}},t.Controller=I,t.ExitSignal=G,t.Guard=B,t.Handle=function(t){return t},t.Plugin=class{constructor(t,e,{author:n,license:r}={}){this.name=t,this.version="string"==typeof e?e:"",this.author="string"==typeof n?n:"",this.license="string"==typeof r?r:""}_initRouter(t){}initRouter(){if(this.__initRouterPromise)return this.__initRouterPromise;const{router:t}=this;return this.__initRouterPromise=Promise.resolve().then((()=>this._initRouter(t))).then((()=>t))}get router(){const t=new z;return Reflect.defineProperty(this,"router",{value:t,configurable:!0}),this.initRouter(),t}get disabled(){return this.router.disabled}set disabled(t){this.router.disabled=t}},t.Router=z,t.Service=n,t.catchSymbol=o,t.dataSymbol=i,t.finallySymbol=s,t.initSymbol=u,t.methodsSymbol=c,t.optionsSymbol=f,t.returnSymbol=r,t.setMethods=function(...t){return e=>vt(e,c,t.length?t:void 0)},t.setOptions=function(t){return e=>vt(e,f,t)},t.setTest=function(t){return e=>vt(e,a,t)},t.testSymbol=a,Object.defineProperty(t,"__esModule",{value:!0})}));
|