@titanpl/native 2.0.4 → 6.0.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 CHANGED
@@ -8,4 +8,3 @@ It acts as the low-level communication bridge offering type definitions and util
8
8
  ## How it works
9
9
  You can import tools and primitives from this package into your server-side actions alongside `@titanpl/core` when you want direct low-level interaction or need access to platform operations that interact directly with the C/Rust 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/index.d.ts CHANGED
@@ -24,6 +24,10 @@ export function drift<T>(op: any): T;
24
24
 
25
25
  // Add more as needed based on native/index.js
26
26
  export const db: any;
27
+ export const ws: {
28
+ send(id: string, message: string): void;
29
+ broadcast(message: string): void;
30
+ };
27
31
  export const path: any;
28
32
  export const jwt: any;
29
33
  export const password: any;
package/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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/native",
3
- "version": "2.0.4",
3
+ "version": "6.0.1",
4
4
  "description": "Titan native utilities package",
5
5
  "type": "module",
6
6
  "keywords": [
package/t.native.d.ts CHANGED
@@ -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://titan-docs-ez.vercel.app/docs
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://titan-docs-ez.vercel.app/docs/03-actions — Actions documentation
32
- * @see https://titan-docs-ez.vercel.app/docs/02-routes — Routes & parameters
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://titan-docs-ez.vercel.app/docs/02-routes — Dynamic routes
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://titan-docs-ez.vercel.app/docs/03-actions — Action definition patterns
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
@@ -331,7 +343,6 @@ export const url: typeof t.url;
331
343
  * Provides schema-based validation for request data. Works with
332
344
  * the `@titanpl/valid` package for advanced validation rules.
333
345
  *
334
- * @see https://titan-docs-ez.vercel.app/docs/12-sdk — TitanPl SDK
335
346
  */
336
347
  export const valid: any;
337
348
 
@@ -406,8 +417,8 @@ declare global {
406
417
  * }
407
418
  * ```
408
419
  *
409
- * @see https://titan-docs-ez.vercel.app/docs/14-drift — Drift documentation
410
- * @see https://titan-docs-ez.vercel.app/docs/runtime-architecture — Gravity Runtime
420
+ * @see https://titanpl.vercel.app/docs/knowledge/04-drift — Drift documentation
421
+ * @see https://titanpl.vercel.app/docs/knowledge/02-runtime-architecture — Gravity Runtime
411
422
  */
412
423
  var drift: <T>(promise: Promise<T> | T) => T;
413
424
 
@@ -440,7 +451,7 @@ declare global {
440
451
  * }
441
452
  * ```
442
453
  *
443
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs
454
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs
444
455
  */
445
456
  interface DbConnection {
446
457
  /**
@@ -500,7 +511,7 @@ declare global {
500
511
  * }
501
512
  * ```
502
513
  *
503
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Complete Runtime APIs reference
514
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Complete Runtime APIs reference
504
515
  */
505
516
  interface TitanRuntimeUtils {
506
517
 
@@ -530,7 +541,7 @@ declare global {
530
541
  * t.log("Multiple", "values", { are: "supported" }, 42);
531
542
  * ```
532
543
  *
533
- * @see https://titan-docs-ez.vercel.app/docs/06-logs — Gravity Logs
544
+ * @see https://titanpl.vercel.app/docs/how-to-use/07-logs — Gravity Logs
534
545
  */
535
546
  log(...args: any[]): void;
536
547
 
@@ -553,7 +564,7 @@ declare global {
553
564
  * }
554
565
  * ```
555
566
  *
556
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs
567
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs
557
568
  */
558
569
  read(path: string): string;
559
570
 
@@ -616,7 +627,7 @@ declare global {
616
627
  * }
617
628
  * ```
618
629
  *
619
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.fetch)
630
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.fetch)
620
631
  */
621
632
  fetch(url: string, options?: {
622
633
  method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
@@ -629,6 +640,38 @@ declare global {
629
640
  error?: string;
630
641
  }>;
631
642
 
643
+ /**
644
+ * WebSocket communication utilities.
645
+ *
646
+ * Allows sending direct messages or broadcasting to all active sockets.
647
+ *
648
+ * @example
649
+ * ```js
650
+ * export default function chat(req) {
651
+ * if (req.event === "open") {
652
+ * t.ws.send(req.socketId, "Welcome!");
653
+ * t.ws.broadcast("Someone joined.");
654
+ * }
655
+ * }
656
+ * ```
657
+ */
658
+ ws: {
659
+ /**
660
+ * Send a text message to a specific WebSocket client.
661
+ *
662
+ * @param socketId - The unique ID of the target connection.
663
+ * @param message - The text message to send.
664
+ */
665
+ send(socketId: string, message: string): void;
666
+
667
+ /**
668
+ * Broadcast a text message to ALL active WebSocket connections.
669
+ *
670
+ * @param message - The text message to broadcast.
671
+ */
672
+ broadcast(message: string): void;
673
+ };
674
+
632
675
 
633
676
  // -------------------------------------------------------------------
634
677
  // Authentication & Security
@@ -669,7 +712,7 @@ declare global {
669
712
  * }
670
713
  * ```
671
714
  *
672
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.jwt)
715
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.jwt)
673
716
  */
674
717
  jwt: {
675
718
  /**
@@ -737,7 +780,7 @@ declare global {
737
780
  * }
738
781
  * ```
739
782
  *
740
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.password)
783
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.password)
741
784
  */
742
785
  password: {
743
786
  /**
@@ -811,7 +854,7 @@ declare global {
811
854
  * }
812
855
  * ```
813
856
  *
814
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.db)
857
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.db)
815
858
  */
816
859
  db: {
817
860
  /**
@@ -884,7 +927,7 @@ declare global {
884
927
  * directories. All methods return `Promise` — use `drift()` to resolve.
885
928
  *
886
929
  * @see {@link TitanCore.FileSystem} for method signatures.
887
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.fs)
930
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.fs)
888
931
  */
889
932
  fs: TitanCore.FileSystem;
890
933
 
@@ -895,7 +938,7 @@ declare global {
895
938
  * cross-platform path joining, resolving, and component extraction.
896
939
  *
897
940
  * @see {@link TitanCore.Path} for method signatures.
898
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.path)
941
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.path)
899
942
  */
900
943
  path: TitanCore.Path;
901
944
 
@@ -911,7 +954,7 @@ declare global {
911
954
  * random bytes generation, and UUID creation. Async methods require `drift()`.
912
955
  *
913
956
  * @see {@link TitanCore.Crypto} for method signatures.
914
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.crypto)
957
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.crypto)
915
958
  */
916
959
  crypto: TitanCore.Crypto;
917
960
 
@@ -921,7 +964,7 @@ declare global {
921
964
  * All methods are **synchronous** — no `drift()` needed.
922
965
  *
923
966
  * @see {@link TitanCore.BufferModule} for method signatures.
924
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.buffer)
967
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.buffer)
925
968
  */
926
969
  buffer: TitanCore.BufferModule;
927
970
 
@@ -940,7 +983,7 @@ declare global {
940
983
  * @suggestion Use `setObject`/`getObject` for complex data structures to maintain types.
941
984
 
942
985
  * @see {@link TitanCore.LocalStorage} for method signatures.
943
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.ls)
986
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.ls)
944
987
  */
945
988
  ls: TitanCore.LocalStorage;
946
989
 
@@ -951,7 +994,7 @@ declare global {
951
994
  * **synchronous**. Identical to `t.ls` — use whichever alias you prefer.
952
995
  *
953
996
  * @see {@link TitanCore.LocalStorage} for method signatures.
954
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.localStorage)
997
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.localStorage)
955
998
  */
956
999
  localStorage: TitanCore.LocalStorage;
957
1000
 
@@ -965,7 +1008,7 @@ declare global {
965
1008
  * All methods are **synchronous**.
966
1009
  *
967
1010
  * @see {@link TitanCore.Session} for method signatures.
968
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.session)
1011
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.session)
969
1012
  */
970
1013
  session: TitanCore.Session;
971
1014
 
@@ -973,7 +1016,7 @@ declare global {
973
1016
  * HTTP cookie utilities for reading, setting, and deleting cookies.
974
1017
  *
975
1018
  * @see {@link TitanCore.Cookies} for method signatures.
976
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.cookies)
1019
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.cookies)
977
1020
  */
978
1021
  cookies: TitanCore.Cookies;
979
1022
 
@@ -989,7 +1032,7 @@ declare global {
989
1032
  * host machine running the Titan server.
990
1033
  *
991
1034
  * @see {@link TitanCore.OS} for method signatures.
992
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.os)
1035
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.os)
993
1036
  */
994
1037
  os: TitanCore.OS;
995
1038
 
@@ -999,7 +1042,7 @@ declare global {
999
1042
  * All methods return `Promise` — use `drift()` to resolve.
1000
1043
  *
1001
1044
  * @see {@link TitanCore.Net} for method signatures.
1002
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.net)
1045
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.net)
1003
1046
  */
1004
1047
  net: TitanCore.Net;
1005
1048
 
@@ -1009,7 +1052,7 @@ declare global {
1009
1052
  * All methods are **synchronous**.
1010
1053
  *
1011
1054
  * @see {@link TitanCore.Process} for method signatures.
1012
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.proc)
1055
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.proc)
1013
1056
  */
1014
1057
  proc: TitanCore.Process;
1015
1058
 
@@ -1024,7 +1067,7 @@ declare global {
1024
1067
  * `t.time.sleep()` is async (requires `drift()`); other methods are synchronous.
1025
1068
  *
1026
1069
  * @see {@link TitanCore.Time} for method signatures.
1027
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.time)
1070
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.time)
1028
1071
  */
1029
1072
  time: TitanCore.Time;
1030
1073
 
@@ -1032,7 +1075,7 @@ declare global {
1032
1075
  * URL parsing and formatting utilities.
1033
1076
  *
1034
1077
  * @see {@link TitanCore.URLModule} for method signatures.
1035
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.url)
1078
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs (t.url)
1036
1079
  */
1037
1080
  url: TitanCore.URLModule;
1038
1081
 
@@ -1055,7 +1098,7 @@ declare global {
1055
1098
  * Custom extensions attach their methods to the `t` object at runtime,
1056
1099
  * making them available as `t.myExtension.someMethod()`.
1057
1100
  *
1058
- * @see https://titan-docs-ez.vercel.app/docs/10-extensions — Extensions documentation
1101
+ * @see https://titanpl.vercel.app/docs/10-extensions — Extensions documentation
1059
1102
  */
1060
1103
  [key: string]: any;
1061
1104
 
@@ -1077,8 +1120,8 @@ declare global {
1077
1120
  * }
1078
1121
  * ```
1079
1122
  *
1080
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Full API reference
1081
- * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs
1123
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Full API reference
1124
+ * @see https://titanpl.vercel.app/docs/knowledge/05-titan-core — TitanCore Runtime APIs
1082
1125
  */
1083
1126
  const t: TitanRuntimeUtils;
1084
1127
 
@@ -1142,7 +1185,7 @@ declare global {
1142
1185
  * }
1143
1186
  * ```
1144
1187
  *
1145
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.fs)
1188
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.fs)
1146
1189
  */
1147
1190
  interface FileSystem {
1148
1191
  /**
@@ -1232,7 +1275,7 @@ declare global {
1232
1275
  * t.path.basename("/a/b/c.txt"); // → "c.txt"
1233
1276
  * ```
1234
1277
  *
1235
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.path)
1278
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.path)
1236
1279
  */
1237
1280
  interface Path {
1238
1281
  /**
@@ -1320,7 +1363,7 @@ declare global {
1320
1363
  * }
1321
1364
  * ```
1322
1365
  *
1323
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.crypto)
1366
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.crypto)
1324
1367
  */
1325
1368
  interface Crypto {
1326
1369
  /**
@@ -1463,7 +1506,7 @@ declare global {
1463
1506
  * const bytes = t.buffer.fromHex(hex);
1464
1507
  * ```
1465
1508
  *
1466
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.buffer)
1509
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.buffer)
1467
1510
  */
1468
1511
  interface BufferModule {
1469
1512
  /**
@@ -1546,7 +1589,7 @@ declare global {
1546
1589
  * t.ls.clear();
1547
1590
  * ```
1548
1591
  *
1549
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.ls / t.localStorage)
1592
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.ls / t.localStorage)
1550
1593
  */
1551
1594
  interface LocalStorage {
1552
1595
  /**
@@ -1651,7 +1694,7 @@ declare global {
1651
1694
  * }
1652
1695
  * ```
1653
1696
  *
1654
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.session)
1697
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.session)
1655
1698
  */
1656
1699
  interface Session {
1657
1700
  /**
@@ -1713,7 +1756,7 @@ declare global {
1713
1756
  * }
1714
1757
  * ```
1715
1758
  *
1716
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.cookies)
1759
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.cookies)
1717
1760
  */
1718
1761
  interface Cookies {
1719
1762
  /**
@@ -1762,7 +1805,7 @@ declare global {
1762
1805
  * }
1763
1806
  * ```
1764
1807
  *
1765
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.os)
1808
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.os)
1766
1809
  */
1767
1810
  interface OS {
1768
1811
  /**
@@ -1816,7 +1859,7 @@ declare global {
1816
1859
  * }
1817
1860
  * ```
1818
1861
  *
1819
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.net)
1862
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.net)
1820
1863
  */
1821
1864
  interface Net {
1822
1865
  /**
@@ -1859,7 +1902,7 @@ declare global {
1859
1902
  * }
1860
1903
  * ```
1861
1904
  *
1862
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.proc)
1905
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.proc)
1863
1906
  */
1864
1907
  interface Process {
1865
1908
  /**
@@ -1900,7 +1943,7 @@ declare global {
1900
1943
  * }
1901
1944
  * ```
1902
1945
  *
1903
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.time)
1946
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.time)
1904
1947
  */
1905
1948
  interface Time {
1906
1949
  /**
@@ -1954,7 +1997,7 @@ declare global {
1954
1997
  * // → "https://api.example.com/v2/users"
1955
1998
  * ```
1956
1999
  *
1957
- * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.url)
2000
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.url)
1958
2001
  */
1959
2002
  interface URLModule {
1960
2003
  /**