titanpl-sdk 2.0.3 → 2.0.4

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.
@@ -1,249 +0,0 @@
1
-
2
- // -- Module Definitions (for imports from "titan") --
3
-
4
- export interface RouteHandler {
5
- reply(value: any): void;
6
- action(name: string): void;
7
- }
8
-
9
- export interface TitanBuilder {
10
- get(route: string): RouteHandler;
11
- post(route: string): RouteHandler;
12
- log(module: string, msg: string): void;
13
- start(port?: number, msg?: string): Promise<void>;
14
- }
15
-
16
- declare const builder: TitanBuilder;
17
- export const Titan: TitanBuilder;
18
- export default builder;
19
-
20
- export declare function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
21
-
22
- // -- Global Definitions (Runtime Environment) --
23
-
24
- /**
25
- * # Drift - Orchestration Engine
26
- *
27
- * Revolutionary system for high-performance asynchronous operations using a **Deterministic Replay-based Suspension** model.
28
- *
29
- * ## Mechanism
30
- * Drift utilizes a suspension model similar to **Algebraic Effects**. When a `drift()` operation is encountered,
31
- * the runtime suspends the isolate, offloads the task to the background Tokio executor, and frees the isolate
32
- * to handle other requests. Upon completion, the code is efficiently **re-played** with the result injected.
33
- *
34
- * @param promise - The promise or expression to drift.
35
- * @returns The resolved value of the input promise.
36
- *
37
- * @example
38
- * ```javascript
39
- * const resp = drift t.fetch("http://api.titan.com");
40
- * ```
41
- */
42
- declare var drift: <T>(promise: Promise<T> | T) => T;
43
-
44
- declare global {
45
- /**
46
- * Titan Global Drift
47
- */
48
- var drift: <T>(promise: Promise<T> | T) => T;
49
-
50
- interface TitanRequest {
51
- body: any;
52
- method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
53
- path: string;
54
- headers: {
55
- host?: string;
56
- "content-type"?: string;
57
- "user-agent"?: string;
58
- authorization?: string;
59
- [key: string]: string | undefined;
60
- };
61
- params: Record<string, string>;
62
- query: Record<string, string>;
63
- }
64
-
65
- interface DbConnection {
66
- query(sql: string, params?: any[]): any[];
67
- }
68
-
69
- function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
70
-
71
- var req: TitanRequest;
72
-
73
- interface TitanRuntimeUtils {
74
- log(...args: any[]): void;
75
- read(path: string): string;
76
- fetch(url: string, options?: {
77
- method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
78
- headers?: Record<string, string>;
79
- body?: string | object;
80
- }): {
81
- ok: boolean;
82
- status?: number;
83
- body?: string;
84
- error?: string;
85
- };
86
-
87
- jwt: {
88
- sign(payload: object, secret: string, options?: { expiresIn?: string | number }): string;
89
- verify(token: string, secret: string): any;
90
- };
91
-
92
- password: {
93
- hash(password: string): string;
94
- verify(password: string, hash: string): boolean;
95
- };
96
-
97
- /** ### `db` (Database Connection) */
98
- db: {
99
- connect(url: string): DbConnection;
100
- };
101
-
102
- /** ### `fs` (File System) */
103
- fs: TitanCore.FileSystem;
104
-
105
- /** ### `path` (Path Manipulation) */
106
- path: TitanCore.Path;
107
-
108
- /** ### `crypto` (Cryptography) */
109
- crypto: TitanCore.Crypto;
110
-
111
- /** ### `buffer` (Buffer Utilities) */
112
- buffer: TitanCore.BufferModule;
113
-
114
- /** ### `ls` / `localStorage` (Persistent Storage) */
115
- ls: TitanCore.LocalStorage;
116
- localStorage: TitanCore.LocalStorage;
117
-
118
- /** ### `session` (Server-side Sessions) */
119
- session: TitanCore.Session;
120
-
121
- /** ### `cookies` (HTTP Cookies) */
122
- cookies: TitanCore.Cookies;
123
-
124
- /** ### `os` (Operating System) */
125
- os: TitanCore.OS;
126
-
127
- /** ### `net` (Network) */
128
- net: TitanCore.Net;
129
-
130
- /** ### `proc` (Process) */
131
- proc: TitanCore.Process;
132
-
133
- /** ### `time` (Time) */
134
- time: TitanCore.Time;
135
-
136
- /** ### `url` (URL) */
137
- url: TitanCore.URLModule;
138
-
139
- /** ### `response` (HTTP Response Builder) */
140
- response: TitanCore.ResponseModule;
141
-
142
- valid: any;
143
- [key: string]: any;
144
- }
145
-
146
- const t: TitanRuntimeUtils;
147
- const Titan: TitanRuntimeUtils;
148
-
149
- namespace TitanCore {
150
- interface FileSystem {
151
- readFile(path: string): string;
152
- writeFile(path: string, content: string): void;
153
- readdir(path: string): string[];
154
- mkdir(path: string): void;
155
- exists(path: string): boolean;
156
- stat(path: string): { size: number, isFile: boolean, isDir: boolean, modified: number };
157
- remove(path: string): void;
158
- }
159
-
160
- interface Path {
161
- join(...args: string[]): string;
162
- resolve(...args: string[]): string;
163
- extname(path: string): string;
164
- dirname(path: string): string;
165
- basename(path: string): string;
166
- }
167
-
168
- interface Crypto {
169
- hash(algorithm: 'sha256' | 'sha512' | 'md5', data: string): string;
170
- randomBytes(size: number): string;
171
- uuid(): string;
172
- compare(hash: string, target: string): boolean;
173
- encrypt(algorithm: string, key: string, plaintext: string): string;
174
- decrypt(algorithm: string, key: string, ciphertext: string): string;
175
- hashKeyed(algorithm: 'hmac-sha256' | 'hmac-sha512', key: string, message: string): string;
176
- }
177
-
178
- interface BufferModule {
179
- fromBase64(str: string): Uint8Array;
180
- toBase64(bytes: Uint8Array | string): string;
181
- fromHex(str: string): Uint8Array;
182
- toHex(bytes: Uint8Array | string): string;
183
- fromUtf8(str: string): Uint8Array;
184
- toUtf8(bytes: Uint8Array): string;
185
- }
186
-
187
- interface LocalStorage {
188
- get(key: string): string | null;
189
- set(key: string, value: string): void;
190
- remove(key: string): void;
191
- clear(): void;
192
- keys(): string[];
193
- }
194
-
195
- interface Session {
196
- get(sessionId: string, key: string): string | null;
197
- set(sessionId: string, key: string, value: string): void;
198
- delete(sessionId: string, key: string): void;
199
- clear(sessionId: string): void;
200
- }
201
-
202
- interface Cookies {
203
- get(req: any, name: string): string | null;
204
- set(res: any, name: string, value: string, options?: any): void;
205
- delete(res: any, name: string): void;
206
- }
207
-
208
- interface OS {
209
- platform(): string;
210
- cpus(): number;
211
- totalMemory(): number;
212
- freeMemory(): number;
213
- tmpdir(): string;
214
- }
215
-
216
- interface Net {
217
- resolveDNS(hostname: string): string[];
218
- ip(): string;
219
- ping(host: string): boolean;
220
- }
221
-
222
- interface Process {
223
- pid(): number;
224
- uptime(): number;
225
- memory(): Record<string, any>;
226
- }
227
-
228
- interface Time {
229
- sleep(ms: number): void;
230
- now(): number;
231
- timestamp(): string;
232
- }
233
-
234
- interface URLModule {
235
- parse(url: string): any;
236
- format(urlObj: any): string;
237
- SearchParams: any;
238
- }
239
-
240
- interface ResponseModule {
241
- (options: any): any;
242
- text(content: string, status?: number): any;
243
- html(content: string, status?: number): any;
244
- json(content: any, status?: number): any;
245
- redirect(url: string, status?: number): any;
246
- empty(status?: number): any;
247
- }
248
- }
249
- }