@adonix.org/cloud-spark 0.0.162 → 0.0.164

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.js CHANGED
@@ -1,2 +1,2 @@
1
- import pe from"cache-control-parser";var I={parse:pe.parse,stringify:pe.stringify,DISABLE:Object.freeze({"no-cache":!0,"no-store":!0,"must-revalidate":!0,"max-age":0})};import{StatusCodes as m}from"http-status-codes";var i;(c=>(c.ALLOW="Allow",c.ACCEPT_ENCODING="Accept-Encoding",c.ORIGIN="Origin",c.CONTENT_TYPE="Content-Type",c.CACHE_CONTROL="Cache-Control",c.USER_AGENT="User-Agent",c.VARY="Vary",c.CONTENT_SECURITY_POLICY="Content-Security-Policy",c.PERMISSIONS_POLICY="Permissions-Policy",c.STRICT_TRANSPORT_SECURITY="Strict-Transport-Security",c.REFERRER_POLICY="Referrer-Policy",c.X_CONTENT_TYPE_OPTIONS="X-Content-Type-Options",c.X_FRAME_OPTIONS="X-Frame-Options",c.ACCESS_CONTROL_ALLOW_CREDENTIALS="Access-Control-Allow-Credentials",c.ACCESS_CONTROL_ALLOW_HEADERS="Access-Control-Allow-Headers",c.ACCESS_CONTROL_ALLOW_METHODS="Access-Control-Allow-Methods",c.ACCESS_CONTROL_ALLOW_ORIGIN="Access-Control-Allow-Origin",c.ACCESS_CONTROL_EXPOSE_HEADERS="Access-Control-Expose-Headers",c.ACCESS_CONTROL_MAX_AGE="Access-Control-Max-Age",c.ACCESS_CONTROL_REQUEST_HEADERS="Access-Control-Request-Headers",c.SEC_WEBSOCKET_VERSION="Sec-WebSocket-Version",c.CONNECTION="Connection",c.UPGRADE="Upgrade"))(i||={});var W=(u=>(u.GET="GET",u.PUT="PUT",u.HEAD="HEAD",u.POST="POST",u.PATCH="PATCH",u.DELETE="DELETE",u.OPTIONS="OPTIONS",u))(W||{}),{GET:f,PUT:vt,HEAD:k,POST:Pt,PATCH:yt,DELETE:It,OPTIONS:g}=W;var ze=(n=>(n.PLAIN_TEXT="text/plain",n.HTML="text/html",n.CSS="text/css",n.CSV="text/csv",n.XML="text/xml",n.MARKDOWN="text/markdown",n.RICH_TEXT="text/richtext",n.JSON="application/json",n.XML_APP="application/xml",n.YAML="application/x-yaml",n.FORM_URLENCODED="application/x-www-form-urlencoded",n.NDJSON="application/x-ndjson",n.MSGPACK="application/x-msgpack",n.PROTOBUF="application/x-protobuf",n.MULTIPART_FORM_DATA="multipart/form-data",n.MULTIPART_MIXED="multipart/mixed",n.MULTIPART_ALTERNATIVE="multipart/alternative",n.MULTIPART_DIGEST="multipart/digest",n.MULTIPART_RELATED="multipart/related",n.MULTIPART_SIGNED="multipart/signed",n.MULTIPART_ENCRYPTED="multipart/encrypted",n.OCTET_STREAM="application/octet-stream",n.PDF="application/pdf",n.ZIP="application/zip",n.GZIP="application/gzip",n.MSWORD="application/msword",n.DOCX="application/vnd.openxmlformats-officedocument.wordprocessingml.document",n.EXCEL="application/vnd.ms-excel",n.XLSX="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",n.POWERPOINT="application/vnd.ms-powerpoint",n.PPTX="application/vnd.openxmlformats-officedocument.presentationml.presentation",n.ICO="image/x-icon",n.ICO_MS="image/vnd.microsoft.icon",n.GIF="image/gif",n.PNG="image/png",n.JPEG="image/jpeg",n.WEBP="image/webp",n.SVG="image/svg+xml",n.HEIF="image/heif",n.AVIF="image/avif",n.EVENT_STREAM="text/event-stream",n.TAR="application/x-tar",n.BZIP2="application/x-bzip2",n))(ze||{});var ue={Second:1,Minute:60,Hour:3600,Day:86400,Week:604800,Month:2592e3,Year:31536e3};var le="upgrade",de="websocket",$="13",me=4999,he=123,O={NORMAL:1e3,GOING_AWAY:1001,PROTOCOL_ERROR:1002,UNSUPPORTED_DATA:1003,NO_STATUS:1005,ABNORMAL:1006,INVALID_PAYLOAD:1007,POLICY_VIOLATION:1008,MESSAGE_TOO_BIG:1009,MISSING_EXTENSION:1010,INTERNAL_ERROR:1011,TLS_HANDSHAKE:1015},fe=new Set([O.NO_STATUS,O.ABNORMAL,O.TLS_HANDSHAKE]);function D(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function R(t){return typeof t=="string"}function Ce(t){return typeof t=="function"}function M(t){return typeof t=="number"&&!Number.isNaN(t)}function Ee(t){return typeof t=="boolean"}var $e=new Set(Object.values(W));function Z(t){return R(t)&&$e.has(t)}function Ze(t){return Array.isArray(t)&&t.every(Z)}function b(t){if(!Ze(t)){let e=Array.isArray(t)?JSON.stringify(t):String(t);throw new TypeError(`Invalid method array: ${e}`)}}var h=class{};function Se(t){if(t!==void 0&&!R(t))throw new TypeError("Cache name must be a string.")}function Ae(t){if(t!==void 0&&!Ce(t))throw new TypeError("getKey must be a function.")}function xe(t){if(!(t instanceof URL))throw new TypeError("getKey must return a URL.")}function E(t,e){return t<e?-1:t>e?1:0}function l(t,e,r){let s=Array.isArray(r)?r:[r],o=Array.from(new Set(s.map(a=>a.trim()))).filter(a=>a.length).sort(E);if(!o.length){t.delete(e);return}t.set(e,o.join(", "))}function H(t,e,r){let s=Array.isArray(r)?r:[r];if(s.length===0)return;let a=T(t,e).concat(s.map(p=>p.trim()));l(t,e,a)}function T(t,e){let r=t.get(e)?.split(",").map(s=>s.trim()).filter(s=>s.length>0)??[];return Array.from(new Set(r)).sort(E)}function Q(t){let e=t.headers.get(i.ORIGIN)?.trim();if(!e||e==="null")return null;try{return new URL(e).origin}catch{return null}}function Oe(t){let e=new URL(t.url),r=new URLSearchParams([...e.searchParams.entries()].sort(([s],[o])=>E(s,o)));return e.search=r.toString(),e.hash="",e}function $t(t){let e=new URL(t.url);return e.search="",e.hash="",e}var Qe=new Set(["text/css","text/csv","text/xml","image/svg+xml","text/html","application/json","application/x-ndjson","application/xml","text/markdown","text/richtext","text/plain","application/x-www-form-urlencoded"]);function Re(t){return Qe.has(t)?`${t}; charset=utf-8`:t}var et="https://vary";function ge(t){return!(!t.ok||ee(t).includes("*"))}function ee(t){let e=T(t.headers,i.VARY);return Array.from(new Set(e.map(r=>r.toLowerCase()))).sort(E)}function te(t){return t.map(e=>e.toLowerCase()).filter(e=>e!==i.ACCEPT_ENCODING.toLowerCase())}function re(t,e,r){let s=[],o=te(e);o.sort(E);for(let p of o){let u=t.headers.get(p);u!==null&&s.push([p,u])}let a=tt(JSON.stringify([r.toString(),s]));return new URL(a,et).href}function tt(t){let e=new TextEncoder().encode(t),r="";for(let s of e)r+=String.fromCodePoint(s);return btoa(r).replaceAll("+","-").replaceAll("/","_").replace(/={1,2}$/,"")}function pr(t,e){return Se(t),Ae(e),new se(t,e)}var se=class extends h{constructor(r,s){super();this.cacheName=r;this.getKey=s;this.cacheName=r?.trim()||void 0}async handle(r,s){if(r.request.method!==f)return s();let o=this.cacheName?await caches.open(this.cacheName):caches.default,a=await this.getCached(o,r.request);if(a)return a;let p=await s();return this.setCached(o,r,p),p}async getCached(r,s){let o=this.getCacheKey(s),a=await r.match(o);if(!a)return;let p=this.getFilteredVary(a);if(p.length===0)return a;let u=re(s,p,o);return r.match(u)}async setCached(r,s,o){if(!ge(o))return;let a=this.getCacheKey(s.request);s.ctx.waitUntil(r.put(a,o.clone()));let p=this.getFilteredVary(o);p.length>0&&s.ctx.waitUntil(r.put(re(s.request,p,a),o.clone()))}getFilteredVary(r){return te(ee(r))}getCacheKey(r){let s=this.getKey?this.getKey(r):Oe(r);return xe(s),s.hash="",s}};import{getReasonPhrase as rt,StatusCodes as S}from"http-status-codes";var oe=class{headers=new Headers;status=S.OK;statusText;webSocket=null;mediaType="text/plain";get responseInit(){return{headers:this.headers,status:this.status,statusText:this.statusText??rt(this.status),webSocket:this.webSocket,encodeBody:"automatic"}}setHeader(e,r){l(this.headers,e,r)}mergeHeader(e,r){H(this.headers,e,r)}addContentType(){this.headers.get(i.CONTENT_TYPE)||this.headers.set(i.CONTENT_TYPE,Re(this.mediaType))}},ne=class extends oe{constructor(r){super();this.cache=r}addCacheHeader(){this.cache&&this.headers.set(i.CACHE_CONTROL,I.stringify(this.cache))}},_=class extends ne{constructor(r=null,s){super(s);this.body=r}async response(){this.addCacheHeader();let r=this.status===S.NO_CONTENT?null:this.body;return r&&this.addContentType(),new Response(r,this.responseInit)}},U=class extends _{constructor(e,r){let s=e.clone();super(s.body,r),this.headers=new Headers(s.headers),this.status=s.status,this.statusText=s.statusText}},w=class extends _{constructor(e=null,r,s=S.OK){super(e,r),this.status=s}},G=class extends w{constructor(e={},r,s=S.OK){super(JSON.stringify(e),r,s),this.mediaType="application/json"}},be=class extends w{constructor(e,r,s=S.OK){super(e,r,s),this.mediaType="text/html"}},Te=class extends w{constructor(e,r,s=S.OK){super(e,r,s),this.mediaType="text/plain"}},_e=class extends _{constructor(e){super(null),this.status=S.SWITCHING_PROTOCOLS,this.webSocket=e}},V=class extends _{constructor(e){super(),this.status=e.status,this.statusText=e.statusText,this.headers=new Headers(e.headers)}},L=class extends w{constructor(){super(null,void 0,S.NO_CONTENT)}};var K="*",we=new Set([f,k,g]),Le=[m.SWITCHING_PROTOCOLS,m.CONTINUE,m.PROCESSING,m.EARLY_HINTS,m.MOVED_PERMANENTLY,m.MOVED_TEMPORARILY,m.SEE_OTHER,m.TEMPORARY_REDIRECT,m.PERMANENT_REDIRECT],Ne={allowedOrigins:[K],allowedHeaders:[i.CONTENT_TYPE],exposedHeaders:[],allowCredentials:!1,maxAge:5*ue.Minute};async function ve(t,e){let r=new L,s=Q(t.request);return s&&(ye(r.headers,e,s),Ie(r.headers,e,s)),st(r.headers,t),nt(r.headers,e),ot(r.headers,e),r.response()}async function Pe(t,e,r){let s=new U(t),o=Q(e.request);return at(s.headers),o&&(ye(s.headers,r,o),Ie(s.headers,r,o),it(s.headers,r)),s.response()}function ye(t,e,r){We(e)?l(t,i.ACCESS_CONTROL_ALLOW_ORIGIN,K):(e.allowedOrigins.includes(r)&&l(t,i.ACCESS_CONTROL_ALLOW_ORIGIN,r),H(t,i.VARY,i.ORIGIN))}function Ie(t,e,r){e.allowCredentials&&(We(e)||e.allowedOrigins.includes(r)&&l(t,i.ACCESS_CONTROL_ALLOW_CREDENTIALS,"true"))}function st(t,e){let r=e.getAllowedMethods();b(r);let s=r.filter(o=>!we.has(o));s.length>0&&l(t,i.ACCESS_CONTROL_ALLOW_METHODS,s)}function ot(t,e){let r=Math.max(0,Math.floor(e.maxAge));l(t,i.ACCESS_CONTROL_MAX_AGE,String(r))}function nt(t,e){e.allowedHeaders.length>0&&l(t,i.ACCESS_CONTROL_ALLOW_HEADERS,e.allowedHeaders)}function it(t,e){l(t,i.ACCESS_CONTROL_EXPOSE_HEADERS,e.exposedHeaders)}function We(t){return t.allowedOrigins.includes(K)}function at(t){t.delete(i.ACCESS_CONTROL_MAX_AGE),t.delete(i.ACCESS_CONTROL_ALLOW_ORIGIN),t.delete(i.ACCESS_CONTROL_ALLOW_HEADERS),t.delete(i.ACCESS_CONTROL_ALLOW_METHODS),t.delete(i.ACCESS_CONTROL_EXPOSE_HEADERS),t.delete(i.ACCESS_CONTROL_ALLOW_CREDENTIALS)}function ke(t){let{status:e,headers:r}=t;return!!(Le.includes(e)||r.has(i.UPGRADE))}function De(t){if(t===void 0)return;if(typeof t!="object"||t===null)throw new TypeError("CorsInit must be an object.");let e=t;if(e.allowedOrigins!==void 0&&!D(e.allowedOrigins))throw new TypeError("CorsInit.allowedOrigins must be a string array.");if(e.allowedHeaders!==void 0&&!D(e.allowedHeaders))throw new TypeError("CorsInit.allowedHeaders must be a string array.");if(e.exposedHeaders!==void 0&&!D(e.exposedHeaders))throw new TypeError("CorsInit.exposedHeaders must be a string array.");if(e.allowCredentials!==void 0&&!Ee(e.allowCredentials))throw new TypeError("CorsInit.allowCredentials must be a boolean.");if(e.maxAge!==void 0&&!M(e.maxAge))throw new TypeError("CorsInit.maxAge must be a number.")}function kr(t){return De(t),new ie(t)}var ie=class extends h{config;constructor(e){super(),this.config={...Ne,...e}}async handle(e,r){if(e.request.method===g)return ve(e,this.config);let s=await r();return ke(s)?s:Pe(s,e,this.config)}};import{getReasonPhrase as ct,StatusCodes as C}from"http-status-codes";var d=class extends G{constructor(r,s){let o={status:r,error:ct(r),details:s??""};super(o,I.DISABLE,r);this.details=s}},P=class extends d{constructor(e){super(C.BAD_REQUEST,e)}},Me=class extends d{constructor(e){super(C.UNAUTHORIZED,e)}},He=class extends d{constructor(e){super(C.FORBIDDEN,e)}},A=class extends d{constructor(e){super(C.NOT_FOUND,e)}},y=class extends d{constructor(e){let r=e.getAllowedMethods();b(r),super(C.METHOD_NOT_ALLOWED,`${e.request.method} method not allowed.`),this.setHeader(i.ALLOW,r)}},q=class extends d{constructor(){super(C.UPGRADE_REQUIRED),this.headers.set(i.SEC_WEBSOCKET_VERSION,"13")}},B=class extends d{constructor(e){super(C.INTERNAL_SERVER_ERROR,e)}},ae=class extends d{constructor(e){super(C.NOT_IMPLEMENTED,e)}},x=class extends ae{constructor(e){super(`${e.request.method} method not implemented.`)}},Ue=class extends d{constructor(e){super(C.SERVICE_UNAVAILABLE,e)}};function Ge(t){return T(t,i.CONNECTION).some(e=>e.toLowerCase()===le)}function Ve(t){return T(t,i.UPGRADE).some(e=>e.toLowerCase()===de)}function Ke(t){return t.get(i.SEC_WEBSOCKET_VERSION)?.trim()==="13"}function $r(t="/"){return new ce(t)}var ce=class extends h{constructor(r){super();this.path=r}handle(r,s){if(r.request.method!==f||this.getPath(r.request)!==this.path)return s();let o=r.request.headers;return Ge(o)?Ve(o)?Ke(o)?s():new q().response():new P("Missing or invalid Upgrade header").response():new P("Missing or invalid Connection header").response()}getPath(r){return new URL(r.url).pathname}};function pt(t){return t instanceof ArrayBuffer||ArrayBuffer.isView(t)}function qe(t){return R(t)?t.length>0:pt(t)?t.byteLength>0:!1}function Be(t){return M(t)?ut(t)&&!lt(t)?t:O.NORMAL:O.NORMAL}function ut(t){return t>=O.NORMAL&&t<=4999}function lt(t){return fe.has(t)}function Xe(t){if(R(t))return t.replaceAll(/[^\x20-\x7E]/g,"").slice(0,123)}function Ye(t){if(t===null||typeof t!="object")throw new TypeError("WebSocket attachment must be a non-null object");try{JSON.stringify(t)}catch{throw new TypeError("WebSocket attachment is non-serializable")}}var X=class t{server;static isCustomEvent(e){return["open","warn"].includes(e)}customListeners={};constructor(e){this.server=e}addEventListener(e,r,s){if(t.isCustomEvent(e)){let o=this.customListeners[e];o||(o=[],this.customListeners[e]=o),o.push(r)}else{let o=e==="close"?{...s,once:!0}:s;this.server.addEventListener(e,r,o)}}removeEventListener(e,r){if(t.isCustomEvent(e)){let s=this.customListeners[e];if(s){let o=s.indexOf(r);o!==-1&&s.splice(o,1)}}else this.server.removeEventListener(e,r)}dispatch(e,r,s=!1){let o=this.customListeners[e]?.slice()??[];s&&(this.customListeners[e]=[]);for(let a of o)a(r)}warn(e){this.dispatch("warn",{type:"warn",message:e})}open(){this.dispatch("open",new Event("open"),!0)}};var N=class extends X{accepted=!1;server;constructor(e){super(e),this.server=e,this.server.addEventListener("close",this.onclose)}send(e){if(this.isState(WebSocket.CONNECTING,WebSocket.CLOSED)){this.warn("Cannot send: WebSocket not open");return}if(!qe(e)){this.warn("Cannot send: empty or invalid data");return}this.server.send(e)}get attachment(){return this.server.deserializeAttachment()??{}}attach(e){e!==void 0&&(e===null?this.server.serializeAttachment({}):(Ye(e),this.server.serializeAttachment(e)))}get readyState(){return this.accepted?this.server.readyState:WebSocket.CONNECTING}isState(...e){return e.includes(this.readyState)}close(e,r){this.server.removeEventListener("close",this.onclose),this.server.close(Be(e),Xe(r))}onclose=e=>{this.close(e.code,e.reason)}};var Y=class extends N{client;constructor(){let e=new WebSocketPair,[r,s]=[e[0],e[1]];super(s),this.client=r}acceptWebSocket(e,r){return e.acceptWebSocket(this.server,r),this.ready()}accept(){return this.server.accept(),this.ready()}ready(){return this.accepted=!0,this.open(),this.client}};var F=class extends N{constructor(e){super(e),this.accepted=!0}accept(){throw new Error("Do not call accept() on restore")}acceptWebSocket(){throw new Error("Do not call acceptWebSocket() on restore")}};var Fe=class{map=new Map;create(e){class r extends Y{constructor(p){super();this.sessions=p}accept(){return this.addEventListener("close",()=>this.sessions.unregister(this.server)),this.sessions.register(this.server,this),super.accept()}acceptWebSocket(p,u){return this.sessions.register(this.server,this),super.acceptWebSocket(p,u)}}let s=new r(this);return s.attach(e),s}restore(e){class r extends F{constructor(o,a){super(a),o.register(this.server,this)}}return new r(this,e)}restoreAll(e){let r=[];for(let s of e)r.push(this.restore(s));return r}get(e){return this.map.get(e)}values(){return this.map.values()}keys(){return this.map.keys()}close(e,r,s){let o=this.get(e);return o&&o.close(r,s),this.unregister(e)}*[Symbol.iterator](){yield*this.values()}register(e,r){this.map.set(e,r)}unregister(e){return this.map.delete(e)}};var v=class{constructor(e,r,s){this._request=e;this._env=r;this._ctx=s}get request(){return this._request}get env(){return this._env}get ctx(){return this._ctx}isAllowed(e){let r=this.getAllowedMethods();return b(r),Z(e)&&r.includes(e)}create(e){let r=this.constructor;return new r(e,this.env,this.ctx)}async response(e,...r){return new e(...r).response()}static ignite(){return{fetch:(e,r,s)=>new this(e,r,s).fetch()}}};function je(t){if(!(t instanceof h))throw new TypeError("Handler must be a subclass of Middleware.")}var j=class extends v{middlewares=[];init(){}use(e){return je(e),this.middlewares.push(e),this}async fetch(){return await this.middlewares.reduceRight((r,s)=>()=>s.handle(this,r),()=>this.dispatch())()}};var J=class extends j{async fetch(){if(!this.isAllowed(this.request.method))return this.response(y,this);try{return await this.init(),await super.fetch()}catch(e){return console.error(e),this.response(B)}}async dispatch(){let e=this.request.method;return({GET:()=>this.get(),PUT:()=>this.put(),HEAD:()=>this.head(),POST:()=>this.post(),PATCH:()=>this.patch(),DELETE:()=>this.delete(),OPTIONS:()=>this.options()}[e]??(()=>this.response(y,this)))()}async get(){return this.response(x,this)}async put(){return this.response(x,this)}async post(){return this.response(x,this)}async patch(){return this.response(x,this)}async delete(){return this.response(x,this)}async options(){return this.response(L)}async head(){let e=this.create(new Request(this.request.url,{method:f,headers:this.request.headers}));return this.response(V,await e.fetch())}getAllowedMethods(){return[f,k,g]}};import{match as dt}from"path-to-regexp";var z=class{routes=[];add(e){for(let[r,s,o]of e){let a=dt(s);this.routes.push({method:r,matcher:a,handler:o})}}match(e,r){let s=new URL(r).pathname;for(let o of this){if(o.method!==e)continue;let a=o.matcher(s);if(a)return{route:o,params:a.params}}return null}*[Symbol.iterator](){yield*this.routes}};var Je=class t extends J{_routes=new z;route(e,r,s){return this.routes([[e,r,s]]),this}routes(e){return this._routes.add(e),this}async dispatch(){let e=this._routes.match(this.request.method,this.request.url);if(!e)return super.dispatch();let{handler:r}=e.route;return t.isWorkerClass(r)?new r(this.request,this.env,this.ctx).fetch():r.call(this,e.params)}static isWorkerClass(e){return v.prototype.isPrototypeOf(e.prototype)}async get(){return this.response(A)}async put(){return this.response(A)}async post(){return this.response(A)}async patch(){return this.response(A)}async delete(){return this.response(A)}};export{P as BadRequest,J as BasicWorker,I as CacheControl,U as ClonedResponse,O as CloseCode,It as DELETE,He as Forbidden,f as GET,k as HEAD,V as Head,be as HtmlResponse,d as HttpError,i as HttpHeader,B as InternalServerError,G as JsonResponse,ze as MediaType,W as Method,y as MethodNotAllowed,x as MethodNotImplemented,A as NotFound,ae as NotImplemented,g as OPTIONS,L as Options,yt as PATCH,Pt as POST,vt as PUT,Je as RouteWorker,Ue as ServiceUnavailable,m as StatusCodes,w as SuccessResponse,Te as TextResponse,ue as Time,Me as Unauthorized,q as UpgradeRequired,me as WS_MAX_CLOSE_CODE,he as WS_MAX_REASON_CHARS,fe as WS_RESERVED_CODES,le as WS_UPGRADE,$ as WS_VERSION,de as WS_WEBSOCKET,Fe as WebSocketSessions,_e as WebSocketUpgrade,_ as WorkerResponse,b as assertMethods,pr as cache,kr as cors,Re as getContentType,T as getHeaderValues,Q as getOrigin,Z as isMethod,Ze as isMethodArray,E as lexCompare,H as mergeHeader,l as setHeader,Oe as sortSearchParams,$t as stripSearchParams,$r as websocket};
1
+ import{StatusCodes as l}from"http-status-codes";import pe from"cache-control-parser";var W={parse:pe.parse,stringify:pe.stringify,DISABLE:Object.freeze({"no-cache":!0,"no-store":!0,"must-revalidate":!0,"max-age":0})};var P=(p=>(p.GET="GET",p.PUT="PUT",p.HEAD="HEAD",p.POST="POST",p.PATCH="PATCH",p.DELETE="DELETE",p.OPTIONS="OPTIONS",p))(P||{}),{GET:m,PUT:Tt,HEAD:I,POST:yt,PATCH:wt,DELETE:_t,OPTIONS:O}=P;var ue={Second:1,Minute:60,Hour:3600,Day:86400,Week:604800,Month:2592e3,Year:31536e3};var h=class{};function k(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function g(t){return typeof t=="string"}function de(t){return typeof t=="function"}function M(t){return typeof t=="number"&&!Number.isNaN(t)}function le(t){return typeof t=="boolean"}function he(t){if(t!==void 0&&!g(t))throw new TypeError("Cache name must be a string.")}function me(t){if(t!==void 0&&!de(t))throw new TypeError("getKey must be a function.")}function fe(t){if(!(t instanceof URL))throw new TypeError("getKey must return a URL.")}var n;(c=>(c.ACCEPT_ENCODING="Accept-Encoding",c.ACCEPT_RANGES="Accept-Ranges",c.ALLOW="Allow",c.CACHE_CONTROL="Cache-Control",c.CONTENT_LENGTH="Content-Length",c.CONTENT_RANGE="Content-Range",c.CONTENT_TYPE="Content-Type",c.ORIGIN="Origin",c.VARY="Vary",c.ACCESS_CONTROL_ALLOW_CREDENTIALS="Access-Control-Allow-Credentials",c.ACCESS_CONTROL_ALLOW_HEADERS="Access-Control-Allow-Headers",c.ACCESS_CONTROL_ALLOW_METHODS="Access-Control-Allow-Methods",c.ACCESS_CONTROL_ALLOW_ORIGIN="Access-Control-Allow-Origin",c.ACCESS_CONTROL_EXPOSE_HEADERS="Access-Control-Expose-Headers",c.ACCESS_CONTROL_MAX_AGE="Access-Control-Max-Age",c.SEC_WEBSOCKET_VERSION="Sec-WebSocket-Version",c.CONNECTION="Connection",c.UPGRADE="Upgrade"))(n||={});function E(t,e){return t<e?-1:t>e?1:0}function u(t,e,r){let s=Array.isArray(r)?r:[r],o=Array.from(new Set(s.map(i=>i.trim()))).filter(i=>i.length).sort(E);if(!o.length){t.delete(e);return}t.set(e,o.join(", "))}function H(t,e,r){let s=Array.isArray(r)?r:[r];if(s.length===0)return;let i=R(t,e).concat(s.map(a=>a.trim()));u(t,e,i)}function R(t,e){let r=t.get(e)?.split(",").map(s=>s.trim()).filter(s=>s.length>0)??[];return Array.from(new Set(r)).sort(E)}var $e="https://vary";function Ce(t){return!(!t.ok||Q(t).includes("*"))}function Q(t){let e=R(t.headers,n.VARY);return Array.from(new Set(e.map(r=>r.toLowerCase()))).sort(E)}function Z(t){return t.map(e=>e.toLowerCase()).filter(e=>e!==n.ACCEPT_ENCODING.toLowerCase())}function ee(t,e,r){let s=[],o=Z(e);o.sort(E);for(let a of o){let p=t.headers.get(a);p!==null&&s.push([a,p])}let i=ze(JSON.stringify([r.toString(),s]));return new URL(i,$e).href}function ze(t){let e=new TextEncoder().encode(t),r="";for(let s of e)r+=String.fromCodePoint(s);return btoa(r).replaceAll("+","-").replaceAll("/","_").replace(/={1,2}$/,"")}function er(t,e){return he(t),me(e),new te(t,e)}function Je(t){let e=new URL(t.url),r=new URLSearchParams([...e.searchParams.entries()].sort(([s],[o])=>E(s,o)));return e.search=r.toString(),e.hash="",e}function tr(t){let e=new URL(t.url);return e.search="",e.hash="",e}var te=class extends h{constructor(r,s){super();this.cacheName=r;this.getKey=s;this.cacheName=r?.trim()||void 0}async handle(r,s){if(r.request.method!==m)return s();let o=this.cacheName?await caches.open(this.cacheName):caches.default,i=await this.getCached(o,r.request);if(i)return i;let a=await s();return this.setCached(o,r,a),a}async getCached(r,s){let o=this.getCacheKey(s),i=await r.match(o);if(!i)return;let a=this.getFilteredVary(i);if(a.length===0)return i;let p=ee(s,a,o);return r.match(p)}async setCached(r,s,o){if(!Ce(o))return;let i=this.getCacheKey(s.request);s.ctx.waitUntil(r.put(i,o.clone()));let a=this.getFilteredVary(o);a.length>0&&s.ctx.waitUntil(r.put(ee(s.request,a,i),o.clone()))}getFilteredVary(r){return Z(Q(r))}getCacheKey(r){let s=this.getKey?this.getKey(r):Je(r);return fe(s),s.hash="",s}};var Qe=new Set(Object.values(P));function re(t){return g(t)&&Qe.has(t)}function Ze(t){return Array.isArray(t)&&t.every(re)}function T(t){if(!Ze(t)){let e=Array.isArray(t)?JSON.stringify(t):String(t);throw new TypeError(`Invalid method array: ${e}`)}}import{getReasonPhrase as et,StatusCodes as f}from"http-status-codes";var D="utf-8";function G(t,e){return!e||t.toLowerCase().includes("charset=")?t:`${t}; charset=${e.toLowerCase()}`}var se=class{headers=new Headers;status=f.OK;statusText;webSocket=null;mediaType="text/plain; charset=utf-8";get responseInit(){return{headers:this.headers,status:this.status,statusText:this.statusText??et(this.status),webSocket:this.webSocket,encodeBody:"automatic"}}setHeader(e,r){u(this.headers,e,r)}mergeHeader(e,r){H(this.headers,e,r)}addContentType(){this.headers.get(n.CONTENT_TYPE)||this.headers.set(n.CONTENT_TYPE,this.mediaType)}},oe=class extends se{constructor(r){super();this.cache=r}addCacheHeader(){this.cache&&this.headers.set(n.CACHE_CONTROL,W.stringify(this.cache))}},S=class extends oe{constructor(r=null,s){super(s);this.body=r}async response(){this.addCacheHeader();let r=this.status===f.NO_CONTENT?null:this.body;return r&&this.addContentType(),new Response(r,this.responseInit)}},U=class extends S{constructor(e,r){let s=e.clone();super(s.body,r),this.headers=new Headers(s.headers),this.status=s.status,this.statusText=s.statusText}},L=class extends S{constructor(e=null,r,s=f.OK){super(e,r),this.status=s}},V=class extends L{constructor(e={},r,s=f.OK){super(JSON.stringify(e),r,s),this.mediaType=G("application/json",D)}},Ee=class extends L{constructor(e,r,s=f.OK,o=D){super(e,r,s),this.mediaType=G("text/html",o)}},Se=class extends L{constructor(e,r,s=f.OK,o=D){super(e,r,s),this.mediaType=G("text/plain",o)}},ne=class extends S{constructor(e,r,s){let{size:o,offset:i=0,length:a=o}=r;super(e,s),this.mediaType="application/octet-stream",this.setHeader(n.ACCEPT_RANGES,"bytes"),this.setHeader(n.CONTENT_LENGTH,`${a}`),(i>0||a<o)&&(this.setHeader(n.CONTENT_RANGE,`bytes ${i}-${i+a-1}/${o}`),this.status=f.PARTIAL_CONTENT)}},Ae=class t extends ne{constructor(e,r){super(e.body,t.computeRange(e),r),e.httpMetadata?.contentType&&(this.mediaType=e.httpMetadata.contentType)}static computeRange(e){let r=e.size;if(!e.range)return{size:r,offset:0,length:r};if("suffix"in e.range){let i=Math.max(0,r-e.range.suffix),a=r-i;return{size:r,offset:i,length:a}}let{offset:s=0,length:o=r}=e.range;return{size:r,offset:s,length:o}}},xe=class extends S{constructor(e){super(null),this.status=f.SWITCHING_PROTOCOLS,this.webSocket=e}},K=class extends S{constructor(e){super(),this.status=e.status,this.statusText=e.statusText,this.headers=new Headers(e.headers)}},y=class extends S{constructor(){super(),this.status=f.NO_CONTENT}};var q="*",ge=new Set([m,I,O]),be=[l.SWITCHING_PROTOCOLS,l.CONTINUE,l.PROCESSING,l.EARLY_HINTS,l.MOVED_PERMANENTLY,l.MOVED_TEMPORARILY,l.SEE_OTHER,l.TEMPORARY_REDIRECT,l.PERMANENT_REDIRECT],Oe={allowedOrigins:[q],allowedHeaders:[n.CONTENT_TYPE],exposedHeaders:[],allowCredentials:!1,maxAge:5*ue.Minute};async function Re(t,e){let r=new y,s=Ne(t.request);return s&&(ye(r.headers,e,s),we(r.headers,e,s)),tt(r.headers,t),st(r.headers,e),rt(r.headers,e),r.response()}async function Te(t,e,r){let s=new U(t),o=Ne(e.request);return nt(s.headers),o&&(ye(s.headers,r,o),we(s.headers,r,o),ot(s.headers,r)),s.response()}function ye(t,e,r){_e(e)?u(t,n.ACCESS_CONTROL_ALLOW_ORIGIN,q):(e.allowedOrigins.includes(r)&&u(t,n.ACCESS_CONTROL_ALLOW_ORIGIN,r),H(t,n.VARY,n.ORIGIN))}function we(t,e,r){e.allowCredentials&&(_e(e)||e.allowedOrigins.includes(r)&&u(t,n.ACCESS_CONTROL_ALLOW_CREDENTIALS,"true"))}function tt(t,e){let r=e.getAllowedMethods();T(r);let s=r.filter(o=>!ge.has(o));s.length>0&&u(t,n.ACCESS_CONTROL_ALLOW_METHODS,s)}function rt(t,e){let r=Math.max(0,Math.floor(e.maxAge));u(t,n.ACCESS_CONTROL_MAX_AGE,String(r))}function st(t,e){e.allowedHeaders.length>0&&u(t,n.ACCESS_CONTROL_ALLOW_HEADERS,e.allowedHeaders)}function ot(t,e){u(t,n.ACCESS_CONTROL_EXPOSE_HEADERS,e.exposedHeaders)}function _e(t){return t.allowedOrigins.includes(q)}function nt(t){t.delete(n.ACCESS_CONTROL_MAX_AGE),t.delete(n.ACCESS_CONTROL_ALLOW_ORIGIN),t.delete(n.ACCESS_CONTROL_ALLOW_HEADERS),t.delete(n.ACCESS_CONTROL_ALLOW_METHODS),t.delete(n.ACCESS_CONTROL_EXPOSE_HEADERS),t.delete(n.ACCESS_CONTROL_ALLOW_CREDENTIALS)}function Le(t){let{status:e,headers:r}=t;return!!(be.includes(e)||r.has(n.UPGRADE))}function Ne(t){let e=t.headers.get(n.ORIGIN)?.trim();if(!e||e==="null")return null;try{return new URL(e).origin}catch{return null}}function ve(t){if(t===void 0)return;if(typeof t!="object"||t===null)throw new TypeError("CorsInit must be an object.");let e=t;if(e.allowedOrigins!==void 0&&!k(e.allowedOrigins))throw new TypeError("CorsInit.allowedOrigins must be a string array.");if(e.allowedHeaders!==void 0&&!k(e.allowedHeaders))throw new TypeError("CorsInit.allowedHeaders must be a string array.");if(e.exposedHeaders!==void 0&&!k(e.exposedHeaders))throw new TypeError("CorsInit.exposedHeaders must be a string array.");if(e.allowCredentials!==void 0&&!le(e.allowCredentials))throw new TypeError("CorsInit.allowCredentials must be a boolean.");if(e.maxAge!==void 0&&!M(e.maxAge))throw new TypeError("CorsInit.maxAge must be a number.")}function kr(t){return ve(t),new ie(t)}var ie=class extends h{config;constructor(e){super(),this.config={...Oe,...e}}async handle(e,r){if(e.request.method===O)return Re(e,this.config);let s=await r();return Le(s)?s:Te(s,e,this.config)}};import{getReasonPhrase as it,StatusCodes as C}from"http-status-codes";var We="upgrade",Pe="websocket";var b={NORMAL:1e3,GOING_AWAY:1001,PROTOCOL_ERROR:1002,UNSUPPORTED_DATA:1003,NO_STATUS:1005,ABNORMAL:1006,INVALID_PAYLOAD:1007,POLICY_VIOLATION:1008,MESSAGE_TOO_BIG:1009,MISSING_EXTENSION:1010,INTERNAL_ERROR:1011,TLS_HANDSHAKE:1015},Ie=new Set([b.NO_STATUS,b.ABNORMAL,b.TLS_HANDSHAKE]);var d=class extends V{constructor(r,s){let o={status:r,error:it(r),details:s??""};super(o,W.DISABLE,r);this.details=s}},N=class extends d{constructor(e){super(C.BAD_REQUEST,e)}},ke=class extends d{constructor(e){super(C.UNAUTHORIZED,e)}},Me=class extends d{constructor(e){super(C.FORBIDDEN,e)}},A=class extends d{constructor(e){super(C.NOT_FOUND,e)}},v=class extends d{constructor(e){let r=e.getAllowedMethods();T(r),super(C.METHOD_NOT_ALLOWED,`${e.request.method} method not allowed.`),this.setHeader(n.ALLOW,r)}},B=class extends d{constructor(){super(C.UPGRADE_REQUIRED),this.headers.set(n.SEC_WEBSOCKET_VERSION,"13")}},Y=class extends d{constructor(e){super(C.INTERNAL_SERVER_ERROR,e)}},ae=class extends d{constructor(e){super(C.NOT_IMPLEMENTED,e)}},x=class extends ae{constructor(e){super(`${e.request.method} method not implemented.`)}},He=class extends d{constructor(e){super(C.SERVICE_UNAVAILABLE,e)}};function Ge(t){return R(t,n.CONNECTION).some(e=>e.toLowerCase()===We)}function Ue(t){return R(t,n.UPGRADE).some(e=>e.toLowerCase()===Pe)}function Ve(t){return t.get(n.SEC_WEBSOCKET_VERSION)?.trim()==="13"}function Qr(t="/"){return new ce(t)}var ce=class extends h{constructor(r){super();this.path=r}handle(r,s){if(r.request.method!==m||this.getPath(r.request)!==this.path)return s();let o=r.request.headers;return Ge(o)?Ue(o)?Ve(o)?s():new B().response():new N("Missing or invalid Upgrade header").response():new N("Missing or invalid Connection header").response()}getPath(r){return new URL(r.url).pathname}};function pt(t){return t instanceof ArrayBuffer||ArrayBuffer.isView(t)}function Ke(t){return g(t)?t.length>0:pt(t)?t.byteLength>0:!1}function qe(t){return M(t)?ut(t)&&!dt(t)?t:b.NORMAL:b.NORMAL}function ut(t){return t>=b.NORMAL&&t<=4999}function dt(t){return Ie.has(t)}function Be(t){if(g(t))return t.replaceAll(/[^\x20-\x7E]/g,"").slice(0,123)}function Ye(t){if(t===null||typeof t!="object")throw new TypeError("WebSocket attachment must be an object");try{JSON.stringify(t)}catch{throw new TypeError("WebSocket attachment is not serializable")}}var j=class t{server;static isCustomEvent(e){return["open","warn"].includes(e)}customListeners={};constructor(e){this.server=e}addEventListener(e,r,s){if(t.isCustomEvent(e)){let o=this.customListeners[e];o||(o=[],this.customListeners[e]=o),o.push(r)}else{let o=e==="close"?{...s,once:!0}:s;this.server.addEventListener(e,r,o)}}removeEventListener(e,r){if(t.isCustomEvent(e)){let s=this.customListeners[e];if(s){let o=s.indexOf(r);o!==-1&&s.splice(o,1)}}else this.server.removeEventListener(e,r)}dispatch(e,r,s=!1){let o=this.customListeners[e]?.slice()??[];s&&(this.customListeners[e]=[]);for(let i of o)i(r)}warn(e){this.dispatch("warn",{type:"warn",message:e})}open(){this.dispatch("open",new Event("open"),!0)}};var w=class extends j{accepted=!1;server;constructor(e){super(e),this.server=e,this.server.addEventListener("close",this.onclose)}send(e){if(this.isState(WebSocket.CONNECTING,WebSocket.CLOSED)){this.warn("Cannot send: WebSocket not open");return}if(!Ke(e)){this.warn("Cannot send: empty or invalid data");return}this.server.send(e)}get attachment(){return this.server.deserializeAttachment()??{}}attach(e){if(e!==void 0)if(e===null)this.server.serializeAttachment({});else{let s={...this.attachment,...e};Ye(s),this.server.serializeAttachment(s)}}get readyState(){return this.accepted?this.server.readyState:WebSocket.CONNECTING}isState(...e){return e.includes(this.readyState)}close(e,r){this.server.removeEventListener("close",this.onclose),this.server.close(qe(e),Be(r))}onclose=e=>{this.close(e.code,e.reason)}};var X=class extends w{client;constructor(){let e=new WebSocketPair,[r,s]=[e[0],e[1]];super(s),this.client=r}acceptWebSocket(e,r){return e.acceptWebSocket(this.server,r),this.ready()}accept(){return this.server.accept(),this.ready()}ready(){return this.accepted=!0,this.open(),this.client}};var F=class extends w{constructor(e){super(e),this.accepted=!0}accept(){throw new Error("Do not call accept() on restore")}acceptWebSocket(){throw new Error("Do not call acceptWebSocket() on restore")}};var je=class{map=new Map;create(e){class r extends X{constructor(a){super();this.sessions=a}accept(){return this.addEventListener("close",()=>this.sessions.unregister(this.server)),this.sessions.register(this.server,this),super.accept()}acceptWebSocket(a,p){return this.sessions.register(this.server,this),super.acceptWebSocket(a,p)}}let s=new r(this);return s.attach(e),s}restore(e){class r extends F{constructor(o,i){super(i),o.register(this.server,this)}}return new r(this,e)}restoreAll(e){let r=[];for(let s of e)r.push(this.restore(s));return r}get(e){return this.map.get(e)}values(){return this.map.values()}keys(){return this.map.keys()}close(e,r,s){let o=this.get(e);return o&&o.close(r,s),this.unregister(e)}*[Symbol.iterator](){yield*this.values()}register(e,r){this.map.set(e,r)}unregister(e){return this.map.delete(e)}};var _=class{constructor(e,r,s){this._request=e;this._env=r;this._ctx=s}get request(){return this._request}get env(){return this._env}get ctx(){return this._ctx}isAllowed(e){let r=this.getAllowedMethods();return T(r),re(e)&&r.includes(e)}create(e){let r=this.constructor;return new r(e,this.env,this.ctx)}async response(e,...r){return new e(...r).response()}static ignite(){return{fetch:(e,r,s)=>new this(e,r,s).fetch()}}};function Xe(t){if(!(t instanceof h))throw new TypeError("Handler must be a subclass of Middleware.")}var $=class extends _{middlewares=[];init(){}use(e){return Xe(e),this.middlewares.push(e),this}async fetch(){return await this.middlewares.reduceRight((r,s)=>()=>s.handle(this,r),()=>this.dispatch())()}};var z=class extends ${async fetch(){if(!this.isAllowed(this.request.method))return this.response(v,this);try{return await this.init(),await super.fetch()}catch(e){return console.error(e),this.response(Y)}}async dispatch(){let e=this.request.method;return({GET:()=>this.get(),PUT:()=>this.put(),HEAD:()=>this.head(),POST:()=>this.post(),PATCH:()=>this.patch(),DELETE:()=>this.delete(),OPTIONS:()=>this.options()}[e]??(()=>this.response(v,this)))()}async get(){return this.response(x,this)}async put(){return this.response(x,this)}async post(){return this.response(x,this)}async patch(){return this.response(x,this)}async delete(){return this.response(x,this)}async options(){return this.response(y)}async head(){let e=this.create(new Request(this.request.url,{method:m,headers:this.request.headers}));return this.response(K,await e.fetch())}getAllowedMethods(){return[m,I,O]}};import{match as lt}from"path-to-regexp";var J=class{routes=[];add(e){for(let[r,s,o]of e){let i=lt(s);this.routes.push({method:r,matcher:i,handler:o})}}match(e,r){let s=new URL(r).pathname;for(let o of this){if(o.method!==e)continue;let i=o.matcher(s);if(i)return{route:o,params:i.params}}return null}*[Symbol.iterator](){yield*this.routes}};var Fe=class t extends z{_routes=new J;route(e,r,s){return this.routes([[e,r,s]]),this}routes(e){return this._routes.add(e),this}async dispatch(){let e=this._routes.match(this.request.method,this.request.url);if(!e)return super.dispatch();let{handler:r}=e.route;return t.isWorkerClass(r)?new r(this.request,this.env,this.ctx).fetch():r.call(this,e.params)}static isWorkerClass(e){return _.prototype.isPrototypeOf(e.prototype)}async get(){return this.response(A)}async put(){return this.response(A)}async post(){return this.response(A)}async patch(){return this.response(A)}async delete(){return this.response(A)}};export{N as BadRequest,z as BasicWorker,W as CacheControl,U as ClonedResponse,_t as DELETE,Me as Forbidden,m as GET,I as HEAD,K as Head,Ee as HtmlResponse,d as HttpError,Y as InternalServerError,V as JsonResponse,P as Method,v as MethodNotAllowed,x as MethodNotImplemented,A as NotFound,ae as NotImplemented,O as OPTIONS,ne as OctetStream,y as Options,wt as PATCH,yt as POST,Tt as PUT,Ae as R2ObjectStream,Fe as RouteWorker,He as ServiceUnavailable,l as StatusCodes,L as SuccessResponse,Se as TextResponse,ue as Time,ke as Unauthorized,B as UpgradeRequired,je as WebSocketSessions,xe as WebSocketUpgrade,S as WorkerResponse,er as cache,kr as cors,Je as sortSearchParams,tr as stripSearchParams,Qr as websocket};
2
2
  //# sourceMappingURL=index.js.map