@ezetgalaxy/titan 26.9.0 → 26.9.1
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 +22 -12
- package/index.js +57 -15
- package/package.json +1 -2
- package/templates/{rust → rust-js}/package.json +1 -1
- package/templates/rust-ts/app/actions/hello.ts +10 -4
- package/templates/rust-ts/app/app.ts +1 -1
- package/templates/rust-ts/titan/bundle.js +15 -9
- package/templates/rust-ts/titan/dev.js +2 -2
- package/templates/rust-ts/titan/titan.d.ts +117 -0
- package/templates/rust-ts/titan/titan.js +95 -95
- package/templates/ts/Dockerfile +16 -42
- package/templates/ts/app/actions/hello.ts +2 -0
- package/templates/ts/app/app.ts +1 -1
- package/templates/ts/titan/builder.js +121 -0
- package/templates/ts/titan/bundle.js +9 -11
- package/templates/ts/titan/dev.js +2 -2
- package/templates/ts/titan/runtime.js +1 -0
- package/templates/ts/titan/titan.d.ts +117 -0
- package/templates/ts/titan/titan.js +95 -95
- package/titanpl-sdk/README.md +4 -4
- package/titanpl-sdk/bin/run.js +74 -77
- package/titanpl-sdk/package.json +1 -1
- package/templates/rust/app/titan.d.ts +0 -101
- package/templates/ts/app/titan.d.ts +0 -102
- /package/templates/{rust → rust-js}/Dockerfile +0 -0
- /package/templates/{rust → rust-js}/_dockerignore +0 -0
- /package/templates/{rust → rust-js}/_gitignore +0 -0
- /package/templates/{rust → rust-js}/app/actions/hello.js +0 -0
- /package/templates/{rust → rust-js}/app/actions/rust_hello.rs +0 -0
- /package/templates/{rust → rust-js}/app/app.js +0 -0
- /package/templates/{rust-ts → rust-js}/app/titan.d.ts +0 -0
- /package/templates/{rust → rust-js}/jsconfig.json +0 -0
- /package/templates/{rust → rust-js}/server/Cargo.lock +0 -0
- /package/templates/{rust → rust-js}/server/Cargo.toml +0 -0
- /package/templates/{rust → rust-js}/server/src/action_management.rs +0 -0
- /package/templates/{rust → rust-js}/server/src/errors.rs +0 -0
- /package/templates/{rust → rust-js}/server/src/extensions.rs +0 -0
- /package/templates/{rust → rust-js}/server/src/main.rs +0 -0
- /package/templates/{rust → rust-js}/server/src/utils.rs +0 -0
- /package/templates/{rust → rust-js}/titan/bundle.js +0 -0
- /package/templates/{rust → rust-js}/titan/dev.js +0 -0
- /package/templates/{rust → rust-js}/titan/titan.js +0 -0
package/titanpl-sdk/bin/run.js
CHANGED
|
@@ -53,85 +53,89 @@ function run() {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
// 3.
|
|
56
|
+
// 3. Setup Test Harness (Mini Titan Project)
|
|
57
57
|
const runDir = path.join(cwd, ".titan_test_run");
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
fs.rmSync(runDir, {
|
|
61
|
-
recursive: true,
|
|
62
|
-
force: true,
|
|
63
|
-
maxRetries: 10,
|
|
64
|
-
retryDelay: 100
|
|
65
|
-
});
|
|
66
|
-
} catch (e) {
|
|
67
|
-
console.log(yellow(`Warning: Could not fully clean ${runDir}. Proceeding anyway...`));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
58
|
+
const isFirstRun = !fs.existsSync(runDir);
|
|
70
59
|
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
if (isFirstRun) {
|
|
61
|
+
console.log(cyan("Initializing test environment..."));
|
|
73
62
|
fs.mkdirSync(runDir, { recursive: true });
|
|
74
|
-
}
|
|
75
63
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
64
|
+
// Create app structure
|
|
65
|
+
const appDir = path.join(runDir, "app");
|
|
66
|
+
fs.mkdirSync(appDir);
|
|
67
|
+
|
|
68
|
+
// Create actions folder (required by Titan build)
|
|
69
|
+
const actionsDir = path.join(appDir, "actions");
|
|
70
|
+
fs.mkdirSync(actionsDir);
|
|
71
|
+
|
|
72
|
+
// Copy titan/ and server/ from templates
|
|
73
|
+
const templatesDir = path.join(__dirname, "..", "templates");
|
|
74
|
+
|
|
75
|
+
const titanSrc = path.join(templatesDir, "titan");
|
|
76
|
+
const titanDest = path.join(runDir, "titan");
|
|
77
|
+
if (fs.existsSync(titanSrc)) {
|
|
78
|
+
copyDir(titanSrc, titanDest);
|
|
79
|
+
// Double check titan.js exists
|
|
80
|
+
if (!fs.existsSync(path.join(titanDest, "titan.js"))) {
|
|
81
|
+
console.log(red(`Error: Failed to copy titan.js to ${titanDest}`));
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
console.log(red(`Error: Titan templates not found at ${titanSrc}`));
|
|
95
86
|
process.exit(1);
|
|
96
87
|
}
|
|
97
|
-
} else {
|
|
98
|
-
console.log(red(`Error: Titan templates not found at ${titanSrc}`));
|
|
99
|
-
process.exit(1);
|
|
100
|
-
}
|
|
101
88
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
89
|
+
const serverSrc = path.join(templatesDir, "server");
|
|
90
|
+
const serverDest = path.join(runDir, "server");
|
|
91
|
+
if (fs.existsSync(serverSrc)) {
|
|
92
|
+
copyDir(serverSrc, serverDest);
|
|
93
|
+
} else {
|
|
94
|
+
console.log(red(`Error: Server templates not found at ${serverSrc}`));
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Create package.json for the test harness
|
|
99
|
+
const pkgJson = {
|
|
100
|
+
"type": "module"
|
|
101
|
+
};
|
|
102
|
+
fs.writeFileSync(path.join(runDir, "package.json"), JSON.stringify(pkgJson, null, 2));
|
|
103
|
+
|
|
104
|
+
// Create 'node_modules'
|
|
105
|
+
fs.mkdirSync(path.join(runDir, "node_modules"));
|
|
107
106
|
} else {
|
|
108
|
-
console.log(
|
|
109
|
-
process.exit(1);
|
|
107
|
+
console.log(cyan("Using existing test environment..."));
|
|
110
108
|
}
|
|
111
109
|
|
|
112
|
-
//
|
|
113
|
-
const pkgJson = {
|
|
114
|
-
"type": "module"
|
|
115
|
-
};
|
|
116
|
-
fs.writeFileSync(path.join(runDir, "package.json"), JSON.stringify(pkgJson, null, 2));
|
|
117
|
-
|
|
118
|
-
// Create 'node_modules' to link the extension
|
|
110
|
+
// Always Ensure Extension Link is Fresh
|
|
119
111
|
const nmDir = path.join(runDir, "node_modules");
|
|
120
|
-
fs.mkdirSync(nmDir);
|
|
112
|
+
if (!fs.existsSync(nmDir)) fs.mkdirSync(nmDir, { recursive: true });
|
|
121
113
|
|
|
122
|
-
// Link current extension to node_modules/NAME
|
|
123
|
-
// Use junction for Windows compat without admin rights
|
|
124
114
|
const extDest = path.join(nmDir, name);
|
|
115
|
+
|
|
116
|
+
// Remove old link/folder if exists to ensure freshness
|
|
117
|
+
if (fs.existsSync(extDest)) {
|
|
118
|
+
try {
|
|
119
|
+
fs.rmSync(extDest, { recursive: true, force: true });
|
|
120
|
+
} catch (e) { }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Link current extension to node_modules/NAME
|
|
125
124
|
try {
|
|
125
|
+
// Use junction for Windows compat without admin rights
|
|
126
126
|
fs.symlinkSync(cwd, extDest, "junction");
|
|
127
127
|
} catch (e) {
|
|
128
128
|
// Fallback to copy if link fails
|
|
129
|
-
console.log(yellow("Linking failed, copying extension files..."));
|
|
129
|
+
// console.log(yellow("Linking failed, copying extension files..."));
|
|
130
130
|
copyDir(cwd, extDest);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
// Create
|
|
134
|
-
const
|
|
133
|
+
// Create default test files ONLY if they don't exist
|
|
134
|
+
const actionsDir = path.join(runDir, "app", "actions");
|
|
135
|
+
const testActionPath = path.join(actionsDir, "test.js");
|
|
136
|
+
|
|
137
|
+
if (!fs.existsSync(testActionPath)) {
|
|
138
|
+
const testAction = `export const test = (req) => {
|
|
135
139
|
const ext = t["${name}"];
|
|
136
140
|
|
|
137
141
|
const results = {
|
|
@@ -160,12 +164,12 @@ function run() {
|
|
|
160
164
|
return results;
|
|
161
165
|
};
|
|
162
166
|
`;
|
|
167
|
+
fs.writeFileSync(testActionPath, testAction);
|
|
168
|
+
}
|
|
163
169
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// This script will be executed by Titan
|
|
168
|
-
const testScript = `import t from "../titan/titan.js";
|
|
170
|
+
const appJsPath = path.join(runDir, "app", "app.js");
|
|
171
|
+
if (!fs.existsSync(appJsPath)) {
|
|
172
|
+
const testScript = `import t from "../titan/titan.js";
|
|
169
173
|
import "${name}";
|
|
170
174
|
|
|
171
175
|
// Extension test harness for: ${name}
|
|
@@ -217,37 +221,30 @@ t.get("/").reply("🚀 Extension Test Harness for ${name}\\n\\nVisit /test to se
|
|
|
217
221
|
|
|
218
222
|
await t.start(3000, "Titan Extension Test Running!");
|
|
219
223
|
`;
|
|
220
|
-
|
|
221
|
-
|
|
224
|
+
fs.writeFileSync(appJsPath, testScript);
|
|
225
|
+
}
|
|
222
226
|
|
|
223
227
|
// Build the app (bundle actions)
|
|
224
228
|
console.log(cyan("Building test app..."));
|
|
225
229
|
try {
|
|
226
|
-
// Ensure we are in runDir and the file exists
|
|
227
|
-
const appJsPath = path.join(runDir, "app", "app.js");
|
|
228
|
-
if (!fs.existsSync(appJsPath)) {
|
|
229
|
-
throw new Error(`app/app.js missing at ${appJsPath}`);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
230
|
execSync("node app/app.js --build", {
|
|
233
231
|
cwd: runDir,
|
|
234
232
|
stdio: "inherit",
|
|
235
233
|
env: { ...process.env, NODE_OPTIONS: "--no-warnings" }
|
|
236
234
|
});
|
|
237
235
|
} catch (e) {
|
|
238
|
-
console.log(red("Failed to build test app.
|
|
239
|
-
// Don't exit here, attempt to continue to show runtime errors if possible
|
|
236
|
+
console.log(red("Failed to build test app. checking for runtime errors..."));
|
|
240
237
|
}
|
|
241
238
|
|
|
242
|
-
// 4. Run Titan Server using cargo run
|
|
243
|
-
console.log(green("
|
|
239
|
+
// 4. Run Titan Server using cargo run
|
|
240
|
+
console.log(green("\\x1b[1m\\n>>> STARTING EXTENSION TEST >>>\\n\\x1b[0m"));
|
|
244
241
|
|
|
245
242
|
const serverDir = path.join(runDir, "server");
|
|
246
243
|
|
|
247
244
|
try {
|
|
248
245
|
execSync("cargo run", { cwd: serverDir, stdio: "inherit" });
|
|
249
246
|
} catch (e) {
|
|
250
|
-
console.log(red("Runtime exited."));
|
|
247
|
+
// console.log(red("Runtime exited."));
|
|
251
248
|
}
|
|
252
249
|
}
|
|
253
250
|
|
package/titanpl-sdk/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "titanpl-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
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",
|
|
@@ -1,101 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TITAN TYPE DEFINITIONS
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The Titan Request Object passed to actions.
|
|
7
|
-
*/
|
|
8
|
-
interface TitanRequest {
|
|
9
|
-
body: any;
|
|
10
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
11
|
-
path: string;
|
|
12
|
-
headers: {
|
|
13
|
-
host?: string;
|
|
14
|
-
"content-type"?: string;
|
|
15
|
-
"user-agent"?: string;
|
|
16
|
-
authorization?: string;
|
|
17
|
-
[key: string]: string | undefined;
|
|
18
|
-
};
|
|
19
|
-
params: Record<string, string>;
|
|
20
|
-
query: Record<string, string>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface DbConnection {
|
|
24
|
-
/**
|
|
25
|
-
* Execute a SQL query.
|
|
26
|
-
* @param sql The SQL query string.
|
|
27
|
-
* @param params (Optional) Parameters for the query ($1, $2, etc).
|
|
28
|
-
*/
|
|
29
|
-
query(sql: string, params?: any[]): any[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Define a Titan Action with type inference.
|
|
34
|
-
* @example
|
|
35
|
-
* export const hello = defineAction((req) => {
|
|
36
|
-
* return req.headers;
|
|
37
|
-
* });
|
|
38
|
-
*/
|
|
39
|
-
declare function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Titan Runtime Utilities
|
|
43
|
-
*/
|
|
44
|
-
declare const t: {
|
|
45
|
-
/**
|
|
46
|
-
* Log messages to the server console with Titan formatting.
|
|
47
|
-
*/
|
|
48
|
-
log(...args: any[]): void;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Read a file contents as string.
|
|
52
|
-
* @param path Relative path to the file from project root.
|
|
53
|
-
*/
|
|
54
|
-
read(path: string): string;
|
|
55
|
-
|
|
56
|
-
fetch(url: string, options?: {
|
|
57
|
-
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
58
|
-
headers?: Record<string, string>;
|
|
59
|
-
body?: string | object;
|
|
60
|
-
}): {
|
|
61
|
-
ok: boolean;
|
|
62
|
-
status?: number;
|
|
63
|
-
body?: string;
|
|
64
|
-
error?: string;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
jwt: {
|
|
68
|
-
sign(
|
|
69
|
-
payload: object,
|
|
70
|
-
secret: string,
|
|
71
|
-
options?: { expiresIn?: string | number }
|
|
72
|
-
): string;
|
|
73
|
-
verify(token: string, secret: string): any;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
password: {
|
|
77
|
-
hash(password: string): string;
|
|
78
|
-
verify(password: string, hash: string): boolean;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
db: {
|
|
82
|
-
connect(url: string): DbConnection;
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// Declaring module for import t from "../titan/titan.js"
|
|
87
|
-
declare module "*titan.js" {
|
|
88
|
-
export interface RouteHandler {
|
|
89
|
-
reply(value: any): void;
|
|
90
|
-
action(name: string): void;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface Titan {
|
|
94
|
-
get(route: string): RouteHandler;
|
|
95
|
-
post(route: string): RouteHandler;
|
|
96
|
-
log(module: string, msg: string): void;
|
|
97
|
-
start(port?: number, msg?: string): Promise<void>;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const t: Titan;
|
|
101
|
-
export default t;
|
|
102
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|