@ezetgalaxy/titan 26.7.5 → 26.8.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 (53) hide show
  1. package/README.md +86 -200
  2. package/index.js +87 -23
  3. package/package.json +4 -3
  4. package/templates/js/_gitignore +37 -0
  5. package/templates/{package.json → js/package.json} +3 -0
  6. package/templates/{server → js/server}/actions/hello.jsbundle +4 -1
  7. package/templates/{server → js/server}/src/extensions.rs +149 -17
  8. package/templates/{server → js/server}/src/main.rs +1 -6
  9. package/templates/{titan → js/titan}/bundle.js +22 -9
  10. package/templates/js/titan/dev.js +258 -0
  11. package/templates/js/titan/titan.js +122 -0
  12. package/templates/rust/Dockerfile +66 -0
  13. package/templates/rust/_dockerignore +3 -0
  14. package/templates/rust/_gitignore +37 -0
  15. package/templates/rust/app/actions/hello.js +5 -0
  16. package/templates/rust/app/actions/rust_hello.rs +14 -0
  17. package/templates/rust/app/app.js +11 -0
  18. package/templates/rust/app/titan.d.ts +101 -0
  19. package/templates/rust/jsconfig.json +19 -0
  20. package/templates/rust/package.json +13 -0
  21. package/templates/rust/server/Cargo.lock +2869 -0
  22. package/templates/rust/server/Cargo.toml +39 -0
  23. package/templates/rust/server/action_map.json +3 -0
  24. package/templates/rust/server/actions/hello.jsbundle +47 -0
  25. package/templates/rust/server/routes.json +22 -0
  26. package/templates/rust/server/src/action_management.rs +131 -0
  27. package/templates/rust/server/src/actions_rust/mod.rs +19 -0
  28. package/templates/rust/server/src/actions_rust/rust_hello.rs +14 -0
  29. package/templates/rust/server/src/errors.rs +10 -0
  30. package/templates/rust/server/src/extensions.rs +989 -0
  31. package/templates/rust/server/src/main.rs +437 -0
  32. package/templates/rust/server/src/utils.rs +33 -0
  33. package/templates/rust/titan/bundle.js +157 -0
  34. package/templates/rust/titan/dev.js +266 -0
  35. package/templates/{titan → rust/titan}/titan.js +122 -98
  36. package/titanpl-sdk/templates/Dockerfile +4 -17
  37. package/titanpl-sdk/templates/server/src/extensions.rs +218 -423
  38. package/titanpl-sdk/templates/server/src/main.rs +68 -134
  39. package/templates/_gitignore +0 -25
  40. package/templates/titan/dev.js +0 -144
  41. /package/templates/{Dockerfile → js/Dockerfile} +0 -0
  42. /package/templates/{.dockerignore → js/_dockerignore} +0 -0
  43. /package/templates/{app → js/app}/actions/hello.js +0 -0
  44. /package/templates/{app → js/app}/app.js +0 -0
  45. /package/templates/{app → js/app}/titan.d.ts +0 -0
  46. /package/templates/{jsconfig.json → js/jsconfig.json} +0 -0
  47. /package/templates/{server → js/server}/Cargo.lock +0 -0
  48. /package/templates/{server → js/server}/Cargo.toml +0 -0
  49. /package/templates/{server → js/server}/action_map.json +0 -0
  50. /package/templates/{server → js/server}/routes.json +0 -0
  51. /package/templates/{server → js/server}/src/action_management.rs +0 -0
  52. /package/templates/{server → js/server}/src/errors.rs +0 -0
  53. /package/templates/{server → js/server}/src/utils.rs +0 -0
@@ -0,0 +1,66 @@
1
+ # ================================================================
2
+ # STAGE 1 — Build Titan (JS → Rust)
3
+ # ================================================================
4
+ FROM rust:1.91.1 AS builder
5
+
6
+ # Install Node for Titan CLI + bundler
7
+ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
8
+ && apt-get install -y nodejs
9
+
10
+ # Install Titan CLI (latest)
11
+ RUN npm install -g @ezetgalaxy/titan@latest
12
+
13
+ WORKDIR /app
14
+
15
+ # Copy project files
16
+ COPY . .
17
+
18
+ # Install JS dependencies (needed for Titan DSL + bundler)
19
+ RUN npm install
20
+
21
+ SHELL ["/bin/bash", "-c"]
22
+
23
+ # Extract Titan extensions into .ext
24
+ RUN mkdir -p /app/.ext && \
25
+ find /app/node_modules -maxdepth 5 -type f -name "titan.json" -print0 | \
26
+ while IFS= read -r -d '' file; do \
27
+ pkg_dir="$(dirname "$file")"; \
28
+ pkg_name="$(basename "$pkg_dir")"; \
29
+ echo "Copying Titan extension: $pkg_name from $pkg_dir"; \
30
+ cp -r "$pkg_dir" "/app/.ext/$pkg_name"; \
31
+ done && \
32
+ echo "Extensions in .ext:" && \
33
+ ls -R /app/.ext
34
+
35
+ # Build Titan metadata + bundle JS actions
36
+ RUN titan build
37
+
38
+ # Build Rust binary
39
+ RUN cd server && cargo build --release
40
+
41
+
42
+
43
+ # ================================================================
44
+ # STAGE 2 — Runtime Image (Lightweight)
45
+ # ================================================================
46
+ FROM debian:stable-slim
47
+
48
+ WORKDIR /app
49
+
50
+ # Copy Rust binary from builder stage
51
+ COPY --from=builder /app/server/target/release/titan-server ./titan-server
52
+
53
+ # Copy Titan routing metadata
54
+ COPY --from=builder /app/server/routes.json ./routes.json
55
+ COPY --from=builder /app/server/action_map.json ./action_map.json
56
+
57
+ # Copy Titan JS bundles
58
+ RUN mkdir -p /app/actions
59
+ COPY --from=builder /app/server/actions /app/actions
60
+
61
+ # Copy only Titan extensions
62
+ COPY --from=builder /app/.ext ./.ext
63
+
64
+ EXPOSE 3000
65
+
66
+ CMD ["./titan-server"]
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ npm-debug.log
3
+ .git
@@ -0,0 +1,37 @@
1
+ # Node & Packages
2
+ node_modules/
3
+ npm-debug.log*
4
+ yarn-debug.log*
5
+ yarn-error.log*
6
+ package-lock.json
7
+ yarn.lock
8
+
9
+ # Titan Runtime (Auto-generated - DO NOT COMMIT)
10
+ titan/server-bin*
11
+ .ext/
12
+ server/routes.json
13
+ server/action_map.json
14
+ server/actions/
15
+ server/titan/
16
+ server/src/actions_rust/
17
+
18
+ # Rust Build Artifacts
19
+ server/target/
20
+ Cargo.lock
21
+
22
+ # OS Files
23
+ .DS_Store
24
+ Thumbs.db
25
+ *.tmp
26
+ *.bak
27
+
28
+ # Environment & Secrets
29
+ .env
30
+ .env.local
31
+ .env.*.local
32
+
33
+ # IDEs
34
+ .vscode/
35
+ .idea/
36
+ *.swp
37
+ *.swo
@@ -0,0 +1,5 @@
1
+ export const hello = (req) => {
2
+ return {
3
+ message: `Hello from Titan ${req.body.name}`,
4
+ };
5
+ }
@@ -0,0 +1,14 @@
1
+ use axum::{response::{IntoResponse, Json}, http::Request, body::Body};
2
+ use serde_json::json;
3
+
4
+ pub async fn run(_req: Request<Body>) -> impl IntoResponse {
5
+ // let _token = t.jwt.sign(json!({"id": 1}), "secret", Some(json!({"expiresIn": "1h"}))).unwrap_or_default();
6
+ // let decoded = t.jwt.verify(&_token, "secret").unwrap_or_default();
7
+
8
+ Json(json!({
9
+ "message": "Hello from Rust Action! 🦀",
10
+ "status": "blazing fast test",
11
+ // "token": _token,
12
+ // "decoded": decoded
13
+ }))
14
+ }
@@ -0,0 +1,11 @@
1
+ import t from "../titan/titan.js";
2
+
3
+
4
+
5
+
6
+ t.post("/hello").action("hello") // pass a json payload { "name": "titan" }
7
+ t.get("/rust").action("rust_hello") // This route uses a rust action
8
+
9
+ t.get("/").reply("Ready to land on Titan Planet 🚀");
10
+
11
+ t.start(3000, "Titan Running!");
@@ -0,0 +1,101 @@
1
+ export { };
2
+
3
+ declare global {
4
+ /**
5
+ * TITAN TYPE DEFINITIONS
6
+ * ----------------------
7
+ * These types are globally available in your Titan project.
8
+ */
9
+
10
+ /**
11
+ * The Titan Request Object passed to actions.
12
+ */
13
+ interface TitanRequest {
14
+ body: any;
15
+ method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
16
+ path: string;
17
+ headers: {
18
+ host?: string;
19
+ "content-type"?: string;
20
+ "user-agent"?: string;
21
+ authorization?: string;
22
+ [key: string]: string | undefined;
23
+ };
24
+ params: Record<string, string>;
25
+ query: Record<string, string>;
26
+ }
27
+
28
+ interface DbConnection {
29
+ /**
30
+ * Execute a SQL query.
31
+ * @param sql The SQL query string.
32
+ * @param params (Optional) Parameters for the query ($1, $2, etc).
33
+ */
34
+ query(sql: string, params?: any[]): any[];
35
+ }
36
+
37
+ /**
38
+ * Define a Titan Action with type inference.
39
+ * @example
40
+ * export const hello = defineAction((req) => {
41
+ * return req.headers;
42
+ * });
43
+ */
44
+ function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
45
+
46
+ /**
47
+ * Titan Runtime Utilities
48
+ */
49
+ const t: {
50
+ /**
51
+ * Log messages to the server console with Titan formatting.
52
+ */
53
+ log(...args: any[]): void;
54
+
55
+ /**
56
+ * Read a file contents as string.
57
+ * @param path Relative path to the file from project root.
58
+ */
59
+ read(path: string): string;
60
+
61
+ fetch(url: string, options?: {
62
+ method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
63
+ headers?: Record<string, string>;
64
+ body?: string | object;
65
+ }): {
66
+ ok: boolean;
67
+ status?: number;
68
+ body?: string;
69
+ error?: string;
70
+ };
71
+
72
+ jwt: {
73
+ sign(
74
+ payload: object,
75
+ secret: string,
76
+ options?: { expiresIn?: string | number }
77
+ ): string;
78
+ verify(token: string, secret: string): any;
79
+ };
80
+
81
+ password: {
82
+ hash(password: string): string;
83
+ verify(password: string, hash: string): boolean;
84
+ };
85
+
86
+ db: {
87
+ connect(url: string): DbConnection;
88
+ };
89
+
90
+ /**
91
+ * Titan Validator (Zod-compatible)
92
+ */
93
+ valid: typeof import("@titanpl/valid");
94
+ };
95
+
96
+ /**
97
+ * Global Request Object
98
+ * Available automatically in actions.
99
+ */
100
+ var req: TitanRequest;
101
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "esnext",
4
+ "target": "esnext",
5
+ "checkJs": false,
6
+ "noImplicitAny": false,
7
+ "allowJs": true,
8
+ "moduleResolution": "node",
9
+ "baseUrl": ".",
10
+ "paths": {
11
+ "*": [
12
+ "./app/*"
13
+ ]
14
+ }
15
+ },
16
+ "include": [
17
+ "app/**/*"
18
+ ]
19
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "titanpl",
3
+ "version": "1.0.0",
4
+ "description": "A Titan Planet server",
5
+ "type": "module",
6
+ "titan": {
7
+ "template": "rust"
8
+ },
9
+ "dependencies": {
10
+ "chokidar": "^5.0.0",
11
+ "esbuild": "^0.27.2"
12
+ }
13
+ }