titanpl-superls 1.0.2 → 1.0.3

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.
@@ -0,0 +1,53 @@
1
+ export const test = (req) => {
2
+ const ext = t["titanpl-superls"];
3
+
4
+ const results = {
5
+ extension: "titanpl-superls",
6
+ loaded: !!ext,
7
+ methods: ext ? Object.keys(ext) : [],
8
+ timestamp: new Date().toISOString()
9
+ };
10
+
11
+ if (ext) {
12
+ // Mock t.ls for local env if missing
13
+ if (!t.ls) {
14
+ const mockStore = new Map();
15
+ t.ls = {
16
+ set: (k, v) => mockStore.set(k, v),
17
+ get: (k) => mockStore.get(k),
18
+ remove: (k) => mockStore.delete(k)
19
+ };
20
+ }
21
+
22
+ try {
23
+ results.debug_ext = {
24
+ keys: Object.keys(ext),
25
+ hasDefault: 'default' in ext,
26
+ type: typeof ext
27
+ };
28
+ const superLs = ext.default || ext;
29
+ if (typeof superLs.set !== 'function') {
30
+ results.debug_superLs = {
31
+ type: typeof superLs,
32
+ keys: Object.keys(superLs),
33
+ isExt: superLs === ext
34
+ };
35
+ }
36
+ const settings = new Map([
37
+ ["theme", "dark"],
38
+ ["language", "en"]
39
+ ]);
40
+
41
+ superLs.set("user_settings", settings);
42
+
43
+ const recovered = superLs.get("user_settings");
44
+ t.log(recovered instanceof Map); // true
45
+ t.log(recovered.get("theme")); // "dark"
46
+ } catch (e) {
47
+ results.hello_error = String(e);
48
+ }
49
+ }
50
+
51
+
52
+ return results;
53
+ };
@@ -0,0 +1,29 @@
1
+ import t from "../titan/titan.js";
2
+ import "titanpl-superls";
3
+
4
+ // Extension test harness for: titanpl-superls
5
+ const ext = t["titanpl-superls"];
6
+
7
+ console.log("---------------------------------------------------");
8
+ console.log("Testing Extension: titanpl-superls");
9
+ console.log("---------------------------------------------------");
10
+
11
+ if (!ext) {
12
+ console.log("ERROR: Extension 'titanpl-superls' not found in global 't'.");
13
+ } else {
14
+ console.log("✓ Extension loaded successfully!");
15
+ console.log("✓ Available methods:", Object.keys(ext).join(", "));
16
+ }
17
+
18
+ console.log("---------------------------------------------------");
19
+ console.log("✓ Test complete!");
20
+ console.log("\n📍 Routes:");
21
+ console.log(" GET http://localhost:3000/ → Test harness info");
22
+ console.log(" GET http://localhost:3000/test → Extension test results (JSON)");
23
+ console.log("---------------------------------------------------\n");
24
+
25
+ // Create routes
26
+ t.get("/test").action("test");
27
+ t.get("/").reply("🚀 Extension Test Harness for titanpl-superls\n\nVisit /test to see extension test results");
28
+
29
+ await t.start(3000, "Titan Extension Test Running!");
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,27 @@
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"
@@ -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,10 @@
1
+ use v8::JsError;
2
+
3
+ // A helper to Format v8 Errors
4
+ pub fn format_js_error(err: JsError, action: &str) -> String {
5
+ format!(
6
+ "Action: {}\n{}",
7
+ action,
8
+ err.to_string()
9
+ )
10
+ }