titan-sdk 0.0.3 → 0.0.5
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 +52 -57
- package/bin/run.js +25 -9
- package/package.json +10 -2
- package/templates/.dockerignore +3 -0
- package/templates/Dockerfile +53 -0
- package/templates/app/actions/hello.js +5 -0
- package/templates/app/app.js +10 -0
- package/templates/app/titan.d.ts +87 -0
- package/templates/jsconfig.json +19 -0
- package/templates/server/Cargo.lock +2839 -0
- package/templates/server/Cargo.toml +27 -0
- package/templates/server/src/action_management.rs +131 -0
- package/templates/server/src/errors.rs +10 -0
- package/templates/server/src/extensions.rs +640 -0
- package/templates/server/src/main.rs +345 -0
- package/templates/server/src/utils.rs +33 -0
- package/templates/titan/bundle.js +65 -0
- package/templates/titan/dev.js +110 -0
- package/templates/titan/titan.js +82 -0
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
# 🛠️ Titan SDK
|
|
3
3
|
|
|
4
|
-
**
|
|
4
|
+
**The Developer Toolkit for Titan Planet. Type safety, IntelliSense, and Extension Testing.**
|
|
5
5
|
|
|
6
6
|
[](https://www.npmjs.com/package/titan-sdk)
|
|
7
7
|
[](https://opensource.org/licenses/ISC)
|
|
@@ -10,97 +10,92 @@
|
|
|
10
10
|
|
|
11
11
|
## 🌌 Overview
|
|
12
12
|
|
|
13
|
-
**Titan SDK** is the
|
|
13
|
+
**Titan SDK** is NOT the runtime engine itself. It is a **development-only toolkit** designed to bridge the gap between your local coding environment and the native Titan Planet binary.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
It provides the necessary **Type Definitions** to make your IDE understand the global `t` object and a **Lite Test Harness** to verify your extensions before they ever touch a production binary.
|
|
16
|
+
|
|
17
|
+
> **Note:** The actual implementation of `t.log`, `t.fetch`, and other APIs are embedded directly into the [Titan Planet Binary](https://github.com/ezet-galaxy/-ezetgalaxy-titan). This SDK simply provides the "blueprints" (types) and a "sandbox" (test runner).
|
|
16
18
|
|
|
17
19
|
---
|
|
18
20
|
|
|
19
21
|
## ✨ Features
|
|
20
22
|
|
|
21
|
-
- **💎
|
|
22
|
-
- **🛡️
|
|
23
|
-
- **🔌 Extension
|
|
24
|
-
- **🚀 Zero
|
|
23
|
+
- **💎 Blueprint Types (IntelliSense)**: Provides the full TypeScript `index.d.ts` for the global `t` object so you get autocomplete in VS Code and other editors.
|
|
24
|
+
- **🛡️ Static Validation**: Catch parameter mismatches and typos in `t.log`, `t.fetch`, `t.db`, etc., during development.
|
|
25
|
+
- **🔌 Extension Test Harness**: A "lite" version of the Titan runtime that simulates the native environment to test extensions in isolation.
|
|
26
|
+
- **🚀 Zero Production Trace**: This is a `devDependencies` package. It never ships with your binary, keeping your production footprint at literal zero.
|
|
25
27
|
|
|
26
28
|
---
|
|
27
29
|
|
|
28
|
-
## 🚀
|
|
30
|
+
## 🚀 The Test Harness (Lite Runtime)
|
|
31
|
+
|
|
32
|
+
The SDK includes a specialized **Test Runner** (`titan-sdk`). This is a "lite" version of the Titan ecosystem that acts as a bridge for developers.
|
|
29
33
|
|
|
30
|
-
###
|
|
34
|
+
### How it works:
|
|
35
|
+
When you run the SDK in an extension folder, it:
|
|
36
|
+
1. **Scaffolds a Virtual Project**: Creates a temporary, minimal Titan environment in `.titan_test_run`.
|
|
37
|
+
2. **Native Compilation**: Automatically builds your native Rust code (`native/`) if it exists.
|
|
38
|
+
3. **Hot-Linking**: Junctions your local extension into the virtual project's `node_modules`.
|
|
39
|
+
4. **Verification**: Generates a test suite that attempts to call your extension's methods via the real `t` object inside the sandbox.
|
|
31
40
|
|
|
32
|
-
|
|
41
|
+
### Usage:
|
|
33
42
|
|
|
34
43
|
```bash
|
|
35
|
-
|
|
44
|
+
# Inside your extension directory
|
|
45
|
+
npx titan-sdk
|
|
36
46
|
```
|
|
37
47
|
|
|
38
|
-
|
|
48
|
+
---
|
|
39
49
|
|
|
40
|
-
|
|
50
|
+
## ⌨️ Enabling IntelliSense
|
|
41
51
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
```
|
|
52
|
+
Since the `t` object is injected globally by the Titan engine at runtime, your IDE won't recognize it by default. The SDK fixes this.
|
|
53
|
+
|
|
54
|
+
1. **Install the SDK**:
|
|
55
|
+
```bash
|
|
56
|
+
npm install --save-dev titan-sdk
|
|
57
|
+
```
|
|
49
58
|
|
|
50
|
-
|
|
59
|
+
2. **Configure Types**:
|
|
60
|
+
Create or update `jsconfig.json` (or `tsconfig.json`) in your project root:
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"compilerOptions": {
|
|
64
|
+
"types": ["titan-sdk"]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
51
68
|
|
|
69
|
+
Now your editor will treat `t` as a first-class citizen:
|
|
52
70
|
```js
|
|
53
71
|
export function myAction(req) {
|
|
54
|
-
t.log.info("Request received", req.path);
|
|
55
|
-
|
|
56
|
-
// Fully typed db queries!
|
|
57
|
-
const data = t.db.query("SELECT * FROM users WHERE id = $1", [req.params.id]);
|
|
58
|
-
|
|
59
|
-
return data;
|
|
72
|
+
t.log.info("Request received", req.path); // Autocomplete works!
|
|
73
|
+
return { status: "ok" };
|
|
60
74
|
}
|
|
61
75
|
```
|
|
62
76
|
|
|
63
77
|
---
|
|
64
78
|
|
|
65
|
-
##
|
|
66
|
-
|
|
67
|
-
The SDK provides types for the entire `t` namespace:
|
|
79
|
+
## 🧱 What's Included? (Types Only)
|
|
68
80
|
|
|
69
|
-
|
|
70
|
-
- **`t.fetch`**: High-performance Rust-native fetch wrapper.
|
|
71
|
-
- **`t.db`**: Native PostgreSQL interface for extreme speed.
|
|
72
|
-
- **`t.read`**: Optimized file system access.
|
|
73
|
-
- **`t.jwt`**: Built-in JWT handling (if enabled).
|
|
81
|
+
The SDK provides types for the native APIs provided by the Titan Planet engine:
|
|
74
82
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
// Define your extension types
|
|
83
|
-
declare global {
|
|
84
|
-
namespace Titan {
|
|
85
|
-
interface Runtime {
|
|
86
|
-
myCustomTool: {
|
|
87
|
-
doSomething: () => void;
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
```
|
|
83
|
+
- **`t.log`**: Standardized logging that appears in the Titan binary console.
|
|
84
|
+
- **`t.fetch`**: Types for the high-performance Rust-native network stack.
|
|
85
|
+
- **`t.db`**: Interface for the native PostgreSQL driver.
|
|
86
|
+
- **`t.read`**: Definitions for optimized filesystem reads.
|
|
87
|
+
- **`t.jwt` / `t.password`**: Security helper types.
|
|
93
88
|
|
|
94
89
|
---
|
|
95
90
|
|
|
96
91
|
## 🌍 Community & Documentation
|
|
97
92
|
|
|
98
|
-
- **
|
|
99
|
-
- **
|
|
100
|
-
- **
|
|
93
|
+
- **Core Framework**: [Titan Planet](https://github.com/ezet-galaxy/-ezetgalaxy-titan)
|
|
94
|
+
- **Official Docs**: [Titan Planet Docs](https://titan-docs-ez.vercel.app/docs)
|
|
95
|
+
- **Author**: [ezetgalaxy](https://github.com/ezet-galaxy)
|
|
101
96
|
|
|
102
97
|
---
|
|
103
98
|
|
|
104
99
|
<p align="center">
|
|
105
|
-
Built with ❤️ for the <a href="https://github.com/ezetgalaxy
|
|
100
|
+
Built with ❤️ for the <a href="https://github.com/ezet-galaxy/-ezetgalaxy-titan">Titan Planet</a> ecosystem.
|
|
106
101
|
</p>
|
package/bin/run.js
CHANGED
|
@@ -13,6 +13,19 @@ const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
|
13
13
|
const red = (t) => `\x1b[31m${t}\x1b[0m`;
|
|
14
14
|
const yellow = (t) => `\x1b[33m${t}\x1b[0m`;
|
|
15
15
|
|
|
16
|
+
function copyDir(src, dest) {
|
|
17
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
18
|
+
for (const file of fs.readdirSync(src)) {
|
|
19
|
+
const srcPath = path.join(src, file);
|
|
20
|
+
const destPath = path.join(dest, file);
|
|
21
|
+
if (fs.lstatSync(srcPath).isDirectory()) {
|
|
22
|
+
copyDir(srcPath, destPath);
|
|
23
|
+
} else {
|
|
24
|
+
fs.copyFileSync(srcPath, destPath);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
16
29
|
function run() {
|
|
17
30
|
console.log(cyan("Titan SDK: Test Runner"));
|
|
18
31
|
|
|
@@ -56,19 +69,24 @@ function run() {
|
|
|
56
69
|
fs.mkdirSync(actionsDir);
|
|
57
70
|
|
|
58
71
|
// Copy titan/ and server/ from templates
|
|
59
|
-
const
|
|
60
|
-
const templatesDir = path.join(repoRoot, "templates");
|
|
72
|
+
const templatesDir = path.join(__dirname, "..", "templates");
|
|
61
73
|
|
|
62
74
|
const titanSrc = path.join(templatesDir, "titan");
|
|
63
75
|
const titanDest = path.join(runDir, "titan");
|
|
64
76
|
if (fs.existsSync(titanSrc)) {
|
|
65
|
-
|
|
77
|
+
copyDir(titanSrc, titanDest);
|
|
78
|
+
} else {
|
|
79
|
+
console.log(red(`Error: Titan templates not found at ${titanSrc}`));
|
|
80
|
+
process.exit(1);
|
|
66
81
|
}
|
|
67
82
|
|
|
68
83
|
const serverSrc = path.join(templatesDir, "server");
|
|
69
84
|
const serverDest = path.join(runDir, "server");
|
|
70
85
|
if (fs.existsSync(serverSrc)) {
|
|
71
|
-
|
|
86
|
+
copyDir(serverSrc, serverDest);
|
|
87
|
+
} else {
|
|
88
|
+
console.log(red(`Error: Server templates not found at ${serverSrc}`));
|
|
89
|
+
process.exit(1);
|
|
72
90
|
}
|
|
73
91
|
|
|
74
92
|
// Create package.json for the test harness
|
|
@@ -89,7 +107,7 @@ function run() {
|
|
|
89
107
|
} catch (e) {
|
|
90
108
|
// Fallback to copy if link fails
|
|
91
109
|
console.log(yellow("Linking failed, copying extension files..."));
|
|
92
|
-
|
|
110
|
+
copyDir(cwd, extDest);
|
|
93
111
|
}
|
|
94
112
|
|
|
95
113
|
// Create a test action in app/actions/test.js
|
|
@@ -138,7 +156,6 @@ console.log("---------------------------------------------------");
|
|
|
138
156
|
|
|
139
157
|
if (!ext) {
|
|
140
158
|
console.log("ERROR: Extension '${name}' not found in global 't'.");
|
|
141
|
-
console.log("Make sure your extension's package.json has 'type': 'commonjs'");
|
|
142
159
|
} else {
|
|
143
160
|
console.log("✓ Extension loaded successfully!");
|
|
144
161
|
console.log("✓ Available methods:", Object.keys(ext).join(", "));
|
|
@@ -177,7 +194,7 @@ console.log("---------------------------------------------------\\n");
|
|
|
177
194
|
t.get("/test").action("test");
|
|
178
195
|
t.get("/").reply("🚀 Extension Test Harness for ${name}\\n\\nVisit /test to see extension test results");
|
|
179
196
|
|
|
180
|
-
t.start(3000, "Titan Extension Test Running!");
|
|
197
|
+
await t.start(3000, "Titan Extension Test Running!");
|
|
181
198
|
`;
|
|
182
199
|
|
|
183
200
|
fs.writeFileSync(path.join(appDir, "app.js"), testScript);
|
|
@@ -188,11 +205,10 @@ t.start(3000, "Titan Extension Test Running!");
|
|
|
188
205
|
execSync("node app/app.js --build", { cwd: runDir, stdio: "inherit" });
|
|
189
206
|
} catch (e) {
|
|
190
207
|
console.log(red("Failed to build test app."));
|
|
191
|
-
console.log(yellow("This is expected if your extension has errors."));
|
|
192
208
|
}
|
|
193
209
|
|
|
194
210
|
// 4. Run Titan Server using cargo run (like dev mode)
|
|
195
|
-
console.log(
|
|
211
|
+
console.log(green("\x1b[1m\n>>> STARTING EXTENSION TEST >>>\n\x1b[0m"));
|
|
196
212
|
|
|
197
213
|
const serverDir = path.join(runDir, "server");
|
|
198
214
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "titan-sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "Development SDK for Titan Planet. Provides TypeScript type definitions for the global 't' runtime object and a 'lite' test-harness runtime for building and verifying extensions.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "index.d.ts",
|
|
8
8
|
"bin": {
|
|
9
9
|
"titan-sdk": "./bin/run.js"
|
|
10
10
|
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin/",
|
|
13
|
+
"templates/",
|
|
14
|
+
"titan",
|
|
15
|
+
"index.js",
|
|
16
|
+
"index.d.ts",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
11
19
|
"keywords": [
|
|
12
20
|
"titan",
|
|
13
21
|
"titan-planet",
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
# Build Titan metadata + bundle JS actions
|
|
22
|
+
RUN titan build
|
|
23
|
+
|
|
24
|
+
# Build Rust binary
|
|
25
|
+
RUN cd server && cargo build --release
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# ================================================================
|
|
30
|
+
# STAGE 2 — Runtime Image (Lightweight)
|
|
31
|
+
# ================================================================
|
|
32
|
+
FROM debian:stable-slim
|
|
33
|
+
|
|
34
|
+
WORKDIR /app
|
|
35
|
+
|
|
36
|
+
# Copy Rust binary from builder stage
|
|
37
|
+
COPY --from=builder /app/server/target/release/server ./titan-server
|
|
38
|
+
|
|
39
|
+
# Copy Titan routing metadata
|
|
40
|
+
COPY --from=builder /app/server/routes.json ./routes.json
|
|
41
|
+
COPY --from=builder /app/server/action_map.json ./action_map.json
|
|
42
|
+
|
|
43
|
+
# Copy Titan JS bundles
|
|
44
|
+
RUN mkdir -p /app/actions
|
|
45
|
+
COPY --from=builder /app/server/actions /app/actions
|
|
46
|
+
|
|
47
|
+
COPY --from=builder /app/db /app/assets
|
|
48
|
+
|
|
49
|
+
# Expose Titan port
|
|
50
|
+
EXPOSE 3000
|
|
51
|
+
|
|
52
|
+
# Start Titan
|
|
53
|
+
CMD ["./titan-server"]
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TITAN TYPE DEFINITIONS
|
|
3
|
+
* ----------------------
|
|
4
|
+
* These types are globally available in your Titan project.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The Titan Request Object passed to actions.
|
|
9
|
+
*/
|
|
10
|
+
interface TitanRequest {
|
|
11
|
+
body: any;
|
|
12
|
+
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
13
|
+
path: string;
|
|
14
|
+
headers: {
|
|
15
|
+
host?: string;
|
|
16
|
+
"content-type"?: string;
|
|
17
|
+
"user-agent"?: string;
|
|
18
|
+
authorization?: string;
|
|
19
|
+
[key: string]: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
params: Record<string, string>;
|
|
22
|
+
query: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface DbConnection {
|
|
26
|
+
/**
|
|
27
|
+
* Execute a SQL query.
|
|
28
|
+
* @param sql The SQL query string.
|
|
29
|
+
* @param params (Optional) Parameters for the query ($1, $2, etc).
|
|
30
|
+
*/
|
|
31
|
+
query(sql: string, params?: any[]): any[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Define a Titan Action with type inference.
|
|
36
|
+
* @example
|
|
37
|
+
* export const hello = defineAction((req) => {
|
|
38
|
+
* return req.headers;
|
|
39
|
+
* });
|
|
40
|
+
*/
|
|
41
|
+
declare function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Titan Runtime Utilities
|
|
45
|
+
*/
|
|
46
|
+
declare const t: {
|
|
47
|
+
/**
|
|
48
|
+
* Log messages to the server console with Titan formatting.
|
|
49
|
+
*/
|
|
50
|
+
log(...args: any[]): void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Read a file contents as string.
|
|
54
|
+
* @param path Relative path to the file from project root.
|
|
55
|
+
*/
|
|
56
|
+
read(path: string): string;
|
|
57
|
+
|
|
58
|
+
fetch(url: string, options?: {
|
|
59
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
60
|
+
headers?: Record<string, string>;
|
|
61
|
+
body?: string | object;
|
|
62
|
+
}): {
|
|
63
|
+
ok: boolean;
|
|
64
|
+
status?: number;
|
|
65
|
+
body?: string;
|
|
66
|
+
error?: string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
jwt: {
|
|
70
|
+
sign(
|
|
71
|
+
payload: object,
|
|
72
|
+
secret: string,
|
|
73
|
+
options?: { expiresIn?: string | number }
|
|
74
|
+
): string;
|
|
75
|
+
verify(token: string, secret: string): any;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
password: {
|
|
79
|
+
hash(password: string): string;
|
|
80
|
+
verify(password: string, hash: string): boolean;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
db: {
|
|
84
|
+
connect(url: string): DbConnection;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "esnext",
|
|
4
|
+
"target": "esnext",
|
|
5
|
+
"checkJs": false,
|
|
6
|
+
"noImplicitAny": false,
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"baseUrl": ".",
|
|
10
|
+
"paths": {
|
|
11
|
+
"*": [
|
|
12
|
+
"./app/*"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"include": [
|
|
17
|
+
"app/**/*"
|
|
18
|
+
]
|
|
19
|
+
}
|