@titanpl/native 7.0.0-beta → 7.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/index.d.ts +43 -1
- package/index.js +7 -0
- package/package.json +2 -2
- package/t.native.d.ts +176 -3
package/index.d.ts
CHANGED
|
@@ -31,8 +31,28 @@ export interface ShareContext {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Add more as needed based on native/index.js
|
|
34
|
+
export interface WebSocketModule {
|
|
35
|
+
send(socketId: string, message: string): void;
|
|
36
|
+
broadcast(message: string): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
34
39
|
export const db: any;
|
|
35
|
-
|
|
40
|
+
/**
|
|
41
|
+
* WebSocket communication utilities.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```js
|
|
45
|
+
* import { ws } from "@titanpl/native";
|
|
46
|
+
*
|
|
47
|
+
* export default function chat(req) {
|
|
48
|
+
* if (req.event === "open") {
|
|
49
|
+
* ws.send(req.socketId, "Welcome!");
|
|
50
|
+
* ws.broadcast("Someone joined.");
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export const ws: WebSocketModule;
|
|
36
56
|
export const path: any;
|
|
37
57
|
export const jwt: any;
|
|
38
58
|
export const password: any;
|
|
@@ -47,5 +67,27 @@ export const net: any;
|
|
|
47
67
|
export const proc: any;
|
|
48
68
|
export const time: any;
|
|
49
69
|
export const url: any;
|
|
70
|
+
/**
|
|
71
|
+
* HTTP Response builder utilities.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```js
|
|
75
|
+
* import { response } from "@titanpl/native";
|
|
76
|
+
*
|
|
77
|
+
* export function get(req) {
|
|
78
|
+
* return response.json({ hello: "world" });
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
50
82
|
export const response: any;
|
|
51
83
|
export const valid: any;
|
|
84
|
+
|
|
85
|
+
// Serialization
|
|
86
|
+
/** Binary-serializes a JavaScript value using V8's fast internal format. */
|
|
87
|
+
export function serialize(value: any): Uint8Array;
|
|
88
|
+
/** Binary-serializes a JavaScript value using V8's fast internal format. Alias for serialize. */
|
|
89
|
+
export function serialise(value: any): Uint8Array;
|
|
90
|
+
/** Deserializes a Uint8Array back into its original JavaScript value/object. */
|
|
91
|
+
export function deserialize(buffer: Uint8Array): any;
|
|
92
|
+
/** Deserializes a Uint8Array back into its original JavaScript value/object. Alias for deserialize. */
|
|
93
|
+
export function deserialise(buffer: Uint8Array): any;
|
package/index.js
CHANGED
|
@@ -39,5 +39,12 @@ export const time = t.time;
|
|
|
39
39
|
export const url = t.url;
|
|
40
40
|
export const response = t.response;
|
|
41
41
|
export const valid = t.valid;
|
|
42
|
+
export const drift = globalThis.drift;
|
|
43
|
+
|
|
44
|
+
// Serialization
|
|
45
|
+
export const serialize = t.serialize;
|
|
46
|
+
export const serialise = t.serialise;
|
|
47
|
+
export const deserialize = t.deserialize;
|
|
48
|
+
export const deserialise = t.deserialise;
|
|
42
49
|
|
|
43
50
|
export const defineAction = (handler) => handler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@titanpl/native",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "Titan native utilities package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@titanpl/core": "
|
|
23
|
+
"@titanpl/core": "7.0.0",
|
|
24
24
|
"@titanpl/node": "latest"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/t.native.d.ts
CHANGED
|
@@ -233,6 +233,46 @@ export const password: typeof t.password;
|
|
|
233
233
|
*/
|
|
234
234
|
export const db: typeof t.db;
|
|
235
235
|
|
|
236
|
+
/**
|
|
237
|
+
* WebSocket communication utilities.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```js
|
|
241
|
+
* import { ws } from "@titanpl/native";
|
|
242
|
+
*
|
|
243
|
+
* export default function chat(req) {
|
|
244
|
+
* if (req.event === "open") {
|
|
245
|
+
* ws.send(req.socketId, "Welcome!");
|
|
246
|
+
* ws.broadcast("Someone joined.");
|
|
247
|
+
* }
|
|
248
|
+
* }
|
|
249
|
+
* ```
|
|
250
|
+
*
|
|
251
|
+
* Re-exported from the `t` global for module-style imports.
|
|
252
|
+
* @see {@link TitanRuntimeUtils.ws} for full documentation.
|
|
253
|
+
*/
|
|
254
|
+
export const ws: typeof t.ws;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Binary serialization using V8's fast format.
|
|
258
|
+
*
|
|
259
|
+
* Re-exported from the `t` global for module-style imports.
|
|
260
|
+
* @see {@link TitanRuntimeUtils.serialize}
|
|
261
|
+
*/
|
|
262
|
+
export const serialize: typeof t.serialize;
|
|
263
|
+
/** Alias for serialize. @see {@link TitanRuntimeUtils.serialise} */
|
|
264
|
+
export const serialise: typeof t.serialise;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Binary deserialization for V8 buffers.
|
|
268
|
+
*
|
|
269
|
+
* Re-exported from the `t` global for module-style imports.
|
|
270
|
+
* @see {@link TitanRuntimeUtils.deserialize}
|
|
271
|
+
*/
|
|
272
|
+
export const deserialize: typeof t.deserialize;
|
|
273
|
+
/** Alias for deserialize. @see {@link TitanRuntimeUtils.deserialise} */
|
|
274
|
+
export const deserialise: typeof t.deserialise;
|
|
275
|
+
|
|
236
276
|
/**
|
|
237
277
|
* Async file system operations (read, write, mkdir, stat, etc.).
|
|
238
278
|
*
|
|
@@ -345,6 +385,23 @@ export const time: typeof t.time;
|
|
|
345
385
|
*/
|
|
346
386
|
export const url: typeof t.url;
|
|
347
387
|
|
|
388
|
+
/**
|
|
389
|
+
* HTTP Response builder utilities.
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```js
|
|
393
|
+
* import { response } from "@titanpl/native";
|
|
394
|
+
*
|
|
395
|
+
* export function get(req) {
|
|
396
|
+
* return response.json({ hello: "world" });
|
|
397
|
+
* }
|
|
398
|
+
* ```
|
|
399
|
+
*
|
|
400
|
+
* Re-exported from the `t` global for module-style imports.
|
|
401
|
+
* @see {@link TitanRuntimeUtils.response} for full documentation.
|
|
402
|
+
*/
|
|
403
|
+
export const response: typeof t.response;
|
|
404
|
+
|
|
348
405
|
/**
|
|
349
406
|
* Runtime validation utilities.
|
|
350
407
|
*
|
|
@@ -647,6 +704,55 @@ declare global {
|
|
|
647
704
|
body?: string;
|
|
648
705
|
error?: string;
|
|
649
706
|
}>;
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Fast binary serialization using V8's internal value format.
|
|
710
|
+
*
|
|
711
|
+
* Highly efficient for complex JavaScript objects including `Date`, `Map`,
|
|
712
|
+
* `Set`, and `TypedArrays`. The resulting `Uint8Array` is stable and
|
|
713
|
+
* can be safely stored in databases (e.g. `t.ls`) or transmitted.
|
|
714
|
+
*
|
|
715
|
+
* @param value - The JavaScript value/object to serialize.
|
|
716
|
+
* @returns A `Uint8Array` containing the binary-serialized representation.
|
|
717
|
+
*
|
|
718
|
+
* @example
|
|
719
|
+
* ```js
|
|
720
|
+
* const complex = { date: new Date(), map: new Map([["a", 1]]) };
|
|
721
|
+
* const bytes = t.serialize(complex);
|
|
722
|
+
* // Store bytes in database or pass to another action
|
|
723
|
+
* ```
|
|
724
|
+
*/
|
|
725
|
+
serialize(value: any): Uint8Array;
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Binary serialization. Alias for `t.serialize`.
|
|
729
|
+
* @see {@link TitanRuntimeUtils.serialize}
|
|
730
|
+
*/
|
|
731
|
+
serialise(value: any): Uint8Array;
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Deserializes a binary buffer back into its original JavaScript value.
|
|
735
|
+
*
|
|
736
|
+
* Restores full object fidelity including native types like `Date` and `Buffer`.
|
|
737
|
+
* Performance is significantly faster than `JSON.parse` for large objects.
|
|
738
|
+
*
|
|
739
|
+
* @param buffer - A `Uint8Array` created by `t.serialize()`.
|
|
740
|
+
* @returns The restored JavaScript value or object.
|
|
741
|
+
* @throws If the buffer is invalid or contains corrupted V8 header data.
|
|
742
|
+
*
|
|
743
|
+
* @example
|
|
744
|
+
* ```js
|
|
745
|
+
* const restored = t.deserialize(bytes);
|
|
746
|
+
* console.log(restored.date instanceof Date); // true
|
|
747
|
+
* ```
|
|
748
|
+
*/
|
|
749
|
+
deserialize(buffer: Uint8Array): any;
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Binary deserialization. Alias for `t.deserialize`.
|
|
753
|
+
* @see {@link TitanRuntimeUtils.deserialize}
|
|
754
|
+
*/
|
|
755
|
+
deserialise(buffer: Uint8Array): any;
|
|
650
756
|
|
|
651
757
|
/**
|
|
652
758
|
* WebSocket communication utilities.
|
|
@@ -655,10 +761,12 @@ declare global {
|
|
|
655
761
|
*
|
|
656
762
|
* @example
|
|
657
763
|
* ```js
|
|
764
|
+
* import { ws } from "@titanpl/native";
|
|
765
|
+
*
|
|
658
766
|
* export default function chat(req) {
|
|
659
767
|
* if (req.event === "open") {
|
|
660
|
-
*
|
|
661
|
-
*
|
|
768
|
+
* ws.send(req.socketId, "Welcome!");
|
|
769
|
+
* ws.broadcast("Someone joined.");
|
|
662
770
|
* }
|
|
663
771
|
* }
|
|
664
772
|
* ```
|
|
@@ -1101,6 +1209,26 @@ declare global {
|
|
|
1101
1209
|
url: TitanCore.URLModule;
|
|
1102
1210
|
|
|
1103
1211
|
/**
|
|
1212
|
+
* HTTP Response builder utilities.
|
|
1213
|
+
*
|
|
1214
|
+
* Provides helpers for crafting standardized HTTP responses, such as JSON,
|
|
1215
|
+
* HTML, redirects, or raw text.
|
|
1216
|
+
*
|
|
1217
|
+
* @example
|
|
1218
|
+
* ```js
|
|
1219
|
+
* import { response } from "@titanpl/native";
|
|
1220
|
+
*
|
|
1221
|
+
* export function get(req) {
|
|
1222
|
+
* if (!req.headers.authorization) {
|
|
1223
|
+
* return response.json({ error: "Unauthorized" }, 401);
|
|
1224
|
+
* }
|
|
1225
|
+
* return response.html("<h1>Welcome</h1>");
|
|
1226
|
+
* }
|
|
1227
|
+
* ```
|
|
1228
|
+
*
|
|
1229
|
+
* @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.response)
|
|
1230
|
+
*/
|
|
1231
|
+
response: TitanCore.ResponseModule;
|
|
1104
1232
|
|
|
1105
1233
|
/**
|
|
1106
1234
|
* Runtime validation utilities.
|
|
@@ -1172,6 +1300,51 @@ declare global {
|
|
|
1172
1300
|
interface TitanResponse {
|
|
1173
1301
|
readonly __titan_response: true;
|
|
1174
1302
|
}
|
|
1303
|
+
|
|
1304
|
+
/**
|
|
1305
|
+
* Response builder interfaces.
|
|
1306
|
+
*/
|
|
1307
|
+
interface ResponseModule {
|
|
1308
|
+
/**
|
|
1309
|
+
* Return a JSON response with an optional status code and headers.
|
|
1310
|
+
*
|
|
1311
|
+
* @param data - The object or value to serialize to JSON.
|
|
1312
|
+
* @param status - The HTTP status code (default: 200).
|
|
1313
|
+
* @param headers - Optional custom headers.
|
|
1314
|
+
* @returns A standard Titan response.
|
|
1315
|
+
*/
|
|
1316
|
+
json(data: any, status?: number, headers?: Record<string, string>): TitanResponse;
|
|
1317
|
+
|
|
1318
|
+
/**
|
|
1319
|
+
* Return an HTML response with an optional status code and headers.
|
|
1320
|
+
*
|
|
1321
|
+
* @param html - The HTML string to return.
|
|
1322
|
+
* @param status - The HTTP status code (default: 200).
|
|
1323
|
+
* @param headers - Optional custom headers.
|
|
1324
|
+
* @returns A standard Titan response.
|
|
1325
|
+
*/
|
|
1326
|
+
html(html: string, status?: number, headers?: Record<string, string>): TitanResponse;
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* Return a plain text response with an optional status code and headers.
|
|
1330
|
+
*
|
|
1331
|
+
* @param text - The string to return.
|
|
1332
|
+
* @param status - The HTTP status code (default: 200).
|
|
1333
|
+
* @param headers - Optional custom headers.
|
|
1334
|
+
* @returns A standard Titan response.
|
|
1335
|
+
*/
|
|
1336
|
+
text(text: string, status?: number, headers?: Record<string, string>): TitanResponse;
|
|
1337
|
+
|
|
1338
|
+
/**
|
|
1339
|
+
* Issue an HTTP redirect to a specific URL.
|
|
1340
|
+
*
|
|
1341
|
+
* @param url - The destination URL.
|
|
1342
|
+
* @param status - The redirect status code (default: 302).
|
|
1343
|
+
* @param headers - Optional custom headers.
|
|
1344
|
+
* @returns A standard Titan response.
|
|
1345
|
+
*/
|
|
1346
|
+
redirect(url: string, status?: number, headers?: Record<string, string>): TitanResponse;
|
|
1347
|
+
}
|
|
1175
1348
|
/**
|
|
1176
1349
|
* Asynchronous file system operations.
|
|
1177
1350
|
*
|
|
@@ -2123,7 +2296,7 @@ declare global {
|
|
|
2123
2296
|
* - t.os
|
|
2124
2297
|
* - t.time
|
|
2125
2298
|
*/
|
|
2126
|
-
|
|
2299
|
+
var process: {
|
|
2127
2300
|
/** Process ID */
|
|
2128
2301
|
pid: number;
|
|
2129
2302
|
|