@ezetgalaxy/titan 26.8.2 โ 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 +65 -25
- package/index.js +62 -15
- package/package.json +2 -2
- 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 +35 -3
- 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 +36 -12
- 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
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
๐ **Enjoy development mode `titan dev`**
|
|
14
14
|
๐ **Titan Planet docs:** https://titan-docs-ez.vercel.app/docs
|
|
15
15
|
๐ **CLI: `titan` is now the canonical command. `tit` remains supported as an alias.**
|
|
16
|
+
๐ก๏ธ **Strict Mode:** Titan now enforces zero type errors before running.
|
|
16
17
|
|
|
17
18
|
---
|
|
18
19
|
|
|
@@ -21,15 +22,15 @@
|
|
|
21
22
|
[](https://www.npmjs.com/package/@ezetgalaxy/titan)
|
|
22
23
|
|
|
23
24
|
|
|
24
|
-
**JavaScript Simplicity. Native Rust Power. Zero Configuration.**
|
|
25
|
+
**TypeScript Precision. JavaScript Simplicity. Native Rust Power. Zero Configuration.**
|
|
25
26
|
|
|
26
|
-
Titan Planet is a **JavaScript-first Backend Framework** that compiles your application into a single, high-performance native binary. It embeds a V8 JavaScript runtime directly into a specialized Rust + Axum server.
|
|
27
|
+
Titan Planet is a **JavaScript/TypeScript-first Backend Framework** that compiles your application into a single, high-performance native binary. It embeds a V8 JavaScript runtime directly into a specialized Rust + Axum server.
|
|
27
28
|
|
|
28
|
-
**Start with pure JavaScript.**
|
|
29
|
+
**Start with pure TypeScript/JavaScript.**
|
|
29
30
|
**Need raw power? Add Rust actions seamlessly.**
|
|
30
31
|
Titan handles the compilation, bundling, and routing automatically for both.
|
|
31
32
|
|
|
32
|
-
Titan = **
|
|
33
|
+
Titan = **TS/JS productivity ร Rust performance ร Zero DevOps**
|
|
33
34
|
|
|
34
35
|
---
|
|
35
36
|
|
|
@@ -38,8 +39,8 @@ Titan = **JavaScript productivity ร Rust performance ร Zero DevOps**
|
|
|
38
39
|
| Feature | Titan | Express/Nest | FastAPI | Bun |
|
|
39
40
|
| ------------------------------------ | ----- | ------------ | ------- | --------- |
|
|
40
41
|
| Native binary output | โ
Yes | โ No | โ No | โ No |
|
|
41
|
-
| Hybrid Rust + JS Actions
|
|
42
|
-
|
|
|
42
|
+
| Hybrid Rust + JS/TS Actions | โ
Yes | โ No | โ No | โ No |
|
|
43
|
+
| Strict TypeScript Enforcement | โ
Yes | โ Setup Req. | โ No | โ Partial |
|
|
43
44
|
| Zero-config Docker deploy | โ
Yes | โ No | โ No | โ No |
|
|
44
45
|
| Action-based architecture | โ
Yes | โ No | โ No | โ No |
|
|
45
46
|
| Hot reload dev server | โ
Yes | โ No | โ No | โ No |
|
|
@@ -62,7 +63,9 @@ npm install -g @ezetgalaxy/titan
|
|
|
62
63
|
titan init my-app
|
|
63
64
|
# Follow the interactive prompt to choose:
|
|
64
65
|
# - JavaScript (Standard)
|
|
66
|
+
# - TypeScript (Strict)
|
|
65
67
|
# - Rust + JavaScript (Beta)
|
|
68
|
+
# - Rust + TypeScript (Beta)
|
|
66
69
|
```
|
|
67
70
|
|
|
68
71
|
Inside your project:
|
|
@@ -73,10 +76,11 @@ titan dev
|
|
|
73
76
|
|
|
74
77
|
You'll see the Titan Dev Server spin up:
|
|
75
78
|
```
|
|
76
|
-
Titan Planet v26.
|
|
79
|
+
Titan Planet v26.9.0 [ Dev Mode ]
|
|
77
80
|
|
|
78
|
-
Type: Rust +
|
|
81
|
+
Type: Rust + TS Actions
|
|
79
82
|
Hot Reload: Enabled
|
|
83
|
+
Strict Mode: Active ๐ก๏ธ
|
|
80
84
|
|
|
81
85
|
โข Preparing runtime... Done
|
|
82
86
|
โข A new orbit is ready for your app in 0.9s
|
|
@@ -87,7 +91,25 @@ You'll see the Titan Dev Server spin up:
|
|
|
87
91
|
|
|
88
92
|
# โก Hybrid Action System
|
|
89
93
|
|
|
90
|
-
Titan is unique because it allows you to write endpoints in **
|
|
94
|
+
Titan is unique because it allows you to write endpoints in **JavaScript, TypeScript, and Rust** within the same project.
|
|
95
|
+
|
|
96
|
+
### ๐ต TypeScript Actions (`app/actions/hello.ts`)
|
|
97
|
+
Fully typed, strict, and auto-compiled.
|
|
98
|
+
```typescript
|
|
99
|
+
import { Context } from '@ezetgalaxy/titan';
|
|
100
|
+
|
|
101
|
+
export function run(req: Context) {
|
|
102
|
+
t.log("Handling request with strict types...");
|
|
103
|
+
|
|
104
|
+
// Type checking allows safe property access
|
|
105
|
+
const user = req.body as { name: string };
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
message: "Hello from TypeScript!",
|
|
109
|
+
user_name: user.name
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
```
|
|
91
113
|
|
|
92
114
|
### ๐ก JavaScript Actions (`app/actions/hello.js`)
|
|
93
115
|
Perfect for business logic, rapid prototyping, and IO-bound tasks.
|
|
@@ -115,33 +137,50 @@ pub async fn run(req: Request<Body>) -> impl IntoResponse {
|
|
|
115
137
|
}
|
|
116
138
|
```
|
|
117
139
|
|
|
118
|
-
**Titan automatically detects, compiles, and routes
|
|
140
|
+
**Titan automatically detects, compiles, and routes all types.**
|
|
141
|
+
* `.ts` files are type-checked and compiled with esbuild.
|
|
119
142
|
* `.js` files are bundled with esbuild.
|
|
120
143
|
* `.rs` files are compiled into the native binary.
|
|
121
|
-
*
|
|
144
|
+
* All share the same `routes.json` configuration.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
# ๐ก๏ธ Strict Type Safety & Error Logs
|
|
149
|
+
|
|
150
|
+
Titan prioritizes code quality by enforcing **Strict TypeScript** logic during development.
|
|
151
|
+
|
|
152
|
+
If `titan dev` detects a type error, the server **will not run**. This ensures you never ship or test broken code.
|
|
153
|
+
|
|
154
|
+
### Sample Error Output
|
|
155
|
+
When a type error occurs, Titan pauses execution and provides a clear, actionable log:
|
|
156
|
+
|
|
157
|
+
```text
|
|
158
|
+
[Titan] โ TypeScript Error:
|
|
159
|
+
app/actions/payment.ts(12,5): error TS2322: Type 'string' is not assignable to type 'number'.
|
|
160
|
+
|
|
161
|
+
10 | const amount: number = req.body.amount;
|
|
162
|
+
11 |
|
|
163
|
+
> 12 | processPayment( "100" ); // Error here
|
|
164
|
+
| ^^^^^^^^^^^^^^^^^^^^^^^
|
|
165
|
+
|
|
166
|
+
[Titan] ๐ Server paused due to type errors. Fix them to resume.
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Once fixed, the server automatically resumes.
|
|
122
170
|
|
|
123
171
|
---
|
|
124
172
|
|
|
125
173
|
# โจ Core Capabilities
|
|
126
174
|
|
|
127
175
|
### ๐ Unified Runtime API (`t`)
|
|
128
|
-
|
|
176
|
+
All actions (JS/TS/Rust) have access to the powerful `t` namespace:
|
|
129
177
|
|
|
130
178
|
* `t.fetch(url, options)` โ High-performance HTTP client
|
|
131
179
|
* `t.log(msg)` โ Sandboxed, structured logging
|
|
132
180
|
* `t.jwt.sign / verify` โ Fast JWT operations
|
|
133
181
|
* `t.password.hash / verify` โ Secure password handling
|
|
134
|
-
* `t.db` โ Database access
|
|
135
|
-
|
|
136
|
-
### ๐ฃ Intelligent Routing
|
|
137
|
-
Define your routes in `routes.json`. Titan maps them to the correct action, regardless of language.
|
|
138
|
-
|
|
139
|
-
```json
|
|
140
|
-
{
|
|
141
|
-
"/hello": "hello", // variable name matches filename (hello.js)
|
|
142
|
-
"/compute": "compute" // variable name matches filename (compute.rs)
|
|
143
|
-
}
|
|
144
|
-
```
|
|
182
|
+
* `t.db` โ Database access
|
|
183
|
+
---
|
|
145
184
|
|
|
146
185
|
### ๐งฉ Extensions System
|
|
147
186
|
Extend the runtime with custom Rust engines using **Titan Extensions**.
|
|
@@ -152,7 +191,7 @@ Extend the runtime with custom Rust engines using **Titan Extensions**.
|
|
|
152
191
|
|
|
153
192
|
# ๐ฆ Deployment
|
|
154
193
|
|
|
155
|
-
Titan compiles your entire appโJS code, Rust code, and server logicโinto a **single executable**.
|
|
194
|
+
Titan compiles your entire appโJS/TS code, Rust code, and server logicโinto a **single executable**.
|
|
156
195
|
|
|
157
196
|
* **Tiny Docker Images**: Alpine-based, ~20MB compressed.
|
|
158
197
|
* **Instant Startup**: No node_modules overhead.
|
|
@@ -161,7 +200,7 @@ Titan compiles your entire appโJS code, Rust code, and server logicโinto a *
|
|
|
161
200
|
---
|
|
162
201
|
|
|
163
202
|
# ๐งฑ Architecture Note
|
|
164
|
-
Titan is **not** a Node.js framework. It is a Rust server that speaks JavaScript.
|
|
203
|
+
Titan is **not** a Node.js framework. It is a Rust server that speaks JavaScript/TypeScript.
|
|
165
204
|
* **No Event Loop** for JS (Request/Response model).
|
|
166
205
|
* **No `require`** (Use raw imports or bundled dependencies).
|
|
167
206
|
* **True Isolation** per request.
|
|
@@ -170,6 +209,7 @@ Titan is **not** a Node.js framework. It is a Rust server that speaks JavaScript
|
|
|
170
209
|
|
|
171
210
|
**Titan v26 โ Stable**
|
|
172
211
|
* Production-ready Hybrid Runtime
|
|
212
|
+
* Strict TypeScript Support
|
|
173
213
|
* Native Rust Performance
|
|
174
214
|
* Zero-Config Cloud Deployment
|
|
175
215
|
|
package/index.js
CHANGED
|
@@ -123,37 +123,82 @@ ${yellow("Note: `tit` is supported as a legacy alias.")}
|
|
|
123
123
|
* INIT
|
|
124
124
|
* ----------------------------------------------------- */
|
|
125
125
|
async function initProject(name, templateName) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
let projName = name;
|
|
127
|
+
|
|
128
|
+
if (!projName) {
|
|
129
|
+
const response = await prompts({
|
|
130
|
+
type: 'text',
|
|
131
|
+
name: 'value',
|
|
132
|
+
message: 'Project name:',
|
|
133
|
+
initial: 'my-titan-app'
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (!response.value) {
|
|
137
|
+
console.log(red("โ Operation cancelled"));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
projName = response.value;
|
|
129
141
|
}
|
|
130
142
|
|
|
131
143
|
let selectedTemplate = templateName;
|
|
132
144
|
|
|
133
145
|
if (!selectedTemplate) {
|
|
134
|
-
|
|
146
|
+
// 1. Language Selection
|
|
147
|
+
const langRes = await prompts({
|
|
135
148
|
type: 'select',
|
|
136
149
|
name: 'value',
|
|
137
|
-
message: 'Select
|
|
150
|
+
message: 'Select language:',
|
|
138
151
|
choices: [
|
|
139
|
-
{ title: 'JavaScript',
|
|
140
|
-
{ title:
|
|
152
|
+
{ title: 'JavaScript', value: 'js' },
|
|
153
|
+
{ title: 'TypeScript', value: 'ts' }
|
|
141
154
|
],
|
|
142
155
|
initial: 0
|
|
143
156
|
});
|
|
144
157
|
|
|
145
|
-
if (!
|
|
158
|
+
if (!langRes.value) {
|
|
159
|
+
console.log(red("โ Operation cancelled"));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const lang = langRes.value;
|
|
163
|
+
|
|
164
|
+
// 2. Template Selection
|
|
165
|
+
const archRes = await prompts({
|
|
166
|
+
type: 'select',
|
|
167
|
+
name: 'value',
|
|
168
|
+
message: 'Select template:',
|
|
169
|
+
choices: [
|
|
170
|
+
{
|
|
171
|
+
title: `Standard (${lang.toUpperCase()})`,
|
|
172
|
+
description: `Standard Titan app with ${lang.toUpperCase()} actions`,
|
|
173
|
+
value: 'standard'
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
title: `Rust + ${lang.toUpperCase()} (Hybrid)`,
|
|
177
|
+
description: `High-performance Rust actions + ${lang.toUpperCase()} flexibility`,
|
|
178
|
+
value: 'hybrid'
|
|
179
|
+
}
|
|
180
|
+
],
|
|
181
|
+
initial: 0
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
if (!archRes.value) {
|
|
146
185
|
console.log(red("โ Operation cancelled"));
|
|
147
186
|
return;
|
|
148
187
|
}
|
|
149
|
-
|
|
188
|
+
const arch = archRes.value;
|
|
189
|
+
|
|
190
|
+
if (lang === 'js') {
|
|
191
|
+
selectedTemplate = arch === 'standard' ? 'js' : 'rust';
|
|
192
|
+
} else {
|
|
193
|
+
selectedTemplate = arch === 'standard' ? 'ts' : 'rust-ts';
|
|
194
|
+
}
|
|
150
195
|
}
|
|
151
196
|
|
|
152
|
-
const target = path.join(process.cwd(),
|
|
197
|
+
const target = path.join(process.cwd(), projName);
|
|
153
198
|
const templateDir = path.join(__dirname, "templates", selectedTemplate);
|
|
154
199
|
|
|
155
200
|
if (!fs.existsSync(templateDir)) {
|
|
156
|
-
console.log(red(`Template '${selectedTemplate}' not found
|
|
201
|
+
console.log(red(`Template '${selectedTemplate}' not found.`));
|
|
157
202
|
return;
|
|
158
203
|
}
|
|
159
204
|
|
|
@@ -164,7 +209,7 @@ async function initProject(name, templateName) {
|
|
|
164
209
|
|
|
165
210
|
console.log("\n" + bold(cyan("๐ Initializing Titan Project...")));
|
|
166
211
|
console.log(gray(` Target: ${target}`));
|
|
167
|
-
console.log(gray(` Template: ${selectedTemplate
|
|
212
|
+
console.log(gray(` Template: ${selectedTemplate}`));
|
|
168
213
|
|
|
169
214
|
// ----------------------------------------------------------
|
|
170
215
|
// 1. Copy full template directory
|
|
@@ -198,7 +243,7 @@ async function initProject(name, templateName) {
|
|
|
198
243
|
console.log(cyan("๐ฆ Installing dependencies..."));
|
|
199
244
|
|
|
200
245
|
try {
|
|
201
|
-
execSync(`npm install
|
|
246
|
+
execSync(`npm install --silent`, {
|
|
202
247
|
cwd: target,
|
|
203
248
|
stdio: "inherit",
|
|
204
249
|
});
|
|
@@ -210,7 +255,7 @@ async function initProject(name, templateName) {
|
|
|
210
255
|
console.log("\n" + bold(green("๐ You're all set!")));
|
|
211
256
|
console.log(`
|
|
212
257
|
${gray("Next steps:")}
|
|
213
|
-
${cyan(`cd ${
|
|
258
|
+
${cyan(`cd ${projName}`)}
|
|
214
259
|
${cyan("titan dev")}
|
|
215
260
|
`);
|
|
216
261
|
}
|
|
@@ -335,7 +380,9 @@ function updateTitan() {
|
|
|
335
380
|
}
|
|
336
381
|
|
|
337
382
|
if (!fs.existsSync(templateServer)) {
|
|
338
|
-
console.log(red(
|
|
383
|
+
console.log(red(`CLI seems corrupted or incomplete.`));
|
|
384
|
+
console.log(red(`Expected server template at: ${templateServer}`));
|
|
385
|
+
console.log(yellow(`If you are running from npx, try clearing cache or installing a specific version.`));
|
|
339
386
|
return;
|
|
340
387
|
}
|
|
341
388
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ezetgalaxy/titan",
|
|
3
|
-
"version": "26.
|
|
3
|
+
"version": "26.9.0",
|
|
4
4
|
"description": "Titan Planet is a JavaScript-first backend framework that embeds JS actions into a Rust + Axum server and ships as a single native binary. Routes are compiled to static metadata; only actions run in the embedded JS runtime. No Node.js. No event loop in production.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "ezetgalaxy",
|
|
@@ -52,4 +52,4 @@
|
|
|
52
52
|
"esbuild": "^0.27.2",
|
|
53
53
|
"prompts": "^2.4.2"
|
|
54
54
|
}
|
|
55
|
-
}
|
|
55
|
+
}
|
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
# ๐ช Titan Extension: {{name}}
|
|
2
|
-
|
|
3
|
-
> Elevate Titan Planet with custom JavaScript and high-performance Native Rust logic.
|
|
4
|
-
|
|
5
|
-
Welcome to your new Titan extension! This template provides everything you need to build, test, and deploy powerful additions to the Titan project.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## ๐ Project Structure
|
|
10
|
-
|
|
11
|
-
- `index.js`: The JavaScript entry point where you define your extension's API on the global `t` object.
|
|
12
|
-
- `titan.json`: Manifest file defining extension metadata and Native module mappings.
|
|
13
|
-
- `native/`: Directory for Rust source code.
|
|
14
|
-
- `src/lib.rs`: Your Native function implementations.
|
|
15
|
-
- `Cargo.toml`: Rust package and dependency configuration.
|
|
16
|
-
- `jsconfig.json`: Enables full IntelliSense for the Titan Runtime API.
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
## ๐ Quick Start
|
|
21
|
-
|
|
22
|
-
### 1. Install Dependencies
|
|
23
|
-
Get full type support in your IDE:
|
|
24
|
-
```bash
|
|
25
|
-
npm install
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### 2. Build Native Module (Optional)
|
|
29
|
-
If your extension uses Rust, compile it to a dynamic library:
|
|
30
|
-
```bash
|
|
31
|
-
cd native
|
|
32
|
-
cargo build --release
|
|
33
|
-
cd ..
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### 3. Test the Extension
|
|
37
|
-
Use the Titan SDK to run a local test harness:
|
|
38
|
-
```bash
|
|
39
|
-
titan run ext
|
|
40
|
-
```
|
|
41
|
-
*Tip: Visit `http://localhost:3000/test` after starting the runner to see your extension in action!*
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
## ๐ป Development Guide
|
|
46
|
-
|
|
47
|
-
### Writing JavaScript
|
|
48
|
-
Extensions interact with the global `t` object. It's best practice to namespace your extension:
|
|
49
|
-
|
|
50
|
-
```javascript
|
|
51
|
-
t.{{name}} = {
|
|
52
|
-
myMethod: (val) => {
|
|
53
|
-
t.log("{{name}}", "Doing something...");
|
|
54
|
-
return val * 2;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### Writing Native Rust Functions
|
|
60
|
-
Native functions should be marked with `#[unsafe(no_mangle)]` and use `extern "C"`:
|
|
61
|
-
|
|
62
|
-
```rust
|
|
63
|
-
#[unsafe(no_mangle)]
|
|
64
|
-
pub extern "C" fn multiply(a: f64, b: f64) -> f64 {
|
|
65
|
-
a * b
|
|
66
|
-
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Mapping Native Functions in `titan.json`
|
|
70
|
-
Expose your Rust functions to JavaScript by adding them to the `native.functions` section:
|
|
71
|
-
|
|
72
|
-
```json
|
|
73
|
-
"functions": {
|
|
74
|
-
"add": {
|
|
75
|
-
"symbol": "add",
|
|
76
|
-
"parameters": ["f64", "f64"],
|
|
77
|
-
"result": "f64"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
---
|
|
83
|
-
|
|
84
|
-
## ๐งช Testing with Titan SDK
|
|
85
|
-
|
|
86
|
-
The `titan run ext` command automates the testing workflow:
|
|
87
|
-
1. It builds your native code.
|
|
88
|
-
2. It sets up a temporary Titan project environment.
|
|
89
|
-
3. It links your extension into `node_modules`.
|
|
90
|
-
4. It starts the Titan Runtime at `http://localhost:3000`.
|
|
91
|
-
|
|
92
|
-
You can modify the test harness or add custom test cases by exploring the generated `.titan_test_run` directory (it is git-ignored).
|
|
93
|
-
|
|
94
|
-
---
|
|
95
|
-
|
|
96
|
-
## ๐ฆ Deployment
|
|
97
|
-
To use your extension in a Titan project:
|
|
98
|
-
1. Publish your extension to npm or link it locally.
|
|
99
|
-
2. In your Titan project: `npm install my-extension`.
|
|
100
|
-
3. The Titan Runtime will automatically detect and load your extension if it contains a `titan.json`.
|
|
101
|
-
|
|
102
|
-
---
|
|
103
|
-
|
|
104
|
-
Happy coding on Titan Planet! ๐
|
|
1
|
+
# ๐ช Titan Extension: {{name}}
|
|
2
|
+
|
|
3
|
+
> Elevate Titan Planet with custom JavaScript and high-performance Native Rust logic.
|
|
4
|
+
|
|
5
|
+
Welcome to your new Titan extension! This template provides everything you need to build, test, and deploy powerful additions to the Titan project.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ๐ Project Structure
|
|
10
|
+
|
|
11
|
+
- `index.js`: The JavaScript entry point where you define your extension's API on the global `t` object.
|
|
12
|
+
- `titan.json`: Manifest file defining extension metadata and Native module mappings.
|
|
13
|
+
- `native/`: Directory for Rust source code.
|
|
14
|
+
- `src/lib.rs`: Your Native function implementations.
|
|
15
|
+
- `Cargo.toml`: Rust package and dependency configuration.
|
|
16
|
+
- `jsconfig.json`: Enables full IntelliSense for the Titan Runtime API.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## ๐ Quick Start
|
|
21
|
+
|
|
22
|
+
### 1. Install Dependencies
|
|
23
|
+
Get full type support in your IDE:
|
|
24
|
+
```bash
|
|
25
|
+
npm install
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Build Native Module (Optional)
|
|
29
|
+
If your extension uses Rust, compile it to a dynamic library:
|
|
30
|
+
```bash
|
|
31
|
+
cd native
|
|
32
|
+
cargo build --release
|
|
33
|
+
cd ..
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 3. Test the Extension
|
|
37
|
+
Use the Titan SDK to run a local test harness:
|
|
38
|
+
```bash
|
|
39
|
+
titan run ext
|
|
40
|
+
```
|
|
41
|
+
*Tip: Visit `http://localhost:3000/test` after starting the runner to see your extension in action!*
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## ๐ป Development Guide
|
|
46
|
+
|
|
47
|
+
### Writing JavaScript
|
|
48
|
+
Extensions interact with the global `t` object. It's best practice to namespace your extension:
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
t.{{name}} = {
|
|
52
|
+
myMethod: (val) => {
|
|
53
|
+
t.log("{{name}}", "Doing something...");
|
|
54
|
+
return val * 2;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Writing Native Rust Functions
|
|
60
|
+
Native functions should be marked with `#[unsafe(no_mangle)]` and use `extern "C"`:
|
|
61
|
+
|
|
62
|
+
```rust
|
|
63
|
+
#[unsafe(no_mangle)]
|
|
64
|
+
pub extern "C" fn multiply(a: f64, b: f64) -> f64 {
|
|
65
|
+
a * b
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Mapping Native Functions in `titan.json`
|
|
70
|
+
Expose your Rust functions to JavaScript by adding them to the `native.functions` section:
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
"functions": {
|
|
74
|
+
"add": {
|
|
75
|
+
"symbol": "add",
|
|
76
|
+
"parameters": ["f64", "f64"],
|
|
77
|
+
"result": "f64"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## ๐งช Testing with Titan SDK
|
|
85
|
+
|
|
86
|
+
The `titan run ext` command automates the testing workflow:
|
|
87
|
+
1. It builds your native code.
|
|
88
|
+
2. It sets up a temporary Titan project environment.
|
|
89
|
+
3. It links your extension into `node_modules`.
|
|
90
|
+
4. It starts the Titan Runtime at `http://localhost:3000`.
|
|
91
|
+
|
|
92
|
+
You can modify the test harness or add custom test cases by exploring the generated `.titan_test_run` directory (it is git-ignored).
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## ๐ฆ Deployment
|
|
97
|
+
To use your extension in a Titan project:
|
|
98
|
+
1. Publish your extension to npm or link it locally.
|
|
99
|
+
2. In your Titan project: `npm install my-extension`.
|
|
100
|
+
3. The Titan Runtime will automatically detect and load your extension if it contains a `titan.json`.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
Happy coding on Titan Planet! ๐
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Titan Extension Entry Point
|
|
3
|
-
* You can attach methods to the global `t` object here.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Define your extension Key
|
|
7
|
-
const EXT_KEY = "{{name}}";
|
|
8
|
-
|
|
9
|
-
t.log(EXT_KEY, "Extension loading...");
|
|
10
|
-
|
|
11
|
-
// Preserve any native functions already attached to this key
|
|
12
|
-
t[EXT_KEY] = Object.assign(t[EXT_KEY] || {}, {
|
|
13
|
-
// Example pure JavaScript function
|
|
14
|
-
hello: function (name) {
|
|
15
|
-
t.log(EXT_KEY, `Hello ${name} from ${EXT_KEY}!`);
|
|
16
|
-
return `Hello ${name}!`;
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
// Example Wrapper for Native function
|
|
20
|
-
calc: function (a, b) {
|
|
21
|
-
t.log(EXT_KEY, `Calculating ${a} + ${b} natively...`);
|
|
22
|
-
// Assumes the native function 'add' is mapped in titan.json
|
|
23
|
-
return t[EXT_KEY].add(a, b);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
t.log(EXT_KEY, "Extension loaded!");
|
|
1
|
+
/**
|
|
2
|
+
* Titan Extension Entry Point
|
|
3
|
+
* You can attach methods to the global `t` object here.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Define your extension Key
|
|
7
|
+
const EXT_KEY = "{{name}}";
|
|
8
|
+
|
|
9
|
+
t.log(EXT_KEY, "Extension loading...");
|
|
10
|
+
|
|
11
|
+
// Preserve any native functions already attached to this key
|
|
12
|
+
t[EXT_KEY] = Object.assign(t[EXT_KEY] || {}, {
|
|
13
|
+
// Example pure JavaScript function
|
|
14
|
+
hello: function (name) {
|
|
15
|
+
t.log(EXT_KEY, `Hello ${name} from ${EXT_KEY}!`);
|
|
16
|
+
return `Hello ${name}!`;
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
// Example Wrapper for Native function
|
|
20
|
+
calc: function (a, b) {
|
|
21
|
+
t.log(EXT_KEY, `Calculating ${a} + ${b} natively...`);
|
|
22
|
+
// Assumes the native function 'add' is mapped in titan.json
|
|
23
|
+
return t[EXT_KEY].add(a, b);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
t.log(EXT_KEY, "Extension loaded!");
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"target": "es2021",
|
|
5
|
-
"checkJs": false,
|
|
6
|
-
"allowJs": true,
|
|
7
|
-
"moduleResolution": "node"
|
|
8
|
-
},
|
|
9
|
-
"include": [
|
|
10
|
-
"index.js",
|
|
11
|
-
"node_modules/titan-sdk/index.d.ts"
|
|
12
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"target": "es2021",
|
|
5
|
+
"checkJs": false,
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"moduleResolution": "node"
|
|
8
|
+
},
|
|
9
|
+
"include": [
|
|
10
|
+
"index.js",
|
|
11
|
+
"node_modules/titan-sdk/index.d.ts"
|
|
12
|
+
]
|
|
13
13
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "{{native_name}}_native"
|
|
3
|
-
version = "0.1.0"
|
|
4
|
-
edition = "2024"
|
|
5
|
-
|
|
6
|
-
[lib]
|
|
7
|
-
crate-type = ["cdylib"]
|
|
8
|
-
|
|
9
|
-
[dependencies]
|
|
1
|
+
[package]
|
|
2
|
+
name = "{{native_name}}_native"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
|
|
6
|
+
[lib]
|
|
7
|
+
crate-type = ["cdylib"]
|
|
8
|
+
|
|
9
|
+
[dependencies]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
#[unsafe(no_mangle)]
|
|
3
|
-
pub extern "C" fn add(a: f64, b: f64) -> f64 {
|
|
4
|
-
a + b
|
|
5
|
-
}
|
|
1
|
+
|
|
2
|
+
#[unsafe(no_mangle)]
|
|
3
|
+
pub extern "C" fn add(a: f64, b: f64) -> f64 {
|
|
4
|
+
a + b
|
|
5
|
+
}
|