@ezetgalaxy/titan 26.8.3 → 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.
- package/README.md +63 -14
- package/index.js +62 -15
- package/package.json +1 -1
- package/templates/extension/README.md +104 -104
- package/templates/extension/index.js +27 -27
- package/templates/extension/jsconfig.json +12 -12
- package/templates/extension/native/Cargo.toml +9 -9
- package/templates/extension/native/src/lib.rs +5 -5
- package/templates/extension/package.json +20 -20
- package/templates/extension/titan.json +17 -17
- package/templates/js/Dockerfile +66 -66
- package/templates/js/_dockerignore +3 -3
- package/templates/js/_gitignore +1 -0
- package/templates/js/app/actions/hello.js +5 -5
- package/templates/js/app/titan.d.ts +87 -87
- package/templates/js/jsconfig.json +18 -18
- package/templates/js/server/src/action_management.rs +131 -131
- package/templates/js/server/src/errors.rs +10 -10
- package/templates/js/server/src/extensions.rs +989 -989
- package/templates/js/server/src/utils.rs +33 -33
- package/templates/js/titan/bundle.js +78 -78
- package/templates/js/titan/dev.js +9 -1
- package/templates/js/titan/titan.js +122 -122
- package/templates/rust/Dockerfile +66 -66
- package/templates/rust/_dockerignore +3 -3
- package/templates/rust/_gitignore +1 -0
- package/templates/rust/app/actions/hello.js +5 -5
- package/templates/rust/app/actions/rust_hello.rs +14 -14
- package/templates/rust/app/titan.d.ts +101 -101
- package/templates/rust/jsconfig.json +18 -18
- package/templates/rust/server/src/action_management.rs +131 -131
- package/templates/rust/server/src/errors.rs +10 -10
- package/templates/rust/server/src/extensions.rs +989 -989
- package/templates/rust/server/src/utils.rs +33 -33
- package/templates/rust/titan/dev.js +9 -1
- package/templates/rust-ts/Dockerfile +66 -0
- package/templates/rust-ts/_dockerignore +3 -0
- package/templates/rust-ts/_gitignore +38 -0
- package/templates/rust-ts/app/actions/hello.ts +5 -0
- package/templates/rust-ts/app/actions/rust_hello.rs +14 -0
- package/templates/rust-ts/app/app.ts +11 -0
- package/templates/rust-ts/app/titan.d.ts +101 -0
- package/templates/rust-ts/package.json +14 -0
- package/templates/rust-ts/server/Cargo.lock +2869 -0
- package/templates/rust-ts/server/Cargo.toml +39 -0
- package/templates/rust-ts/server/src/action_management.rs +131 -0
- package/templates/rust-ts/server/src/errors.rs +51 -0
- package/templates/rust-ts/server/src/extensions.rs +989 -0
- package/templates/rust-ts/server/src/main.rs +468 -0
- package/templates/rust-ts/server/src/utils.rs +33 -0
- package/templates/rust-ts/titan/bundle.js +157 -0
- package/templates/rust-ts/titan/dev.js +402 -0
- package/templates/rust-ts/titan/titan.js +122 -0
- package/templates/rust-ts/tsconfig.json +21 -0
- package/templates/ts/Dockerfile +66 -0
- package/templates/ts/_dockerignore +3 -0
- package/templates/ts/_gitignore +38 -0
- package/templates/ts/app/actions/hello.ts +9 -0
- package/templates/ts/app/app.ts +10 -0
- package/templates/ts/app/titan.d.ts +102 -0
- package/templates/ts/package.json +26 -0
- package/templates/ts/server/Cargo.lock +2869 -0
- package/templates/ts/server/Cargo.toml +27 -0
- package/templates/ts/server/src/action_management.rs +131 -0
- package/templates/ts/server/src/errors.rs +51 -0
- package/templates/ts/server/src/extensions.rs +989 -0
- package/templates/ts/server/src/main.rs +437 -0
- package/templates/ts/server/src/utils.rs +33 -0
- package/templates/ts/titan/bundle.js +78 -0
- package/templates/ts/titan/dev.js +402 -0
- package/templates/ts/titan/titan.js +122 -0
- package/templates/ts/tsconfig.json +16 -0
- package/titanpl-sdk/README.md +109 -109
- package/titanpl-sdk/bin/run.js +254 -254
- package/titanpl-sdk/index.d.ts +46 -46
- package/titanpl-sdk/index.js +5 -5
- package/titanpl-sdk/package.json +32 -32
- package/titanpl-sdk/templates/.dockerignore +3 -3
- package/titanpl-sdk/templates/Dockerfile +53 -53
- package/titanpl-sdk/templates/app/actions/hello.js +5 -5
- package/titanpl-sdk/templates/app/titan.d.ts +87 -87
- package/titanpl-sdk/templates/jsconfig.json +18 -18
- package/titanpl-sdk/templates/server/src/action_management.rs +131 -131
- package/titanpl-sdk/templates/server/src/errors.rs +10 -10
- package/titanpl-sdk/templates/server/src/extensions.rs +640 -640
- package/titanpl-sdk/templates/server/src/utils.rs +33 -33
- package/titanpl-sdk/templates/titan/bundle.js +65 -65
- package/titanpl-sdk/templates/titan/dev.js +113 -113
- package/titanpl-sdk/templates/titan/titan.js +98 -98
- package/templates/js/server/action_map.json +0 -3
- package/templates/js/server/actions/hello.jsbundle +0 -48
- package/templates/js/server/routes.json +0 -16
- package/templates/rust/server/action_map.json +0 -3
- package/templates/rust/server/actions/hello.jsbundle +0 -47
- package/templates/rust/server/routes.json +0 -22
- package/templates/rust/server/src/actions_rust/mod.rs +0 -19
- 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
|
+
|
|
@@ -227,7 +227,15 @@ async function startDev() {
|
|
|
227
227
|
hasRust = fs.readdirSync(actionsDir).some(f => f.endsWith(".rs"));
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
const
|
|
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,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,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
|
+
}
|