@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
@@ -0,0 +1,39 @@
1
+
2
+ [package]
3
+ name = "titan-server"
4
+ version = "0.1.0"
5
+ edition = "2024"
6
+
7
+ [dependencies]
8
+ axum = "0.8.7"
9
+ dotenv = "0.15.0"
10
+ reqwest = { version = "0.12.24", features = ["json", "rustls-tls", "gzip", "brotli", "blocking"] }
11
+ serde = { version = "1.0.228", features = ["derive"] }
12
+ serde_json = "1.0.145"
13
+ thiserror = "2.0.17"
14
+ tokio = { version = "1.48.0", features = ["rt-multi-thread", "macros", "process"] }
15
+ tower-http = { version = "0.6.7", features = ["cors"] }
16
+ tracing = "0.1.43"
17
+ tracing-subscriber = "0.3.22"
18
+ anyhow = "1"
19
+ v8 = "0.106.0"
20
+ dotenvy = "0.15"
21
+ base64 = "0.21"
22
+ regex = "1.10"
23
+ bcrypt = "0.15"
24
+ jsonwebtoken = "9"
25
+ postgres = { version = "0.19", features = ["with-serde_json-1"] }
26
+ libloading = "0.8"
27
+ walkdir = "2"
28
+
29
+ [profile.dev]
30
+ opt-level = 0
31
+ debug = 1
32
+ incremental = true
33
+
34
+ [profile.release]
35
+ opt-level = 3
36
+ lto = true
37
+ codegen-units = 1
38
+ panic = "abort"
39
+ strip = true
@@ -0,0 +1,131 @@
1
+ use std::collections::HashMap;
2
+ use std::env;
3
+ use std::path::{Path, PathBuf};
4
+ use serde::Deserialize;
5
+ use serde_json::Value;
6
+
7
+ /// Route configuration (loaded from routes.json)
8
+ #[derive(Debug, Deserialize, Clone)]
9
+ pub struct RouteVal {
10
+ pub r#type: String,
11
+ pub value: Value,
12
+ }
13
+
14
+ #[derive(Debug, Deserialize, Clone)]
15
+ pub struct DynamicRoute {
16
+ pub method: String,
17
+ pub pattern: String,
18
+ pub action: String,
19
+ }
20
+
21
+ // -------------------------
22
+ // ACTION DIRECTORY RESOLUTION
23
+ // -------------------------
24
+
25
+ pub fn resolve_actions_dir() -> PathBuf {
26
+ // Respect explicit override first
27
+ if let Ok(override_dir) = env::var("TITAN_ACTIONS_DIR") {
28
+ return PathBuf::from(override_dir);
29
+ }
30
+
31
+ // Production container layout
32
+ if Path::new("/app/actions").exists() {
33
+ return PathBuf::from("/app/actions");
34
+ }
35
+
36
+ // Try to walk up from the executing binary to discover `<...>/server/actions`
37
+ if let Ok(exe) = std::env::current_exe() {
38
+ if let Some(parent) = exe.parent() {
39
+ if let Some(target_dir) = parent.parent() {
40
+ if let Some(server_dir) = target_dir.parent() {
41
+ let candidate = server_dir.join("actions");
42
+ if candidate.exists() {
43
+ return candidate;
44
+ }
45
+ }
46
+ }
47
+ }
48
+ }
49
+
50
+ // Fall back to local ./actions
51
+ PathBuf::from("./actions")
52
+ }
53
+
54
+ /// Try to find the directory that contains compiled action bundles.
55
+ pub fn find_actions_dir(project_root: &PathBuf) -> Option<PathBuf> {
56
+ let candidates = [
57
+ project_root.join("server").join("actions"),
58
+ project_root.join("actions"),
59
+ project_root.join("..").join("server").join("actions"),
60
+ PathBuf::from("/app").join("actions"),
61
+ PathBuf::from("actions"),
62
+ ];
63
+
64
+ for p in &candidates {
65
+ if p.exists() && p.is_dir() {
66
+ return Some(p.clone());
67
+ }
68
+ }
69
+
70
+ None
71
+ }
72
+
73
+ // Dynamic Matcher (Core Logic)
74
+
75
+ pub fn match_dynamic_route(
76
+ method: &str,
77
+ path: &str,
78
+ routes: &[DynamicRoute],
79
+ ) -> Option<(String, HashMap<String, String>)> {
80
+ let path_segments: Vec<&str> =
81
+ path.trim_matches('/').split('/').collect();
82
+
83
+ for route in routes {
84
+ if route.method != method {
85
+ continue;
86
+ }
87
+
88
+ let pattern_segments: Vec<&str> =
89
+ route.pattern.trim_matches('/').split('/').collect();
90
+
91
+ if pattern_segments.len() != path_segments.len() {
92
+ continue;
93
+ }
94
+
95
+ let mut params = HashMap::new();
96
+ let mut matched = true;
97
+
98
+ for (pat, val) in pattern_segments.iter().zip(path_segments.iter()) {
99
+ if pat.starts_with(':') {
100
+ let inner = &pat[1..];
101
+
102
+ let (name, ty) = inner
103
+ .split_once('<')
104
+ .map(|(n, t)| (n, t.trim_end_matches('>')))
105
+ .unwrap_or((inner, "string"));
106
+
107
+ let valid = match ty {
108
+ "number" => val.parse::<i64>().is_ok(),
109
+ "string" => true,
110
+ _ => false,
111
+ };
112
+
113
+ if !valid {
114
+ matched = false;
115
+ break;
116
+ }
117
+
118
+ params.insert(name.to_string(), (*val).to_string());
119
+ } else if pat != val {
120
+ matched = false;
121
+ break;
122
+ }
123
+ }
124
+
125
+ if matched {
126
+ return Some((route.action.clone(), params));
127
+ }
128
+ }
129
+
130
+ None
131
+ }
@@ -0,0 +1,51 @@
1
+ use v8::{HandleScope, TryCatch};
2
+
3
+ pub fn format_v8_error(scope: &mut TryCatch<HandleScope>, action_name: &str) -> String {
4
+ let message = match scope.message() {
5
+ Some(m) => m,
6
+ None => return format!("Unknown error in action '{}'", action_name),
7
+ };
8
+
9
+ // File info
10
+ let resource_name = message
11
+ .get_script_resource_name(scope)
12
+ .map(|s| s.to_rust_string_lossy(scope))
13
+ .unwrap_or_else(|| format!("app/actions/{}.ts", action_name));
14
+
15
+ let line_number = message.get_line_number(scope).unwrap_or(0);
16
+ let start_col = message.get_start_column();
17
+
18
+ // The actual error message
19
+ let exception = scope.exception().unwrap();
20
+ let exception_string = exception.to_rust_string_lossy(scope);
21
+
22
+ // Source line
23
+ let source_line = message
24
+ .get_source_line(scope)
25
+ .map(|s| s.to_rust_string_lossy(scope))
26
+ .unwrap_or_default();
27
+
28
+ let mut out = String::new();
29
+ out.push_str(&format!(
30
+ "[JS] {}:{}:{} - {}\n",
31
+ resource_name, line_number, start_col, exception_string
32
+ ));
33
+
34
+ if !source_line.is_empty() {
35
+ out.push_str(&format!("[JS] {} {}\n", line_number, source_line));
36
+
37
+ let mut pointer = String::from("[JS] ");
38
+ let padding = line_number.to_string().len() + 4;
39
+ for _ in 0..padding {
40
+ pointer.push(' ');
41
+ }
42
+
43
+ for _ in 0..start_col {
44
+ pointer.push(' ');
45
+ }
46
+ pointer.push('^');
47
+ out.push_str(&pointer);
48
+ }
49
+
50
+ out
51
+ }