Global names of Total.js 5
Total.js 5 exposes global functions and objects for routing, actions, storage, messaging and application utilities. Use the table to find a name and its usage recipe.
| Name | Kind | What it does | Recipe |
|---|---|---|---|
ON | function | Registers a listener for an application event. | events |
ONCE | function | Like ON, but the listener runs only for the first event. | events |
OFF | function | Removes a listener registered with ON. | events |
EMIT | function | Emits an event with up to seven arguments. | events |
LOAD | function | Loads the files of the project (controllers, definitions...); the framework calls it for you at start. | load-and-npminstall |
LOADCONFIG | function | Parses a text in the config format and applies it to CONF. | configuration-file |
LOADRESOURCE | function | Loads a resource (a translation file) from a text or from a URL. | localization |
PAUSESERVER | function | Pauses or resumes the server by name: while paused, requests get a 503 page. | pause-server |
DEBUG | boolean | true in debug mode, false in release mode. | release-mode-and-debugging |
CONF | object | The configuration of the application (the config file and its defaults). | configuration-file |
DEF | object | Default handlers and settings of the framework (DEF.onMail, DEF.helpers, DEF.onCSRFcheck...). | view-helpers-and-config |
F | object | The framework object. Total is the same object. | utility-globals |
Total | object | The framework object (same as F). Total.run() starts the application. | release-mode-and-debugging |
MAIN | object | An empty object that the framework creates for your own application data. | utility-globals |
REPO | object | An empty object that the framework creates for your own data. | utility-globals |
FUNC | object | An empty object that the framework creates for your own functions. | utility-globals |
TEMP | object | An object for temporary data; the framework replaces it with a new empty object from time to time. | utility-globals |
NOW | object | The current date, refreshed by the framework once a minute and by some calls such as CACHE. | utility-globals |
EMPTYARRAY | object | A frozen empty array, to avoid creating new ones. | utility-globals |
EMPTYOBJECT | object | A frozen empty object, to avoid creating new ones. | utility-globals |
MODS | object | The loaded modules of the modules/ folder, by id. | utility-globals |
PLUGINS | object | The loaded plugins of the plugins/ folder, by id. | utility-globals |
NOOP | function | A function that does nothing. | utility-globals |
print | function | The same as console.log. | utility-globals |
REQUIRE | function | Like require, but also looks in the node_modules folder of the application and accepts node: names. | utility-globals |
Routing, actions and middleware
| Name | Kind | What it does | Recipe |
|---|---|---|---|
ROUTE | function | Declares a route (HTTP, SOCKET, FILE, API or a fallback such as #404). | http-methods |
NEWACTION | function | Declares an action with its input, params, query, output and permissions. | actions-crud |
NEWSCHEMA | function | Groups the actions of an entity under one name. | schemas |
ACTION | function | Runs an action from your own code. | calling-actions-from-code |
EXEC | function | The same function as ACTION. | calling-actions-from-code |
NEWTRANSFORM | function | Adds a step to a named chain of transformations. | transforms |
TRANSFORM | function | Runs a value through a chain of transformations. | transforms |
MIDDLEWARE | function | Registers a middleware to be used in routes with #name. | middleware |
NEWMIDDLEWARE | function | The same function as MIDDLEWARE. | middleware |
PROXY | function | Forwards the requests below a URL prefix to another server. | proxy |
CORS | function | Sets the origins that may call the application from a browser. | cors |
ErrorBuilder | function | The class that collects validation errors. | errors-and-audit |
SUCCESS | function | Returns the object that the framework sends for a successful operation ({ success: true, value: value }). | errors-and-audit |
ERROR | function | ERROR(name) returns a callback that logs the error it receives under that name; ERROR() returns the default error callback. | errors-and-audit |
UNAUTHORIZED | function | UNAUTHORIZED($, ...permissions) answers 401 and returns true when the user has none of the permissions; it returns false when the user has one of them or is a super administrator. | action-user-and-permissions |
AUTH | function | Authenticates every request: a function, or the options of the built-in sessions. | sessions-with-built-in-auth |
BLOCKED | function | Counts the calls of an IP address and tells when it reached the limit. | rate-limiting |
AUDIT | function | Appends an audit entry (user, message and type) to a log file in logs/. | errors-and-audit |
Data and cache
| Name | Kind | What it does | Recipe |
|---|---|---|---|
NOSQL | function | Opens a table of the built-in NoSQL database. | nosql-crud |
DATA | object | Database-independent entry to the query builder. | data-api |
DB | function | Starts a query with the query builder (DB().find('table').where(...).callback($)); the query is run by the driver registered with NEWDB. | query-builder-db |
NEWDB | function | Registers a database driver function(options, callback) for the query builder: the default one, or a named one with NEWDB('name', fn). | query-builder-db |
CACHE | object | An in-memory store with expiration. | cache |
FILECACHE | function | Computes a result once and keeps it in a file for a while. | filecache |
MEMORIZE | function | A JSON object saved on disk. | memorize |
FILESTORAGE | function | A storage for uploaded files. | filestorage |
HTTP, WebSocket and messaging clients
| Name | Kind | What it does | Recipe |
|---|---|---|---|
REQUEST | function | Low-level HTTP client. | request-and-download |
DOWNLOAD | function | Saves the response of a URL into a file. | request-and-download |
RESTBuilder | function | Builder for calls to other HTTP APIs. | restbuilder |
AJAX | function | AJAX('METHOD /url/', data, callback) makes a request with the header x-requested-with and returns the parsed body; it returns a promise when there is no callback. | ajax-requests |
API | function | Calls an operation of an external service through its driver: API('service', 'operation', data).callback($). | api-drivers |
NEWAPI | function | Registers the driver function(options, next) of a service for API, with an optional configuration. | api-drivers |
TotalAPI | function | Calls a Total.js platform service through API('TAPI', name, model). | remote-service-boundaries |
WEBSOCKETCLIENT | function | A WebSocket client for your application. | websocket-client |
TMSCLIENT | function | A client of the Total Messaging Service. | tms |
PUBLISH | function | Sends a message to the TMS clients that subscribed to it. | tms |
NEWPUBLISH | function | Declares a message that the application publishes. | tms |
SUBSCRIBE | function | Adds a listener for a message that clients send to the application. | tms |
UNSUBSCRIBE | function | Removes the listeners of a TMS message. | tms |
NEWSUBSCRIBE | function | Declares a message that the application receives. | tms |
NEWCALL | function | Declares a function that TMS clients can call. | tms |
OPENCLIENT | function | Connects to OpenPlatform over WebSocket for remote calls, events and shared connections. | openclient-protocol |
PROXYCLIENT | function | Connects to a PROXYSERVER over WebSocket and answers its requests with a local server (a port or ip:port). | proxy-tunnel |
PROXYSERVER | function | Turns the application into a tunnel server: the HTTP requests of an endpoint are sent through a WebSocket route to a PROXYCLIENT. | proxy-tunnel |
LDAP | function | Connects to an LDAP server (port 389 unless ldap.port says otherwise) and calls back with the result. | ldap-openldap |
MAIL | function | Sends an email whose body is a view. | send-email |
HTMLMAIL | function | Sends an email whose body is a string of HTML. | send-email |
LOGMAIL | function | Sends an email whose body is a text printed in a <pre> block (pass the body as a text). | logmail |
Mail | object | The class behind the email sending (SMTP). | send-email |
AIMODEL | function | Starts a request for a language model registered with NEWAIMODEL: AIMODEL('name').user('text').callback($.callback()). | ai-models |
AIPARSER | function | Creates a parser for the streamed answer of an AI provider (openai, claude...): write() takes pieces and end() returns the content, thinking and tool calls. | ai-models |
NEWAIMODEL | function | Registers the driver function(ai, done) of one or more AI models for AIMODEL, with an optional configuration. | ai-models |
PYPELINE | function | Runs a Python file of the pypelines/ folder (or inline Python code) from the application and talks to it with JSON frames over a socket. | pypeline |
Files, system and workers
| Name | Kind | What it does | Recipe |
|---|---|---|---|
PATH | object | Helpers that build paths in the project folders (PATH.root(), PATH.public(), PATH.tmp()...). | file-download |
MERGE | function | Registers a virtual file made of several files, minified. | minification |
TOUCH | function | Clears the cached minified, temporary and not-found entries of a URL, or of all of them. | touch-static-cache |
CLEANUP | function | Destroys a stream when it has finished. | cleanup-streams |
BACKUP | function | Packs a directory into one file. | backup-restore-shell |
RESTORE | function | Unpacks a file created with BACKUP. | backup-restore-shell |
SHELL | function | Runs a shell command in the folder of the project. | backup-restore-shell |
NPMINSTALL | function | Installs an npm package in the modules folder of the application. | load-and-npminstall |
IMPORT | function | Downloads a JavaScript file from a URL and loads it. | import-remote-module |
Image | object | Image processing with GraphicsMagick or ImageMagick. | images |
NEWTHREAD | function | Starts a worker thread. | workers-and-threads |
NEWFORK | function | Starts a child process. | workers-and-threads |
NEWTHREADPOOL | function | Creates a pool of workers that jobs borrow one at a time. | thread-pool |
CRON | function | Runs a function on a schedule. | cron-jobs |
setTimeout2 | function | setTimeout with an id: calling it again with the same id replaces the previous timer. | debounce-timers |
clearTimeout2 | function | Cancels a timer created with setTimeout2. | debounce-timers |
Flow | object | The manager of the FlowStreams of the application: Flow.load(schema), Flow.remove(id), Flow.instances and Flow.test() for one component. | flowstream, flowstream-component-test |
FlowStream | object | The same object as Flow. | flowstream |
NEWMACRO | function | Compiles a macro from a string. | macros |
NEWCOMPONENT | function | Compiles the HTML of a component. | native-components |
COMPONENTATOR | function | Downloads a Componentator bundle into public/ as ui-<name>-<hash>.min.js and stores its address in F.repo[name]. | remote-service-boundaries |
Utilities, templates and localization
| Name | Kind | What it does | Recipe |
|---|---|---|---|
U | object | The utility object of the framework (U.extend(), U.clone()...). | utilities |
Utils | object | The same object as U. | utilities |
UID | function | Creates a short unique id sorted by time. | unique-ids-and-hashes |
GUID | function | Creates a random string of the given length. | unique-ids-and-hashes |
HASH | function | Returns a fast numeric hash (not for passwords). | unique-ids-and-hashes |
CLONE | function | Makes a deep copy of an object. | utility-globals |
COPY | function | Copies the properties of the first object into the second one and returns the second. | utility-globals |
DIFFARR | function | Compares two arrays of objects by a property and returns the objects to add, the pairs to update and the values to remove. | diffarr-sync-lists |
QUERIFY | function | Builds a URL with a query string from an object. | utility-globals |
PROMISIFY | function | PROMISIFY(fn, a, b, c) calls a function that takes a callback as the last argument and returns a promise. | utility-globals |
ENCRYPT | function | Turns a value into an opaque token. | encrypt-and-decrypt |
DECRYPT | function | Reads a value from a token created with ENCRYPT. | encrypt-and-decrypt |
ENCRYPTREQ | function | Encrypts a value together with the user agent of a request (and its IP address when strict). | request-bound-tokens |
DECRYPTREQ | function | Reads a value created with ENCRYPTREQ; returns nothing when the request does not match. | request-bound-tokens |
LOCALIZE | function | Chooses the language of every request. | localization |
TRANSLATE | function | Translates the @(...) texts of a string into a language. | localization |
Tangular | object | The template engine (Tangular.render()). | tangular-templates |
Ta | object | Another name of Tangular, the template engine. | template-files |
Thelpers | object | The helper functions available in Tangular templates. | tangular-templates |
TEMPLATE | function | Renders a Tangular template that is a text, a file of the templates folder or a URL, and returns a promise with the text. | template-files |
exports.install = function() {
ROUTE('GET /globals/', globals);
};
function globals($) {
var output = {};
for (var name of Object.getOwnPropertyNames(globalThis)) {
var value;
try {
value = globalThis[name];
} catch (e) {
value = undefined;
}
output[name] = typeof(value) === 'function' ? 'function' : value === null ? 'null' : typeof(value);
}
$.json(output);
}