UNPKG

insite-server

Version:
3 lines (2 loc) 4.96 kB
function h(){}var S=new WeakMap,x=class o extends Promise{constructor(t,e){let r,n;if(super((i,f)=>{r=i,n=f}),S.set(this,{resolve:r,reject:n}),e?.signal)if(e.signal.aborted)this.reject(new DOMException("Aborted","AbortError"));else{let i=()=>this.reject(new DOMException("Aborted","AbortError"));e.signal.addEventListener("abort",i),this.finally(()=>e.signal?.removeEventListener("abort",i))}if(typeof e?.timeout=="number"&&Number.isFinite(e.timeout)){let i=setTimeout(()=>this.reject(new DOMException("Timeout exceeded","TimeoutError")),e.timeout);this.finally(()=>clearTimeout(i))}t?.(this.resolve,this.reject)}isPending=!0;isFulfilled=!1;isRejected=!1;state="pending";result;resolve=t=>{if(this.isPending){this.isPending=!1,this.isFulfilled=!0,this.state="fulfilled",this.result=t;let e=S.get(this);e&&(e.resolve.call(this,t),S.delete(this))}};reject=t=>{if(this.isPending){this.isPending=!1,this.isRejected=!0,this.state="rejected",this.result=t;let e=S.get(this);e&&(e.reject.call(this,t),S.delete(this))}};static resolved(t){return new o(e=>e(t))}static rejected(t){return new o((e,r)=>r(t))}};function E(o,t=0,e={}){let{leading:r=!1,trailing:n=!0}=e,{maxWait:i=1/0}=e,f,l,a,u,O,m,c,s,w=async()=>{let d=Date.now();d>=a?(f=void 0,a=void 0,clearTimeout(l),l=void 0,typeof c=="function"&&await c(),p.resolve(s),m=r):(clearTimeout(f),f=setTimeout(w,a-d))},g=Number.isFinite(i)?()=>{c===y&&(c=!1),y(),l=setTimeout(g,i)}:null;async function y(){try{return s=await o.apply(u,O),s}catch(d){throw p.reject(d),d}}r&&typeof r=="boolean"&&(r=y),m=r,n&&typeof n=="boolean"&&(n=y),c=n;let p=Object.assign(function(...d){return O=d,u=this,a=Date.now()+t,c=n,p.promise.isPending||(p.promise=new x((k,$)=>{p.resolve=k,p.reject=$,typeof m=="function"&&(m(),m=!1,c===y&&(c=!1)),f||(f=setTimeout(w,t),g&&(l=setTimeout(g,i)))})),p.promise},{callback:o,promise:x.resolved(void 0),resolve:h,reject:h,run:y,clear:async d=>{clearTimeout(f),f=void 0,clearTimeout(l),l=void 0,p.resolve(d?await y():s)}});return p}E.noop=Object.assign(()=>{},{callback:h,promise:x.resolved(void 0),resolve:h,reject:h,run:h,clear:h});function v(o,t,e,r,n=!0){return Array.isArray(o)&&(o=o.length),typeof r!="string"&&(n=r??!0,r=e),(n?`${o}\xA0`:"")+v.raw(o,t,e,r)}v.raw=(o,t,e,r=e)=>{o=Math.abs(o);let n=o%10,i=o%100;return n===1&&i!==11?t:n>=2&&n<=4&&!(i>=12&&i<=15)?e:r};import{createServer as A}from"insite-common/backend";import{init as M}from"insite-config";import{CookieMiddleware as I,CookieSetter as P}from"insite-cookie/server";import{connect as W}from"insite-db";import{HTTPServer as b,StaticMiddleware as C,TemplateMiddleware as D}from"insite-http";import{SubscriptionHandler as B}from"insite-subscriptions-server/ws";import{Users as N}from"insite-users-server";import{UsersServer as R}from"insite-users-server-ws";import{IncomingTransport as U,OutgoingTransport as F}from"insite-ws-transfers/node";import{WSServer as T}from"insite-ws/server";var j=class o{constructor(t){t&&this.init(t)}mongoClient;db;config;collections;wss;incomingTransport;outgoingTransport;subscriptionHandler;usersServer;users;cookie;http;#e=!1;async init(t){if(!this.#e){this.#e=!0;let{db:e,config:r,ssl:n,port:i,wss:f,users:l,cookie:a,http:u,public:O}=t;e&&({client:this.mongoClient,db:this.db,collections:this.collections}=await W(e)),this.collections&&r&&(this.config=await M(this.collections,r));let m=i&&(f||u)?await A({...f&&T.makeProps({...f,ssl:n}),...u&&b.makeProps({...typeof u=="object"?u:{},ssl:n})},i):void 0;if(f){let{subscriptions:c,incomingTransport:s,outgoingTransport:w,...g}=f;this.wss=new T({server:m,...g}),c!==null&&(this.subscriptionHandler=new B(this.wss,!!this.collections)),s!==null&&(s||this.collections&&l)&&(this.incomingTransport=new U(this.wss,!s||s===!0?{}:s)),w&&(this.outgoingTransport=new F(this.wss))}if(l&&this.collections){let{server:c,...s}=l;this.wss&&this.subscriptionHandler?(this.usersServer=await R.init({public:O,...c,users:s,wss:this.wss,collections:this.collections,incomingTransport:this.incomingTransport}),this.users=this.usersServer.users):this.users=await N.init(this.collections,s)}if(u){let{static:c=void 0,middlewares:s=void 0,template:w=void 0,...g}=typeof u=="object"?u:{};this.http=new b({server:m,...g},[...s??[],a!==null&&new I(a?.middleware??{}),c!==null&&new C(c??{}),w!==null&&new D(w??{})].filter(Boolean))}if(a!==null&&this.usersServer&&this.http){let{middleware:c,...s}=a??{};this.cookie=new P({...s,usersServer:this.usersServer})}this.#t.resolve(this)}}#t=new x;whenReady(){return this.#t}static init(t,e=!0){let r=new o(t);return e?r.whenReady():r}};export*from"insite-common/backend";export*from"insite-cookie/server";export*from"insite-db";import{connect as Yr}from"insite-db";export*from"insite-http";export*from"insite-subscriptions-server";export*from"insite-users-server";export*from"insite-users-server-ws";export*from"insite-ws-transfers";export*from"insite-ws/server";export{j as InSite,Yr as connectToDB}; //# sourceMappingURL=index.js.map