tachyon-rs 0.2.16 → 0.2.17
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 +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{TachyonRawServer as O}from"@tachyon-rs/server";class f{method;path;body;_headers;constructor(d){this.method=d.method,this.path=d.path,this.body=d.body,this._headers=new Map(d.headers.map((m)=>[m.name.toLowerCase(),m.value]))}header(d){return this._headers.get(d.toLowerCase())}get headers(){return this._headers}}function C(d){if(d===null||d===void 0)return{value:"null",valueType:"null"};switch(typeof d){case"string":return{value:d};case"number":return{value:String(d),valueType:"number"};case"boolean":return{value:String(d),valueType:"bool"};case"object":if(Array.isArray(d))return{valueType:"array",children:d.map((m)=>C(m))};return{valueType:"object",children:Object.entries(d).map(([m,M])=>({key:m,...C(M)}))};default:return{value:String(d)}}}class b{status;body;headers=[];_contentType="json";constructor(d,m){this.status=d;this.body=m}header(d,m){return this.headers.push({name:d,value:m}),this}text(){return this._contentType="text",this}convertToRustJson(){if(typeof this.body!=="object"||this.body===null)return;if(Array.isArray(this.body))return{array:this.body.map((d)=>C(d))};return{json:Object.entries(this.body).map(([d,m])=>({key:d,...C(m)}))}}toRaw(){let d=this.convertToRustJson();return{status:this.status,body:typeof this.body==="string"?this.body:void 0,contentType:this._contentType,headers:this.headers.length>0?this.headers:void 0,json:d?.json,array:d?.array}}}class L{routes;plugins=[];config;constructor(d){this.routes=new Map,this.config=d??{}}use(d){return this.plugins.push(d),this}transformToResponse(d){return typeof d==="function"?d:()=>new b(200,d)}get(d,m){return this.routes.set("GET@"+d,this.transformToResponse(m)),this}post(d,m){return this.routes.set("POST@"+d,this.transformToResponse(m)),this}put(d,m){return this.routes.set("PUT@"+d,this.transformToResponse(m)),this}delete(d,m){return this.routes.set("DELETE@"+d,this.transformToResponse(m)),this}listen(d){new O({bindAddr:"0.0.0.0:"+d,workers:this.config.workers??4,security:this.config.security??"basic",compressionThreshold:this.config.compressionThreshold}).start((M)=>{let x=new f(M);for(let y of this.plugins){let _=y.pre?.(x);if(_)return _.toRaw()}let H=this.routes.get(x.method+"@"+x.path),i=H?H(x):new b(404,"Not Found");for(let y of this.plugins){let _=y.pos?.(x,i);if(_)i=_}return i.toRaw()})}}export{b as TachyonResponse,f as TachyonRequest,L as Tachyon};
|
|
1
|
+
import{TachyonRawServer as O}from"@tachyon-rs/server";class f{method;path;body;_headers;constructor(d){this.method=d.method,this.path=d.path,this.body=d.body,this._headers=new Map(d.headers.map((m)=>[m.name.toLowerCase(),m.value]))}header(d){return this._headers.get(d.toLowerCase())}get headers(){return this._headers}}function C(d){if(d===null||d===void 0)return{value:"null",valueType:"null"};switch(typeof d){case"string":return{value:d};case"number":return{value:String(d),valueType:"number"};case"boolean":return{value:String(d),valueType:"bool"};case"object":if(Array.isArray(d))return{valueType:"array",children:d.map((m)=>C(m))};return{valueType:"object",children:Object.entries(d).map(([m,M])=>({key:m,...C(M)}))};default:return{value:String(d)}}}class b{status;body;headers=[];_contentType="json";constructor(d,m){this.status=d;this.body=m}header(d,m){return this.headers.push({name:d,value:m}),this}text(){return this._contentType="text",this}convertToRustJson(){if(typeof this.body!=="object"||this.body===null)return;if(Array.isArray(this.body))return{array:this.body.map((d)=>C(d))};return{json:Object.entries(this.body).map(([d,m])=>({key:d,...C(m)}))}}toRaw(){let d=this.convertToRustJson();return{status:this.status,body:typeof this.body==="string"?this.body:void 0,contentType:typeof this.body==="string"?"text":this._contentType,headers:this.headers.length>0?this.headers:void 0,json:d?.json,array:d?.array}}}class L{routes;plugins=[];config;constructor(d){this.routes=new Map,this.config=d??{}}use(d){return this.plugins.push(d),this}transformToResponse(d){return typeof d==="function"?d:()=>new b(200,d)}get(d,m){return this.routes.set("GET@"+d,this.transformToResponse(m)),this}post(d,m){return this.routes.set("POST@"+d,this.transformToResponse(m)),this}put(d,m){return this.routes.set("PUT@"+d,this.transformToResponse(m)),this}delete(d,m){return this.routes.set("DELETE@"+d,this.transformToResponse(m)),this}listen(d){new O({bindAddr:"0.0.0.0:"+d,workers:this.config.workers??4,security:this.config.security??"basic",compressionThreshold:this.config.compressionThreshold}).start((M)=>{let x=new f(M);for(let y of this.plugins){let _=y.pre?.(x);if(_)return _.toRaw()}let H=this.routes.get(x.method+"@"+x.path),i=H?H(x):new b(404,"Not Found");for(let y of this.plugins){let _=y.pos?.(x,i);if(_)i=_}return i.toRaw()})}}export{b as TachyonResponse,f as TachyonRequest,L as Tachyon};
|
package/package.json
CHANGED
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"build": "bun build src/index.ts --outdir dist --format esm --minify --external @tachyon-rs/server && tsc"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@tachyon-rs/server": "0.2.
|
|
20
|
+
"@tachyon-rs/server": "0.2.17"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/bun": "latest",
|
|
24
24
|
"typescript": "^5"
|
|
25
25
|
},
|
|
26
|
-
"version": "0.2.
|
|
26
|
+
"version": "0.2.17"
|
|
27
27
|
}
|