Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bit-js/byte

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bit-js/byte - npm Package Compare versions

Comparing version 1.3.12 to 1.4.0

2

index.js
// @bun
var objectSerializers={Object:JSON.stringify,Promise:(input)=>input.then(serialize)};function serialize(input){switch(typeof input){case"string":return input;case"object":return input===null?null:objectSerializers[input.constructor.name]?.(input)??input;case"number":return`${input}`;case"bigint":return`${input}`;case"boolean":return`${input}`;default:return null}}var buildPathInject=function(path){let parts="";let paramIdx=path.indexOf(":");let start=0;while(paramIdx!==-1){if(paramIdx!==start)parts+=path.substring(start,paramIdx);++paramIdx;start=path.indexOf("/",paramIdx);if(start===-1){parts+=`\${p.${path.substring(paramIdx)}}`;return Function(`return (p)=>\`${parts}\``)()}parts+=`\${p.${path.substring(paramIdx,start)}}`;paramIdx=path.indexOf(":",start+1)}parts+=path.charCodeAt(path.length-1)===42?`${path.substring(start,path.length-2)}\${p.$}`:path.substring(start);return Function(`return (p)=>\`${parts}\``)()};var injectPath={};function getInjectFn(path){return injectPath[path]??=buildPathInject(path)}function stringifyQuery(query){if(typeof query==="undefined")return"";const parts=[];for(const key in query){const value=query[key];if(value===false)continue;if(value===true)parts.push(encodeURIComponent(key));else if(typeof value==="object"){const encodedKey=encodeURIComponent(key);for(let i=0,{length:length2}=value;i<length2;++i)parts.push(`${encodedKey}=${encodeURIComponent(`${value[i]}`)}`)}else parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(`${value}`)}`)}return`?${parts.join("&")}`}var forbidden={status:403};var emptyObj={};var emptyList=[];var default404=(ctx)=>{ctx.status=404;return new Response(`Cannot ${ctx.req.method} ${ctx.path}`,ctx)};var fetchFn=globalThis.fetch.bind(globalThis);class BitClient{url;fetch;defaultInit;constructor(url,options){if(typeof options==="undefined"){this.fetch=fetchFn;this.defaultInit=emptyObj}else{this.fetch=options.fetch??fetchFn;this.defaultInit=options.init??emptyObj}const lastIdx=url.length-1;this.url=url.charCodeAt(lastIdx)===47?url.substring(0,lastIdx):url}$(path,init){const{defaultInit}=this;if(typeof init==="undefined")return this.fetch(new Request(this.url+path,defaultInit));for(const key in defaultInit)init[key]??=defaultInit[key];const{params,body,query}=init;if(typeof body!=="undefined")init.body=serialize(body);return this.fetch(new Request(`${this.url}${typeof params==="undefined"?path:getInjectFn(path)(params)}${stringifyQuery(query)}`,init))}get(path,init){if(typeof init==="undefined")return this.$(path,getInit);init.method="GET";return this.$(path,init)}head(path,init){if(typeof init==="undefined")return this.$(path,headInit);init.method="HEAD";return this.$(path,init)}post(path,init){if(typeof init==="undefined")return this.$(path,postInit);init.method="POST";return this.$(path,init)}put(path,init){if(typeof init==="undefined")return this.$(path,putInit);init.method="PUT";return this.$(path,init)}delete(path,init){if(typeof init==="undefined")return this.$(path,deleteInit);init.method="DELETE";return this.$(path,init)}options(path,init){if(typeof init==="undefined")return this.$(path,optionsInit);init.method="OPTIONS";return this.$(path,init)}any(path,init){return typeof init==="undefined"?this.$(path):this.$(path,init)}}var getInit={method:"GET"};var headInit={method:"HEAD"};var postInit={method:"POST"};var putInit={method:"PUT"};var deleteInit={method:"DELETE"};var optionsInit={method:"OPTIONS"};function bit(url,options){return typeof options==="undefined"?new BitClient(url):new BitClient(url,options)}import Blitz from"@bit-js/blitz";function $async(fn){fn.constructor=AsyncFunction;return fn}function isAsync(fn){return fn.constructor===AsyncFunction}function $pass(fn){fn[passSymbol]=true;return fn}function passChecks(fn){return passSymbol in fn}var AsyncFunction=async function(){}.constructor;var passSymbol=Symbol("pass");class Route{method;path;validator;handler;actions;defers;constructor(method,path,validator,handler,actions,defers){this.method=method;this.path=path;this.validator=validator;this.handler=handler;this.actions=actions;this.defers=defers}clone(base,otherAppActions,otherAppDefers){const{path}=this;return new Route(this.method,base.length===1?path:path.length===1?base:base+path,this.validator,this.handler,otherAppActions.length===0?this.actions:[otherAppActions,...this.actions],otherAppDefers.length===0?this.defers:[...this.defers,otherAppDefers])}register(router){if(this.method===null)router.handle(this.path,this.compile());else router.on(this.method,this.path,this.compile())}compile(){const{handler,validator,actions,defers}=this;const noActions=actions.length===0;const noValidator=validator===null;const noDefers=defers.length===0;if(noValidator&&noActions&&noDefers)return handler;const keys=[];const statements=[];const values=[];const paramsKeys=[];let hasAsync=false;let noContext=true;let idx=0;if(!noActions)for(let i=0,{length:length2}=actions;i<length2;++i){const list=actions[i];for(let i2=0,{length:length3}=list;i2<length3;++i2){const fn=list[i2];const fnKey=`f${idx}`;keys.push(fnKey);values.push(fn);const fnAsync=isAsync(fn);hasAsync=hasAsync||fnAsync;const fnNoContext=fn.length===0;noContext=noContext&&fnNoContext;const result=`${fnAsync?"await ":""}${fnKey}(${noContext?"":"c"})`;if(passChecks(fn))statements.push(result);else{const valKey=`c${idx}`;statements.push(`const ${valKey}=${result};if(${valKey} instanceof Response)return ${valKey}`)}++idx}}if(!noValidator){for(const key in validator){const fn=validator[key],fnKey="f"+idx;keys.push(fnKey);values.push(fn);const fnAsync=isAsync(fn);hasAsync=hasAsync||fnAsync;const fnNoContext=fn.length===0;noContext=noContext&&fnNoContext;const result=`${fnAsync?"await ":""}${fnKey}(${noContext?"":"c"})`;if(passChecks(fn))paramsKeys.push(`${key}:${result}`);else{paramsKeys.push(key);statements.push(`const ${key}=${result};if(${key} instanceof Response)return ${key}`)}++idx}statements.push(`c.state={${paramsKeys.join()}}`)}keys.push("$");values.push(handler);const handlerNoContext=handler.length===0;noContext=noContext&&handlerNoContext;if(noDefers)statements.push(`return ${isAsync(handler)&&hasAsync?"await ":""}\$(${handlerNoContext?"":"c"});`);else{const fnAsync=isAsync(handler);hasAsync=hasAsync||fnAsync;statements.push(`c.res=${fnAsync?"await ":""}\$(${handlerNoContext?"":"c"})`);for(let i=0,{length:length2}=defers;i<length2;++i){const list=defers[i];for(let i2=list.length-1;i2>-1;--i2){const fn=list[i2];const fnKey=`f${idx}`;keys.push(fnKey);values.push(fn);const fnAsync2=isAsync(fn);hasAsync=hasAsync||fnAsync2;const fnNoContext=fn.length===0;noContext=noContext&&fnNoContext;statements.push(`${fnAsync2?"await ":""}${fnKey}(${noContext?"":"c"})`);++idx}}statements.push("return c.res;")}return Function(...keys,`return ${hasAsync?"async ":""}(${noContext?"":"c"})=>{${statements.join(";")}}`)(...values)}}class Context{state;status;headers;path;pathStart;pathEnd;params;req;constructor(req){this.req=req;this.headers={};const{url}=req;const start=url.indexOf("/",12);const end=url.indexOf("?",start+1);const pathEnd=end===-1?url.length:end;this.pathStart=start;this.pathEnd=pathEnd;this.path=url.substring(start,pathEnd)}body(body){return new Response(body,this)}json(body){this.headers["Content-Type"]="application/json";return new Response(JSON.stringify(body),this)}html(body){this.headers["Content-Type"]="text/html";return new Response(body,this)}redirect(location,status){this.headers.Location=location;this.status=status;return new Response(null,this)}}var jsonHeaders={"Content-Type":"application/json"};var jsonInit={headers:jsonHeaders};var htmlHeaders={"Content-Type":"text/html"};var htmlInit={headers:htmlHeaders};var send={body(body,init){const res=typeof init==="undefined"?new Response(body):new Response(body,init);return()=>res.clone()},json(body,init){if(typeof init==="undefined")init=jsonInit;if(typeof init.headers==="undefined")init.headers=jsonHeaders;else init.headers["Content-Type"]="application/json";const res=new Response(JSON.stringify(body),init);return()=>res.clone()},html(body,init){if(typeof init==="undefined")init=htmlInit;if(typeof init.headers==="undefined")init.headers=htmlHeaders;else init.headers["Content-Type"]="text/html";const res=new Response(body,init);return()=>res.clone()}};class Plugin{}class Byte{actions=[];defers=[];use(...fns){this.actions.push(...fns);return this}defer(...fns){this.defers.push(...fns);return this}register(...plugin){for(let i=0,{length:length2}=plugin;i<length2;++i)plugin[i].plug(this);return this}routes=[];route(base,{routes}){const currentRoutes=this.routes;const{actions,defers}=this;for(let i=0,{length:length2}=routes;i<length2;++i)currentRoutes.push(routes[i].clone(base,actions,defers));return this}#fetch;build(router=new Blitz){const{routes}=this;router.fallback??=default404;for(let i=0,{length:length2}=routes;i<length2;++i)routes[i].register(router);return this.#fetch=router.build(Context)}get fetch(){return this.#fetch??=this.build()}client(){return bit("http://127.0.0.1",this)}handle(method,path,...args){const{actions,defers}=this;this.routes.push(typeof args[0]==="function"?new Route(method,path,null,args[0],actions.length===0?emptyList:[actions],defers.length===0?emptyList:[defers]):new Route(method,path,args[0],args[1],actions.length===0?emptyList:[actions],defers.length===0?emptyList:[defers]));return this}static state(validator2){return validator2}static handle(fn){return fn}static defer(fn){return fn}static plugin(plugin){return plugin}static route(base,app){return new Byte().route(base,app)}get(...args){return this.handle("GET",...args)}head(...args){return this.handle("HEAD",...args)}post(...args){return this.handle("POST",...args)}put(...args){return this.handle("PUT",...args)}delete(...args){return this.handle("DELETE",...args)}options(...args){return this.handle("OPTIONS",...args)}any(...args){return this.handle(null,...args)}}var parseValue=function(value){return JSON.stringify(typeof value==="string"?value:value.join(","))};function cors(options){if(typeof options==="undefined")return defaultCors;const builder=[];if(typeof options.allowHeaders!=="undefined")builder.push(`headers['Access-Control-Allow-Headers']=${parseValue(options.allowHeaders)};`);if(typeof options.allowMethods!=="undefined")builder.push(`headers['Access-Control-Allow-Methods']=${parseValue(options.allowMethods)};`);if(typeof options.exposeHeaders!=="undefined")builder.push(`headers['Access-Control-Expose-Headers']=${parseValue(options.exposeHeaders)};`);if(typeof options.maxAge==="number")builder.push(`headers['Access-Control-Max-Age']=${options.maxAge};`);if(options.allowCredentials===true)builder.push(`headers['Access-Control-Allow-Credentials']='true';`);if(typeof options.allowOrigin==="string"&&options.allowOrigin!=="*")builder.push(`headers['Access-Control-Allow-Origin']=${JSON.stringify(options.allowOrigin)};headers.Vary='Origin';`);else builder.push(`headers['Access-Control-Allow-Origin']='*';`);return $pass(Function(builder.length>1?`return ({headers})=>{${builder.join("")}}`:`return (c)=>{c.${builder[0]}}`)())}var defaultCors=$pass((c)=>{c.headers["Access-Control-Allow-Origin"]="*"});function csrf(options){if(typeof options==="undefined")return defaultCSRF;const literals=[];const keys=[];const values=[];if(typeof options.origins!=="undefined"){const obj={};const{origins}=options;for(let i=0,{length:length2}=origins;i<length2;++i)obj[origins[i]]=null;keys.push("o");values.push(obj);literals.push("_ in o")}if(typeof options.verify!=="undefined"){keys.push("f");values.push(options.verify);literals.push("f(_)")}if(literals.length===0)return defaultCSRF;let fallbackCall;if(typeof options.fallback==="undefined"){keys.push("h");values.push(forbidden);fallbackCall="new Response(null,h)"}else{const{fallback}=options;keys.push("h");values.push(fallback);fallbackCall=`h${fallback.length===0?"()":"(c)"}`}return Function(...keys,`return (c)=>{const _=c.req.headers.get('Origin');return ${literals.join("&&")}?null:${fallbackCall};}`)(...values)}var defaultCSRF=(ctx)=>{if(ctx.req.headers.get("Origin")!==ctx.req.url.substring(0,ctx.pathStart))return new Response(null,forbidden)};var createHex=function(shift){return[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,1<<shift,2<<shift,3<<shift,4<<shift,5<<shift,6<<shift,7<<shift,8<<shift,9<<shift,255,255,255,255,255,255,255,10<<shift,11<<shift,12<<shift,13<<shift,14<<shift,15<<shift,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,10<<shift,11<<shift,12<<shift,13<<shift,14<<shift,15<<shift]};var highHex=function(code){return code>102?255:h4[code]};var lowHex=function(code){return code>102?255:h0[code]};var h4=createHex(4);var h0=createHex(0);var data=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,7,7,7,7,7,7,7,7,7,7,7,7,8,7,7,10,9,9,9,11,4,4,4,4,4,4,4,4,4,4,4,256,256,256,256,256,256,256,256,256,256,256,256,268,256,256,256,256,280,292,304,316,328,340,352,256,268,268,268,256,256,256,256,256,256,256,256,256,256,256,280,256,256,256,256,256,256,256,256,256,280,280,280,256,256,256,256,256,256,256,256,256,280,280,256,256,256,256,256,256,256,256,256,256,304,304,304,256,256,256,256,256,256,256,256,256,256,304,304,256,256,256,256,256,256,256,256,256,304,256,256,256,256,256,256,256,256,256,256];var mask=[127,63,63,63,0,31,15,15,15,7,7,7];function decodeURIComponent(url,start,end){let percentPosition=url.indexOf("%",start);if(percentPosition===-1)return url.substring(start,end);let decoded="";let last=0;let codepoint=0;let startOfOctets=percentPosition;let state=268;while(percentPosition<end){const byte=highHex(url.charCodeAt(percentPosition+1))|lowHex(url.charCodeAt(percentPosition+2));const type=data[byte];codepoint=codepoint<<6|byte&mask[type];state=data[state+type];if(state===256)return url.substring(start,end);if(state===268){decoded+=url.substring(last,startOfOctets);decoded+=codepoint>65535?String.fromCharCode(55232+(codepoint>>10),56320+(codepoint&1023)):String.fromCharCode(codepoint);last=percentPosition+3;percentPosition=url.indexOf("%",last);if(percentPosition===-1)return decoded+url.substring(last);startOfOctets=percentPosition;codepoint=0}else{percentPosition+=3;if(percentPosition>=length||url.charCodeAt(percentPosition)!==37)return url.substring(start,end)}}return decoded+url.substring(last)}var defaultOptions4={type:"string"};var query={decodeValue:true,get(name,{type,maxItems}=defaultOptions4){if(type==="bool"){const search2=JSON.stringify(encodeURIComponent(name));const searchLen2=search2.length-2;return Function(`return ({pathEnd,req:{url}})=>{const i=url.indexOf(${search2},pathEnd+1);return i!==-1&&(i===pathEnd+1||url.charCodeAt(i-1)===38)&&(i+${searchLen2}===url.length||url.charCodeAt(i+${searchLen2})===38);}`)()}const search=JSON.stringify(encodeURIComponent(name)+"=");const searchLen=search.length-2;if(type==="string"){const{decodeValue}=this;return typeof maxItems==="undefined"||maxItems<2?Function("d",`return ({pathEnd,req:{url}})=>{const i=url.indexOf(${search},pathEnd+1)+${searchLen};if(i===${searchLen-1})return null;const n=url.indexOf("&",i);return ${decodeValue?"d(url,i,n===-1?url.length:n)":"n===-1?url.substring(i):url.substring(i,n)"};}`)(this.decode):Function("d",`return ({pathEnd,req:{url}})=>{let i=url.indexOf(${search},pathEnd+1)+${searchLen};if(i===${searchLen-1})return [];const r=[];${decodeValue?"const {length}=url;":""}let l=0;do{const n=url.indexOf("&",i);if(n===-1){r.push(${decodeValue?"d(url,i,length)":"url.substring(i)"});return r;}r.push(${decodeValue?"d(url,i,n)":"url.substring(i,n)"});if(l===${maxItems-1})return r;i=url.indexOf(${search},n+1)+${searchLen};++l;}while(i!==${searchLen-1});return r;}`)(this.decode)}return typeof maxItems==="undefined"||maxItems<2?Function(`return ({pathEnd,req:{url}})=>{const i=url.indexOf(${search},pathEnd+1)+${searchLen};if(i===${searchLen-1})return Number.NaN;const n=url.indexOf("&",i);return n===-1?+url.substring(i):+url.substring(i,n);}`)():Function(`return ({pathEnd,req:{url}})=>{let i=url.indexOf(${search},pathEnd+1)+${searchLen};if(i===${searchLen-1})return [];const r=[];let l=0;do{const n=url.indexOf("&",i);if(n===-1){const v=+url.substring(i);if(!Number.isNaN(v))r.push(v);return r;}const v=+url.substring(i,n);if(!Number.isNaN(v)){r.push(v);if(l===${maxItems-1})return r;++l}i=url.indexOf(${search},n+1)+${searchLen};}while(i!==${searchLen-1});return r;}`)()},schema(schema){const{decodeValue}=this;const idxChecks=["++pathEnd;const {length}=url;"],valueChecks=[],idxs=[],objParts=[];let idx=0;for(const key in schema){const{type,maxItems}=schema[key];if(type==="bool"){const search=JSON.stringify(encodeURIComponent(key));const searchLen=search.length-2;idxs.push(`const i${idx}=url.indexOf(${search},pathEnd);`);objParts.push(`${key}:i${idx}!==-1&&(i${idx}===pathEnd||url.charCodeAt(i${idx}-1)===38)&&(i${idx}+${searchLen}===length||url.charCodeAt(i${idx}+${searchLen})===38)`)}else{const search=JSON.stringify(encodeURIComponent(key)+"=");const searchLen=search.length-2;if(type==="string"){if(typeof maxItems==="undefined"||maxItems<2){idxChecks.push(`const s${idx}=url.indexOf(${search},pathEnd)+${searchLen};if(s${idx}===${searchLen-1})return null;`);idxs.push(`const i${idx}=url.indexOf("&",s${idx});`);objParts.push(`${key}:${decodeValue?`d(url,s${idx},i${idx}===-1?length:i${idx})`:`i${idx}===-1?url.substring(s${idx}):url.substring(s${idx},i${idx})`}`)}else{idxs.push(`const ${key}=[];let l${idx}=0;let i${idx}=url.indexOf(${search},pathEnd)+${searchLen};while(i${idx}!==${searchLen-1}){const n=url.indexOf("&",i${idx});if(n===-1){${key}.push(${decodeValue?`d(url,i${idx},length)`:`url.substring(i${idx})`});break;}${key}.push(${decodeValue?`d(url,i${idx},n)`:`url.substring(i${idx},n)`});if(l${idx}===${maxItems-1})break;i${idx}=url.indexOf(${search},n+1)+${searchLen};++l${idx};}`);objParts.push(key)}}else{if(typeof maxItems==="undefined"||maxItems<2){idxChecks.push(`const s${idx}=url.indexOf(${search},pathEnd)+${searchLen};if(s${idx}===${searchLen-1})return null;`);valueChecks.push(`const i${idx}=url.indexOf("&",s${idx});const ${key}=i${idx}===-1?+url.substring(s${idx}):+url.substring(s${idx},i${idx});if(Number.isNaN(${key}))return null;`);objParts.push(key)}else{idxs.push(`const ${key}=[];let l${idx}=0;let i${idx}=url.indexOf(${search},pathEnd)+${searchLen};while(i${idx}!==${searchLen-1}){const n=url.indexOf("&",i${idx});if(n===-1){const v=+url.substring(i${idx});if(!Number.isNaN(v))${key}.push(v);break;}const v=+url.substring(i${idx},n);if(!Number.isNaN(v)){${key}.push(v);if(l${idx}===${maxItems-1})break;}i${idx}=url.indexOf(${search},n+1)+${searchLen};++l${idx};}`);objParts.push(key)}}}++idx}return Function("d",`return ({pathEnd,req:{url}})=>{${idxChecks.join("")}${valueChecks.join("")}${idxs.join("")}return {${objParts.join()}};}`)(this.decode)},decode:decodeURIComponent};export{stringifyQuery,serialize,send,query,passChecks,isAsync,getInjectFn,csrf,cors,bit,Route,Plugin,Context,Byte,BitClient,AsyncFunction,$pass,$async};
var objectSerializers={Object:JSON.stringify,Promise:(input)=>input.then(serialize)};function serialize(input){switch(typeof input){case"string":return input;case"object":return input===null?null:objectSerializers[input.constructor.name]?.(input)??input;case"number":return`${input}`;case"bigint":return`${input}`;case"boolean":return`${input}`;default:return null}}var buildPathInject=function(path){let parts="";let paramIdx=path.indexOf(":");let start=0;while(paramIdx!==-1){if(paramIdx!==start)parts+=path.substring(start,paramIdx);++paramIdx;start=path.indexOf("/",paramIdx);if(start===-1){parts+=`\${p.${path.substring(paramIdx)}}`;return Function(`return (p)=>\`${parts}\``)()}parts+=`\${p.${path.substring(paramIdx,start)}}`;paramIdx=path.indexOf(":",start+1)}parts+=path.charCodeAt(path.length-1)===42?`${path.substring(start,path.length-2)}\${p.$}`:path.substring(start);return Function(`return (p)=>\`${parts}\``)()};var injectPath={};function getInjectFn(path){return injectPath[path]??=buildPathInject(path)}function stringifyQuery(query){if(typeof query==="undefined")return"";const parts=[];for(const key in query){const value=query[key];if(value===false)continue;if(value===true)parts.push(encodeURIComponent(key));else if(typeof value==="object"){const encodedKey=encodeURIComponent(key);for(let i=0,{length:length2}=value;i<length2;++i)parts.push(`${encodedKey}=${encodeURIComponent(`${value[i]}`)}`)}else parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(`${value}`)}`)}return`?${parts.join("&")}`}var forbidden={status:403};var emptyObj={};var emptyList=[];var default404=(ctx)=>{ctx.status=404;return new Response(`Cannot ${ctx.req.method} ${ctx.path}`,ctx)};var fetchFn=globalThis.fetch.bind(globalThis);class BitClient{url;fetch;defaultInit;constructor(url,options){if(typeof options==="undefined"){this.fetch=fetchFn;this.defaultInit=emptyObj}else{this.fetch=options.fetch??fetchFn;this.defaultInit=options.init??emptyObj}const lastIdx=url.length-1;this.url=url.charCodeAt(lastIdx)===47?url.substring(0,lastIdx):url}$(path,init){const{defaultInit}=this;if(typeof init==="undefined")return this.fetch(new Request(this.url+path,defaultInit));for(const key in defaultInit)init[key]??=defaultInit[key];const{params,body,query}=init;if(typeof body!=="undefined")init.body=serialize(body);return this.fetch(new Request(`${this.url}${typeof params==="undefined"?path:getInjectFn(path)(params)}${stringifyQuery(query)}`,init))}get(path,init){if(typeof init==="undefined")return this.$(path,getInit);init.method="GET";return this.$(path,init)}head(path,init){if(typeof init==="undefined")return this.$(path,headInit);init.method="HEAD";return this.$(path,init)}post(path,init){if(typeof init==="undefined")return this.$(path,postInit);init.method="POST";return this.$(path,init)}put(path,init){if(typeof init==="undefined")return this.$(path,putInit);init.method="PUT";return this.$(path,init)}delete(path,init){if(typeof init==="undefined")return this.$(path,deleteInit);init.method="DELETE";return this.$(path,init)}options(path,init){if(typeof init==="undefined")return this.$(path,optionsInit);init.method="OPTIONS";return this.$(path,init)}any(path,init){return typeof init==="undefined"?this.$(path):this.$(path,init)}}var getInit={method:"GET"};var headInit={method:"HEAD"};var postInit={method:"POST"};var putInit={method:"PUT"};var deleteInit={method:"DELETE"};var optionsInit={method:"OPTIONS"};function bit(url,options){return typeof options==="undefined"?new BitClient(url):new BitClient(url,options)}import Blitz from"@bit-js/blitz";function $async(fn){fn.constructor=AsyncFunction;return fn}function isAsync(fn){return fn.constructor===AsyncFunction}function $pass(fn){fn[passSymbol]=true;return fn}function passChecks(fn){return passSymbol in fn}var AsyncFunction=async function(){}.constructor;var passSymbol=Symbol("pass");class Route{method;path;validator;handler;actions;defers;constructor(method,path,validator,handler,actions,defers){this.method=method;this.path=path;this.validator=validator;this.handler=handler;this.actions=actions;this.defers=defers}clone(base,otherAppActions,otherAppDefers){const{path}=this;return new Route(this.method,base.length===1?path:path.length===1?base:base+path,this.validator,this.handler,otherAppActions.length===0?this.actions:[otherAppActions,...this.actions],otherAppDefers.length===0?this.defers:[...this.defers,otherAppDefers])}register(router){if(this.method===null)router.handle(this.path,this.compile());else router.on(this.method,this.path,this.compile())}compile(){const{handler,validator,actions,defers}=this;const noActions=actions.length===0;const noValidator=validator===null;const noDefers=defers.length===0;if(noValidator&&noActions&&noDefers)return handler;const keys=[];const statements=[];const values=[];const paramsKeys=[];let hasAsync=false;let noContext=true;let idx=0;if(!noActions)for(let i=0,{length:length2}=actions;i<length2;++i){const list=actions[i];for(let i2=0,{length:length3}=list;i2<length3;++i2){const fn=list[i2];const fnKey=`f${idx}`;keys.push(fnKey);values.push(fn);const fnAsync=isAsync(fn);hasAsync=hasAsync||fnAsync;const fnNoContext=fn.length===0;noContext=noContext&&fnNoContext;const result=`${fnAsync?"await ":""}${fnKey}(${noContext?"":"c"})`;if(passChecks(fn))statements.push(result);else{const valKey=`c${idx}`;statements.push(`const ${valKey}=${result};if(${valKey} instanceof Response)return ${valKey}`)}++idx}}if(!noValidator){for(const key in validator){const fn=validator[key],fnKey="f"+idx;keys.push(fnKey);values.push(fn);const fnAsync=isAsync(fn);hasAsync=hasAsync||fnAsync;const fnNoContext=fn.length===0;noContext=noContext&&fnNoContext;const result=`${fnAsync?"await ":""}${fnKey}(${noContext?"":"c"})`;if(passChecks(fn))paramsKeys.push(`${key}:${result}`);else{paramsKeys.push(key);statements.push(`const ${key}=${result};if(${key} instanceof Response)return ${key}`)}++idx}statements.push(`c.state={${paramsKeys.join()}}`)}keys.push("$");values.push(handler);const handlerNoContext=handler.length===0;noContext=noContext&&handlerNoContext;if(noDefers)statements.push(`return ${isAsync(handler)&&hasAsync?"await ":""}\$(${handlerNoContext?"":"c"});`);else{const fnAsync=isAsync(handler);hasAsync=hasAsync||fnAsync;statements.push(`c.res=${fnAsync?"await ":""}\$(${handlerNoContext?"":"c"})`);for(let i=0,{length:length2}=defers;i<length2;++i){const list=defers[i];for(let i2=list.length-1;i2>-1;--i2){const fn=list[i2];const fnKey=`f${idx}`;keys.push(fnKey);values.push(fn);const fnAsync2=isAsync(fn);hasAsync=hasAsync||fnAsync2;const fnNoContext=fn.length===0;noContext=noContext&&fnNoContext;statements.push(`${fnAsync2?"await ":""}${fnKey}(${noContext?"":"c"})`);++idx}}statements.push("return c.res;")}return Function(...keys,`return ${hasAsync?"async ":""}(${noContext?"":"c"})=>{${statements.join(";")}}`)(...values)}}class Context{state;status;headers;path;pathStart;pathEnd;params;req;constructor(req){this.req=req;this.headers={};const{url}=req;const start=url.indexOf("/",12);const end=url.indexOf("?",start+1);const pathEnd=end===-1?url.length:end;this.pathStart=start;this.pathEnd=pathEnd;this.path=url.substring(start,pathEnd)}body(body){return new Response(body,this)}json(body){this.headers["Content-Type"]="application/json";return new Response(JSON.stringify(body),this)}html(body){this.headers["Content-Type"]="text/html";return new Response(body,this)}redirect(location,status){this.headers.Location=location;this.status=status;return new Response(null,this)}}var jsonHeaders={"Content-Type":"application/json"};var jsonInit={headers:jsonHeaders};var htmlHeaders={"Content-Type":"text/html"};var htmlInit={headers:htmlHeaders};var send={body(body,init){const res=typeof init==="undefined"?new Response(body):new Response(body,init);return()=>res.clone()},json(body,init){if(typeof init==="undefined")init=jsonInit;if(typeof init.headers==="undefined")init.headers=jsonHeaders;else init.headers["Content-Type"]="application/json";const res=new Response(JSON.stringify(body),init);return()=>res.clone()},html(body,init){if(typeof init==="undefined")init=htmlInit;if(typeof init.headers==="undefined")init.headers=htmlHeaders;else init.headers["Content-Type"]="text/html";const res=new Response(body,init);return()=>res.clone()}};class Plugin{}class Byte{actions=[];defers=[];use(...fns){this.actions.push(...fns);return this}set(name,fn){const fnAsync=isAsync(fn);const noContext=fn.length===0;return this.use($pass(Function("f",`return ${fnAsync?"async ":""}(c)=>{c.${name}=${fnAsync?"await ":""}f(${noContext?"":"c"});}`)(fn)))}defer(...fns){this.defers.push(...fns);return this}register(...plugin){for(let i=0,{length:length2}=plugin;i<length2;++i)plugin[i].plug(this);return this}routes=[];route(base,{routes}){const currentRoutes=this.routes;const{actions,defers}=this;for(let i=0,{length:length2}=routes;i<length2;++i)currentRoutes.push(routes[i].clone(base,actions,defers));return this}#fetch;build(router=new Blitz){const{routes}=this;router.fallback??=default404;for(let i=0,{length:length2}=routes;i<length2;++i)routes[i].register(router);return this.#fetch=router.build(Context)}get fetch(){return this.#fetch??=this.build()}client(){return bit("http://127.0.0.1",this)}handle(method,path,...args){const{actions,defers}=this;this.routes.push(typeof args[0]==="function"?new Route(method,path,null,args[0],actions.length===0?emptyList:[actions],defers.length===0?emptyList:[defers]):new Route(method,path,args[0],args[1],actions.length===0?emptyList:[actions],defers.length===0?emptyList:[defers]));return this}static state(validator2){return validator2}static handle(fn){return fn}static defer(fn){return fn}static plugin(plugin){return plugin}static route(base,app){return new Byte().route(base,app)}get(...args){return this.handle("GET",...args)}head(...args){return this.handle("HEAD",...args)}post(...args){return this.handle("POST",...args)}put(...args){return this.handle("PUT",...args)}delete(...args){return this.handle("DELETE",...args)}options(...args){return this.handle("OPTIONS",...args)}any(...args){return this.handle(null,...args)}}var parseValue=function(value){return JSON.stringify(typeof value==="string"?value:value.join(","))};function cors(options){if(typeof options==="undefined")return defaultCors;const builder=[];if(typeof options.allowHeaders!=="undefined")builder.push(`headers['Access-Control-Allow-Headers']=${parseValue(options.allowHeaders)};`);if(typeof options.allowMethods!=="undefined")builder.push(`headers['Access-Control-Allow-Methods']=${parseValue(options.allowMethods)};`);if(typeof options.exposeHeaders!=="undefined")builder.push(`headers['Access-Control-Expose-Headers']=${parseValue(options.exposeHeaders)};`);if(typeof options.maxAge==="number")builder.push(`headers['Access-Control-Max-Age']=${options.maxAge};`);if(options.allowCredentials===true)builder.push(`headers['Access-Control-Allow-Credentials']='true';`);if(typeof options.allowOrigin==="string"&&options.allowOrigin!=="*")builder.push(`headers['Access-Control-Allow-Origin']=${JSON.stringify(options.allowOrigin)};headers.Vary='Origin';`);else builder.push(`headers['Access-Control-Allow-Origin']='*';`);return $pass(Function(builder.length>1?`return ({headers})=>{${builder.join("")}}`:`return (c)=>{c.${builder[0]}}`)())}var defaultCors=$pass((c)=>{c.headers["Access-Control-Allow-Origin"]="*"});function csrf(options){if(typeof options==="undefined")return defaultCSRF;const literals=[];const keys=[];const values=[];if(typeof options.origins!=="undefined"){const obj={};const{origins}=options;for(let i=0,{length:length2}=origins;i<length2;++i)obj[origins[i]]=null;keys.push("o");values.push(obj);literals.push("_ in o")}if(typeof options.verify!=="undefined"){keys.push("f");values.push(options.verify);literals.push("f(_)")}if(literals.length===0)return defaultCSRF;let fallbackCall;if(typeof options.fallback==="undefined"){keys.push("h");values.push(forbidden);fallbackCall="new Response(null,h)"}else{const{fallback}=options;keys.push("h");values.push(fallback);fallbackCall=`h${fallback.length===0?"()":"(c)"}`}return Function(...keys,`return (c)=>{const _=c.req.headers.get('Origin');return ${literals.join("&&")}?null:${fallbackCall};}`)(...values)}var defaultCSRF=(ctx)=>{if(ctx.req.headers.get("Origin")!==ctx.req.url.substring(0,ctx.pathStart))return new Response(null,forbidden)};var createHex=function(shift){return[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,1<<shift,2<<shift,3<<shift,4<<shift,5<<shift,6<<shift,7<<shift,8<<shift,9<<shift,255,255,255,255,255,255,255,10<<shift,11<<shift,12<<shift,13<<shift,14<<shift,15<<shift,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,10<<shift,11<<shift,12<<shift,13<<shift,14<<shift,15<<shift]};var highHex=function(code){return code>102?255:h4[code]};var lowHex=function(code){return code>102?255:h0[code]};var h4=createHex(4);var h0=createHex(0);var data=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,7,7,7,7,7,7,7,7,7,7,7,7,8,7,7,10,9,9,9,11,4,4,4,4,4,4,4,4,4,4,4,256,256,256,256,256,256,256,256,256,256,256,256,268,256,256,256,256,280,292,304,316,328,340,352,256,268,268,268,256,256,256,256,256,256,256,256,256,256,256,280,256,256,256,256,256,256,256,256,256,280,280,280,256,256,256,256,256,256,256,256,256,280,280,256,256,256,256,256,256,256,256,256,256,304,304,304,256,256,256,256,256,256,256,256,256,256,304,304,256,256,256,256,256,256,256,256,256,304,256,256,256,256,256,256,256,256,256,256];var mask=[127,63,63,63,0,31,15,15,15,7,7,7];function decodeURIComponent(url,start,end){let percentPosition=url.indexOf("%",start);if(percentPosition===-1)return url.substring(start,end);let decoded="";let last=0;let codepoint=0;let startOfOctets=percentPosition;let state=268;while(percentPosition<end){const byte=highHex(url.charCodeAt(percentPosition+1))|lowHex(url.charCodeAt(percentPosition+2));const type=data[byte];codepoint=codepoint<<6|byte&mask[type];state=data[state+type];if(state===256)return url.substring(start,end);if(state===268){decoded+=url.substring(last,startOfOctets);decoded+=codepoint>65535?String.fromCharCode(55232+(codepoint>>10),56320+(codepoint&1023)):String.fromCharCode(codepoint);last=percentPosition+3;percentPosition=url.indexOf("%",last);if(percentPosition===-1)return decoded+url.substring(last);startOfOctets=percentPosition;codepoint=0}else{percentPosition+=3;if(percentPosition>=length||url.charCodeAt(percentPosition)!==37)return url.substring(start,end)}}return decoded+url.substring(last)}var defaultOptions4={type:"string"};var query={decodeValue:true,get(name,{type,maxItems}=defaultOptions4){if(type==="bool"){const search2=JSON.stringify(encodeURIComponent(name));const searchLen2=search2.length-2;return Function(`return ({pathEnd,req:{url}})=>{const i=url.indexOf(${search2},pathEnd+1);return i!==-1&&(i===pathEnd+1||url.charCodeAt(i-1)===38)&&(i+${searchLen2}===url.length||url.charCodeAt(i+${searchLen2})===38);}`)()}const search=JSON.stringify(encodeURIComponent(name)+"=");const searchLen=search.length-2;if(type==="string"){const{decodeValue}=this;return typeof maxItems==="undefined"||maxItems<2?Function("d",`return ({pathEnd,req:{url}})=>{const i=url.indexOf(${search},pathEnd+1)+${searchLen};if(i===${searchLen-1})return null;const n=url.indexOf("&",i);return ${decodeValue?"d(url,i,n===-1?url.length:n)":"n===-1?url.substring(i):url.substring(i,n)"};}`)(this.decode):Function("d",`return ({pathEnd,req:{url}})=>{let i=url.indexOf(${search},pathEnd+1)+${searchLen};if(i===${searchLen-1})return [];const r=[];${decodeValue?"const {length}=url;":""}let l=0;do{const n=url.indexOf("&",i);if(n===-1){r.push(${decodeValue?"d(url,i,length)":"url.substring(i)"});return r;}r.push(${decodeValue?"d(url,i,n)":"url.substring(i,n)"});if(l===${maxItems-1})return r;i=url.indexOf(${search},n+1)+${searchLen};++l;}while(i!==${searchLen-1});return r;}`)(this.decode)}return typeof maxItems==="undefined"||maxItems<2?Function(`return ({pathEnd,req:{url}})=>{const i=url.indexOf(${search},pathEnd+1)+${searchLen};if(i===${searchLen-1})return Number.NaN;const n=url.indexOf("&",i);return n===-1?+url.substring(i):+url.substring(i,n);}`)():Function(`return ({pathEnd,req:{url}})=>{let i=url.indexOf(${search},pathEnd+1)+${searchLen};if(i===${searchLen-1})return [];const r=[];let l=0;do{const n=url.indexOf("&",i);if(n===-1){const v=+url.substring(i);if(!Number.isNaN(v))r.push(v);return r;}const v=+url.substring(i,n);if(!Number.isNaN(v)){r.push(v);if(l===${maxItems-1})return r;++l}i=url.indexOf(${search},n+1)+${searchLen};}while(i!==${searchLen-1});return r;}`)()},schema(schema){const{decodeValue}=this;const idxChecks=["++pathEnd;const {length}=url;"],valueChecks=[],idxs=[],objParts=[];let idx=0;for(const key in schema){const{type,maxItems}=schema[key];if(type==="bool"){const search=JSON.stringify(encodeURIComponent(key));const searchLen=search.length-2;idxs.push(`const i${idx}=url.indexOf(${search},pathEnd);`);objParts.push(`${key}:i${idx}!==-1&&(i${idx}===pathEnd||url.charCodeAt(i${idx}-1)===38)&&(i${idx}+${searchLen}===length||url.charCodeAt(i${idx}+${searchLen})===38)`)}else{const search=JSON.stringify(encodeURIComponent(key)+"=");const searchLen=search.length-2;if(type==="string"){if(typeof maxItems==="undefined"||maxItems<2){idxChecks.push(`const s${idx}=url.indexOf(${search},pathEnd)+${searchLen};if(s${idx}===${searchLen-1})return null;`);idxs.push(`const i${idx}=url.indexOf("&",s${idx});`);objParts.push(`${key}:${decodeValue?`d(url,s${idx},i${idx}===-1?length:i${idx})`:`i${idx}===-1?url.substring(s${idx}):url.substring(s${idx},i${idx})`}`)}else{idxs.push(`const ${key}=[];let l${idx}=0;let i${idx}=url.indexOf(${search},pathEnd)+${searchLen};while(i${idx}!==${searchLen-1}){const n=url.indexOf("&",i${idx});if(n===-1){${key}.push(${decodeValue?`d(url,i${idx},length)`:`url.substring(i${idx})`});break;}${key}.push(${decodeValue?`d(url,i${idx},n)`:`url.substring(i${idx},n)`});if(l${idx}===${maxItems-1})break;i${idx}=url.indexOf(${search},n+1)+${searchLen};++l${idx};}`);objParts.push(key)}}else{if(typeof maxItems==="undefined"||maxItems<2){idxChecks.push(`const s${idx}=url.indexOf(${search},pathEnd)+${searchLen};if(s${idx}===${searchLen-1})return null;`);valueChecks.push(`const i${idx}=url.indexOf("&",s${idx});const ${key}=i${idx}===-1?+url.substring(s${idx}):+url.substring(s${idx},i${idx});if(Number.isNaN(${key}))return null;`);objParts.push(key)}else{idxs.push(`const ${key}=[];let l${idx}=0;let i${idx}=url.indexOf(${search},pathEnd)+${searchLen};while(i${idx}!==${searchLen-1}){const n=url.indexOf("&",i${idx});if(n===-1){const v=+url.substring(i${idx});if(!Number.isNaN(v))${key}.push(v);break;}const v=+url.substring(i${idx},n);if(!Number.isNaN(v)){${key}.push(v);if(l${idx}===${maxItems-1})break;}i${idx}=url.indexOf(${search},n+1)+${searchLen};++l${idx};}`);objParts.push(key)}}}++idx}return Function("d",`return ({pathEnd,req:{url}})=>{${idxChecks.join("")}${valueChecks.join("")}${idxs.join("")}return {${objParts.join()}};}`)(this.decode)},decode:decodeURIComponent};export{stringifyQuery,serialize,send,query,passChecks,isAsync,getInjectFn,csrf,cors,bit,Route,Plugin,Context,Byte,BitClient,AsyncFunction,$pass,$async};
{
"name": "@bit-js/byte",
"version": "1.3.12",
"version": "1.4.0",
"module": "index.js",

@@ -5,0 +5,0 @@ "devDependencies": {

@@ -1,2 +0,2 @@

import type { BaseByte, InferByteRecord } from '../server';
import type { BaseByte } from '../server';
import type { UnionToIntersection } from '../utils/types';

@@ -8,3 +8,3 @@ import type { InferRoutes } from './types/route';

*/
export type InferClient<T extends BaseByte> = UnionToIntersection<InferRoutes<InferByteRecord<T>>>;
export type InferClient<T extends BaseByte> = UnionToIntersection<InferRoutes<T['routes']>>;
/**

@@ -11,0 +11,0 @@ * Customize client

import { BaseRouter } from '@bit-js/blitz';
import type { ProtoSchema, RequestMethod } from '../utils/methods';
import { Route, type BaseRoute, type RoutesRecord } from './route';
import { Route, type RoutesRecord } from './route';
import type { InferValidatorRecord, ValidatorRecord } from './types/validator';
import { type BaseHandler, type DeferFn, type Fn } from './types/handler';
interface Register<Method extends string, T extends RoutesRecord> {
<const Path extends string, const Validator extends ValidatorRecord<Path>, const Handler extends BaseHandler<Path, InferValidatorRecord<Validator>>>(path: Path, validator: Validator, handler: Handler): Byte<[...T, Route<Method, Path, Validator, Handler>]>;
<const Path extends string, const Handler extends BaseHandler<Path>>(path: Path, handlers: Handler): Byte<[...T, Route<Method, Path, null, Handler>]>;
import type { AwaitedReturn } from '../utils/types';
interface Register<Method extends string, T extends RoutesRecord, State> {
<const Path extends string, const Validator extends ValidatorRecord<Path>, const Handler extends BaseHandler<Path, State, InferValidatorRecord<Validator>>>(path: Path, validator: Validator, handler: Handler): Byte<[...T, Route<Method, Path, Validator, Handler>]>;
<const Path extends string, const Handler extends BaseHandler<Path, State>>(path: Path, handlers: Handler): Byte<[...T, Route<Method, Path, null, Handler>]>;
}
type HandlerRegisters<T extends RoutesRecord> = {
[Method in RequestMethod | 'any']: Register<Method, T>;
type HandlerRegisters<T extends RoutesRecord, State> = {
[Method in RequestMethod | 'any']: Register<Method, T, State>;
};

@@ -22,14 +23,20 @@ /**

*/
export declare class Byte<Rec extends RoutesRecord = []> implements ProtoSchema {
export declare class Byte<Rec extends RoutesRecord = [], State = {}> implements ProtoSchema {
#private;
readonly actions: Fn[];
readonly defers: DeferFn[];
readonly actions: Fn<State>[];
readonly defers: DeferFn<State>[];
/**
* Run before validation
*/
use(...fns: Fn[]): this;
use(...fns: Fn<State>[]): this;
/**
* Bind a prop to the context
*/
set<Name extends string, Getter extends Fn<State>>(name: Name, fn: Getter): Byte<Rec, State & {
[K in Name]: AwaitedReturn<Getter>;
}>;
/**
* Run after response handler
*/
defer(...fns: DeferFn[]): this;
defer(...fns: DeferFn<State>[]): this;
/**

@@ -42,3 +49,3 @@ * Register plugins

*/
readonly routes: BaseRoute[];
readonly routes: Rec;
/**

@@ -85,6 +92,5 @@ * Register sub-routes

}
export interface Byte<Rec> extends HandlerRegisters<Rec> {
export interface Byte<Rec, State> extends HandlerRegisters<Rec, State> {
}
export type BaseByte = Byte<RoutesRecord>;
export type InferByteRecord<T extends BaseByte> = T extends Byte<infer R> ? R : [];
export type BaseByte = Byte<RoutesRecord, any>;
export * from './route';

@@ -91,0 +97,0 @@ export * from './types/handler';

@@ -7,3 +7,3 @@ import type { BaseRouter } from '@bit-js/blitz';

*/
export declare class Route<Method extends string, Path extends string, Validator extends ValidatorRecord<Path>, Handler extends Fn> {
export declare class Route<Method extends string, Path extends string, Validator extends ValidatorRecord<Path>, Handler extends Fn<any>> {
readonly method: Method;

@@ -10,0 +10,0 @@ readonly path: Path;

@@ -35,6 +35,6 @@ import type { Params } from '@bit-js/blitz';

export type BaseContext = Context<any, any>;
export type BaseHandler<Path extends string, State = undefined> = (c: Context<Params<Path>, State>) => any;
export type Fn<R = any> = (c: BaseContext) => R;
export type DeferFn = (c: BaseContext & {
export type BaseHandler<Path extends string, Set, State = undefined> = (c: Context<Params<Path>, State> & Set) => any;
export type Fn<T = any> = (c: BaseContext & T) => any;
export type DeferFn<T = any> = (c: BaseContext & T & {
res: any;
}) => any;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc