@ezetgalaxy/titan 26.8.2 → 26.9.0

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 (97) hide show
  1. package/README.md +65 -25
  2. package/index.js +62 -15
  3. package/package.json +2 -2
  4. package/templates/extension/README.md +104 -104
  5. package/templates/extension/index.js +27 -27
  6. package/templates/extension/jsconfig.json +12 -12
  7. package/templates/extension/native/Cargo.toml +9 -9
  8. package/templates/extension/native/src/lib.rs +5 -5
  9. package/templates/extension/package.json +20 -20
  10. package/templates/extension/titan.json +17 -17
  11. package/templates/js/Dockerfile +66 -66
  12. package/templates/js/_dockerignore +3 -3
  13. package/templates/js/_gitignore +1 -0
  14. package/templates/js/app/actions/hello.js +5 -5
  15. package/templates/js/app/titan.d.ts +87 -87
  16. package/templates/js/jsconfig.json +18 -18
  17. package/templates/js/server/src/action_management.rs +131 -131
  18. package/templates/js/server/src/errors.rs +10 -10
  19. package/templates/js/server/src/extensions.rs +989 -989
  20. package/templates/js/server/src/utils.rs +33 -33
  21. package/templates/js/titan/bundle.js +78 -78
  22. package/templates/js/titan/dev.js +35 -3
  23. package/templates/js/titan/titan.js +122 -122
  24. package/templates/rust/Dockerfile +66 -66
  25. package/templates/rust/_dockerignore +3 -3
  26. package/templates/rust/_gitignore +1 -0
  27. package/templates/rust/app/actions/hello.js +5 -5
  28. package/templates/rust/app/actions/rust_hello.rs +14 -14
  29. package/templates/rust/app/titan.d.ts +101 -101
  30. package/templates/rust/jsconfig.json +18 -18
  31. package/templates/rust/server/src/action_management.rs +131 -131
  32. package/templates/rust/server/src/errors.rs +10 -10
  33. package/templates/rust/server/src/extensions.rs +989 -989
  34. package/templates/rust/server/src/utils.rs +33 -33
  35. package/templates/rust/titan/dev.js +36 -12
  36. package/templates/rust-ts/Dockerfile +66 -0
  37. package/templates/rust-ts/_dockerignore +3 -0
  38. package/templates/rust-ts/_gitignore +38 -0
  39. package/templates/rust-ts/app/actions/hello.ts +5 -0
  40. package/templates/rust-ts/app/actions/rust_hello.rs +14 -0
  41. package/templates/rust-ts/app/app.ts +11 -0
  42. package/templates/rust-ts/app/titan.d.ts +101 -0
  43. package/templates/rust-ts/package.json +14 -0
  44. package/templates/rust-ts/server/Cargo.lock +2869 -0
  45. package/templates/rust-ts/server/Cargo.toml +39 -0
  46. package/templates/rust-ts/server/src/action_management.rs +131 -0
  47. package/templates/rust-ts/server/src/errors.rs +51 -0
  48. package/templates/rust-ts/server/src/extensions.rs +989 -0
  49. package/templates/rust-ts/server/src/main.rs +468 -0
  50. package/templates/rust-ts/server/src/utils.rs +33 -0
  51. package/templates/rust-ts/titan/bundle.js +157 -0
  52. package/templates/rust-ts/titan/dev.js +402 -0
  53. package/templates/rust-ts/titan/titan.js +122 -0
  54. package/templates/rust-ts/tsconfig.json +21 -0
  55. package/templates/ts/Dockerfile +66 -0
  56. package/templates/ts/_dockerignore +3 -0
  57. package/templates/ts/_gitignore +38 -0
  58. package/templates/ts/app/actions/hello.ts +9 -0
  59. package/templates/ts/app/app.ts +10 -0
  60. package/templates/ts/app/titan.d.ts +102 -0
  61. package/templates/ts/package.json +26 -0
  62. package/templates/ts/server/Cargo.lock +2869 -0
  63. package/templates/ts/server/Cargo.toml +27 -0
  64. package/templates/ts/server/src/action_management.rs +131 -0
  65. package/templates/ts/server/src/errors.rs +51 -0
  66. package/templates/ts/server/src/extensions.rs +989 -0
  67. package/templates/ts/server/src/main.rs +437 -0
  68. package/templates/ts/server/src/utils.rs +33 -0
  69. package/templates/ts/titan/bundle.js +78 -0
  70. package/templates/ts/titan/dev.js +402 -0
  71. package/templates/ts/titan/titan.js +122 -0
  72. package/templates/ts/tsconfig.json +16 -0
  73. package/titanpl-sdk/README.md +109 -109
  74. package/titanpl-sdk/bin/run.js +254 -254
  75. package/titanpl-sdk/index.d.ts +46 -46
  76. package/titanpl-sdk/index.js +5 -5
  77. package/titanpl-sdk/package.json +32 -32
  78. package/titanpl-sdk/templates/.dockerignore +3 -3
  79. package/titanpl-sdk/templates/Dockerfile +53 -53
  80. package/titanpl-sdk/templates/app/actions/hello.js +5 -5
  81. package/titanpl-sdk/templates/app/titan.d.ts +87 -87
  82. package/titanpl-sdk/templates/jsconfig.json +18 -18
  83. package/titanpl-sdk/templates/server/src/action_management.rs +131 -131
  84. package/titanpl-sdk/templates/server/src/errors.rs +10 -10
  85. package/titanpl-sdk/templates/server/src/extensions.rs +640 -640
  86. package/titanpl-sdk/templates/server/src/utils.rs +33 -33
  87. package/titanpl-sdk/templates/titan/bundle.js +65 -65
  88. package/titanpl-sdk/templates/titan/dev.js +113 -113
  89. package/titanpl-sdk/templates/titan/titan.js +98 -98
  90. package/templates/js/server/action_map.json +0 -3
  91. package/templates/js/server/actions/hello.jsbundle +0 -48
  92. package/templates/js/server/routes.json +0 -16
  93. package/templates/rust/server/action_map.json +0 -3
  94. package/templates/rust/server/actions/hello.jsbundle +0 -47
  95. package/templates/rust/server/routes.json +0 -22
  96. package/templates/rust/server/src/actions_rust/mod.rs +0 -19
  97. package/templates/rust/server/src/actions_rust/rust_hello.rs +0 -14
@@ -1,33 +1,33 @@
1
- pub fn blue(s: &str) -> String {
2
- format!("\x1b[38;5;39m{}\x1b[0m", s)
3
- }
4
- pub fn white(s: &str) -> String {
5
- format!("\x1b[39m{}\x1b[0m", s)
6
- }
7
- pub fn yellow(s: &str) -> String {
8
- format!("\x1b[33m{}\x1b[0m", s)
9
- }
10
- pub fn green(s: &str) -> String {
11
- format!("\x1b[32m{}\x1b[0m", s)
12
- }
13
- pub fn gray(s: &str) -> String {
14
- format!("\x1b[90m{}\x1b[0m", s)
15
- }
16
- pub fn red(s: &str) -> String {
17
- format!("\x1b[31m{}\x1b[0m", s)
18
- }
19
-
20
- pub fn parse_expires_in(value: &str) -> Option<u64> {
21
- let (num, unit) = value.split_at(value.len() - 1);
22
- let n: u64 = num.parse().ok()?;
23
-
24
- match unit {
25
- "s" => Some(n),
26
- "m" => Some(n * 60),
27
- "h" => Some(n * 60 * 60),
28
- "d" => Some(n * 60 * 60 * 24),
29
- _ => None,
30
- }
31
- }
32
-
33
-
1
+ pub fn blue(s: &str) -> String {
2
+ format!("\x1b[38;5;39m{}\x1b[0m", s)
3
+ }
4
+ pub fn white(s: &str) -> String {
5
+ format!("\x1b[39m{}\x1b[0m", s)
6
+ }
7
+ pub fn yellow(s: &str) -> String {
8
+ format!("\x1b[33m{}\x1b[0m", s)
9
+ }
10
+ pub fn green(s: &str) -> String {
11
+ format!("\x1b[32m{}\x1b[0m", s)
12
+ }
13
+ pub fn gray(s: &str) -> String {
14
+ format!("\x1b[90m{}\x1b[0m", s)
15
+ }
16
+ pub fn red(s: &str) -> String {
17
+ format!("\x1b[31m{}\x1b[0m", s)
18
+ }
19
+
20
+ pub fn parse_expires_in(value: &str) -> Option<u64> {
21
+ let (num, unit) = value.split_at(value.len() - 1);
22
+ let n: u64 = num.parse().ok()?;
23
+
24
+ match unit {
25
+ "s" => Some(n),
26
+ "m" => Some(n * 60),
27
+ "h" => Some(n * 60 * 60),
28
+ "d" => Some(n * 60 * 60 * 24),
29
+ _ => None,
30
+ }
31
+ }
32
+
33
+
@@ -3,7 +3,6 @@ import { spawn, execSync } from "child_process";
3
3
  import path from "path";
4
4
  import { fileURLToPath } from "url";
5
5
  import fs from "fs";
6
- import { bundle } from "./bundle.js";
7
6
 
8
7
  // Required for __dirname in ES modules
9
8
  const __filename = fileURLToPath(import.meta.url);
@@ -39,12 +38,20 @@ function getTitanVersion() {
39
38
  cur = path.join(cur, "..");
40
39
  }
41
40
  } catch (e2) { }
41
+
42
+ try {
43
+ // Fallback to calling tit --version
44
+ const output = execSync("tit --version", { encoding: "utf-8" }).trim();
45
+ const match = output.match(/v(\d+\.\d+\.\d+)/);
46
+ if (match) return match[1];
47
+ } catch (e3) { }
42
48
  }
43
49
  return "0.1.0";
44
50
  }
45
51
 
46
52
  let serverProcess = null;
47
53
  let isKilling = false;
54
+ let isFirstBoot = true;
48
55
 
49
56
  // ... (killServer same as before)
50
57
  async function killServer() {
@@ -156,7 +163,24 @@ async function startRustServer(retryCount = 0) {
156
163
  isReady = true;
157
164
  clearTimeout(slowTimer);
158
165
  stopSpinner(true, "Your app is now orbiting Titan Planet");
159
- process.stdout.write(stdoutBuffer);
166
+
167
+ if (isFirstBoot) {
168
+ process.stdout.write(stdoutBuffer);
169
+ isFirstBoot = false;
170
+ } else {
171
+ // On subsequent reloads, only print non-banner lines from the buffer
172
+ const lines = stdoutBuffer.split("\n");
173
+ for (const line of lines) {
174
+ const isBanner = line.includes("Titan server running") ||
175
+ line.includes("████████╗") ||
176
+ line.includes("╚══") ||
177
+ line.includes(" ██║") ||
178
+ line.includes(" ╚═╝");
179
+ if (!isBanner && line.trim()) {
180
+ process.stdout.write(line + "\n");
181
+ }
182
+ }
183
+ }
160
184
  stdoutBuffer = "";
161
185
  }
162
186
  } else {
@@ -188,7 +212,7 @@ async function startRustServer(retryCount = 0) {
188
212
  async function rebuild() {
189
213
  try {
190
214
  execSync("node app/app.js", { stdio: "ignore" });
191
- await bundle();
215
+ // bundle is called inside app.js (t.start)
192
216
  } catch (e) {
193
217
  stopSpinner(false, "Failed to prepare runtime");
194
218
  console.log(red(`[Titan] Error: ${e.message}`));
@@ -203,7 +227,15 @@ async function startDev() {
203
227
  hasRust = fs.readdirSync(actionsDir).some(f => f.endsWith(".rs"));
204
228
  }
205
229
 
206
- const mode = hasRust ? "Rust + JS Actions" : "JS Actions";
230
+ const isTs = fs.existsSync(path.join(root, "tsconfig.json")) ||
231
+ fs.existsSync(path.join(root, "app", "app.ts"));
232
+
233
+ let mode = "";
234
+ if (hasRust) {
235
+ mode = isTs ? "Rust + TS Actions" : "Rust + JS Actions";
236
+ } else {
237
+ mode = isTs ? "TS Actions" : "JS Actions";
238
+ }
207
239
  const version = getTitanVersion();
208
240
 
209
241
  console.clear();
@@ -234,14 +266,6 @@ async function startDev() {
234
266
  watcher.on("all", async (event, file) => {
235
267
  if (timer) clearTimeout(timer);
236
268
  timer = setTimeout(async () => {
237
- // console.log("");
238
- /*
239
- if (file.includes(".env")) {
240
- console.log(yellow("[Titan] Env Refreshed"));
241
- } else {
242
- console.log(cyan(`[Titan] Change: ${path.basename(file)}`));
243
- }
244
- */
245
269
  try {
246
270
  await killServer();
247
271
  await rebuild();
@@ -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,38 @@
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
+ .titan/
12
+ .ext/
13
+ server/routes.json
14
+ server/action_map.json
15
+ server/actions/
16
+ server/titan/
17
+ server/src/actions_rust/
18
+
19
+ # Rust Build Artifacts
20
+ server/target/
21
+ Cargo.lock
22
+
23
+ # OS Files
24
+ .DS_Store
25
+ Thumbs.db
26
+ *.tmp
27
+ *.bak
28
+
29
+ # Environment & Secrets
30
+ .env
31
+ .env.local
32
+ .env.*.local
33
+
34
+ # IDEs
35
+ .vscode/
36
+ .idea/
37
+ *.swp
38
+ *.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,14 @@
1
+ {
2
+ "name": "titanpl",
3
+ "version": "1.0.0",
4
+ "description": "A Titan Planet server (Rust + TypeScript)",
5
+ "type": "module",
6
+ "titan": {
7
+ "template": "rust-ts"
8
+ },
9
+ "dependencies": {
10
+ "chokidar": "^5.0.0",
11
+ "esbuild": "^0.27.2",
12
+ "typescript": "^5.0.0"
13
+ }
14
+ }