@titanpl/route 2.0.1 → 2.0.2

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.
Files changed (4) hide show
  1. package/README.md +24 -24
  2. package/index.d.ts +16 -16
  3. package/index.js +52 -52
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -1,24 +1,24 @@
1
- # @titanpl/route
2
-
3
- The declarative Routing DSL for Titan Planet.
4
-
5
- ## What it works (What it does)
6
- This is a zero-runtime-overhead DSL used to define your backend API routes. It captures routing metadata that the Titan engine uses to static-map requests directly to your actions.
7
-
8
- ## How it works
9
- Import `t` and use it to define your endpoints.
10
-
11
- ```javascript
12
- import t from "@titanpl/route";
13
-
14
- // Define an action-based route
15
- t.post("/hello").action("hello"); // pass a json payload { "name": "titan" }
16
-
17
- // Define a direct reply route
18
- t.get("/").reply("Ready to land on Titan Planet 🚀");
19
-
20
- // Configure the server
21
- t.start(5100, "Titan Running!");
22
- ```
23
-
24
- **Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux version is in development (dev only) for the new architecture and will be launched later.
1
+ # @titanpl/route
2
+
3
+ The declarative Routing DSL for Titan Planet.
4
+
5
+ ## What it works (What it does)
6
+ This is a zero-runtime-overhead DSL used to define your backend API routes. It captures routing metadata that the Titan engine uses to static-map requests directly to your actions.
7
+
8
+ ## How it works
9
+ Import `t` and use it to define your endpoints.
10
+
11
+ ```javascript
12
+ import t from "@titanpl/route";
13
+
14
+ // Define an action-based route
15
+ t.post("/hello").action("hello"); // pass a json payload { "name": "titan" }
16
+
17
+ // Define a direct reply route
18
+ t.get("/").reply("Ready to land on Titan Planet 🚀");
19
+
20
+ // Configure the server
21
+ t.start(5100, "Titan Running!");
22
+ ```
23
+
24
+ **Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux version is in development (dev only) for the new architecture and will be launched later.
package/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- export interface RouteBuilder {
2
- reply(value: any): void;
3
- action(name: string): void;
4
- }
5
-
6
- export interface TitanRoute {
7
- get(route: string): RouteBuilder;
8
- post(route: string): RouteBuilder;
9
- put(route: string): RouteBuilder;
10
- delete(route: string): RouteBuilder;
11
- log(module: string, msg: string): void;
12
- start(port?: number, msg?: string, threads?: number, stack_mb?: number): void;
13
- }
14
-
15
- declare const t: TitanRoute;
16
- export default t;
1
+ export interface RouteBuilder {
2
+ reply(value: any): void;
3
+ action(name: string): void;
4
+ }
5
+
6
+ export interface TitanRoute {
7
+ get(route: string): RouteBuilder;
8
+ post(route: string): RouteBuilder;
9
+ put(route: string): RouteBuilder;
10
+ delete(route: string): RouteBuilder;
11
+ log(module: string, msg: string): void;
12
+ start(port?: number, msg?: string, threads?: number, stack_mb?: number): void;
13
+ }
14
+
15
+ declare const t: TitanRoute;
16
+ export default t;
package/index.js CHANGED
@@ -1,52 +1,52 @@
1
- const routes = {};
2
- const dynamicRoutes = {};
3
- const actionMap = {};
4
-
5
- function addRoute(method, route) {
6
- const key = `${method.toUpperCase()}:${route}`;
7
-
8
- return {
9
- reply(value) {
10
- routes[key] = {
11
- type: typeof value === "object" ? "json" : "text",
12
- value
13
- };
14
- },
15
-
16
- action(name) {
17
- if (route.includes(":")) {
18
- if (!dynamicRoutes[method]) dynamicRoutes[method] = [];
19
- dynamicRoutes[method].push({
20
- method: method.toUpperCase(),
21
- pattern: route,
22
- action: name
23
- });
24
- actionMap[key] = name;
25
- } else {
26
- routes[key] = {
27
- type: "action",
28
- value: name
29
- };
30
- actionMap[key] = name;
31
- }
32
- }
33
- };
34
- }
35
-
36
- const t = {
37
- get(route) { return addRoute("GET", route); },
38
- post(route) { return addRoute("POST", route); },
39
- put(route) { return addRoute("PUT", route); },
40
- delete(route) { return addRoute("DELETE", route); },
41
- log(module, msg) { console.log(`[${module}] ${msg}`); },
42
-
43
- start(port = 3000, msg = "", threads, stack_mb = 8) {
44
- globalThis.__TITAN_CONFIG__ = { port, msg, threads, stack_mb };
45
- }
46
- };
47
-
48
- globalThis.__TITAN_ROUTES_MAP__ = routes;
49
- globalThis.__TITAN_DYNAMIC_ROUTES__ = dynamicRoutes;
50
- globalThis.__TITAN_ACTION_MAP__ = actionMap;
51
-
52
- export default t;
1
+ const routes = {};
2
+ const dynamicRoutes = {};
3
+ const actionMap = {};
4
+
5
+ function addRoute(method, route) {
6
+ const key = `${method.toUpperCase()}:${route}`;
7
+
8
+ return {
9
+ reply(value) {
10
+ routes[key] = {
11
+ type: typeof value === "object" ? "json" : "text",
12
+ value
13
+ };
14
+ },
15
+
16
+ action(name) {
17
+ if (route.includes(":")) {
18
+ if (!dynamicRoutes[method]) dynamicRoutes[method] = [];
19
+ dynamicRoutes[method].push({
20
+ method: method.toUpperCase(),
21
+ pattern: route,
22
+ action: name
23
+ });
24
+ actionMap[key] = name;
25
+ } else {
26
+ routes[key] = {
27
+ type: "action",
28
+ value: name
29
+ };
30
+ actionMap[key] = name;
31
+ }
32
+ }
33
+ };
34
+ }
35
+
36
+ const t = {
37
+ get(route) { return addRoute("GET", route); },
38
+ post(route) { return addRoute("POST", route); },
39
+ put(route) { return addRoute("PUT", route); },
40
+ delete(route) { return addRoute("DELETE", route); },
41
+ log(module, msg) { console.log(`[${module}] ${msg}`); },
42
+
43
+ start(port = 3000, msg = "", threads, stack_mb = 8) {
44
+ globalThis.__TITAN_CONFIG__ = { port, msg, threads, stack_mb };
45
+ }
46
+ };
47
+
48
+ globalThis.__TITAN_ROUTES_MAP__ = routes;
49
+ globalThis.__TITAN_DYNAMIC_ROUTES__ = dynamicRoutes;
50
+ globalThis.__TITAN_ACTION_MAP__ = actionMap;
51
+
52
+ export default t;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/route",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Titan routing DSL",
5
5
  "type": "module",
6
6
  "main": "index.js",