titanpl 4.0.2 → 7.0.0-beta
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.
- package/package.json +11 -5
- package/packages/cli/index.js +25 -11
- package/packages/cli/package.json +5 -5
- package/packages/cli/src/commands/build-ext.js +157 -0
- package/packages/cli/src/commands/build.js +12 -0
- package/packages/cli/src/commands/create.js +160 -0
- package/packages/cli/src/commands/init.js +5 -11
- package/packages/cli/src/commands/run-ext.js +104 -0
- package/packages/engine-darwin-arm64/README.md +0 -2
- package/packages/engine-darwin-arm64/package.json +1 -1
- package/packages/engine-linux-x64/README.md +0 -2
- package/packages/engine-linux-x64/package.json +1 -1
- package/packages/engine-win32-x64/README.md +0 -1
- package/packages/engine-win32-x64/bin/titan-server.exe +0 -0
- package/packages/engine-win32-x64/package.json +1 -1
- package/packages/native/README.md +0 -1
- package/packages/native/index.d.ts +10 -0
- package/packages/native/index.js +4 -0
- package/packages/native/package.json +1 -1
- package/packages/native/t.native.d.ts +175 -44
- package/packages/packet/README.md +0 -1
- package/packages/packet/index.js +19 -2
- package/packages/packet/package.json +1 -1
- package/packages/route/README.md +21 -0
- package/packages/route/index.d.ts +1 -0
- package/packages/route/index.js +22 -0
- package/packages/route/package.json +1 -1
- package/packages/sdk/index.js +2 -0
- package/packages/sdk/package.json +18 -0
- package/packages/sdk/test/index.js +120 -0
- package/templates/common/Dockerfile +9 -45
- package/templates/common/_tanfig.json +17 -13
- package/templates/extension/index.d.ts +26 -22
- package/templates/extension/index.js +15 -15
- package/templates/extension/native/Cargo.toml +5 -3
- package/templates/extension/native/src/lib.rs +2 -3
- package/templates/extension/package.json +10 -20
- package/templates/extension/titan.json +5 -16
- package/templates/extension/utils/registerExtension.js +44 -0
- package/templates/js/package.json +8 -8
- package/templates/rust-js/package.json +4 -4
- package/templates/rust-ts/package.json +4 -4
- package/templates/ts/package.json +8 -8
- package/templates/common/app/t.native.d.ts +0 -2043
- package/templates/common/app/t.native.js +0 -39
- package/titanpl-sdk/LICENSE +0 -15
- package/titanpl-sdk/README.md +0 -111
- package/titanpl-sdk/assets/titanpl-sdk.png +0 -0
- package/titanpl-sdk/bin/run.js +0 -274
- package/titanpl-sdk/index.js +0 -5
- package/titanpl-sdk/package-lock.json +0 -28
- package/titanpl-sdk/package.json +0 -40
- package/titanpl-sdk/templates/app/actions/hello.js +0 -5
- package/titanpl-sdk/templates/app/app.js +0 -7
- package/titanpl-sdk/templates/jsconfig.json +0 -19
- package/titanpl-sdk/templates/server/Cargo.toml +0 -52
- package/titanpl-sdk/templates/server/src/action_management.rs +0 -175
- package/titanpl-sdk/templates/server/src/errors.rs +0 -12
- package/titanpl-sdk/templates/server/src/extensions/builtin.rs +0 -1055
- package/titanpl-sdk/templates/server/src/extensions/external.rs +0 -338
- package/titanpl-sdk/templates/server/src/extensions/mod.rs +0 -580
- package/titanpl-sdk/templates/server/src/extensions/titan_core.js +0 -249
- package/titanpl-sdk/templates/server/src/fast_path.rs +0 -719
- package/titanpl-sdk/templates/server/src/main.rs +0 -607
- package/titanpl-sdk/templates/server/src/runtime.rs +0 -284
- package/titanpl-sdk/templates/server/src/utils.rs +0 -33
- package/titanpl-sdk/templates/titan/bundle.js +0 -259
- package/titanpl-sdk/templates/titan/dev.js +0 -390
- package/titanpl-sdk/templates/titan/error-box.js +0 -277
- package/titanpl-sdk/templates/titan/titan.js +0 -129
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
//! Action Management and Dynamic Routing
|
|
2
|
-
//!
|
|
3
|
-
//! Handles resolution of action directories, scanning for available actions,
|
|
4
|
-
//! and matching dynamic routes (e.g. `/users/:id`).
|
|
5
|
-
|
|
6
|
-
use std::collections::HashMap;
|
|
7
|
-
use std::env;
|
|
8
|
-
use std::path::{Path, PathBuf};
|
|
9
|
-
use serde::Deserialize;
|
|
10
|
-
use serde_json::Value;
|
|
11
|
-
|
|
12
|
-
/// Route configuration (loaded from routes.json)
|
|
13
|
-
#[derive(Debug, Deserialize, Clone)]
|
|
14
|
-
pub struct RouteVal {
|
|
15
|
-
pub r#type: String,
|
|
16
|
-
#[serde(alias = "target")]
|
|
17
|
-
pub value: Value,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
#[derive(Debug, Deserialize, Clone)]
|
|
21
|
-
pub struct DynamicRoute {
|
|
22
|
-
pub method: String,
|
|
23
|
-
pub pattern: String,
|
|
24
|
-
pub action: String,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/// Resolve the directory path where actions are stored.
|
|
28
|
-
pub fn resolve_actions_dir() -> PathBuf {
|
|
29
|
-
// Respect explicit override first
|
|
30
|
-
if let Ok(override_dir) = env::var("TITAN_ACTIONS_DIR") {
|
|
31
|
-
return PathBuf::from(override_dir);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Production container layout
|
|
35
|
-
if Path::new("/app/actions").exists() {
|
|
36
|
-
return PathBuf::from("/app/actions");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Try to walk up from the executing binary to discover `<...>/server/src/actions`
|
|
40
|
-
if let Ok(exe) = std::env::current_exe() {
|
|
41
|
-
if let Some(parent) = exe.parent() {
|
|
42
|
-
if let Some(target_dir) = parent.parent() {
|
|
43
|
-
if let Some(server_dir) = target_dir.parent() {
|
|
44
|
-
let candidate = server_dir.join("src").join("actions");
|
|
45
|
-
if candidate.exists() {
|
|
46
|
-
return candidate;
|
|
47
|
-
}
|
|
48
|
-
let candidate2 = server_dir.join("actions");
|
|
49
|
-
if candidate2.exists() {
|
|
50
|
-
return candidate2;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Fall back to local ./src/actions
|
|
58
|
-
PathBuf::from("./src/actions")
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/// Try to find the directory that contains compiled action bundles.
|
|
62
|
-
pub fn find_actions_dir(project_root: &PathBuf) -> Option<PathBuf> {
|
|
63
|
-
let candidates = [
|
|
64
|
-
project_root.join("server").join("src").join("actions"),
|
|
65
|
-
project_root.join("server").join("actions"),
|
|
66
|
-
project_root.join("app").join("actions"),
|
|
67
|
-
project_root.join("actions"),
|
|
68
|
-
|
|
69
|
-
project_root.join("..").join("server").join("actions"),
|
|
70
|
-
PathBuf::from("/app").join("actions"),
|
|
71
|
-
PathBuf::from("actions"),
|
|
72
|
-
];
|
|
73
|
-
|
|
74
|
-
for p in &candidates {
|
|
75
|
-
if p.exists() && p.is_dir() {
|
|
76
|
-
return Some(p.clone());
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
None
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/// Match a dynamic route against the current request path.
|
|
84
|
-
pub fn match_dynamic_route(
|
|
85
|
-
method: &str,
|
|
86
|
-
path: &str,
|
|
87
|
-
routes: &[DynamicRoute],
|
|
88
|
-
) -> Option<(String, HashMap<String, String>)> {
|
|
89
|
-
let path_segments: Vec<&str> =
|
|
90
|
-
path.trim_matches('/').split('/').collect();
|
|
91
|
-
|
|
92
|
-
for route in routes {
|
|
93
|
-
if route.method != method {
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
let pattern_segments: Vec<&str> =
|
|
98
|
-
route.pattern.trim_matches('/').split('/').collect();
|
|
99
|
-
|
|
100
|
-
if pattern_segments.len() != path_segments.len() {
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let mut params = HashMap::new();
|
|
105
|
-
let mut matched = true;
|
|
106
|
-
|
|
107
|
-
for (pat, val) in pattern_segments.iter().zip(path_segments.iter()) {
|
|
108
|
-
if pat.starts_with(':') {
|
|
109
|
-
let inner = &pat[1..];
|
|
110
|
-
|
|
111
|
-
let (name, ty) = inner
|
|
112
|
-
.split_once('<')
|
|
113
|
-
.map(|(n, t)| (n, t.trim_end_matches('>')))
|
|
114
|
-
.unwrap_or((inner, "string"));
|
|
115
|
-
|
|
116
|
-
let valid = match ty {
|
|
117
|
-
"number" => val.parse::<i64>().is_ok(),
|
|
118
|
-
"string" => true,
|
|
119
|
-
_ => false,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
if !valid {
|
|
123
|
-
matched = false;
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
params.insert(name.to_string(), (*val).to_string());
|
|
128
|
-
} else if pat != val {
|
|
129
|
-
matched = false;
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if matched {
|
|
135
|
-
return Some((route.action.clone(), params));
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
None
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/// Scan the resolved actions directory and return a map of action names to file paths.
|
|
143
|
-
pub fn scan_actions(root: &PathBuf) -> HashMap<String, PathBuf> {
|
|
144
|
-
let mut map = HashMap::new();
|
|
145
|
-
|
|
146
|
-
// Locate actions dir - Priority: project root relative paths
|
|
147
|
-
let dir = match find_actions_dir(root) {
|
|
148
|
-
Some(d) => d,
|
|
149
|
-
None => {
|
|
150
|
-
let ad = resolve_actions_dir();
|
|
151
|
-
if ad.exists() { ad } else { return map; }
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
// Scanning actions
|
|
156
|
-
if let Ok(entries) = std::fs::read_dir(dir) {
|
|
157
|
-
for entry in entries.flatten() {
|
|
158
|
-
let path = entry.path();
|
|
159
|
-
if !path.is_file() { continue; }
|
|
160
|
-
|
|
161
|
-
let ext = path.extension().and_then(|s| s.to_str()).unwrap_or("");
|
|
162
|
-
if ext != "js" && ext != "jsbundle" {
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
let file_stem = path.file_stem().and_then(|s| s.to_str()).unwrap_or("");
|
|
167
|
-
if file_stem.is_empty() { continue; }
|
|
168
|
-
|
|
169
|
-
// Found action
|
|
170
|
-
map.insert(file_stem.to_string(), path);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
map
|
|
175
|
-
}
|