rossa 0.0.1 → 0.0.2

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/dist/index.d.ts CHANGED
@@ -84,6 +84,7 @@ declare class response extends ResponseSession implements response {
84
84
  [key: string]: any;
85
85
  status?: number;
86
86
  stream?: eStream;
87
+ path: string;
87
88
  private headers;
88
89
  constructor(request: request, args?: Record<string, string>);
89
90
  get?(): Promise<any> | any;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- var tt=function(t,r,n,o){var s=arguments.length,i=s<3?r:o===null?o=Object.getOwnPropertyDescriptor(r,n):o,e;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")i=Reflect.decorate(t,r,n,o);else for(var f=t.length-1;f>=0;f--)if(e=t[f])i=(s<3?e(i):s>3?e(r,n,i):e(r,n))||i;return s>3&&i&&Object.defineProperty(r,n,i),i};var rt=(t,r)=>{if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(t,r)};import{Auth as dr}from"authored";var B=(t)=>typeof t==="function";var D=(t)=>{return!isNaN(parseFloat(t))&&isFinite(t)};var nt=(t)=>{return t instanceof Uint8Array||t instanceof ArrayBuffer||typeof t==="string"};var L=(t)=>typeof t==="string",M=(t)=>Array.isArray(t),ot=(t)=>typeof t==="object";var st=(t)=>{return Number.isInteger(Number(t))};function it(t,r){m(r).forEach(([n,o])=>{ft(t,n,{value:o,writable:!1,configurable:!1,enumerable:!0})})}class S{static set p(t){if(Array.isArray(t))console.log(...t);else console.log(t)}}class Z{_c=0;_id="";constructor(t){if(this._c=0,this._id=t??y(5),t?.includes("-")){let[r,n]=[t.split("-").slice(0,-1).join("-"),t.split("-").slice(-1)[0]];this._id=r,this._c=D(n)?parseInt(n):0}}get id(){return this._id+"-"+this._c}get mid(){return this._id+"-"+ ++this._c}}var et=(t,r)=>{let[n,o]=r.replace(/bytes=/,"").split("-").map((s,i)=>{let e=parseInt(s,10);return isNaN(e)?i===0?0:t-1:e});return[n,o,t]};var Yr=new RegExp(/(\d+)(\d*)/,"m"),At=(t)=>Array.from({length:t},(r,n)=>n),Kt="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Ft="abcdefghijklmnopqrstuvwxyz",Vt=At(10).join("");var R=(t)=>JSON.stringify(t),ut=(t)=>{return JSON.parse(t)},W=(t)=>{if(t.startsWith("webkit"))t="-"+t;return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()},y=(t)=>{let r=Kt+Ft;return Array.from({length:t},(n,o)=>r+(o?Vt:"")).reduce((n,o)=>{return n+=o.charAt(Math.floor(Math.random()*o.length))},"")};class l extends Map{obj(t){t&&m(t).forEach(([r,n])=>this.set(r,n))}map(t){t.forEach((r,n)=>{if(r instanceof l)this.set(n,r);else if(M(r)){if(this.lacks(n))this.set(n,[]);this.get(n).push(...r)}else if(ot(r))this.ass(n,r);else this.set(n,r)})}ass(t,r){if(!this.has(t))this.set(t,{});T(this.get(t),r)}lacks(t){return!this.has(t)}init(t,r){return this.has(t)?this.get(t):this.set(t,r).get(t)}}var{values:E,keys:H,entries:m,fromEntries:mt,hasOwn:_t}=Object;var{defineProperty:ft,assign:T}=Object,q=(t)=>{return Object.keys(t).length};function pt(t){return class extends t{constructor(...r){super(...r);let n=new Map;return new Proxy(this,{get(o,s){let i=`__${s}`;if(!n.has(i)){let e=o[s];if(B(e))e=function(...f){let u=`${i}_${JSON.stringify(f)}`;if(!n.has(u)){let c=o[s].apply(o,f);n.set(u,c)}return n.get(u)};n.set(i,e)}return n.get(i)},set(o,s,i){let e=`__${s}`;return n.set(e,i),!0}})}}}var w=(t,r)=>{return{name:t,content:r}},kt=(t,r)=>{return{property:t,content:r}},vt=(t,r)=>{return{"http-equiv":t,content:r}};class j{metas=[];constructor(t){t&&this.metas.push(w("description",t))}author(t){return this.meta=w("author",t),this}charset(t){return this.meta={charset:t},this}keywords(...t){return this.meta=w("keywords",t.join(", ")),this}viewport(t){let r=m(t).map(([n,o])=>[W(n),String(o)].join("="));return this.meta=w("viewport",r.join(", ")),this}httpEquiv(t){return m(t).forEach(([r,n])=>{this.meta=vt(W(r),String(n))}),this}robots(...t){return this.meta=w("robots",t.join(", ")),this}themeColor(t){return this.meta=w("theme-color",t),this}openGraph(t){return m(t).forEach(([r,n])=>{this.meta=kt("og:"+r,String(n))}),this}twitter(t){return m(t).forEach(([r,n])=>{this.meta=w("twitter:"+r,String(n))}),this}and(t){return this}set meta(t){this.metas.push(t)}}var tr=["charset","name","property","http-equiv"],ct=(t,r)=>{r.forEach((n)=>{for(let o of tr)if(o in n){let s=n[o];t[`${o}_${o==="charset"?"":s}`]=n}})},rr=(t,r)=>{r.forEach((n)=>{if("href"in n){let o=n.href;t[`${o}`]=n}})};class lt{_head;idm;constructor(t){this._head=new l(t)}set head(t){m(t).forEach(([r,n])=>{if(r==="title"||r==="base"){if(n!==void 0)this._head.set(r,n);return}if(n instanceof j)return ct(this._head.init("meta",{}),n.metas);if(!M(n))return;switch(r){case"meta":return ct(this._head.init("meta",{}),n);case"link":return rr(this._head.init("link",{}),n);case"script":if(n.length){this._head.init(r,[]);let o=n.map((s)=>{if(!s.yid&&this.idm)s.yid="sc"+this.idm.mid;return s});this._head.get(r).push(...o)}return}})}get head(){return this._head}set id(t){this.idm=new Z(t)}}class nr{lang="en";htmlHead=new l;head;constructor(){this.head=(t={})=>{let r=new lt(this.htmlHead);r.head=t,this.htmlHead=r.head}}}var ht=(t,r="",{maxAge:n,expires:o,path:s,domain:i,secure:e,httpOnly:f,sameSite:u})=>{if(n instanceof Date)n=n.getSeconds();if(o instanceof Date)o=o.toUTCString();else if(o===0)o=new Date().toUTCString();return[["Domain",i],["Expires",o],["Max-Age",n],["Secure",e],["HttpOnly",f],["Path",s],["SameSite",u]].reduce((a,[x,g])=>{if(g!==void 0)a.push(`${x}=${g}`);return a},[`${t}=${r}`]).join("; ")};var N=(t,r=!1)=>{if(D(t))return[+t,st(t)?"int":"float"];if(r&&/\.\w+$/.test(t))return[t,"file"];if(t==="/")return[t,"-"];if(t.length===36&&t.match(/\-/g)?.length===4)return[t,"uuid"];return[t,"string"]},b=(t)=>{let r=t.startsWith("/")?t:"/"+t,n=r.match(/(?<=\/)[^/].*?(?=\/|$)/g)??["/"],[o,s]=n.reduce(([i,e],f)=>{if(f.includes("<")){let u=f.match(/(?<=<)[^/].*?(?=>|$)/g);if(u?.length){let[c,a]=u[0].split(":");if(c&&a)i.push(c),e.push(a)}}else i.push(f===">"?"/":f);return[i,e]},[[],[]]);if(r.endsWith("/")&&r.length>1)o.push("/");return{parsed:o,args:s}};class U{storage=new l;cache(t,r){if(this.storage.lacks(t))this.storage.set(t,r());return this.storage.get(t)}}var or=["int","float","file","uuid","string"],sr=new U;class z{_storage=new l;set(t){let{parsed:r,path:n}=t,o=R(r);if(!this._storage.get(o))this._storage.set(o,t);else throw`path: ${n} already used.`}get(t){let{parsed:r}=sr.cache(t,()=>b(t)),n={},o=this._storage.get(R(r));if(!o&&t!=="/")for(let s of this._storage.keys()){let i=[],e=ut(s);if(r.length===e.length){let f=e.map((a,x)=>{let g=N(r[x],r.length-1===x);if(a===g[0])return g[0];if(or.includes(g[1]))return i.push(g[0]),g[1];return a}),u=R(f);if(this._storage.has(u)){o=this._storage.get(u),o?.args.forEach((a,x)=>{n[a]=i[x]});break}}}return[o,n]}}class G{constructor(...t){t.forEach((r)=>{if(!this[r])this[r]=new z})}get(t){return this[t]}}class P{path="";parsed=[];args=[];constructor(t){it(this,{path:t,...b(t)})}}class I{date;constructor(t){this.date=t?new Date(t):new Date}delta(t=null,r=!1){let n=I.delta(this.date.getTime(),t);return r?new Date(n):n}timed(t){if(!t)return this.date;return[["year","FullYear"],["month","Month"],["day","Date"],["hour","Hours"],["minute","Minutes"],["second","Seconds"]].reduce((n,[o,s])=>{let i=t[o];return i?new Date(n[`set${s}`](n[`get${s}`]()+i)):n},new Date(this.date))}static delta(t,r=null){return r?r-t:t-Date.now()}static get now(){return Date.now()}}var{file:fr}=globalThis.Bun;import{JWTInterface as ir}from"authored";class at{session;jwt;jwtInt;constructor(){this.jwtInt=new ir}init(t){this.session=t.session,this.jwt=t.jwt}}var p=new at;class d{__session;__jwt;get session(){if(!this.__session)this.__session=p.session.new;return this.__session}set session(t){this.__session=t}get jwt(){if(!this.__jwt)this.__jwt=p.jwt.new;return this.__jwt}set jwt(t){this.__jwt=t}get timedJWT(){return p.jwtInt.jwt()}setServerSession(t){let{__jwt:r,__session:n}=t;this.__session=n,this.__jwt=r}}var gt=async(t,r)=>{await p.session.saveSession(t,r)};async function St({sid:t,jwtv:r,refreshjwt:n},o){let s=new d;if(t){if(s.session=await p.session.openSession(t),!s.session.new)o.session=!0}if(r){if(s.jwt=p.jwtInt.open(r,{hours:6}),!s.jwt.new)o.jwt=!0;if(n){if(!(await p.jwt.openSession(n)).new)o.jwt_refresh=!0}}if("session"in o||"jwt"in o)return s}var er={session(...t){return A(t[0],t[2],"session")},jwt(...t){return A(t[0],t[2],"jwt")},jwt_refresh(...t){return A(t[0],t[2],"jwt_refresh")}},A=(t,r,n)=>{let o=r.value;return r.value=async function(s={}){if(n in s&&s.session)return delete s[n],o.call(t,s);return{error:401}},r};var ur=["GET","POST","PUT","DELETE","OPTIONS"];class bt extends P{config;_class;options="";bytes;fileType="text/plain";fileSize=0;constructor(t,r={}){super(t);this.config=r}set serverClass(t){this._class=t,this.options=ur.filter((r)=>t.prototype[r.toLowerCase()]).join(", ")}get serverClass(){return this._class}async loadBytes(t){if(!this.config.preload)return;try{let r=fr(this.path);this.fileType=r.type,this.bytes=await r.bytes(),this.fileSize=this.bytes.byteLength}catch{throw`error: can't preload ${this.path}. File not found.`}}}var Rt={path:Symbol("path"),wss:Symbol("wss"),file:Symbol("file"),folder:Symbol("folder"),error:Symbol("error")},mr=new G(...E(Rt)),wt=(t)=>{let r=Rt[t];if(!r)throw new Error("Invalid storage type");return mr[r]},C=(t,r,n={},o)=>{return(s)=>{let i=new bt(r,n);if(s)i.serverClass=s;if(t==="file")i.loadBytes(o);return wt(t).set(i),s}},yt={args:{}};async function h(t){let[r,n]=wt(t).get(this.path);if(!r)return yt;let{requireSession:o}=r.config,s=void 0;if(o){if(s=await St(await this.request.authgroup(),n),!s)return yt}return{serverPath:r,args:n,session:s}}class K{dir;apt;files;_statics;statics;constructor(t=".",r={}){this.dir=t;let{dir:n,appDir:o}=r;if(n)this.dir=n;this.apt=this.dir+"/"+(o??"app"),this.files=(...s)=>{s.forEach((i)=>{let[e,f]=Ct(i),u=e.replace(/^\.+/,""),c=u.startsWith("/")?u:"/"+u;C("file",c,f,this.apt)()})},this.statics=(s={})=>{if(!this._statics)this._statics={};T(this._statics,s)}}route(t){return C("path",t)}wss(t,r={}){return C("wss",t,r)}error(...t){return(r)=>{if(t.length)t.forEach((n)=>{C("error",n.toString(),{})(r)});else C("error","404",{})(r);return r}}folders(...t){t.forEach((r)=>{C("folder",...Ct(r))()})}redirect(t,r={}){return new Response("",{status:302,headers:new Headers({...r,Location:t})})}}var Ct=(t)=>{let r=L(t);return[r?t:t[0],r?{}:t[1]]};var{inflateSync:Cr,serve:xr,write:Tr}=globalThis.Bun;class xt extends l{}var F=new xt;var V={async open(t){let r=t.data.wclass,{args:n,client:o}=t.data;if(r){r.ws=t;let s=r.id,i=q(o);if(!(s in o)){let e=i?"joiner":"maker";o[s]={role:e}}if(typeof r.init=="function")await r.init(n);if(r.broadcasting)r.ws.subscribe(r.path);await r.open()}else t.close()},async message(t,r){let n=t.data.wclass;if(n)await n.message(r)},async close(t,r,n){let o=t.data.wclass,s=t.data.client;if(o){if(await o.close(r,n),o.broadcasting)o.ws.unsubscribe(o.path);let i=o.id;if(delete s[i],q(s)===1)H(s).forEach((e)=>{s[e].role="maker"})}}};async function _(){let{serverPath:t,args:r,session:n}=await h.call(this,"wss");if(!t)return this.status=426,"upgrade error";let{serverClass:o}=t;if(!o)return"upgrade error";let s=new o(this.request);n&&s.setServerSession(n);let i=s.path,e=Tt(i),f=e?.size??0,{broadcast:u,maxClient:c}=t.config;if(s.broadcasting=!!u,s.max=c??0,c&&f>=c)return this.status=400,"upgrade error";return this.request.upgradeConnection({data:{wclass:s,args:r,client:e}}),null}class dt extends d{request;ws;path;id;broadcasting=!1;max=0;constructor(t){super();this.request=t;this.path=t.path,this.id=y(10)}open(){}message(t){}close(t,r){}set send(t){if(t)if(this.broadcasting)this.ws.publish(this.path,t);else this.ws.send(t)}get role(){let t=F.get(this.path);if(t&&t.has(this.id))return t.get(this.id)?.role}}var Tt=(t)=>{return F.init(t,new l)};var{deflateSync:Sr,gzipSync:yr}=globalThis.Bun;var{Server:pr,file:cr}=globalThis.Bun;class ${req;server;formData;url;method;__cookies=new Map;constructor(t,r){this.req=t;this.server=r;this.url=new URL(t.url),this.method=this.req.method.toLowerCase()}async form(){if(this.isForm){if(!this.formData)this.formData=await this.req.formData();return this.formData}return new FormData}async authgroup(){let{cookies:t,auth:r}=this,n=t.get("session")??"",o=r??"",s="",i=this.isForm?await this.form():void 0;if(i){let e=i.get("refresh_token");s=e?e.toString():""}return{sid:n,jwtv:o,refreshjwt:s}}upgradeConnection(t={}){return!!this.server?.upgrade(this.req,t)}get auth(){let t=this.headers.get("authorization");if(t){let[r,n]=t.split(" ",2);if(r.trim()=="Bearer")return n.trim()}}get accept(){return this.headers.get("accept")}get contentType(){return this.headers.get("content-type")}get cookies(){if(!this.__cookies.size){let t=this.headers.get("cookie");if(t){let r=t.split(";").reduce((n,o)=>{let[s,i]=o.trim().split(/=(.*)/s);return n.push([s,i]),n},[]);this.__cookies=new Map(r)}}return this.__cookies}get headers(){return this.req.headers??new Headers}get ip(){return this.server?.requestIP(this.req)}get isForm(){let t=this.contentType;return t?t.indexOf("multipart/form-data")>=0||t.indexOf("x-www-form-urlencoded")>=0:!1}get path(){return this.url.pathname}get parsed(){let{parsed:t}=b(this.path);return t}get searchParams(){return this.url.searchParams}get range(){return this.headers.get("range")??void 0}get isEventStream(){return this.accept?.includes("text/event-stream")}get isWSS(){return!!this.headers.get("upgrade")}get isFile(){let t=this.parsed.slice().pop();return t?N(t,!0).pop()==="file":!1}get type(){return cr(this.path).type}get upgrade(){return this.headers.get("upgrade")}get request(){return this.req}get signal(){return this.req.signal}}$=tt([pt,rt("design:paramtypes",[typeof Request==="undefined"?Object:Request,typeof pr==="undefined"?Object:pr])],$);class Et{ctrl;intervalID=[];constructor(t){this.ctrl=t}push(t,r=2000){if(this.ctrl){let n=setInterval(()=>{let{id:o,retry:s,data:i,event:e,end:f}=t();if(this.ctrl){let u=f?"end":i;if(s){let c=s>2000?s:2000;this.ctrl.enqueue(`retry: ${c}\\n`)}if(this.ctrl.enqueue(`id: ${o}\\n`),e&&this.ctrl.enqueue(`event: ${e}\\n`),typeof u=="object")this.ctrl.enqueue("data: "+JSON.stringify(u)+"\\n\\\n");else this.ctrl.enqueue("data: "+JSON.stringify({message:u})+"\\n\\n");f&&this.close()}},r>1000?r:1000);this.intervalID.push(n)}}close(){if(this.intervalID.length)this.intervalID.forEach((t)=>{clearInterval(t)}),this.intervalID=[];this.ctrl?.close()}}async function qt(t,r,n){this.status=200,this.header={"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"};let o=this.request,s=new ReadableStream({async start(e){t.stream=new Et(e),await n.call(t,r),o.signal.addEventListener("abort",()=>{if(t.stream?.close(),t.stream?.intervalID.length)e.close()})}}),i=await n.call(t,r);if(typeof i==="object"&&"error"in i)return this.status=i.error,null;return s}async function $t(t){let r=p.jwtInt.save(t);return t.access_token=r,await p.jwt.saveSession(t,this.headers),{access_token:r,refresh_token:t.sid,status:"ok"}}function Ot(t){return this.status=403,{error:t}}async function Jt(t){let{jwtv:r,refreshjwt:n}=await this.request.authgroup();if(!n){if(r||!t.modified)return this.status=204,this.type="application/json",JSON.stringify({});return JSON.stringify(await $t.call(this,t))}let o=await p.jwt.openSession(n),s=o.data.access_token,i={};if(r!==s)i=Ot.call(this,"tokens don't match.");else if(!p.jwtInt.verify(s,{days:5}))await p.jwt.saveSession(o,void 0,!0),i=Ot.call(this,"expired refresh_token.");else i=await $t.call(this,o);return this.type="application/json",JSON.stringify(i)}var{file:lr}=globalThis.Bun;async function Bt(){let t=this.path,{parsed:r}=b(this.path),n=r.slice(0,-1).join("/");this.path=n;let{serverPath:o}=await h.call(this,"folder");if(!o)return null;return this.path=t,await k.call(this)}async function Dt(){let{serverPath:t}=await h.call(this,"file");if(!t)return await Bt.call(this);if(t.bytes)return v.call(this,t.bytes,t.fileSize);return await k.call(this)}async function k(){try{let t=lr(this.dir+this.path);if(t.type.startsWith("video/"))return v.call(this,t,t.size);else{let r=await t.bytes();return v.call(this,r,r.byteLength)}}catch{return`${this.path} file not found.`}}function v(t,r){let{type:n,range:o}=this.request;if(this.type=n,this.status=206,!o)return this.header={"Cache-Control":"max-age=86400, must-revalidate"},nt(t)?this.compress("gzip",t):t;let[s,i,e]=et(r,o);return this.header={"Content-Range":`bytes ${s}-${i}/${e}`,"Content-Length":r.toString()},t.slice(s,i+1)}async function Mt(t){return this.status=t.status,this.header=t.headers.toJSON(),await t.arrayBuffer()}import{ServerSide as hr}from"authored";function O(t,r){if(this.status=r||200,typeof t==="object")return this.type="application/json",JSON.stringify(t);return this.type="text/html",String(t)}async function Wt(t){if(t instanceof hr)return Jt.call(this,t);return O.call(this,t)}class J{type;render;data;constructor(t,r,n={}){this.type=t;this.render=r;this.data=n}static async jwt(t){return new J("jwt",t)}}async function Nt(t,r=!1){let{type:n,render:o,data:s}=t;switch(n){case"jwt":return"jwt"}return"render"}function ar(t){return this.status=t??204,null}async function gr(t){let{header:r,status:n,__session:o}=t;if(q(r))this.header=r;if(n)this.status=n;o&&await gt(o,this.headers)}async function Q(t,r,n=!1){if(!r)return ar.call(this,t.status);if(typeof r==="object"&&"error"in r)return this.status=r.error,null;if(await gr.call(this,t),r instanceof Response)return await Mt.call(this,r);if(r instanceof J){if(t.status)this.status=t.status;return await Nt.call(this,r,n)}switch(this.request.method){case"post":return Wt.call(this,r);default:return O.call(this,r)}}async function Ut(){let{serverPath:t,args:r,session:n}=await h.call(this,"path");if(!t)return this.request.isFile?Dt.call(this):null;let{serverClass:o}=t;if(!o)return null;let s=new o(this.request,r);n&&s.setServerSession(n);let{isEventStream:i,method:e}=this.request;if(i&&s?.eventStream)return qt.call(this,s,r,s.eventStream);if(e==="options")return this.status=204,this.options(t.options);if(s?.[e]){let f=await s[e]();return this.status=200,this.compress("deflate",await Q.call(this,s,f)??"")}return null}async function Gt(){let t=this.path;this.path=this.status.toString();let{serverPath:r,args:n,session:o}=await h.call(this,"error");if(this.path=t,!r)return null;let{serverClass:s}=r;if(!s)return null;let i=new s(this.request,n);i.status=this.status;let{method:e}=this.request;if(i?.[e]){let f=await i[e]();return this.compress("deflate",await Q.call(this,i,f,!0)??"")}return null}class Pt extends d{request;args;status;stream;headers={};constructor(t,r={}){super();this.request=t;this.args=r}set header(t){T(this.headers,t)}get header(){return this.headers}set type(t){this.header={"Content-Type":t}}setCookie({key:t,val:r,path:n="/",days:o=31,httpOnly:s=!1}){let i=ht(t,r,{expires:new I().timed({day:o}),path:n,httpOnly:s,sameSite:"Strict"});this.header={"Set-Cookie":i}}deleteCookie(t){this.setCookie({key:t,val:"",days:0})}}class It{status=404;headers=new Headers({"Content-Type":"text/plain"});set header(t){m(t).forEach(([r,n])=>{this.headers.set(r,n)})}set type(t){this.headers.set("Content-Type",t)}options(t){return t+=", OPTIONS",this.header={Allow:t,"Access-Control-Allow-Methods":t,"Access-Control-Max-Age":"86400"},null}compress(t,r){let o=(t==="gzip"?yr:Sr)(r);return this.header={"Content-Length":o.byteLength.toString(),"Content-Encoding":t},o}get init(){return{status:this.status,headers:this.headers}}}class X extends It{dir;request;path="";constructor(t,r,n="./"){super();this.dir=n;this.request=new $(t,r)}async response(){let{path:t,isWSS:r}=this.request;this.path=t;let n=await(r?_:Ut).call(this);if(!n)n=await Gt.call(this);return new Response(n,this.init)}}import{mkdirSync as br,writeFileSync as Rr,existsSync as Xt}from"fs";var{file:wr}=globalThis.Bun;var Qt=(t,r="")=>{if(Xt(t))return!0;return Rr(t,r,{flag:"wx"}),!0},Y=(t)=>{if(Xt(t))return!0;return br(t,{recursive:!0}),!0},Yt=(t,r)=>{if(!r)Y(t),Qt(t+"/.env",`SECRET_KEY="${y(20)}"
2
+ var tt=function(t,r,n,o){var s=arguments.length,i=s<3?r:o===null?o=Object.getOwnPropertyDescriptor(r,n):o,e;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")i=Reflect.decorate(t,r,n,o);else for(var f=t.length-1;f>=0;f--)if(e=t[f])i=(s<3?e(i):s>3?e(r,n,i):e(r,n))||i;return s>3&&i&&Object.defineProperty(r,n,i),i};var rt=(t,r)=>{if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(t,r)};import{Auth as dr}from"authored";var B=(t)=>typeof t==="function";var D=(t)=>{return!isNaN(parseFloat(t))&&isFinite(t)};var nt=(t)=>{return t instanceof Uint8Array||t instanceof ArrayBuffer||typeof t==="string"};var L=(t)=>typeof t==="string",M=(t)=>Array.isArray(t),ot=(t)=>typeof t==="object";var st=(t)=>{return Number.isInteger(Number(t))};function it(t,r){p(r).forEach(([n,o])=>{ft(t,n,{value:o,writable:!1,configurable:!1,enumerable:!0})})}class S{static set p(t){if(Array.isArray(t))console.log(...t);else console.log(t)}}class Z{_c=0;_id="";constructor(t){if(this._c=0,this._id=t??y(5),t?.includes("-")){let[r,n]=[t.split("-").slice(0,-1).join("-"),t.split("-").slice(-1)[0]];this._id=r,this._c=D(n)?parseInt(n):0}}get id(){return this._id+"-"+this._c}get mid(){return this._id+"-"+ ++this._c}}var et=(t,r)=>{let[n,o]=r.replace(/bytes=/,"").split("-").map((s,i)=>{let e=parseInt(s,10);return isNaN(e)?i===0?0:t-1:e});return[n,o,t]};var Yr=new RegExp(/(\d+)(\d*)/,"m"),At=(t)=>Array.from({length:t},(r,n)=>n),Kt="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Ft="abcdefghijklmnopqrstuvwxyz",Vt=At(10).join("");var R=(t)=>JSON.stringify(t),ut=(t)=>{return JSON.parse(t)},W=(t)=>{if(t.startsWith("webkit"))t="-"+t;return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()},y=(t)=>{let r=Kt+Ft;return Array.from({length:t},(n,o)=>r+(o?Vt:"")).reduce((n,o)=>{return n+=o.charAt(Math.floor(Math.random()*o.length))},"")};class c extends Map{obj(t){t&&p(t).forEach(([r,n])=>this.set(r,n))}map(t){t.forEach((r,n)=>{if(r instanceof c)this.set(n,r);else if(M(r)){if(this.lacks(n))this.set(n,[]);this.get(n).push(...r)}else if(ot(r))this.ass(n,r);else this.set(n,r)})}ass(t,r){if(!this.has(t))this.set(t,{});T(this.get(t),r)}lacks(t){return!this.has(t)}init(t,r){return this.has(t)?this.get(t):this.set(t,r).get(t)}}var{values:E,keys:H,entries:p,fromEntries:pt,hasOwn:_t}=Object;var{defineProperty:ft,assign:T}=Object,q=(t)=>{return Object.keys(t).length};function mt(t){return class extends t{constructor(...r){super(...r);let n=new Map;return new Proxy(this,{get(o,s){let i=`__${s}`;if(!n.has(i)){let e=o[s];if(B(e))e=function(...f){let u=`${i}_${JSON.stringify(f)}`;if(!n.has(u)){let h=o[s].apply(o,f);n.set(u,h)}return n.get(u)};n.set(i,e)}return n.get(i)},set(o,s,i){let e=`__${s}`;return n.set(e,i),!0}})}}}var w=(t,r)=>{return{name:t,content:r}},kt=(t,r)=>{return{property:t,content:r}},vt=(t,r)=>{return{"http-equiv":t,content:r}};class j{metas=[];constructor(t){t&&this.metas.push(w("description",t))}author(t){return this.meta=w("author",t),this}charset(t){return this.meta={charset:t},this}keywords(...t){return this.meta=w("keywords",t.join(", ")),this}viewport(t){let r=p(t).map(([n,o])=>[W(n),String(o)].join("="));return this.meta=w("viewport",r.join(", ")),this}httpEquiv(t){return p(t).forEach(([r,n])=>{this.meta=vt(W(r),String(n))}),this}robots(...t){return this.meta=w("robots",t.join(", ")),this}themeColor(t){return this.meta=w("theme-color",t),this}openGraph(t){return p(t).forEach(([r,n])=>{this.meta=kt("og:"+r,String(n))}),this}twitter(t){return p(t).forEach(([r,n])=>{this.meta=w("twitter:"+r,String(n))}),this}and(t){return this}set meta(t){this.metas.push(t)}}var tr=["charset","name","property","http-equiv"],ht=(t,r)=>{r.forEach((n)=>{for(let o of tr)if(o in n){let s=n[o];t[`${o}_${o==="charset"?"":s}`]=n}})},rr=(t,r)=>{r.forEach((n)=>{if("href"in n){let o=n.href;t[`${o}`]=n}})};class ct{_head;idm;constructor(t){this._head=new c(t)}set head(t){p(t).forEach(([r,n])=>{if(r==="title"||r==="base"){if(n!==void 0)this._head.set(r,n);return}if(n instanceof j)return ht(this._head.init("meta",{}),n.metas);if(!M(n))return;switch(r){case"meta":return ht(this._head.init("meta",{}),n);case"link":return rr(this._head.init("link",{}),n);case"script":if(n.length){this._head.init(r,[]);let o=n.map((s)=>{if(!s.yid&&this.idm)s.yid="sc"+this.idm.mid;return s});this._head.get(r).push(...o)}return}})}get head(){return this._head}set id(t){this.idm=new Z(t)}}class nr{lang="en";htmlHead=new c;head;constructor(){this.head=(t={})=>{let r=new ct(this.htmlHead);r.head=t,this.htmlHead=r.head}}}var lt=(t,r="",{maxAge:n,expires:o,path:s,domain:i,secure:e,httpOnly:f,sameSite:u})=>{if(n instanceof Date)n=n.getSeconds();if(o instanceof Date)o=o.toUTCString();else if(o===0)o=new Date().toUTCString();return[["Domain",i],["Expires",o],["Max-Age",n],["Secure",e],["HttpOnly",f],["Path",s],["SameSite",u]].reduce((a,[x,g])=>{if(g!==void 0)a.push(`${x}=${g}`);return a},[`${t}=${r}`]).join("; ")};var N=(t,r=!1)=>{if(D(t))return[+t,st(t)?"int":"float"];if(r&&/\.\w+$/.test(t))return[t,"file"];if(t==="/")return[t,"-"];if(t.length===36&&t.match(/\-/g)?.length===4)return[t,"uuid"];return[t,"string"]},b=(t)=>{let r=t.startsWith("/")?t:"/"+t,n=r.match(/(?<=\/)[^/].*?(?=\/|$)/g)??["/"],[o,s]=n.reduce(([i,e],f)=>{if(f.includes("<")){let u=f.match(/(?<=<)[^/].*?(?=>|$)/g);if(u?.length){let[h,a]=u[0].split(":");if(h&&a)i.push(h),e.push(a)}}else i.push(f===">"?"/":f);return[i,e]},[[],[]]);if(r.endsWith("/")&&r.length>1)o.push("/");return{parsed:o,args:s}};class U{storage=new c;cache(t,r){if(this.storage.lacks(t))this.storage.set(t,r());return this.storage.get(t)}}var or=["int","float","file","uuid","string"],sr=new U;class z{_storage=new c;set(t){let{parsed:r,path:n}=t,o=R(r);if(!this._storage.get(o))this._storage.set(o,t);else throw`path: ${n} already used.`}get(t){let{parsed:r}=sr.cache(t,()=>b(t)),n={},o=this._storage.get(R(r));if(!o&&t!=="/")for(let s of this._storage.keys()){let i=[],e=ut(s);if(r.length===e.length){let f=e.map((a,x)=>{let g=N(r[x],r.length-1===x);if(a===g[0])return g[0];if(or.includes(g[1]))return i.push(g[0]),g[1];return a}),u=R(f);if(this._storage.has(u)){o=this._storage.get(u),o?.args.forEach((a,x)=>{n[a]=i[x]});break}}}return[o,n]}}class G{constructor(...t){t.forEach((r)=>{if(!this[r])this[r]=new z})}get(t){return this[t]}}class P{path="";parsed=[];args=[];constructor(t){it(this,{path:t,...b(t)})}}class I{date;constructor(t){this.date=t?new Date(t):new Date}delta(t=null,r=!1){let n=I.delta(this.date.getTime(),t);return r?new Date(n):n}timed(t){if(!t)return this.date;return[["year","FullYear"],["month","Month"],["day","Date"],["hour","Hours"],["minute","Minutes"],["second","Seconds"]].reduce((n,[o,s])=>{let i=t[o];return i?new Date(n[`set${s}`](n[`get${s}`]()+i)):n},new Date(this.date))}static delta(t,r=null){return r?r-t:t-Date.now()}static get now(){return Date.now()}}var{file:fr}=globalThis.Bun;import{JWTInterface as ir}from"authored";class at{session;jwt;jwtInt;constructor(){this.jwtInt=new ir}init(t){this.session=t.session,this.jwt=t.jwt}}var m=new at;class d{__session;__jwt;get session(){if(!this.__session)this.__session=m.session.new;return this.__session}set session(t){this.__session=t}get jwt(){if(!this.__jwt)this.__jwt=m.jwt.new;return this.__jwt}set jwt(t){this.__jwt=t}get timedJWT(){return m.jwtInt.jwt()}setServerSession(t){let{__jwt:r,__session:n}=t;this.__session=n,this.__jwt=r}}var gt=async(t,r)=>{await m.session.saveSession(t,r)};async function St({sid:t,jwtv:r,refreshjwt:n},o){let s=new d;if(t){if(s.session=await m.session.openSession(t),!s.session.new)o.session=!0}if(r){if(s.jwt=m.jwtInt.open(r,{hours:6}),!s.jwt.new)o.jwt=!0;if(n){if(!(await m.jwt.openSession(n)).new)o.jwt_refresh=!0}}if("session"in o||"jwt"in o)return s}var er={session(...t){return A(t[0],t[2],"session")},jwt(...t){return A(t[0],t[2],"jwt")},jwt_refresh(...t){return A(t[0],t[2],"jwt_refresh")}},A=(t,r,n)=>{let o=r.value;return r.value=async function(s={}){if(n in s&&s.session)return delete s[n],o.call(t,s);return{error:401}},r};var ur=["GET","POST","PUT","DELETE","OPTIONS"];class bt extends P{config;_class;options="";bytes;fileType="text/plain";fileSize=0;constructor(t,r={}){super(t);this.config=r}set serverClass(t){this._class=t,this.options=ur.filter((r)=>t.prototype[r.toLowerCase()]).join(", ")}get serverClass(){return this._class}async loadBytes(t){if(!this.config.preload)return;try{let r=fr(this.path);this.fileType=r.type,this.bytes=await r.bytes(),this.fileSize=this.bytes.byteLength}catch{throw`error: can't preload ${this.path}. File not found.`}}}var Rt={path:Symbol("path"),wss:Symbol("wss"),file:Symbol("file"),folder:Symbol("folder"),error:Symbol("error")},pr=new G(...E(Rt)),wt=(t)=>{let r=Rt[t];if(!r)throw new Error("Invalid storage type");return pr[r]},C=(t,r,n={},o)=>{return(s)=>{let i=new bt(r,n);if(s)i.serverClass=s;if(t==="file")i.loadBytes(o);return wt(t).set(i),s}},yt={args:{}};async function l(t){let[r,n]=wt(t).get(this.path);if(!r)return yt;let{requireSession:o}=r.config,s=void 0;if(o){if(s=await St(await this.request.authgroup(),n),!s)return yt}return{serverPath:r,args:n,session:s}}class K{dir;apt;files;_statics;statics;constructor(t=".",r={}){this.dir=t;let{dir:n,appDir:o}=r;if(n)this.dir=n;this.apt=this.dir+"/"+(o??"app"),this.files=(...s)=>{s.forEach((i)=>{let[e,f]=Ct(i),u=e.replace(/^\.+/,""),h=u.startsWith("/")?u:"/"+u;C("file",h,f,this.apt)()})},this.statics=(s={})=>{if(!this._statics)this._statics={};T(this._statics,s)}}route(t){return C("path",t)}wss(t,r={}){return C("wss",t,r)}error(...t){return(r)=>{if(t.length)t.forEach((n)=>{C("error",n.toString(),{})(r)});else C("error","404",{})(r);return r}}folders(...t){t.forEach((r)=>{C("folder",...Ct(r))()})}redirect(t,r={}){return new Response("",{status:302,headers:new Headers({...r,Location:t})})}}var Ct=(t)=>{let r=L(t);return[r?t:t[0],r?{}:t[1]]};var{inflateSync:Cr,serve:xr,write:Tr}=globalThis.Bun;class xt extends c{}var F=new xt;var V={async open(t){let r=t.data.wclass,{args:n,client:o}=t.data;if(r){r.ws=t;let s=r.id,i=q(o);if(!(s in o)){let e=i?"joiner":"maker";o[s]={role:e}}if(typeof r.init=="function")await r.init(n);if(r.broadcasting)r.ws.subscribe(r.path);await r.open()}else t.close()},async message(t,r){let n=t.data.wclass;if(n)await n.message(r)},async close(t,r,n){let o=t.data.wclass,s=t.data.client;if(o){if(await o.close(r,n),o.broadcasting)o.ws.unsubscribe(o.path);let i=o.id;if(delete s[i],q(s)===1)H(s).forEach((e)=>{s[e].role="maker"})}}};async function _(){let{serverPath:t,args:r,session:n}=await l.call(this,"wss");if(!t)return this.status=426,"upgrade error";let{serverClass:o}=t;if(!o)return"upgrade error";let s=new o(this.request);n&&s.setServerSession(n);let i=s.path,e=Tt(i),f=e?.size??0,{broadcast:u,maxClient:h}=t.config;if(s.broadcasting=!!u,s.max=h??0,h&&f>=h)return this.status=400,"upgrade error";return this.request.upgradeConnection({data:{wclass:s,args:r,client:e}}),null}class dt extends d{request;ws;path;id;broadcasting=!1;max=0;constructor(t){super();this.request=t;this.path=t.path,this.id=y(10)}open(){}message(t){}close(t,r){}set send(t){if(t)if(this.broadcasting)this.ws.publish(this.path,t);else this.ws.send(t)}get role(){let t=F.get(this.path);if(t&&t.has(this.id))return t.get(this.id)?.role}}var Tt=(t)=>{return F.init(t,new c)};var{deflateSync:Sr,gzipSync:yr}=globalThis.Bun;var{Server:mr,file:hr}=globalThis.Bun;class ${req;server;formData;url;method;__cookies=new Map;constructor(t,r){this.req=t;this.server=r;this.url=new URL(t.url),this.method=this.req.method.toLowerCase()}async form(){if(this.isForm){if(!this.formData)this.formData=await this.req.formData();return this.formData}return new FormData}async authgroup(){let{cookies:t,auth:r}=this,n=t.get("session")??"",o=r??"",s="",i=this.isForm?await this.form():void 0;if(i){let e=i.get("refresh_token");s=e?e.toString():""}return{sid:n,jwtv:o,refreshjwt:s}}upgradeConnection(t={}){return!!this.server?.upgrade(this.req,t)}get auth(){let t=this.headers.get("authorization");if(t){let[r,n]=t.split(" ",2);if(r.trim()=="Bearer")return n.trim()}}get accept(){return this.headers.get("accept")}get contentType(){return this.headers.get("content-type")}get cookies(){if(!this.__cookies.size){let t=this.headers.get("cookie");if(t){let r=t.split(";").reduce((n,o)=>{let[s,i]=o.trim().split(/=(.*)/s);return n.push([s,i]),n},[]);this.__cookies=new Map(r)}}return this.__cookies}get headers(){return this.req.headers??new Headers}get ip(){return this.server?.requestIP(this.req)}get isForm(){let t=this.contentType;return t?t.indexOf("multipart/form-data")>=0||t.indexOf("x-www-form-urlencoded")>=0:!1}get path(){return this.url.pathname}get parsed(){let{parsed:t}=b(this.path);return t}get searchParams(){return this.url.searchParams}get range(){return this.headers.get("range")??void 0}get isEventStream(){return this.accept?.includes("text/event-stream")}get isWSS(){return!!this.headers.get("upgrade")}get isFile(){let t=this.parsed.slice().pop();return t?N(t,!0).pop()==="file":!1}get type(){return hr(this.path).type}get upgrade(){return this.headers.get("upgrade")}get request(){return this.req}get signal(){return this.req.signal}}$=tt([mt,rt("design:paramtypes",[typeof Request==="undefined"?Object:Request,typeof mr==="undefined"?Object:mr])],$);class Et{ctrl;intervalID=[];constructor(t){this.ctrl=t}push(t,r=2000){if(this.ctrl){let n=setInterval(()=>{let{id:o,retry:s,data:i,event:e,end:f}=t();if(this.ctrl){let u=f?"end":i;if(s){let h=s>2000?s:2000;this.ctrl.enqueue(`retry: ${h}\\n`)}if(this.ctrl.enqueue(`id: ${o}\\n`),e&&this.ctrl.enqueue(`event: ${e}\\n`),typeof u=="object")this.ctrl.enqueue("data: "+JSON.stringify(u)+"\\n\\\n");else this.ctrl.enqueue("data: "+JSON.stringify({message:u})+"\\n\\n");f&&this.close()}},r>1000?r:1000);this.intervalID.push(n)}}close(){if(this.intervalID.length)this.intervalID.forEach((t)=>{clearInterval(t)}),this.intervalID=[];this.ctrl?.close()}}async function qt(t,r,n){this.status=200,this.header={"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"};let o=this.request,s=new ReadableStream({async start(e){t.stream=new Et(e),await n.call(t,r),o.signal.addEventListener("abort",()=>{if(t.stream?.close(),t.stream?.intervalID.length)e.close()})}}),i=await n.call(t,r);if(typeof i==="object"&&"error"in i)return this.status=i.error,null;return s}async function $t(t){let r=m.jwtInt.save(t);return t.access_token=r,await m.jwt.saveSession(t,this.headers),{access_token:r,refresh_token:t.sid,status:"ok"}}function Ot(t){return this.status=403,{error:t}}async function Jt(t){let{jwtv:r,refreshjwt:n}=await this.request.authgroup();if(!n){if(r||!t.modified)return this.status=204,this.type="application/json",JSON.stringify({});return JSON.stringify(await $t.call(this,t))}let o=await m.jwt.openSession(n),s=o.data.access_token,i={};if(r!==s)i=Ot.call(this,"tokens don't match.");else if(!m.jwtInt.verify(s,{days:5}))await m.jwt.saveSession(o,void 0,!0),i=Ot.call(this,"expired refresh_token.");else i=await $t.call(this,o);return this.type="application/json",JSON.stringify(i)}var{file:cr}=globalThis.Bun;async function Bt(){let t=this.path,{parsed:r}=b(this.path),n=r.slice(0,-1).join("/");this.path=n;let{serverPath:o}=await l.call(this,"folder");if(!o)return null;return this.path=t,await k.call(this)}async function Dt(){let{serverPath:t}=await l.call(this,"file");if(!t)return await Bt.call(this);if(t.bytes)return v.call(this,t.bytes,t.fileSize);return await k.call(this)}async function k(){try{let t=cr(this.dir+this.path);if(t.type.startsWith("video/"))return v.call(this,t,t.size);else{let r=await t.bytes();return v.call(this,r,r.byteLength)}}catch{return`${this.path} file not found.`}}function v(t,r){let{type:n,range:o}=this.request;if(this.type=n,this.status=206,!o)return this.header={"Cache-Control":"max-age=86400, must-revalidate"},nt(t)?this.compress("gzip",t):t;let[s,i,e]=et(r,o);return this.header={"Content-Range":`bytes ${s}-${i}/${e}`,"Content-Length":r.toString()},t.slice(s,i+1)}async function Mt(t){return this.status=t.status,this.header=t.headers.toJSON(),await t.arrayBuffer()}import{ServerSide as lr}from"authored";function O(t,r){if(this.status=r||200,typeof t==="object")return this.type="application/json",JSON.stringify(t);return this.type="text/html",String(t)}async function Wt(t){if(t instanceof lr)return Jt.call(this,t);return O.call(this,t)}class J{type;render;data;constructor(t,r,n={}){this.type=t;this.render=r;this.data=n}static async jwt(t){return new J("jwt",t)}}async function Nt(t,r=!1){let{type:n,render:o,data:s}=t;switch(n){case"jwt":return"jwt"}return"render"}function ar(t){return this.status=t??204,null}async function gr(t){let{header:r,status:n,__session:o}=t;if(q(r))this.header=r;if(n)this.status=n;o&&await gt(o,this.headers)}async function Q(t,r,n=!1){if(!r)return ar.call(this,t.status);if(typeof r==="object"&&"error"in r)return this.status=r.error,null;if(await gr.call(this,t),r instanceof Response)return await Mt.call(this,r);if(r instanceof J){if(t.status)this.status=t.status;return await Nt.call(this,r,n)}switch(this.request.method){case"post":return Wt.call(this,r);default:return O.call(this,r)}}async function Ut(){let{serverPath:t,args:r,session:n}=await l.call(this,"path");if(!t)return this.request.isFile?Dt.call(this):null;let{serverClass:o}=t;if(!o)return null;let s=new o(this.request,r);n&&s.setServerSession(n);let{isEventStream:i,method:e}=this.request;if(i&&s?.eventStream)return qt.call(this,s,r,s.eventStream);if(e==="options")return this.status=204,this.options(t.options);if(s?.[e]){let f=await s[e]();return this.status=200,this.compress("deflate",await Q.call(this,s,f)??"")}return null}async function Gt(){let t=this.path;this.path=this.status.toString();let{serverPath:r,args:n,session:o}=await l.call(this,"error");if(this.path=t,!r)return null;let{serverClass:s}=r;if(!s)return null;let i=new s(this.request,n);i.status=this.status;let{method:e}=this.request;if(i?.[e]){let f=await i[e]();return this.compress("deflate",await Q.call(this,i,f,!0)??"")}return null}class Pt extends d{request;args;status;stream;path;headers={};constructor(t,r={}){super();this.request=t;this.args=r;this.path=t.path}set header(t){T(this.headers,t)}get header(){return this.headers}set type(t){this.header={"Content-Type":t}}setCookie({key:t,val:r,path:n="/",days:o=31,httpOnly:s=!1}){let i=lt(t,r,{expires:new I().timed({day:o}),path:n,httpOnly:s,sameSite:"Strict"});this.header={"Set-Cookie":i}}deleteCookie(t){this.setCookie({key:t,val:"",days:0})}}class It{status=404;headers=new Headers({"Content-Type":"text/plain"});set header(t){p(t).forEach(([r,n])=>{this.headers.set(r,n)})}set type(t){this.headers.set("Content-Type",t)}options(t){return t+=", OPTIONS",this.header={Allow:t,"Access-Control-Allow-Methods":t,"Access-Control-Max-Age":"86400"},null}compress(t,r){let o=(t==="gzip"?yr:Sr)(r);return this.header={"Content-Length":o.byteLength.toString(),"Content-Encoding":t},o}get init(){return{status:this.status,headers:this.headers}}}class X extends It{dir;request;path="";constructor(t,r,n="./"){super();this.dir=n;this.request=new $(t,r)}async response(){let{path:t,isWSS:r}=this.request;this.path=t;let n=await(r?_:Ut).call(this);if(!n)n=await Gt.call(this);return new Response(n,this.init)}}import{mkdirSync as br,writeFileSync as Rr,existsSync as Xt}from"fs";var{file:wr}=globalThis.Bun;var Qt=(t,r="")=>{if(Xt(t))return!0;return Rr(t,r,{flag:"wx"}),!0},Y=(t)=>{if(Xt(t))return!0;return br(t,{recursive:!0}),!0},Yt=(t,r)=>{if(!r)Y(t),Qt(t+"/.env",`SECRET_KEY="${y(20)}"
3
3
  TLS_KEY=""
4
- TLS_CERT=""`)},Lt=(t)=>{return m(process.env).filter(([r])=>r.startsWith("TLS_")).reduce((r,[n,o])=>{if(o){let s=n.replace("TLS_","").toLowerCase();r[s]=wr(t+"/"+o)}return r},{})};async function Zt(t){let{server:r,wss:n}=t,o=xr({...r,...this._statics&&{static:this._statics},port:r.port||3000,tls:Lt(this.dir),fetch:async(i,e)=>{return await new X(i,e,this.apt).response()},websocket:{sendPings:!0,perMessageDeflate:!0,...n,...V}}),s=()=>{o.stop(),process.exit(0)};process.on("SIGINT",s),process.on("SIGTERM",s)}var Ht=async(t,r)=>{let{path:n,hostname:o,method:s,port:i}=t,f=await(await new X({url:`http://${o??"127.0.0.1"}:${i||3000}${n}`,method:s??"GET"},void 0,r).response()).arrayBuffer();if(f.byteLength)Tr(r+"/index.html",Cr(f));return};import{config as Er}from"dotenv";class jt extends K{index;serve;constructor(t={}){super(".",t);let{envPath:r,appDir:n,session:o}=t,s=this.dir+"/.private";Yt(s,r),Er({path:(r?r:s)+"/.env"});let i=o??new dr({dir:this.dir});p.init(i),this.index=async(e={})=>{e.path=e.path||"/",await Ht(e,this.apt);let f=new Date().toLocaleTimeString();S.p=`index @ ${f}`},this.serve=async(e={},f)=>await Zt.call(this,{server:e,wss:f})}}import{readdirSync as qr,rmSync as $r,statSync as Or,unlinkSync as Jr,watch as Br}from"fs";import Dr from"path";class zt{dir="./src";out="./app";files;external;drop;target;define;exclude=["index.html"];hashAsset;plugins=[];clearing=!1;constructor({files:t,target:r="browser",define:n={},hashAsset:o,external:s=[],drop:i=[],plugins:e=[]}){this.files=t.map((f)=>(this.dir+"/"+f).replaceAll("//","/")),this.hashAsset=o==null?!0:o,this.external=s,this.drop=i,this.plugins=e,Y(this.out),this.target=r,this.define=n}clear(t={exclude:[]}){t.exclude.length&&this.exclude.push(...t.exclude),this.clearing=!0;let r=(n)=>{let o=qr(n);if(o.length==0){$r(n,{recursive:!0});return}o.forEach((s)=>{if(s.startsWith(".")||this.exclude.includes(s))return;let i=Dr.join(n,s);if(Or(i).isDirectory())r(i);else Jr(i)})};return r(this.out),this}build(){let t=`[dir]/[name]${this.hashAsset?"-[hash]":""}.[ext]`;if(this.files.length)Bun.build({entrypoints:this.files,outdir:this.out,splitting:!0,minify:{identifiers:!0,whitespace:!0,syntax:!0},target:this.target??"browser",naming:{chunk:"[dir]/[name]-[hash].[ext]",entry:"[dir]/[name].[ext]",asset:t},define:{...Mr(this.define)},loader:{".css":"file"},external:this.external,drop:this.drop,plugins:this.plugins}).then((r)=>{if(r.success){let n=new Date().toLocaleTimeString();S.p=`builder @ ${n}`}else S.p=r.logs}).catch((r)=>{S.p=r});return this}watch(t){let r=Br(this.dir,{recursive:!0},async(n,o)=>{if(o&&o.endsWith("tsx")){this.clearing&&this.clear();try{this.build()}catch(s){console.error(s)}t?.(n,o)}});process.on("SIGINT",()=>{console.log(`
5
- watcher closed...`),r.close(),process.exit(0)})}}var Mr=(t)=>{return mt(m(t).map(([r,n])=>{let o=n;if(B(n))o=n();return[r,R(o)]}))};export{dt as websocket,Pt as response,er as auths,jt as Rossa,J as Render,zt as Builder,S as $$};
4
+ TLS_CERT=""`)},Lt=(t)=>{return p(process.env).filter(([r])=>r.startsWith("TLS_")).reduce((r,[n,o])=>{if(o){let s=n.replace("TLS_","").toLowerCase();r[s]=wr(t+"/"+o)}return r},{})};async function Zt(t){let{server:r,wss:n}=t,o=xr({...r,...this._statics&&{static:this._statics},port:r.port||3000,tls:Lt(this.dir),fetch:async(i,e)=>{return await new X(i,e,this.apt).response()},websocket:{sendPings:!0,perMessageDeflate:!0,...n,...V}}),s=()=>{o.stop(),process.exit(0)};process.on("SIGINT",s),process.on("SIGTERM",s)}var Ht=async(t,r)=>{let{path:n,hostname:o,method:s,port:i}=t,f=await(await new X({url:`http://${o??"127.0.0.1"}:${i||3000}${n}`,method:s??"GET"},void 0,r).response()).arrayBuffer();if(f.byteLength)Tr(r+"/index.html",Cr(f));return};import{config as Er}from"dotenv";class jt extends K{index;serve;constructor(t={}){super(".",t);let{envPath:r,appDir:n,session:o}=t,s=this.dir+"/.private";Yt(s,r),Er({path:(r?r:s)+"/.env"});let i=o??new dr({dir:this.dir});m.init(i),this.index=async(e={})=>{e.path=e.path||"/",await Ht(e,this.apt);let f=new Date().toLocaleTimeString();S.p=`index @ ${f}`},this.serve=async(e={},f)=>await Zt.call(this,{server:e,wss:f})}}import{readdirSync as qr,rmSync as $r,statSync as Or,unlinkSync as Jr,watch as Br}from"fs";import Dr from"path";class zt{dir="./src";out="./app";files;external;drop;target;define;exclude=["index.html"];hashAsset;plugins=[];clearing=!1;constructor({files:t,target:r="browser",define:n={},hashAsset:o,external:s=[],drop:i=[],plugins:e=[]}){this.files=t.map((f)=>(this.dir+"/"+f).replaceAll("//","/")),this.hashAsset=o==null?!0:o,this.external=s,this.drop=i,this.plugins=e,Y(this.out),this.target=r,this.define=n}clear(t={exclude:[]}){t.exclude.length&&this.exclude.push(...t.exclude),this.clearing=!0;let r=(n)=>{let o=qr(n);if(o.length==0){$r(n,{recursive:!0});return}o.forEach((s)=>{if(s.startsWith(".")||this.exclude.includes(s))return;let i=Dr.join(n,s);if(Or(i).isDirectory())r(i);else Jr(i)})};return r(this.out),this}build(){let t=`[dir]/[name]${this.hashAsset?"-[hash]":""}.[ext]`;if(this.files.length)Bun.build({entrypoints:this.files,outdir:this.out,splitting:!0,minify:{identifiers:!0,whitespace:!0,syntax:!0},target:this.target??"browser",naming:{chunk:"[dir]/[name]-[hash].[ext]",entry:"[dir]/[name].[ext]",asset:t},define:{...Mr(this.define)},loader:{".css":"file"},external:this.external,drop:this.drop,plugins:this.plugins}).then((r)=>{if(r.success){let n=new Date().toLocaleTimeString();S.p=`builder @ ${n}`}else S.p=r.logs}).catch((r)=>{S.p=r});return this}watch(t){let r=Br(this.dir,{recursive:!0},async(n,o)=>{if(o&&o.endsWith("tsx")){this.clearing&&this.clear();try{this.build()}catch(s){console.error(s)}t?.(n,o)}});process.on("SIGINT",()=>{console.log(`
5
+ watcher closed...`),r.close(),process.exit(0)})}}var Mr=(t)=>{return pt(p(t).map(([r,n])=>{let o=n;if(B(n))o=n();return[r,R(o)]}))};export{dt as websocket,Pt as response,er as auths,jt as Rossa,J as Render,zt as Builder,S as $$};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rossa",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Rossa Bun JS framework",
5
5
  "author": "Marky <markjotep@gmail.com>",
6
6
  "license": "MIT",