@titanpl/core 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.
Files changed (2) hide show
  1. package/index.d.ts +265 -0
  2. package/package.json +2 -1
package/index.d.ts ADDED
@@ -0,0 +1,265 @@
1
+ // Type definitions for @titanpl/core
2
+ // This file facilitates type inference when this extension is installed in a Titan project.
3
+
4
+ declare global {
5
+ namespace Titan {
6
+ interface Runtime {
7
+ /**
8
+ * @titanpl/core Extension - Titan Core Standard Library
9
+ */
10
+ "@titanpl/core": TitanCore.Core;
11
+
12
+ /**
13
+ * Alias for @titanpl/core
14
+ */
15
+ "titan-core": TitanCore.Core;
16
+
17
+ /** File System module */
18
+ fs: TitanCore.FileSystem;
19
+ /** Path manipulation module */
20
+ path: TitanCore.Path;
21
+ /** Cryptography module */
22
+ crypto: TitanCore.Crypto;
23
+ /** Operating System module */
24
+ os: TitanCore.OS;
25
+ /** Network module */
26
+ net: TitanCore.Net;
27
+ /** Process module */
28
+ proc: TitanCore.Process;
29
+ /** Time module */
30
+ time: TitanCore.Time;
31
+ /** URL module */
32
+ url: TitanCore.URLModule;
33
+ /** Buffer utility module */
34
+ buffer: TitanCore.BufferModule;
35
+ /** Local Storage module */
36
+ ls: TitanCore.LocalStorage;
37
+ /** Local Storage alias */
38
+ localStorage: TitanCore.LocalStorage;
39
+ /** Session management */
40
+ session: TitanCore.Session;
41
+ /** Cookie utilities */
42
+ cookies: TitanCore.Cookies;
43
+ /** Core namespace alias */
44
+ core: TitanCore.Core;
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Titan Core Global Namespace
50
+ */
51
+ namespace TitanCore {
52
+ interface Core {
53
+ fs: FileSystem;
54
+ path: Path;
55
+ crypto: Crypto;
56
+ os: OS;
57
+ net: Net;
58
+ proc: Process;
59
+ time: Time;
60
+ url: URLModule;
61
+ buffer: BufferModule;
62
+ ls: LocalStorage;
63
+ session: Session;
64
+ cookies: Cookies;
65
+ }
66
+
67
+ // --- File System ---
68
+ interface FileSystem {
69
+ /** Reads file content as UTF-8 string */
70
+ readFile(path: string): string;
71
+ /** Writes content to file */
72
+ writeFile(path: string, content: string): void;
73
+ /** Reads directory contents */
74
+ readdir(path: string): string[];
75
+ /** Creates directory recursively */
76
+ mkdir(path: string): void;
77
+ /** Checks if path exists */
78
+ exists(path: string): boolean;
79
+ /** Returns file stats */
80
+ stat(path: string): Stats;
81
+ /** Removes file or directory */
82
+ remove(path: string): void;
83
+ }
84
+
85
+ interface Stats {
86
+ size: number;
87
+ isFile: boolean;
88
+ isDir: boolean;
89
+ modified: number;
90
+ }
91
+
92
+ // --- Path ---
93
+ interface Path {
94
+ /** Joins path segments */
95
+ join(...args: string[]): string;
96
+ /** Resolves path segments to an absolute path */
97
+ resolve(...args: string[]): string;
98
+ /** Returns the extension of the path */
99
+ extname(path: string): string;
100
+ /** Returns the directory name of a path */
101
+ dirname(path: string): string;
102
+ /** Returns the last portion of a path */
103
+ basename(path: string): string;
104
+ }
105
+
106
+ // --- Crypto ---
107
+ interface Crypto {
108
+ /** Computes hash of data using specified algorithm (e.g., 'sha256', 'sha512') */
109
+ hash(algorithm: string, data: string): string;
110
+ /** Generates random bytes as a hex string */
111
+ randomBytes(size: number): string;
112
+ /** Generates a UUID v4 string */
113
+ uuid(): string;
114
+ base64: {
115
+ encode(str: string): string;
116
+ decode(str: string): string;
117
+ };
118
+ /** Encrypts data using AES-256-GCM. Returns Base64 string. */
119
+ encrypt(algorithm: string, key: string, plaintext: string): string;
120
+ /** Decrypts data using AES-256-GCM. Returns plaintext string. */
121
+ decrypt(algorithm: string, key: string, ciphertext: string): string;
122
+ /** Computes HMAC-SHA256/512. Returns Hex string. */
123
+ hashKeyed(algorithm: string, key: string, message: string): string;
124
+ /** Constant-time string comparison */
125
+ compare(a: string, b: string): boolean;
126
+ }
127
+
128
+ // --- OS ---
129
+ interface OS {
130
+ /** Returns the operating system platform */
131
+ platform(): string;
132
+ /** Returns the number of logical CPUs */
133
+ cpus(): number;
134
+ /** Returns total system memory in bytes */
135
+ totalMemory(): number;
136
+ /** Returns free system memory in bytes */
137
+ freeMemory(): number;
138
+ /** Returns the system temporary directory */
139
+ tmpdir(): string;
140
+ }
141
+
142
+ // --- Net ---
143
+ interface Net {
144
+ /** Resolves hostname to IP addresses */
145
+ resolveDNS(hostname: string): string[];
146
+ /** Returns the local machine's IP address */
147
+ ip(): string;
148
+ /** Pings a host (mock implementation always returns true) */
149
+ ping(host: string): boolean;
150
+ }
151
+
152
+ // --- Process ---
153
+ interface Process {
154
+ /** Returns the current process ID */
155
+ pid(): number;
156
+ /** Returns the process uptime in seconds */
157
+ uptime(): number;
158
+ /** Returns memory usage statistics */
159
+ memory(): Record<string, any>;
160
+ }
161
+
162
+ // --- Time ---
163
+ interface Time {
164
+ /** Pauses execution for the specified number of milliseconds */
165
+ sleep(ms: number): void;
166
+ /** Returns the number of milliseconds elapsed since the epoch */
167
+ now(): number;
168
+ /** Returns the current time as an ISO string */
169
+ timestamp(): string;
170
+ }
171
+
172
+ // --- URL ---
173
+ interface URLModule {
174
+ /** Parses a URL string */
175
+ parse(url: string): UrlObject;
176
+ /** Formats a URL object into a string */
177
+ format(urlObj: any): string;
178
+ /** URLSearchParams constructor */
179
+ SearchParams: typeof TitanURLSearchParams;
180
+ }
181
+
182
+ interface UrlObject {
183
+ protocol: string;
184
+ hostname: string;
185
+ port: string;
186
+ pathname: string;
187
+ search: string;
188
+ hash: string;
189
+ }
190
+
191
+ class TitanURLSearchParams {
192
+ constructor(init?: string | Record<string, string>);
193
+ get(key: string): string | null;
194
+ set(key: string, value: string): void;
195
+ has(key: string): boolean;
196
+ delete(key: string): void;
197
+ toString(): string;
198
+ entries(): [string, string][];
199
+ keys(): string[];
200
+ values(): string[];
201
+ }
202
+
203
+ // --- Buffer ---
204
+ interface BufferModule {
205
+ /** Creates Uint8Array from Base64 string */
206
+ fromBase64(str: string): Uint8Array;
207
+ /** Encodes Uint8Array or String to Base64 string */
208
+ toBase64(bytes: Uint8Array | string): string;
209
+ /** Creates Uint8Array from Hex string */
210
+ fromHex(str: string): Uint8Array;
211
+ /** Encodes bytes to Hex string */
212
+ toHex(bytes: Uint8Array | string): string;
213
+ /** Creates Uint8Array from UTF-8 string */
214
+ fromUtf8(str: string): Uint8Array;
215
+ /** Decodes bytes to UTF-8 string */
216
+ toUtf8(bytes: Uint8Array): string;
217
+ }
218
+
219
+ // --- Local Storage ---
220
+ interface LocalStorage {
221
+ /** Gets a value from local storage */
222
+ get(key: string): string | null;
223
+ /** Sets a value in local storage */
224
+ set(key: string, value: string): void;
225
+ /** Removes a value from local storage */
226
+ remove(key: string): void;
227
+ /** Clears all local storage */
228
+ clear(): void;
229
+ /** Returns all keys in local storage */
230
+ keys(): string[];
231
+ }
232
+
233
+ // --- Session ---
234
+ interface Session {
235
+ /** Gets a value from a session */
236
+ get(sessionId: string, key: string): string | null;
237
+ /** Sets a value in a session */
238
+ set(sessionId: string, key: string, value: string): void;
239
+ /** Deletes a value from a session */
240
+ delete(sessionId: string, key: string): void;
241
+ /** Clears a session */
242
+ clear(sessionId: string): void;
243
+ }
244
+
245
+ // --- Cookies ---
246
+ interface Cookies {
247
+ /** Parses cookie from request headers */
248
+ get(req: any, name: string): string | null;
249
+ /** Sets Set-Cookie header on response */
250
+ set(res: any, name: string, value: string, options?: CookieOptions): void;
251
+ /** Deletes cookie by setting maxAge=0 */
252
+ delete(res: any, name: string): void;
253
+ }
254
+
255
+ interface CookieOptions {
256
+ maxAge?: number;
257
+ path?: string;
258
+ httpOnly?: boolean;
259
+ secure?: boolean;
260
+ sameSite?: string;
261
+ }
262
+ }
263
+ }
264
+
265
+ export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/core",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "The official Core Standard Library for Titan Planet - provides fs, path, crypto, os, net, proc, time, and url modules",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,6 +27,7 @@
27
27
  "index.js",
28
28
  "titan.json",
29
29
  "globals.d.ts",
30
+ "index.d.ts",
30
31
  "native/target/release/*.dll",
31
32
  "native/target/release/*.so",
32
33
  "native/target/release/*.dylib",