docs: Expose the rest of core to docs.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 31m24s

This commit is contained in:
2025-07-30 20:25:20 -04:00
parent f1d0151d71
commit c3415ab75c
3 changed files with 57 additions and 18 deletions

View File

@@ -1,7 +1,23 @@
/**
* \file
* \defgroup tfapp Tilde Friends App JS
* Tilde Friends server-side app wrapper.
* @{
*/
/** \cond */
import * as core from './core.js';
let gSessionIndex = 0;
export {App};
/** \endcond */
/** A sequence number of apps. */
let g_session_index = 0;
/**
** App constructor.
** @return An app instance.
*/
function App() {
this._send_queue = [];
this.calls = {};
@@ -9,6 +25,12 @@ function App() {
return this;
}
/**
** Create a function wrapper that when called invokes a function on the app
** itself.
** @param api The function and argument names.
** @return A function.
*/
App.prototype.makeFunction = function (api) {
let self = this;
let result = function () {
@@ -32,6 +54,10 @@ App.prototype.makeFunction = function (api) {
return result;
};
/**
** Send a message to the app.
** @param message The message to send.
*/
App.prototype.send = function (message) {
if (this._send_queue) {
if (this._on_output) {
@@ -46,6 +72,11 @@ App.prototype.send = function (message) {
}
};
/**
** App socket handler.
** @param request The HTTP request of the WebSocket connection.
** @param response The HTTP response.
*/
exports.app_socket = async function socket(request, response) {
let process;
let options = {};
@@ -133,7 +164,7 @@ exports.app_socket = async function socket(request, response) {
options.packageOwner = packageOwner;
options.packageName = packageName;
options.url = message.url;
let sessionId = 'session_' + (gSessionIndex++).toString();
let sessionId = 'session_' + (g_session_index++).toString();
if (blobId) {
if (message.edit_only) {
response.send(
@@ -218,4 +249,4 @@ exports.app_socket = async function socket(request, response) {
response.upgrade(100, {});
};
export {App};
/** @} */

View File

@@ -1,8 +1,14 @@
/**
* TODOC
* TODO: document so we can improve this
* @param {*} url
* @returns
* \file
* \defgroup tfhttp Tilde Friends HTTP Client JS
* Tilde Friends server-side HTTP client.
* @{
*/
/**
* Parse a URL into protocol, host, path, and port parts.
* @param url
* @returns An object of the URL parts.
*/
function parseUrl(url) {
// XXX: Hack.
@@ -16,9 +22,9 @@ function parseUrl(url) {
}
/**
* TODOC
* @param {*} data
* @returns
* Parse an HTTP response into headers and body content.
* @param data The response data, headers and body included.
* @returns headers and body data.
*/
function parseResponse(data) {
let firstLine;
@@ -36,15 +42,15 @@ function parseResponse(data) {
headers[line.substring(colon)] = line.substring(colon + 1);
}
}
return {body: data};
return {headers: headers, body: data};
}
/**
* TODOC
* @param {*} url
* @param {*} options
* @param {*} allowed_hosts
* @returns
* Make an HTTP request.
* @param url The URL.
* @param options Request options.
* @param allowed_hosts List of allowed hosts.
* @return A promise resolved with the response headers and body.
*/
export function fetch(url, options, allowed_hosts) {
let parsed = parseUrl(url);
@@ -111,3 +117,5 @@ export function fetch(url, options, allowed_hosts) {
});
});
}
/** @} */

View File

@@ -15,8 +15,8 @@ let g_next_id = 1;
let g_calls = {};
/**
* TODOC
* @returns
* Check if being called from a browser vs. server-side.
* @return true if called from a browser.
*/
function get_is_browser() {
try {