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
|
@@ -22,8 +22,17 @@ export function defineAction<T = any>(handler: (req: Request) => T | Promise<T>)
|
|
|
22
22
|
export function fetch(url: string, options?: any): any;
|
|
23
23
|
export function drift<T>(op: any): T;
|
|
24
24
|
|
|
25
|
+
export interface ShareContext {
|
|
26
|
+
get(key: string): any;
|
|
27
|
+
set(key: string, value: any): void;
|
|
28
|
+
delete(key: string): void;
|
|
29
|
+
keys(): string[];
|
|
30
|
+
broadcast(event: string, payload: any): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
// Add more as needed based on native/index.js
|
|
26
34
|
export const db: any;
|
|
35
|
+
export const ws: any;
|
|
27
36
|
export const path: any;
|
|
28
37
|
export const jwt: any;
|
|
29
38
|
export const password: any;
|
|
@@ -32,6 +41,7 @@ export const buffer: any;
|
|
|
32
41
|
export const ls: any;
|
|
33
42
|
export const session: any;
|
|
34
43
|
export const cookies: any;
|
|
44
|
+
export const shareContext: ShareContext;
|
|
35
45
|
export const os: any;
|
|
36
46
|
export const net: any;
|
|
37
47
|
export const proc: any;
|
package/packages/native/index.js
CHANGED
|
@@ -11,6 +11,9 @@ export const password = t.password;
|
|
|
11
11
|
// Database
|
|
12
12
|
export const db = t.db;
|
|
13
13
|
|
|
14
|
+
// WebSockets
|
|
15
|
+
export const ws = t.ws;
|
|
16
|
+
|
|
14
17
|
// File System & Path
|
|
15
18
|
export const fs = t.fs;
|
|
16
19
|
export const path = t.path;
|
|
@@ -24,6 +27,7 @@ export const ls = t.ls;
|
|
|
24
27
|
export const localStorage = t.localStorage;
|
|
25
28
|
export const session = t.session;
|
|
26
29
|
export const cookies = t.cookies;
|
|
30
|
+
export const shareContext = t.shareContext;
|
|
27
31
|
|
|
28
32
|
// System
|
|
29
33
|
export const os = t.os;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Titan Planet — Type Definitions
|
|
3
3
|
// Framework: JavaScript-first backend compiled to native Rust + Axum binary
|
|
4
4
|
// Version: v26 (Stable)
|
|
5
|
-
// Docs: https://
|
|
5
|
+
// Docs: https://titanpl.vercel.app/docs
|
|
6
6
|
// GitHub: https://github.com/ezet-galaxy/titanpl
|
|
7
7
|
// =============================================================================
|
|
8
8
|
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
* }
|
|
29
29
|
* ```
|
|
30
30
|
*
|
|
31
|
-
* @see https://
|
|
32
|
-
* @see https://
|
|
31
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/02-actions — Actions documentation
|
|
32
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/01-routes — Routes & parameters
|
|
33
33
|
*/
|
|
34
34
|
export interface TitanRequest {
|
|
35
35
|
/**
|
|
@@ -106,7 +106,7 @@ export interface TitanRequest {
|
|
|
106
106
|
* }
|
|
107
107
|
* ```
|
|
108
108
|
*
|
|
109
|
-
* @see https://
|
|
109
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/01-routes#dynamic-routes-useridnumber — Dynamic routes
|
|
110
110
|
*/
|
|
111
111
|
params: Record<string, string>;
|
|
112
112
|
|
|
@@ -130,6 +130,18 @@ export interface TitanRequest {
|
|
|
130
130
|
* ```
|
|
131
131
|
*/
|
|
132
132
|
query: Record<string, string>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The unique ID of the WebSocket connection.
|
|
136
|
+
* Only present during WebSocket events (`open`, `message`, `close`).
|
|
137
|
+
*/
|
|
138
|
+
socketId?: string;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The type of WebSocket event: "open", "message", or "close".
|
|
142
|
+
* Only present during WebSocket execution.
|
|
143
|
+
*/
|
|
144
|
+
event?: "open" | "message" | "close";
|
|
133
145
|
}
|
|
134
146
|
|
|
135
147
|
/**
|
|
@@ -167,7 +179,7 @@ export interface TitanRequest {
|
|
|
167
179
|
* });
|
|
168
180
|
* ```
|
|
169
181
|
*
|
|
170
|
-
* @see https://
|
|
182
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/02-actions — Action definition patterns
|
|
171
183
|
*/
|
|
172
184
|
export function defineAction<T>(
|
|
173
185
|
handler: (req: TitanRequest) => T
|
|
@@ -285,6 +297,14 @@ export const session: typeof t.session;
|
|
|
285
297
|
*/
|
|
286
298
|
export const cookies: typeof t.cookies;
|
|
287
299
|
|
|
300
|
+
/**
|
|
301
|
+
* Titan Shared Context (Shared In-Memory State) shorthand.
|
|
302
|
+
*
|
|
303
|
+
* Re-exported from the `t` global for module-style imports.
|
|
304
|
+
* @see {@link TitanCore.ShareContext} for full documentation.
|
|
305
|
+
*/
|
|
306
|
+
export const shareContext: typeof t.shareContext;
|
|
307
|
+
|
|
288
308
|
/**
|
|
289
309
|
* Operating system information (platform, CPU count, memory).
|
|
290
310
|
*
|
|
@@ -331,7 +351,6 @@ export const url: typeof t.url;
|
|
|
331
351
|
* Provides schema-based validation for request data. Works with
|
|
332
352
|
* the `@titanpl/valid` package for advanced validation rules.
|
|
333
353
|
*
|
|
334
|
-
* @see https://titan-docs-ez.vercel.app/docs/12-sdk — TitanPl SDK
|
|
335
354
|
*/
|
|
336
355
|
export const valid: any;
|
|
337
356
|
|
|
@@ -406,8 +425,8 @@ declare global {
|
|
|
406
425
|
* }
|
|
407
426
|
* ```
|
|
408
427
|
*
|
|
409
|
-
* @see https://
|
|
410
|
-
* @see https://
|
|
428
|
+
* @see https://titanpl.vercel.app/docs/knowledge/04-drift — Drift documentation
|
|
429
|
+
* @see https://titanpl.vercel.app/docs/knowledge/02-runtime-architecture — Gravity Runtime
|
|
411
430
|
*/
|
|
412
431
|
var drift: <T>(promise: Promise<T> | T) => T;
|
|
413
432
|
|
|
@@ -440,7 +459,7 @@ declare global {
|
|
|
440
459
|
* }
|
|
441
460
|
* ```
|
|
442
461
|
*
|
|
443
|
-
* @see https://
|
|
462
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs
|
|
444
463
|
*/
|
|
445
464
|
interface DbConnection {
|
|
446
465
|
/**
|
|
@@ -500,7 +519,7 @@ declare global {
|
|
|
500
519
|
* }
|
|
501
520
|
* ```
|
|
502
521
|
*
|
|
503
|
-
* @see https://
|
|
522
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Complete Runtime APIs reference
|
|
504
523
|
*/
|
|
505
524
|
interface TitanRuntimeUtils {
|
|
506
525
|
|
|
@@ -530,7 +549,7 @@ declare global {
|
|
|
530
549
|
* t.log("Multiple", "values", { are: "supported" }, 42);
|
|
531
550
|
* ```
|
|
532
551
|
*
|
|
533
|
-
* @see https://
|
|
552
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/07-logs — Gravity Logs
|
|
534
553
|
*/
|
|
535
554
|
log(...args: any[]): void;
|
|
536
555
|
|
|
@@ -553,7 +572,7 @@ declare global {
|
|
|
553
572
|
* }
|
|
554
573
|
* ```
|
|
555
574
|
*
|
|
556
|
-
* @see https://
|
|
575
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs
|
|
557
576
|
*/
|
|
558
577
|
read(path: string): string;
|
|
559
578
|
|
|
@@ -616,7 +635,7 @@ declare global {
|
|
|
616
635
|
* }
|
|
617
636
|
* ```
|
|
618
637
|
*
|
|
619
|
-
* @see https://
|
|
638
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.fetch)
|
|
620
639
|
*/
|
|
621
640
|
fetch(url: string, options?: {
|
|
622
641
|
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
@@ -629,6 +648,38 @@ declare global {
|
|
|
629
648
|
error?: string;
|
|
630
649
|
}>;
|
|
631
650
|
|
|
651
|
+
/**
|
|
652
|
+
* WebSocket communication utilities.
|
|
653
|
+
*
|
|
654
|
+
* Allows sending direct messages or broadcasting to all active sockets.
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```js
|
|
658
|
+
* export default function chat(req) {
|
|
659
|
+
* if (req.event === "open") {
|
|
660
|
+
* t.ws.send(req.socketId, "Welcome!");
|
|
661
|
+
* t.ws.broadcast("Someone joined.");
|
|
662
|
+
* }
|
|
663
|
+
* }
|
|
664
|
+
* ```
|
|
665
|
+
*/
|
|
666
|
+
ws: {
|
|
667
|
+
/**
|
|
668
|
+
* Send a text message to a specific WebSocket client.
|
|
669
|
+
*
|
|
670
|
+
* @param socketId - The unique ID of the target connection.
|
|
671
|
+
* @param message - The text message to send.
|
|
672
|
+
*/
|
|
673
|
+
send(socketId: string, message: string): void;
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Broadcast a text message to ALL active WebSocket connections.
|
|
677
|
+
*
|
|
678
|
+
* @param message - The text message to broadcast.
|
|
679
|
+
*/
|
|
680
|
+
broadcast(message: string): void;
|
|
681
|
+
};
|
|
682
|
+
|
|
632
683
|
|
|
633
684
|
// -------------------------------------------------------------------
|
|
634
685
|
// Authentication & Security
|
|
@@ -669,7 +720,7 @@ declare global {
|
|
|
669
720
|
* }
|
|
670
721
|
* ```
|
|
671
722
|
*
|
|
672
|
-
* @see https://
|
|
723
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.jwt)
|
|
673
724
|
*/
|
|
674
725
|
jwt: {
|
|
675
726
|
/**
|
|
@@ -737,7 +788,7 @@ declare global {
|
|
|
737
788
|
* }
|
|
738
789
|
* ```
|
|
739
790
|
*
|
|
740
|
-
* @see https://
|
|
791
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.password)
|
|
741
792
|
*/
|
|
742
793
|
password: {
|
|
743
794
|
/**
|
|
@@ -811,7 +862,7 @@ declare global {
|
|
|
811
862
|
* }
|
|
812
863
|
* ```
|
|
813
864
|
*
|
|
814
|
-
* @see https://
|
|
865
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.db)
|
|
815
866
|
*/
|
|
816
867
|
db: {
|
|
817
868
|
/**
|
|
@@ -884,7 +935,7 @@ declare global {
|
|
|
884
935
|
* directories. All methods return `Promise` — use `drift()` to resolve.
|
|
885
936
|
*
|
|
886
937
|
* @see {@link TitanCore.FileSystem} for method signatures.
|
|
887
|
-
* @see https://
|
|
938
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.fs)
|
|
888
939
|
*/
|
|
889
940
|
fs: TitanCore.FileSystem;
|
|
890
941
|
|
|
@@ -895,7 +946,7 @@ declare global {
|
|
|
895
946
|
* cross-platform path joining, resolving, and component extraction.
|
|
896
947
|
*
|
|
897
948
|
* @see {@link TitanCore.Path} for method signatures.
|
|
898
|
-
* @see https://
|
|
949
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.path)
|
|
899
950
|
*/
|
|
900
951
|
path: TitanCore.Path;
|
|
901
952
|
|
|
@@ -911,7 +962,7 @@ declare global {
|
|
|
911
962
|
* random bytes generation, and UUID creation. Async methods require `drift()`.
|
|
912
963
|
*
|
|
913
964
|
* @see {@link TitanCore.Crypto} for method signatures.
|
|
914
|
-
* @see https://
|
|
965
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.crypto)
|
|
915
966
|
*/
|
|
916
967
|
crypto: TitanCore.Crypto;
|
|
917
968
|
|
|
@@ -921,7 +972,7 @@ declare global {
|
|
|
921
972
|
* All methods are **synchronous** — no `drift()` needed.
|
|
922
973
|
*
|
|
923
974
|
* @see {@link TitanCore.BufferModule} for method signatures.
|
|
924
|
-
* @see https://
|
|
975
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.buffer)
|
|
925
976
|
*/
|
|
926
977
|
buffer: TitanCore.BufferModule;
|
|
927
978
|
|
|
@@ -940,7 +991,7 @@ declare global {
|
|
|
940
991
|
* @suggestion Use `setObject`/`getObject` for complex data structures to maintain types.
|
|
941
992
|
|
|
942
993
|
* @see {@link TitanCore.LocalStorage} for method signatures.
|
|
943
|
-
* @see https://
|
|
994
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.ls)
|
|
944
995
|
*/
|
|
945
996
|
ls: TitanCore.LocalStorage;
|
|
946
997
|
|
|
@@ -951,7 +1002,7 @@ declare global {
|
|
|
951
1002
|
* **synchronous**. Identical to `t.ls` — use whichever alias you prefer.
|
|
952
1003
|
*
|
|
953
1004
|
* @see {@link TitanCore.LocalStorage} for method signatures.
|
|
954
|
-
* @see https://
|
|
1005
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.localStorage)
|
|
955
1006
|
*/
|
|
956
1007
|
localStorage: TitanCore.LocalStorage;
|
|
957
1008
|
|
|
@@ -965,15 +1016,28 @@ declare global {
|
|
|
965
1016
|
* All methods are **synchronous**.
|
|
966
1017
|
*
|
|
967
1018
|
* @see {@link TitanCore.Session} for method signatures.
|
|
968
|
-
* @see https://
|
|
1019
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.session)
|
|
969
1020
|
*/
|
|
970
1021
|
session: TitanCore.Session;
|
|
971
1022
|
|
|
1023
|
+
/**
|
|
1024
|
+
* Titan Shared Context — Cross-isolate Shared In-Memory State.
|
|
1025
|
+
*
|
|
1026
|
+
* Provides a mechanism for sharing data across different isolates (requests)
|
|
1027
|
+
* and broadcasting events within the same server process.
|
|
1028
|
+
*
|
|
1029
|
+
* Data in `shareContext` is volatile and lost when the server exits.
|
|
1030
|
+
*
|
|
1031
|
+
* @see {@link TitanCore.ShareContext} for method signatures.
|
|
1032
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.shareContext)
|
|
1033
|
+
*/
|
|
1034
|
+
shareContext: TitanCore.ShareContext;
|
|
1035
|
+
|
|
972
1036
|
/**
|
|
973
1037
|
* HTTP cookie utilities for reading, setting, and deleting cookies.
|
|
974
1038
|
*
|
|
975
1039
|
* @see {@link TitanCore.Cookies} for method signatures.
|
|
976
|
-
* @see https://
|
|
1040
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.cookies)
|
|
977
1041
|
*/
|
|
978
1042
|
cookies: TitanCore.Cookies;
|
|
979
1043
|
|
|
@@ -989,7 +1053,7 @@ declare global {
|
|
|
989
1053
|
* host machine running the Titan server.
|
|
990
1054
|
*
|
|
991
1055
|
* @see {@link TitanCore.OS} for method signatures.
|
|
992
|
-
* @see https://
|
|
1056
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.os)
|
|
993
1057
|
*/
|
|
994
1058
|
os: TitanCore.OS;
|
|
995
1059
|
|
|
@@ -999,7 +1063,7 @@ declare global {
|
|
|
999
1063
|
* All methods return `Promise` — use `drift()` to resolve.
|
|
1000
1064
|
*
|
|
1001
1065
|
* @see {@link TitanCore.Net} for method signatures.
|
|
1002
|
-
* @see https://
|
|
1066
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.net)
|
|
1003
1067
|
*/
|
|
1004
1068
|
net: TitanCore.Net;
|
|
1005
1069
|
|
|
@@ -1009,7 +1073,7 @@ declare global {
|
|
|
1009
1073
|
* All methods are **synchronous**.
|
|
1010
1074
|
*
|
|
1011
1075
|
* @see {@link TitanCore.Process} for method signatures.
|
|
1012
|
-
* @see https://
|
|
1076
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.proc)
|
|
1013
1077
|
*/
|
|
1014
1078
|
proc: TitanCore.Process;
|
|
1015
1079
|
|
|
@@ -1024,7 +1088,7 @@ declare global {
|
|
|
1024
1088
|
* `t.time.sleep()` is async (requires `drift()`); other methods are synchronous.
|
|
1025
1089
|
*
|
|
1026
1090
|
* @see {@link TitanCore.Time} for method signatures.
|
|
1027
|
-
* @see https://
|
|
1091
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.time)
|
|
1028
1092
|
*/
|
|
1029
1093
|
time: TitanCore.Time;
|
|
1030
1094
|
|
|
@@ -1032,7 +1096,7 @@ declare global {
|
|
|
1032
1096
|
* URL parsing and formatting utilities.
|
|
1033
1097
|
*
|
|
1034
1098
|
* @see {@link TitanCore.URLModule} for method signatures.
|
|
1035
|
-
* @see https://
|
|
1099
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.url)
|
|
1036
1100
|
*/
|
|
1037
1101
|
url: TitanCore.URLModule;
|
|
1038
1102
|
|
|
@@ -1055,7 +1119,7 @@ declare global {
|
|
|
1055
1119
|
* Custom extensions attach their methods to the `t` object at runtime,
|
|
1056
1120
|
* making them available as `t.myExtension.someMethod()`.
|
|
1057
1121
|
*
|
|
1058
|
-
* @see https://
|
|
1122
|
+
* @see https://titanpl.vercel.app/docs/10-extensions — Extensions documentation
|
|
1059
1123
|
*/
|
|
1060
1124
|
[key: string]: any;
|
|
1061
1125
|
|
|
@@ -1077,8 +1141,8 @@ declare global {
|
|
|
1077
1141
|
* }
|
|
1078
1142
|
* ```
|
|
1079
1143
|
*
|
|
1080
|
-
* @see https://
|
|
1081
|
-
* @see https://
|
|
1144
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Full API reference
|
|
1145
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs
|
|
1082
1146
|
*/
|
|
1083
1147
|
const t: TitanRuntimeUtils;
|
|
1084
1148
|
|
|
@@ -1142,7 +1206,7 @@ declare global {
|
|
|
1142
1206
|
* }
|
|
1143
1207
|
* ```
|
|
1144
1208
|
*
|
|
1145
|
-
* @see https://
|
|
1209
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.fs)
|
|
1146
1210
|
*/
|
|
1147
1211
|
interface FileSystem {
|
|
1148
1212
|
/**
|
|
@@ -1232,7 +1296,7 @@ declare global {
|
|
|
1232
1296
|
* t.path.basename("/a/b/c.txt"); // → "c.txt"
|
|
1233
1297
|
* ```
|
|
1234
1298
|
*
|
|
1235
|
-
* @see https://
|
|
1299
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.path)
|
|
1236
1300
|
*/
|
|
1237
1301
|
interface Path {
|
|
1238
1302
|
/**
|
|
@@ -1320,7 +1384,7 @@ declare global {
|
|
|
1320
1384
|
* }
|
|
1321
1385
|
* ```
|
|
1322
1386
|
*
|
|
1323
|
-
* @see https://
|
|
1387
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.crypto)
|
|
1324
1388
|
*/
|
|
1325
1389
|
interface Crypto {
|
|
1326
1390
|
/**
|
|
@@ -1463,7 +1527,7 @@ declare global {
|
|
|
1463
1527
|
* const bytes = t.buffer.fromHex(hex);
|
|
1464
1528
|
* ```
|
|
1465
1529
|
*
|
|
1466
|
-
* @see https://
|
|
1530
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.buffer)
|
|
1467
1531
|
*/
|
|
1468
1532
|
interface BufferModule {
|
|
1469
1533
|
/**
|
|
@@ -1546,7 +1610,7 @@ declare global {
|
|
|
1546
1610
|
* t.ls.clear();
|
|
1547
1611
|
* ```
|
|
1548
1612
|
*
|
|
1549
|
-
* @see https://
|
|
1613
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.ls / t.localStorage)
|
|
1550
1614
|
*/
|
|
1551
1615
|
interface LocalStorage {
|
|
1552
1616
|
/**
|
|
@@ -1651,7 +1715,7 @@ declare global {
|
|
|
1651
1715
|
* }
|
|
1652
1716
|
* ```
|
|
1653
1717
|
*
|
|
1654
|
-
* @see https://
|
|
1718
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.session)
|
|
1655
1719
|
*/
|
|
1656
1720
|
interface Session {
|
|
1657
1721
|
/**
|
|
@@ -1688,6 +1752,73 @@ declare global {
|
|
|
1688
1752
|
clear(sessionId: string): void;
|
|
1689
1753
|
}
|
|
1690
1754
|
|
|
1755
|
+
/**
|
|
1756
|
+
* Titan Shared Context — Cross-isolate Shared In-Memory State.
|
|
1757
|
+
*
|
|
1758
|
+
* Provides a mechanism for sharing data across different isolates (requests)
|
|
1759
|
+
* and broadcasting events within the same server process.
|
|
1760
|
+
*
|
|
1761
|
+
* Data in `shareContext` is in-memory only and is lost when the server process exits.
|
|
1762
|
+
*
|
|
1763
|
+
* @example
|
|
1764
|
+
* ```js
|
|
1765
|
+
* export function getStats(req) {
|
|
1766
|
+
* // Store a value common to all requests
|
|
1767
|
+
* t.shareContext.set("last_login", t.time.now());
|
|
1768
|
+
*
|
|
1769
|
+
* // Retrieve a value
|
|
1770
|
+
* const users = t.shareContext.get("active_users");
|
|
1771
|
+
*
|
|
1772
|
+
* // Broadcast a message to other workers
|
|
1773
|
+
* t.shareContext.broadcast("user_login", { user: "Titan" });
|
|
1774
|
+
* }
|
|
1775
|
+
* ```
|
|
1776
|
+
*
|
|
1777
|
+
* @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.shareContext)
|
|
1778
|
+
*/
|
|
1779
|
+
interface ShareContext {
|
|
1780
|
+
/**
|
|
1781
|
+
* Retrieve a value from the shared context.
|
|
1782
|
+
*
|
|
1783
|
+
* @param key - The key of the value to retrieve.
|
|
1784
|
+
* @returns The parsed value, or `null` if the key does not exist.
|
|
1785
|
+
*/
|
|
1786
|
+
get(key: string): any;
|
|
1787
|
+
|
|
1788
|
+
/**
|
|
1789
|
+
* Store a value in the shared context.
|
|
1790
|
+
*
|
|
1791
|
+
* Values are serialized as JSON and must be serializable.
|
|
1792
|
+
*
|
|
1793
|
+
* @param key - The key to store under.
|
|
1794
|
+
* @param value - The JSON-serializable value to store.
|
|
1795
|
+
*/
|
|
1796
|
+
set(key: string, value: any): void;
|
|
1797
|
+
|
|
1798
|
+
/**
|
|
1799
|
+
* Remove a key and its value from the shared context.
|
|
1800
|
+
*
|
|
1801
|
+
* @param key - The key to remove.
|
|
1802
|
+
*/
|
|
1803
|
+
delete(key: string): void;
|
|
1804
|
+
|
|
1805
|
+
/**
|
|
1806
|
+
* Get a list of all keys currently in the shared context.
|
|
1807
|
+
*
|
|
1808
|
+
* @returns An array of string keys.
|
|
1809
|
+
*/
|
|
1810
|
+
keys(): string[];
|
|
1811
|
+
|
|
1812
|
+
/**
|
|
1813
|
+
* Broadcast an event and payload to other active isolates (requests)
|
|
1814
|
+
* and workers in this server process.
|
|
1815
|
+
*
|
|
1816
|
+
* @param event - The name of the event to broadcast.
|
|
1817
|
+
* @param payload - The payload of the event.
|
|
1818
|
+
*/
|
|
1819
|
+
broadcast(event: string, payload: any): void;
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1691
1822
|
/**
|
|
1692
1823
|
* HTTP cookie management utilities.
|
|
1693
1824
|
*
|
|
@@ -1713,7 +1844,7 @@ declare global {
|
|
|
1713
1844
|
* }
|
|
1714
1845
|
* ```
|
|
1715
1846
|
*
|
|
1716
|
-
* @see https://
|
|
1847
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.cookies)
|
|
1717
1848
|
*/
|
|
1718
1849
|
interface Cookies {
|
|
1719
1850
|
/**
|
|
@@ -1762,7 +1893,7 @@ declare global {
|
|
|
1762
1893
|
* }
|
|
1763
1894
|
* ```
|
|
1764
1895
|
*
|
|
1765
|
-
* @see https://
|
|
1896
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.os)
|
|
1766
1897
|
*/
|
|
1767
1898
|
interface OS {
|
|
1768
1899
|
/**
|
|
@@ -1816,7 +1947,7 @@ declare global {
|
|
|
1816
1947
|
* }
|
|
1817
1948
|
* ```
|
|
1818
1949
|
*
|
|
1819
|
-
* @see https://
|
|
1950
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.net)
|
|
1820
1951
|
*/
|
|
1821
1952
|
interface Net {
|
|
1822
1953
|
/**
|
|
@@ -1859,7 +1990,7 @@ declare global {
|
|
|
1859
1990
|
* }
|
|
1860
1991
|
* ```
|
|
1861
1992
|
*
|
|
1862
|
-
* @see https://
|
|
1993
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.proc)
|
|
1863
1994
|
*/
|
|
1864
1995
|
interface Process {
|
|
1865
1996
|
/**
|
|
@@ -1900,7 +2031,7 @@ declare global {
|
|
|
1900
2031
|
* }
|
|
1901
2032
|
* ```
|
|
1902
2033
|
*
|
|
1903
|
-
* @see https://
|
|
2034
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.time)
|
|
1904
2035
|
*/
|
|
1905
2036
|
interface Time {
|
|
1906
2037
|
/**
|
|
@@ -1954,7 +2085,7 @@ declare global {
|
|
|
1954
2085
|
* // → "https://api.example.com/v2/users"
|
|
1955
2086
|
* ```
|
|
1956
2087
|
*
|
|
1957
|
-
* @see https://
|
|
2088
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.url)
|
|
1958
2089
|
*/
|
|
1959
2090
|
interface URLModule {
|
|
1960
2091
|
/**
|
|
@@ -8,4 +8,3 @@ This library parses all your app routes, components, middleware, and logic paths
|
|
|
8
8
|
## How it works
|
|
9
9
|
This package is triggered whenever you run `titan init` or `titan build` from the `@titanpl/cli`. It hooks into tools like `esbuild` to optimize your scripts efficiently. It strips unnecessary pieces out so that only explicit route actions make their way aggressively over to the Titan runtime engine.
|
|
10
10
|
|
|
11
|
-
**Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux version is in development (dev only) for the new architecture and will be launched later.
|
package/packages/packet/index.js
CHANGED
|
@@ -67,6 +67,15 @@ export async function build(root = process.cwd()) {
|
|
|
67
67
|
outDir: dist,
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
+
const tanfigPath = path.join(root, "tanfig.json");
|
|
71
|
+
if (fs.existsSync(tanfigPath)) {
|
|
72
|
+
fs.copyFileSync(tanfigPath, path.join(dist, "tanfig.json"));
|
|
73
|
+
}
|
|
74
|
+
const titanExtPath = path.join(root, "titan.json");
|
|
75
|
+
if (fs.existsSync(titanExtPath)) {
|
|
76
|
+
fs.copyFileSync(titanExtPath, path.join(dist, "titan.json"));
|
|
77
|
+
}
|
|
78
|
+
|
|
70
79
|
return dist;
|
|
71
80
|
}
|
|
72
81
|
|
|
@@ -91,7 +100,7 @@ export async function release(root = process.cwd()) {
|
|
|
91
100
|
} catch (e) { }
|
|
92
101
|
}
|
|
93
102
|
|
|
94
|
-
const filesToCopy = config.build && config.build.files ? config.build.files : ["public", "static", "db", "config"];
|
|
103
|
+
const filesToCopy = config.build && config.build.files ? config.build.files : ["public", "static", "db", "config", "tanfig.json", "titan.json"];
|
|
95
104
|
|
|
96
105
|
// Clear or ensure build dir
|
|
97
106
|
if (fs.existsSync(buildDir)) {
|
|
@@ -111,11 +120,19 @@ export async function release(root = process.cwd()) {
|
|
|
111
120
|
}
|
|
112
121
|
}
|
|
113
122
|
|
|
114
|
-
// 3. Copy package.json
|
|
123
|
+
// 3. Copy package.json & tanfig.json
|
|
115
124
|
const pkgPath = path.join(root, "package.json");
|
|
116
125
|
if (fs.existsSync(pkgPath)) {
|
|
117
126
|
fs.copyFileSync(pkgPath, path.join(buildDir, "package.json"));
|
|
118
127
|
}
|
|
128
|
+
const tanfigPath = path.join(root, "tanfig.json");
|
|
129
|
+
if (fs.existsSync(tanfigPath)) {
|
|
130
|
+
fs.copyFileSync(tanfigPath, path.join(buildDir, "tanfig.json"));
|
|
131
|
+
}
|
|
132
|
+
const titanConfigPath = path.join(root, "titan.json");
|
|
133
|
+
if (fs.existsSync(titanConfigPath)) {
|
|
134
|
+
fs.copyFileSync(titanConfigPath, path.join(buildDir, "titan.json"));
|
|
135
|
+
}
|
|
119
136
|
|
|
120
137
|
// 4. Create .env
|
|
121
138
|
fs.writeFileSync(path.join(buildDir, ".env"), "TITAN_DEV=0\n");
|
package/packages/route/README.md
CHANGED
|
@@ -14,6 +14,9 @@ import t from "@titanpl/route";
|
|
|
14
14
|
// Define an action-based route
|
|
15
15
|
t.post("/hello").action("hello"); // pass a json payload { "name": "titan" }
|
|
16
16
|
|
|
17
|
+
// Define a WebSocket route
|
|
18
|
+
t.ws("/chat").action("chat");
|
|
19
|
+
|
|
17
20
|
// Define a direct reply route
|
|
18
21
|
t.get("/").reply("Ready to land on Titan Planet 🚀");
|
|
19
22
|
|
|
@@ -21,4 +24,22 @@ t.get("/").reply("Ready to land on Titan Planet 🚀");
|
|
|
21
24
|
t.start(5100, "Titan Running!");
|
|
22
25
|
```
|
|
23
26
|
|
|
27
|
+
### WebSocket Action Handling
|
|
28
|
+
When using `t.ws()`, your action receives the `event`, `socketId`, and `body`:
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
export const chat = (req) => {
|
|
32
|
+
const { event, socketId, body } = req;
|
|
33
|
+
|
|
34
|
+
if (event === "open") {
|
|
35
|
+
t.ws.send(socketId, "Connected to Titan Orbital Hub!");
|
|
36
|
+
t.ws.broadcast(`User ${socketId} has docked.`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (event === "message") {
|
|
40
|
+
t.ws.broadcast(`${socketId}: ${body}`);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
24
45
|
**Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux version is in development (dev only) for the new architecture and will be launched later.
|
|
@@ -8,6 +8,7 @@ export interface TitanRoute {
|
|
|
8
8
|
post(route: string): RouteBuilder;
|
|
9
9
|
put(route: string): RouteBuilder;
|
|
10
10
|
delete(route: string): RouteBuilder;
|
|
11
|
+
ws(route: string): { action(name: string): void };
|
|
11
12
|
log(module: string, msg: string): void;
|
|
12
13
|
start(port?: number, msg?: string, threads?: number, stack_mb?: number): void;
|
|
13
14
|
}
|