tachyon-rs 0.2.8

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/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # tachyon-rs
2
+
3
+ To install dependencies:
4
+
5
+ ```bash
6
+ bun install
7
+ ```
8
+
9
+ To run:
10
+
11
+ ```bash
12
+ bun run index.ts
13
+ ```
14
+
15
+ This project was created using `bun init` in bun v1.3.10. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
@@ -0,0 +1,5 @@
1
+ export { Tachyon } from "./tachyon";
2
+ export { TachyonRequest } from "./request";
3
+ export { TachyonResponse } from "./response";
4
+ export type { SecurityPreset, TachyonConfig, OnRequestHook, OnResponseHook } from "./tachyon";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{TachyonRawServer as _}from"@tachyon-rs/server";class b{method;path;body;_headers;constructor(t){this.method=t.method,this.path=t.path,this.body=t.body,this._headers=new Map(t.headers.map((i)=>[i.name.toLowerCase(),i.value]))}header(t){return this._headers.get(t.toLowerCase())}get headers(){return this._headers}}class d{status;body;headers=[];constructor(t,i){this.status=t;this.body=i}header(t,i){return this.headers.push({name:t,value:i}),this}json(){return{status:this.status,body:this.body,headers:this.headers.length>0?this.headers:void 0}}}class x{routes;plugins=[];config;constructor(t){this.routes=new Map,this.config=t??{}}use(t){return this.plugins.push(t),this}transformToResponse(t){if(typeof t==="string")return()=>new d(200,t);else if(typeof t==="function")return t;else return()=>new d(200,JSON.stringify(t))}get(t,i){return this.routes.set("GET@"+t,this.transformToResponse(i)),this}post(t,i){return this.routes.set("POST@"+t,this.transformToResponse(i)),this}put(t,i){return this.routes.set("PUT@"+t,this.transformToResponse(i)),this}delete(t,i){return this.routes.set("DELETE@"+t,this.transformToResponse(i)),this}listen(t){new _({bindAddr:"0.0.0.0:"+t,workers:this.config.workers??4,security:this.config.security??"basic",compressionThreshold:this.config.compressionThreshold}).start((f)=>{let m=new b(f);for(let a of this.plugins){let h=a.pre?.(m);if(h)return h.json()}let g=this.routes.get(m.method+"@"+m.path),y=g?g(m):new d(404,"Not Found");for(let a of this.plugins){let h=a.pos?.(m,y);if(h)y=h}return y.json()})}}export{d as TachyonResponse,b as TachyonRequest,x as Tachyon};
@@ -0,0 +1,12 @@
1
+ import type { TachyonRawRequest } from "@tachyon-rs/server";
2
+ declare class TachyonRequest {
3
+ method: string;
4
+ path: string;
5
+ body: string | undefined;
6
+ private _headers;
7
+ constructor(raw: TachyonRawRequest);
8
+ header(name: string): string | undefined;
9
+ get headers(): ReadonlyMap<string, string>;
10
+ }
11
+ export { TachyonRequest };
12
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,cAAM,cAAc;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;IACxB,OAAO,CAAC,QAAQ,CAAqB;gBAEzB,GAAG,EAAE,iBAAiB;IASlC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIxC,IAAI,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAEzC;CACF;AAED,OAAO,EAAE,cAAc,EAAE,CAAA"}
@@ -0,0 +1,17 @@
1
+ declare class TachyonResponse {
2
+ status: number;
3
+ body: string;
4
+ private headers;
5
+ constructor(status: number, body: string);
6
+ header(name: string, value: string): this;
7
+ json(): {
8
+ status: number;
9
+ body: string;
10
+ headers: {
11
+ name: string;
12
+ value: string;
13
+ }[] | undefined;
14
+ };
15
+ }
16
+ export { TachyonResponse };
17
+ //# sourceMappingURL=response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AAAA,cAAM,eAAe;IAGA,MAAM,EAAE,MAAM;IAAS,IAAI,EAAE,MAAM;IAFtD,OAAO,CAAC,OAAO,CAAwC;gBAEpC,MAAM,EAAE,MAAM,EAAS,IAAI,EAAE,MAAM;IAEtD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAKlC,IAAI;;;;kBATqB,MAAM;mBAAS,MAAM;;;CAgB/C;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
@@ -0,0 +1,40 @@
1
+ import { TachyonRequest } from "./request";
2
+ import { TachyonResponse } from "./response";
3
+ export type SecurityPreset = 'none' | 'basic' | 'strict';
4
+ export interface TachyonConfig {
5
+ workers?: number;
6
+ security?: SecurityPreset;
7
+ /** Minimum body size in bytes to trigger gzip compression. 0 = compress all, -1 = disabled. Default: 1024 */
8
+ compressionThreshold?: number;
9
+ }
10
+ /**
11
+ * Pre-request hook. Runs before the route handler.
12
+ * - Return a `TachyonResponse` to short-circuit (e.g., 401 Unauthorized).
13
+ * - Return `void` to let the request continue to the next hook / route handler.
14
+ */
15
+ export type OnRequestHook = (req: TachyonRequest) => TachyonResponse | void;
16
+ /**
17
+ * Post-response hook. Runs after the route handler has produced a response.
18
+ * - Return a new `TachyonResponse` to replace the original.
19
+ * - Return `void` to keep the original response unchanged (useful for logging).
20
+ */
21
+ export type OnResponseHook = (req: TachyonRequest, res: TachyonResponse) => TachyonResponse | void;
22
+ export type Plugin = {
23
+ pre?: OnRequestHook;
24
+ pos?: OnResponseHook;
25
+ };
26
+ declare class Tachyon {
27
+ private routes;
28
+ private plugins;
29
+ private config;
30
+ constructor(config?: TachyonConfig);
31
+ use(plugin: Plugin): this;
32
+ private transformToResponse;
33
+ get(path: string, response: ((req: TachyonRequest) => TachyonResponse) | string | Record<string, string>): this;
34
+ post(path: string, response: ((req: TachyonRequest) => TachyonResponse) | string | Record<string, string>): this;
35
+ put(path: string, response: ((req: TachyonRequest) => TachyonResponse) | string | Record<string, string>): this;
36
+ delete(path: string, response: ((req: TachyonRequest) => TachyonResponse) | string | Record<string, string>): this;
37
+ listen(port: number): void;
38
+ }
39
+ export { Tachyon };
40
+ //# sourceMappingURL=tachyon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tachyon.d.ts","sourceRoot":"","sources":["../src/tachyon.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAA;AAExD,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB,6GAA6G;IAC7G,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,cAAc,KAAK,eAAe,GAAG,IAAI,CAAA;AAE3E;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,EAAE,eAAe,KAAK,eAAe,GAAG,IAAI,CAAA;AAElG,MAAM,MAAM,MAAM,GAAG;IACnB,GAAG,CAAC,EAAE,aAAa,CAAC;IACpB,GAAG,CAAC,EAAE,cAAc,CAAC;CACtB,CAAA;AAED,cAAM,OAAO;IAEX,OAAO,CAAC,MAAM,CAAwD;IACtE,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,CAAC,EAAE,aAAa;IAK3B,GAAG,CAAC,MAAM,EAAE,MAAM;IAKzB,OAAO,CAAC,mBAAmB;IAWpB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,cAAc,KAAK,eAAe,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAKxG,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,cAAc,KAAK,eAAe,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAKzG,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,cAAc,KAAK,eAAe,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAKxG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,cAAc,KAAK,eAAe,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAK3G,MAAM,CAAC,IAAI,EAAE,MAAM;CAiC3B;AAED,OAAO,EAAE,OAAO,EAAE,CAAA"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "tachyon-rs",
3
+ "main": "dist/index.js",
4
+ "module": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "type": "module",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "scripts": {
17
+ "build": "bun build src/index.ts --outdir dist --format esm --minify --external @tachyon-rs/server && tsc"
18
+ },
19
+ "dependencies": {
20
+ "@tachyon-rs/server": "0.2.8"
21
+ },
22
+ "devDependencies": {
23
+ "@types/bun": "latest",
24
+ "typescript": "^5"
25
+ },
26
+ "version": "0.2.8"
27
+ }