@ezetgalaxy/titan 26.8.3 → 26.9.1

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 (106) hide show
  1. package/README.md +76 -17
  2. package/index.js +118 -29
  3. package/package.json +1 -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 +9 -1
  23. package/templates/js/titan/titan.js +122 -122
  24. package/templates/{rust → rust-js}/Dockerfile +66 -66
  25. package/templates/{rust → rust-js}/_dockerignore +3 -3
  26. package/templates/{rust → rust-js}/_gitignore +1 -0
  27. package/templates/{rust → rust-js}/app/actions/hello.js +5 -5
  28. package/templates/{rust → rust-js}/app/actions/rust_hello.rs +14 -14
  29. package/templates/{rust → rust-js}/app/titan.d.ts +101 -101
  30. package/templates/{rust → rust-js}/jsconfig.json +18 -18
  31. package/templates/{rust → rust-js}/package.json +1 -1
  32. package/templates/{rust → rust-js}/server/src/action_management.rs +131 -131
  33. package/templates/{rust → rust-js}/server/src/errors.rs +10 -10
  34. package/templates/{rust → rust-js}/server/src/extensions.rs +989 -989
  35. package/templates/{rust → rust-js}/server/src/utils.rs +33 -33
  36. package/templates/{rust → rust-js}/titan/dev.js +9 -1
  37. package/templates/rust-ts/Dockerfile +66 -0
  38. package/templates/rust-ts/_dockerignore +3 -0
  39. package/templates/rust-ts/_gitignore +38 -0
  40. package/templates/rust-ts/app/actions/hello.ts +11 -0
  41. package/templates/rust-ts/app/actions/rust_hello.rs +14 -0
  42. package/templates/rust-ts/app/app.ts +11 -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 +163 -0
  52. package/templates/rust-ts/titan/dev.js +402 -0
  53. package/templates/rust-ts/titan/titan.d.ts +117 -0
  54. package/templates/rust-ts/titan/titan.js +122 -0
  55. package/templates/rust-ts/tsconfig.json +21 -0
  56. package/templates/ts/Dockerfile +40 -0
  57. package/templates/ts/_dockerignore +3 -0
  58. package/templates/ts/_gitignore +38 -0
  59. package/templates/ts/app/actions/hello.ts +11 -0
  60. package/templates/ts/app/app.ts +10 -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/builder.js +121 -0
  70. package/templates/ts/titan/bundle.js +76 -0
  71. package/templates/ts/titan/dev.js +402 -0
  72. package/templates/ts/titan/runtime.js +1 -0
  73. package/templates/ts/titan/titan.d.ts +117 -0
  74. package/templates/ts/titan/titan.js +122 -0
  75. package/templates/ts/tsconfig.json +16 -0
  76. package/titanpl-sdk/README.md +109 -109
  77. package/titanpl-sdk/bin/run.js +251 -254
  78. package/titanpl-sdk/index.d.ts +46 -46
  79. package/titanpl-sdk/index.js +5 -5
  80. package/titanpl-sdk/package.json +32 -32
  81. package/titanpl-sdk/templates/.dockerignore +3 -3
  82. package/titanpl-sdk/templates/Dockerfile +53 -53
  83. package/titanpl-sdk/templates/app/actions/hello.js +5 -5
  84. package/titanpl-sdk/templates/app/titan.d.ts +87 -87
  85. package/titanpl-sdk/templates/jsconfig.json +18 -18
  86. package/titanpl-sdk/templates/server/src/action_management.rs +131 -131
  87. package/titanpl-sdk/templates/server/src/errors.rs +10 -10
  88. package/titanpl-sdk/templates/server/src/extensions.rs +640 -640
  89. package/titanpl-sdk/templates/server/src/utils.rs +33 -33
  90. package/titanpl-sdk/templates/titan/bundle.js +65 -65
  91. package/titanpl-sdk/templates/titan/dev.js +113 -113
  92. package/titanpl-sdk/templates/titan/titan.js +98 -98
  93. package/templates/js/server/action_map.json +0 -3
  94. package/templates/js/server/actions/hello.jsbundle +0 -48
  95. package/templates/js/server/routes.json +0 -16
  96. package/templates/rust/server/action_map.json +0 -3
  97. package/templates/rust/server/actions/hello.jsbundle +0 -47
  98. package/templates/rust/server/routes.json +0 -22
  99. package/templates/rust/server/src/actions_rust/mod.rs +0 -19
  100. package/templates/rust/server/src/actions_rust/rust_hello.rs +0 -14
  101. /package/templates/{rust → rust-js}/app/app.js +0 -0
  102. /package/templates/{rust → rust-js}/server/Cargo.lock +0 -0
  103. /package/templates/{rust → rust-js}/server/Cargo.toml +0 -0
  104. /package/templates/{rust → rust-js}/server/src/main.rs +0 -0
  105. /package/templates/{rust → rust-js}/titan/bundle.js +0 -0
  106. /package/templates/{rust → rust-js}/titan/titan.js +0 -0
@@ -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
+
@@ -227,7 +227,15 @@ async function startDev() {
227
227
  hasRust = fs.readdirSync(actionsDir).some(f => f.endsWith(".rs"));
228
228
  }
229
229
 
230
- 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
+ }
231
239
  const version = getTitanVersion();
232
240
 
233
241
  console.clear();
@@ -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,11 @@
1
+ interface HelloResponse {
2
+ message: string;
3
+ }
4
+
5
+ import { defineAction } from "../../titan/titan";
6
+
7
+ export const hello = defineAction((req): HelloResponse => {
8
+ return {
9
+ message: `Hello from Titan ${req.body.name || "World"}`,
10
+ };
11
+ });
@@ -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";
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,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
+ }