titanpl-sdk 1.0.9 → 2.0.0
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 +1 -1
- package/templates/index.d.ts +249 -0
- package/templates/titan/bundle.js +1 -4
- package/index.d.ts +0 -50
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "titanpl-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Development SDK for Titan Planet. Provides TypeScript type definitions for the global 't' runtime object and a 'lite' test-harness runtime for building and verifying extensions.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -0,0 +1,249 @@
|
|
|
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
|
+
}
|
|
@@ -210,10 +210,7 @@ export async function bundle() {
|
|
|
210
210
|
throw new Error("[Titan] Action '${actionName}' not found or not a function");
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
globalThis["${actionName}"] =
|
|
214
|
-
globalThis.req = request_arg;
|
|
215
|
-
return fn(request_arg);
|
|
216
|
-
};
|
|
213
|
+
globalThis["${actionName}"] = globalThis.defineAction(fn);
|
|
217
214
|
})();
|
|
218
215
|
`
|
|
219
216
|
}
|
package/index.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export { };
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
/**
|
|
5
|
-
* Titan Runtime Global Object
|
|
6
|
-
*/
|
|
7
|
-
const t: Titan.Runtime;
|
|
8
|
-
/**
|
|
9
|
-
* Titan Runtime Global Object
|
|
10
|
-
*/
|
|
11
|
-
const Titan: Titan.Runtime;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export namespace Titan {
|
|
15
|
-
interface Runtime {
|
|
16
|
-
/**
|
|
17
|
-
* Log messages to the Titan console
|
|
18
|
-
*/
|
|
19
|
-
log: LogInterface;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Read file content
|
|
23
|
-
*/
|
|
24
|
-
read(path: string): string;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Fetch API wrapper
|
|
28
|
-
*/
|
|
29
|
-
fetch(url: string, options?: any): Promise<any>;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Database operations
|
|
33
|
-
*/
|
|
34
|
-
db: {
|
|
35
|
-
query(sql: string, params?: any[]): Promise<any>;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Titan Extensions
|
|
40
|
-
*/
|
|
41
|
-
[key: string]: any;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface LogInterface {
|
|
45
|
-
(...args: any[]): void;
|
|
46
|
-
info(...args: any[]): void;
|
|
47
|
-
warn(...args: any[]): void;
|
|
48
|
-
error(...args: any[]): void;
|
|
49
|
-
}
|
|
50
|
-
}
|