rossa 0.0.1 → 0.0.3
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/dist/index.d.ts +3 -30
- package/dist/index.js +2 -3
- package/package.json +6 -6
package/LICENSE
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ServerSide, Auth } from 'authored';
|
|
2
2
|
import * as bun from 'bun';
|
|
3
|
-
import { Server, ServerWebSocket, Serve, WebSocketHandler
|
|
3
|
+
import { Server, ServerWebSocket, Serve, WebSocketHandler } from 'bun';
|
|
4
4
|
|
|
5
5
|
type obj<T> = Record<string, T>;
|
|
6
6
|
|
|
@@ -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;
|
|
@@ -174,34 +175,6 @@ declare class Rossa extends Formula {
|
|
|
174
175
|
constructor(options?: yveOptions);
|
|
175
176
|
}
|
|
176
177
|
|
|
177
|
-
declare class Builder {
|
|
178
|
-
dir: string;
|
|
179
|
-
out: string;
|
|
180
|
-
files: string[];
|
|
181
|
-
external: string[];
|
|
182
|
-
drop: string[];
|
|
183
|
-
target: string;
|
|
184
|
-
define: Record<string, any>;
|
|
185
|
-
exclude: string[];
|
|
186
|
-
hashAsset: boolean;
|
|
187
|
-
plugins: BunPlugin[];
|
|
188
|
-
private clearing?;
|
|
189
|
-
constructor({ files, target, define, hashAsset, external, drop, plugins, }: {
|
|
190
|
-
files: string[];
|
|
191
|
-
target?: "browser" | "bun";
|
|
192
|
-
define?: Record<string, any>;
|
|
193
|
-
hashAsset?: boolean;
|
|
194
|
-
external?: string[];
|
|
195
|
-
drop?: string[];
|
|
196
|
-
plugins?: BunPlugin[];
|
|
197
|
-
});
|
|
198
|
-
clear(c?: {
|
|
199
|
-
exclude: string[];
|
|
200
|
-
}): this;
|
|
201
|
-
build(): this;
|
|
202
|
-
watch(fn?: (event: any, filename: any) => void): void;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
178
|
declare class Render<T> {
|
|
206
179
|
type: "yra" | "jwt";
|
|
207
180
|
render: T;
|
|
@@ -210,4 +183,4 @@ declare class Render<T> {
|
|
|
210
183
|
static jwt(jwtSession: any): Promise<Render<ServerSide>>;
|
|
211
184
|
}
|
|
212
185
|
|
|
213
|
-
export { $$,
|
|
186
|
+
export { $$, Render, Rossa, auths, response, websocket };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
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 k=function(t,n,r,o){var i=arguments.length,s=i<3?n:o===null?o=Object.getOwnPropertyDescriptor(n,r):o,e;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")s=Reflect.decorate(t,n,r,o);else for(var f=t.length-1;f>=0;f--)if(e=t[f])s=(i<3?e(s):i>3?e(n,r,s):e(n,r))||s;return i>3&&s&&Object.defineProperty(n,r,s),s};var v=(t,n)=>{if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(t,n)};import{Auth as Tn}from"authored";var tt=(t)=>typeof t==="function";var J=(t)=>{return!isNaN(parseFloat(t))&&isFinite(t)};var nt=(t)=>{return t instanceof Uint8Array||t instanceof ArrayBuffer||typeof t==="string"};var A=(t)=>typeof t==="string",C=(t)=>Array.isArray(t),rt=(t)=>typeof t==="object";var ot=(t)=>{return Number.isInteger(Number(t))};function it(t,n){m(n).forEach(([r,o])=>{et(t,r,{value:o,writable:!1,configurable:!1,enumerable:!0})})}class M{static set p(t){if(Array.isArray(t))console.log(...t);else console.log(t)}}class Q{_c=0;_id="";constructor(t){if(this._c=0,this._id=t??S(5),t?.includes("-")){let[n,r]=[t.split("-").slice(0,-1).join("-"),t.split("-").slice(-1)[0]];this._id=n,this._c=J(r)?parseInt(r):0}}get id(){return this._id+"-"+this._c}get mid(){return this._id+"-"+ ++this._c}}var st=(t,n)=>{let[r,o]=n.replace(/bytes=/,"").split("-").map((i,s)=>{let e=parseInt(i,10);return isNaN(e)?s===0?0:t-1:e});return[r,o,t]};var Bn=new RegExp(/(\d+)(\d*)/,"m"),jt=(t)=>Array.from({length:t},(n,r)=>r),zt="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Ft="abcdefghijklmnopqrstuvwxyz",Kt=jt(10).join("");var T=(t)=>JSON.stringify(t),ft=(t)=>{return JSON.parse(t)},P=(t)=>{if(t.startsWith("webkit"))t="-"+t;return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()},S=(t)=>{let n=zt+Ft;return Array.from({length:t},(r,o)=>n+(o?Kt:"")).reduce((r,o)=>{return r+=o.charAt(Math.floor(Math.random()*o.length))},"")};class l extends Map{obj(t){t&&m(t).forEach(([n,r])=>this.set(n,r))}map(t){t.forEach((n,r)=>{if(n instanceof l)this.set(r,n);else if(C(n)){if(this.lacks(r))this.set(r,[]);this.get(r).push(...n)}else if(rt(n))this.ass(r,n);else this.set(r,n)})}ass(t,n){if(!this.has(t))this.set(t,{});d(this.get(t),n)}lacks(t){return!this.has(t)}init(t,n){return this.has(t)?this.get(t):this.set(t,n).get(t)}}var{values:E,keys:X,entries:m}=Object;var _t=Object.hasOwn;var{defineProperty:et,assign:d}=Object,$=(t)=>{return Object.keys(t).length};function ut(t){return class extends t{constructor(...n){super(...n);let r=new Map;return new Proxy(this,{get(o,i){let s=`__${i}`;if(!r.has(s)){let e=o[i];if(tt(e))e=function(...f){let u=`${s}_${JSON.stringify(f)}`;if(!r.has(u)){let h=o[i].apply(o,f);r.set(u,h)}return r.get(u)};r.set(s,e)}return r.get(s)},set(o,i,s){let e=`__${i}`;return r.set(e,s),!0}})}}}var b=(t,n)=>{return{name:t,content:n}},Vt=(t,n)=>{return{property:t,content:n}},kt=(t,n)=>{return{"http-equiv":t,content:n}};class Y{metas=[];constructor(t){t&&this.metas.push(b("description",t))}author(t){return this.meta=b("author",t),this}charset(t){return this.meta={charset:t},this}keywords(...t){return this.meta=b("keywords",t.join(", ")),this}viewport(t){let n=m(t).map(([r,o])=>[P(r),String(o)].join("="));return this.meta=b("viewport",n.join(", ")),this}httpEquiv(t){return m(t).forEach(([n,r])=>{this.meta=kt(P(n),String(r))}),this}robots(...t){return this.meta=b("robots",t.join(", ")),this}themeColor(t){return this.meta=b("theme-color",t),this}openGraph(t){return m(t).forEach(([n,r])=>{this.meta=Vt("og:"+n,String(r))}),this}twitter(t){return m(t).forEach(([n,r])=>{this.meta=b("twitter:"+n,String(r))}),this}and(t){return this}set meta(t){this.metas.push(t)}}var vt=["charset","name","property","http-equiv"],mt=(t,n)=>{n.forEach((r)=>{for(let o of vt)if(o in r){let i=r[o];t[`${o}_${o==="charset"?"":i}`]=r}})},tn=(t,n)=>{n.forEach((r)=>{if("href"in r){let o=r.href;t[`${o}`]=r}})};class pt{_head;idm;constructor(t){this._head=new l(t)}set head(t){m(t).forEach(([n,r])=>{if(n==="title"||n==="base"){if(r!==void 0)this._head.set(n,r);return}if(r instanceof Y)return mt(this._head.init("meta",{}),r.metas);if(!C(r))return;switch(n){case"meta":return mt(this._head.init("meta",{}),r);case"link":return tn(this._head.init("link",{}),r);case"script":if(r.length){this._head.init(n,[]);let o=r.map((i)=>{if(!i.yid&&this.idm)i.yid="sc"+this.idm.mid;return i});this._head.get(n).push(...o)}return}})}get head(){return this._head}set id(t){this.idm=new Q(t)}}class nn{lang="en";htmlHead=new l;head;constructor(){this.head=(t={})=>{let n=new pt(this.htmlHead);n.head=t,this.htmlHead=n.head}}}var ht=(t,n="",{maxAge:r,expires:o,path:i,domain:s,secure:e,httpOnly:f,sameSite:u})=>{if(r instanceof Date)r=r.getSeconds();if(o instanceof Date)o=o.toUTCString();else if(o===0)o=new Date().toUTCString();return[["Domain",s],["Expires",o],["Max-Age",r],["Secure",e],["HttpOnly",f],["Path",i],["SameSite",u]].reduce((c,[w,g])=>{if(g!==void 0)c.push(`${w}=${g}`);return c},[`${t}=${n}`]).join("; ")};var B=(t,n=!1)=>{if(J(t))return[+t,ot(t)?"int":"float"];if(n&&/\.\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"]},y=(t)=>{let n=t.startsWith("/")?t:"/"+t,r=n.match(/(?<=\/)[^/].*?(?=\/|$)/g)??["/"],[o,i]=r.reduce(([s,e],f)=>{if(f.includes("<")){let u=f.match(/(?<=<)[^/].*?(?=>|$)/g);if(u?.length){let[h,c]=u[0].split(":");if(h&&c)s.push(h),e.push(c)}}else s.push(f===">"?"/":f);return[s,e]},[[],[]]);if(n.endsWith("/")&&n.length>1)o.push("/");return{parsed:o,args:i}};class W{storage=new l;cache(t,n){if(this.storage.lacks(t))this.storage.set(t,n());return this.storage.get(t)}}var rn=["int","float","file","uuid","string"],on=new W;class L{_storage=new l;set(t){let{parsed:n,path:r}=t,o=T(n);if(!this._storage.get(o))this._storage.set(o,t);else throw`path: ${r} already used.`}get(t){let{parsed:n}=on.cache(t,()=>y(t)),r={},o=this._storage.get(T(n));if(!o&&t!=="/")for(let i of this._storage.keys()){let s=[],e=ft(i);if(n.length===e.length){let f=e.map((c,w)=>{let g=B(n[w],n.length-1===w);if(c===g[0])return g[0];if(rn.includes(g[1]))return s.push(g[0]),g[1];return c}),u=T(f);if(this._storage.has(u)){o=this._storage.get(u),o?.args.forEach((c,w)=>{r[c]=s[w]});break}}}return[o,r]}}class N{constructor(...t){t.forEach((n)=>{if(!this[n])this[n]=new L})}get(t){return this[t]}}class U{path="";parsed=[];args=[];constructor(t){it(this,{path:t,...y(t)})}}class G{date;constructor(t){this.date=t?new Date(t):new Date}delta(t=null,n=!1){let r=G.delta(this.date.getTime(),t);return n?new Date(r):r}timed(t){if(!t)return this.date;return[["year","FullYear"],["month","Month"],["day","Date"],["hour","Hours"],["minute","Minutes"],["second","Seconds"]].reduce((r,[o,i])=>{let s=t[o];return s?new Date(r[`set${i}`](r[`get${i}`]()+s)):r},new Date(this.date))}static delta(t,n=null){return n?n-t:t-Date.now()}static get now(){return Date.now()}}var{file:fn}=globalThis.Bun;import{JWTInterface as sn}from"authored";class lt{session;jwt;jwtInt;constructor(){this.jwtInt=new sn}init(t){this.session=t.session,this.jwt=t.jwt}}var p=new lt;class x{__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:n,__session:r}=t;this.__session=r,this.__jwt=n}}var at=async(t,n)=>{await p.session.saveSession(t,n)};async function ct({sid:t,jwtv:n,refreshjwt:r},o){let i=new x;if(t){if(i.session=await p.session.openSession(t),!i.session.new)o.session=!0}if(n){if(i.jwt=p.jwtInt.open(n,{hours:6}),!i.jwt.new)o.jwt=!0;if(r){if(!(await p.jwt.openSession(r)).new)o.jwt_refresh=!0}}if("session"in o||"jwt"in o)return i}var en={session(...t){return Z(t[0],t[2],"session")},jwt(...t){return Z(t[0],t[2],"jwt")},jwt_refresh(...t){return Z(t[0],t[2],"jwt_refresh")}},Z=(t,n,r)=>{let o=n.value;return n.value=async function(i={}){if(r in i&&i.session)return delete i[r],o.call(t,i);return{error:401}},n};var un=["GET","POST","PUT","DELETE","OPTIONS"];class St extends U{config;_class;options="";bytes;fileType="text/plain";fileSize=0;constructor(t,n={}){super(t);this.config=n}set serverClass(t){this._class=t,this.options=un.filter((n)=>t.prototype[n.toLowerCase()]).join(", ")}get serverClass(){return this._class}async loadBytes(t){if(!this.config.preload)return;try{let n=fn(this.path);this.fileType=n.type,this.bytes=await n.bytes(),this.fileSize=this.bytes.byteLength}catch{throw`error: can't preload ${this.path}. File not found.`}}}var yt={path:Symbol("path"),wss:Symbol("wss"),file:Symbol("file"),folder:Symbol("folder"),error:Symbol("error")},mn=new N(...E(yt)),bt=(t)=>{let n=yt[t];if(!n)throw new Error("Invalid storage type");return mn[n]},R=(t,n,r={},o)=>{return(i)=>{let s=new St(n,r);if(i)s.serverClass=i;if(t==="file")s.loadBytes(o);return bt(t).set(s),i}},gt={args:{}};async function a(t){let[n,r]=bt(t).get(this.path);if(!n)return gt;let{requireSession:o}=n.config,i=void 0;if(o){if(i=await ct(await this.request.authgroup(),r),!i)return gt}return{serverPath:n,args:r,session:i}}class j{dir;apt;files;_statics;statics;constructor(t=".",n={}){this.dir=t;let{dir:r,appDir:o}=n;if(r)this.dir=r;this.apt=this.dir+"/"+(o??"app"),this.files=(...i)=>{i.forEach((s)=>{let[e,f]=Rt(s),u=e.replace(/^\.+/,""),h=u.startsWith("/")?u:"/"+u;R("file",h,f,this.apt)()})},this.statics=(i={})=>{if(!this._statics)this._statics={};d(this._statics,i)}}route(t){return R("path",t)}wss(t,n={}){return R("wss",t,n)}error(...t){return(n)=>{if(t.length)t.forEach((r)=>{R("error",r.toString(),{})(n)});else R("error","404",{})(n);return n}}folders(...t){t.forEach((n)=>{R("folder",...Rt(n))()})}redirect(t,n={}){return new Response("",{status:302,headers:new Headers({...n,Location:t})})}}var Rt=(t)=>{let n=A(t);return[n?t:t[0],n?{}:t[1]]};var{inflateSync:dn,serve:xn,write:Cn}=globalThis.Bun;class wt extends l{}var z=new wt;var F={async open(t){let n=t.data.wclass,{args:r,client:o}=t.data;if(n){n.ws=t;let i=n.id,s=$(o);if(!(i in o)){let e=s?"joiner":"maker";o[i]={role:e}}if(typeof n.init=="function")await n.init(r);if(n.broadcasting)n.ws.subscribe(n.path);await n.open()}else t.close()},async message(t,n){let r=t.data.wclass;if(r)await r.message(n)},async close(t,n,r){let o=t.data.wclass,i=t.data.client;if(o){if(await o.close(n,r),o.broadcasting)o.ws.unsubscribe(o.path);let s=o.id;if(delete i[s],$(i)===1)X(i).forEach((e)=>{i[e].role="maker"})}}};async function K(){let{serverPath:t,args:n,session:r}=await a.call(this,"wss");if(!t)return this.status=426,"upgrade error";let{serverClass:o}=t;if(!o)return"upgrade error";let i=new o(this.request);r&&i.setServerSession(r);let s=i.path,e=dt(s),f=e?.size??0,{broadcast:u,maxClient:h}=t.config;if(i.broadcasting=!!u,i.max=h??0,h&&f>=h)return this.status=400,"upgrade error";return this.request.upgradeConnection({data:{wclass:i,args:n,client:e}}),null}class xt extends x{request;ws;path;id;broadcasting=!1;max=0;constructor(t){super();this.request=t;this.path=t.path,this.id=S(10)}open(){}message(t){}close(t,n){}set send(t){if(t)if(this.broadcasting)this.ws.publish(this.path,t);else this.ws.send(t)}get role(){let t=z.get(this.path);if(t&&t.has(this.id))return t.get(this.id)?.role}}var dt=(t)=>{return z.init(t,new l)};var{deflateSync:Sn,gzipSync:yn}=globalThis.Bun;var{Server:pn,file:hn}=globalThis.Bun;class q{req;server;formData;url;method;__cookies=new Map;constructor(t,n){this.req=t;this.server=n;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:n}=this,r=t.get("session")??"",o=n??"",i="",s=this.isForm?await this.form():void 0;if(s){let e=s.get("refresh_token");i=e?e.toString():""}return{sid:r,jwtv:o,refreshjwt:i}}upgradeConnection(t={}){return!!this.server?.upgrade(this.req,t)}get auth(){let t=this.headers.get("authorization");if(t){let[n,r]=t.split(" ",2);if(n.trim()=="Bearer")return r.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 n=t.split(";").reduce((r,o)=>{let[i,s]=o.trim().split(/=(.*)/s);return r.push([i,s]),r},[]);this.__cookies=new Map(n)}}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}=y(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?B(t,!0).pop()==="file":!1}get type(){return hn(this.path).type}get upgrade(){return this.headers.get("upgrade")}get request(){return this.req}get signal(){return this.req.signal}}q=k([ut,v("design:paramtypes",[typeof Request==="undefined"?Object:Request,typeof pn==="undefined"?Object:pn])],q);class Ct{ctrl;intervalID=[];constructor(t){this.ctrl=t}push(t,n=2000){if(this.ctrl){let r=setInterval(()=>{let{id:o,retry:i,data:s,event:e,end:f}=t();if(this.ctrl){let u=f?"end":s;if(i){let h=i>2000?i: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()}},n>1000?n:1000);this.intervalID.push(r)}}close(){if(this.intervalID.length)this.intervalID.forEach((t)=>{clearInterval(t)}),this.intervalID=[];this.ctrl?.close()}}async function Tt(t,n,r){this.status=200,this.header={"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"};let o=this.request,i=new ReadableStream({async start(e){t.stream=new Ct(e),await r.call(t,n),o.signal.addEventListener("abort",()=>{if(t.stream?.close(),t.stream?.intervalID.length)e.close()})}}),s=await r.call(t,n);if(typeof s==="object"&&"error"in s)return this.status=s.error,null;return i}async function Et(t){let n=p.jwtInt.save(t);return t.access_token=n,await p.jwt.saveSession(t,this.headers),{access_token:n,refresh_token:t.sid,status:"ok"}}function $t(t){return this.status=403,{error:t}}async function qt(t){let{jwtv:n,refreshjwt:r}=await this.request.authgroup();if(!r){if(n||!t.modified)return this.status=204,this.type="application/json",JSON.stringify({});return JSON.stringify(await Et.call(this,t))}let o=await p.jwt.openSession(r),i=o.data.access_token,s={};if(n!==i)s=$t.call(this,"tokens don't match.");else if(!p.jwtInt.verify(i,{days:5}))await p.jwt.saveSession(o,void 0,!0),s=$t.call(this,"expired refresh_token.");else s=await Et.call(this,o);return this.type="application/json",JSON.stringify(s)}var{file:ln}=globalThis.Bun;async function Ot(){let t=this.path,{parsed:n}=y(this.path),r=n.slice(0,-1).join("/");this.path=r;let{serverPath:o}=await a.call(this,"folder");if(!o)return null;return this.path=t,await _.call(this)}async function Dt(){let{serverPath:t}=await a.call(this,"file");if(!t)return await Ot.call(this);if(t.bytes)return V.call(this,t.bytes,t.fileSize);return await _.call(this)}async function _(){try{let t=ln(this.dir+this.path);if(t.type.startsWith("video/"))return V.call(this,t,t.size);else{let n=await t.bytes();return V.call(this,n,n.byteLength)}}catch{return`${this.path} file not found.`}}function V(t,n){let{type:r,range:o}=this.request;if(this.type=r,this.status=206,!o)return this.header={"Cache-Control":"max-age=86400, must-revalidate"},nt(t)?this.compress("gzip",t):t;let[i,s,e]=st(n,o);return this.header={"Content-Range":`bytes ${i}-${s}/${e}`,"Content-Length":n.toString()},t.slice(i,s+1)}async function Jt(t){return this.status=t.status,this.header=t.headers.toJSON(),await t.arrayBuffer()}import{ServerSide as an}from"authored";function O(t,n){if(this.status=n||200,typeof t==="object")return this.type="application/json",JSON.stringify(t);return this.type="text/html",String(t)}async function Mt(t){if(t instanceof an)return qt.call(this,t);return O.call(this,t)}class D{type;render;data;constructor(t,n,r={}){this.type=t;this.render=n;this.data=r}static async jwt(t){return new D("jwt",t)}}async function Pt(t,n=!1){let{type:r,render:o,data:i}=t;switch(r){case"jwt":return"jwt"}return"render"}function cn(t){return this.status=t??204,null}async function gn(t){let{header:n,status:r,__session:o}=t;if($(n))this.header=n;if(r)this.status=r;o&&await at(o,this.headers)}async function I(t,n,r=!1){if(!n)return cn.call(this,t.status);if(typeof n==="object"&&"error"in n)return this.status=n.error,null;if(await gn.call(this,t),n instanceof Response)return await Jt.call(this,n);if(n instanceof D){if(t.status)this.status=t.status;return await Pt.call(this,n,r)}switch(this.request.method){case"post":return Mt.call(this,n);default:return O.call(this,n)}}async function Bt(){let{serverPath:t,args:n,session:r}=await a.call(this,"path");if(!t)return this.request.isFile?Dt.call(this):null;let{serverClass:o}=t;if(!o)return null;let i=new o(this.request,n);r&&i.setServerSession(r);let{isEventStream:s,method:e}=this.request;if(s&&i?.eventStream)return Tt.call(this,i,n,i.eventStream);if(e==="options")return this.status=204,this.options(t.options);if(i?.[e]){let f=await i[e]();return this.status=200,this.compress("deflate",await I.call(this,i,f)??"")}return null}async function Wt(){let t=this.path;this.path=this.status.toString();let{serverPath:n,args:r,session:o}=await a.call(this,"error");if(this.path=t,!n)return null;let{serverClass:i}=n;if(!i)return null;let s=new i(this.request,r);s.status=this.status;let{method:e}=this.request;if(s?.[e]){let f=await s[e]();return this.compress("deflate",await I.call(this,s,f,!0)??"")}return null}class Nt extends x{request;args;status;stream;path;headers={};constructor(t,n={}){super();this.request=t;this.args=n;this.path=t.path}set header(t){d(this.headers,t)}get header(){return this.headers}set type(t){this.header={"Content-Type":t}}setCookie({key:t,val:n,path:r="/",days:o=31,httpOnly:i=!1}){let s=ht(t,n,{expires:new G().timed({day:o}),path:r,httpOnly:i,sameSite:"Strict"});this.header={"Set-Cookie":s}}deleteCookie(t){this.setCookie({key:t,val:"",days:0})}}class Ut{status=404;headers=new Headers({"Content-Type":"text/plain"});set header(t){m(t).forEach(([n,r])=>{this.headers.set(n,r)})}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,n){let o=(t==="gzip"?yn:Sn)(n);return this.header={"Content-Length":o.byteLength.toString(),"Content-Encoding":t},o}get init(){return{status:this.status,headers:this.headers}}}class H extends Ut{dir;request;path="";constructor(t,n,r="./"){super();this.dir=r;this.request=new q(t,n)}async response(){let{path:t,isWSS:n}=this.request;this.path=t;let r=await(n?K:Bt).call(this);if(!r)r=await Wt.call(this);return new Response(r,this.init)}}import{mkdirSync as bn,writeFileSync as Rn,existsSync as Ht}from"fs";var{file:wn}=globalThis.Bun;var Gt=(t,n="")=>{if(Ht(t))return!0;return Rn(t,n,{flag:"wx"}),!0},It=(t)=>{if(Ht(t))return!0;return bn(t,{recursive:!0}),!0},At=(t,n)=>{if(!n)It(t),Gt(t+"/.env",`SECRET_KEY="${S(20)}"
|
|
3
3
|
TLS_KEY=""
|
|
4
|
-
TLS_CERT=""`)},
|
|
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=""`)},Qt=(t)=>{return m(process.env).filter(([n])=>n.startsWith("TLS_")).reduce((n,[r,o])=>{if(o){let i=r.replace("TLS_","").toLowerCase();n[i]=wn(t+"/"+o)}return n},{})};async function Xt(t){let{server:n,wss:r}=t,o=xn({...n,...this._statics&&{static:this._statics},port:n.port||3000,tls:Qt(this.dir),fetch:async(s,e)=>{return await new H(s,e,this.apt).response()},websocket:{sendPings:!0,perMessageDeflate:!0,...r,...F}}),i=()=>{o.stop(),process.exit(0)};process.on("SIGINT",i),process.on("SIGTERM",i)}var Yt=async(t,n)=>{let{path:r,hostname:o,method:i,port:s}=t,f=await(await new H({url:`http://${o??"127.0.0.1"}:${s||3000}${r}`,method:i??"GET"},void 0,n).response()).arrayBuffer();if(f.byteLength)Cn(n+"/index.html",dn(f));return};import{config as En}from"dotenv";class Lt extends j{index;serve;constructor(t={}){super(".",t);let{envPath:n,session:r}=t,o=this.dir+"/.private";At(o,n),En({path:(n?n:o)+"/.env"});let i=r??new Tn({dir:this.dir});p.init(i),this.index=async(s={})=>{s.path=s.path||"/",await Yt(s,this.apt);let e=new Date().toLocaleTimeString();M.p=`index @ ${e}`},this.serve=async(s={},e)=>await Xt.call(this,{server:s,wss:e})}}export{xt as websocket,Nt as response,en as auths,Lt as Rossa,D as Render,M as $$};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rossa",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Rossa Bun JS framework",
|
|
5
5
|
"author": "Marky <markjotep@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"jsonwebtoken": "^9.0.2",
|
|
37
37
|
"authored": "latest",
|
|
38
|
-
"dotenv": "^16.4.7"
|
|
39
|
-
"rollup": "^4.34.6",
|
|
40
|
-
"rollup-plugin-dts": "^6.1.1"
|
|
38
|
+
"dotenv": "^16.4.7"
|
|
41
39
|
},
|
|
42
40
|
"devDependencies": {
|
|
43
|
-
"@types/jsonwebtoken": "^9.0.
|
|
44
|
-
"@types/bun": "
|
|
41
|
+
"@types/jsonwebtoken": "^9.0.9",
|
|
42
|
+
"@types/bun": "1.2.2",
|
|
43
|
+
"rollup": "^4.34.8",
|
|
44
|
+
"rollup-plugin-dts": "^6.1.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"typescript": "^5.7.2"
|