@titanpl/native 6.0.1 → 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/index.d.ts +10 -4
- package/index.js +1 -0
- package/package.json +1 -1
- package/t.native.d.ts +88 -0
package/index.d.ts
CHANGED
|
@@ -22,12 +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;
|
|
27
|
-
export const ws:
|
|
28
|
-
send(id: string, message: string): void;
|
|
29
|
-
broadcast(message: string): void;
|
|
30
|
-
};
|
|
35
|
+
export const ws: any;
|
|
31
36
|
export const path: any;
|
|
32
37
|
export const jwt: any;
|
|
33
38
|
export const password: any;
|
|
@@ -36,6 +41,7 @@ export const buffer: any;
|
|
|
36
41
|
export const ls: any;
|
|
37
42
|
export const session: any;
|
|
38
43
|
export const cookies: any;
|
|
44
|
+
export const shareContext: ShareContext;
|
|
39
45
|
export const os: any;
|
|
40
46
|
export const net: any;
|
|
41
47
|
export const proc: any;
|
package/index.js
CHANGED
package/package.json
CHANGED
package/t.native.d.ts
CHANGED
|
@@ -297,6 +297,14 @@ export const session: typeof t.session;
|
|
|
297
297
|
*/
|
|
298
298
|
export const cookies: typeof t.cookies;
|
|
299
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
|
+
|
|
300
308
|
/**
|
|
301
309
|
* Operating system information (platform, CPU count, memory).
|
|
302
310
|
*
|
|
@@ -1012,6 +1020,19 @@ declare global {
|
|
|
1012
1020
|
*/
|
|
1013
1021
|
session: TitanCore.Session;
|
|
1014
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
|
+
|
|
1015
1036
|
/**
|
|
1016
1037
|
* HTTP cookie utilities for reading, setting, and deleting cookies.
|
|
1017
1038
|
*
|
|
@@ -1731,6 +1752,73 @@ declare global {
|
|
|
1731
1752
|
clear(sessionId: string): void;
|
|
1732
1753
|
}
|
|
1733
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
|
+
|
|
1734
1822
|
/**
|
|
1735
1823
|
* HTTP cookie management utilities.
|
|
1736
1824
|
*
|