@titanpl/native 7.0.0 → 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 CHANGED
@@ -37,6 +37,21 @@ export interface WebSocketModule {
37
37
  }
38
38
 
39
39
  export const db: any;
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
+ */
40
55
  export const ws: WebSocketModule;
41
56
  export const path: any;
42
57
  export const jwt: any;
@@ -52,6 +67,18 @@ export const net: any;
52
67
  export const proc: any;
53
68
  export const time: any;
54
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
+ */
55
82
  export const response: any;
56
83
  export const valid: any;
57
84
 
package/index.js CHANGED
@@ -39,6 +39,7 @@ 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;
42
43
 
43
44
  // Serialization
44
45
  export const serialize = t.serialize;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/native",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "Titan native utilities package",
5
5
  "type": "module",
6
6
  "keywords": [
package/t.native.d.ts CHANGED
@@ -236,6 +236,18 @@ export const db: typeof t.db;
236
236
  /**
237
237
  * WebSocket communication utilities.
238
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
+ *
239
251
  * Re-exported from the `t` global for module-style imports.
240
252
  * @see {@link TitanRuntimeUtils.ws} for full documentation.
241
253
  */
@@ -373,6 +385,23 @@ export const time: typeof t.time;
373
385
  */
374
386
  export const url: typeof t.url;
375
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
+
376
405
  /**
377
406
  * Runtime validation utilities.
378
407
  *
@@ -732,10 +761,12 @@ declare global {
732
761
  *
733
762
  * @example
734
763
  * ```js
764
+ * import { ws } from "@titanpl/native";
765
+ *
735
766
  * export default function chat(req) {
736
767
  * if (req.event === "open") {
737
- * t.ws.send(req.socketId, "Welcome!");
738
- * t.ws.broadcast("Someone joined.");
768
+ * ws.send(req.socketId, "Welcome!");
769
+ * ws.broadcast("Someone joined.");
739
770
  * }
740
771
  * }
741
772
  * ```
@@ -1178,6 +1209,26 @@ declare global {
1178
1209
  url: TitanCore.URLModule;
1179
1210
 
1180
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;
1181
1232
 
1182
1233
  /**
1183
1234
  * Runtime validation utilities.
@@ -1249,6 +1300,51 @@ declare global {
1249
1300
  interface TitanResponse {
1250
1301
  readonly __titan_response: true;
1251
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
+ }
1252
1348
  /**
1253
1349
  * Asynchronous file system operations.
1254
1350
  *
@@ -2200,7 +2296,7 @@ declare global {
2200
2296
  * - t.os
2201
2297
  * - t.time
2202
2298
  */
2203
- const process: {
2299
+ var process: {
2204
2300
  /** Process ID */
2205
2301
  pid: number;
2206
2302