# Global names of Total.js 5

> Global functions and objects of Total.js 5, with their purpose and usage recipes.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: 9a640579fbb48a0ccec8890088be894d9fbf539324ee4c7d49aa4e8833979023
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

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](/en/total5/events/) |
| `ONCE` | function | Like `ON`, but the listener runs only for the first event. | [events](/en/total5/events/) |
| `OFF` | function | Removes a listener registered with `ON`. | [events](/en/total5/events/) |
| `EMIT` | function | Emits an event with up to seven arguments. | [events](/en/total5/events/) |
| `LOAD` | function | Loads the files of the project (controllers, definitions...); the framework calls it for you at start. | [load-and-npminstall](/en/total5/load-and-npminstall/) |
| `LOADCONFIG` | function | Parses a text in the `config` format and applies it to `CONF`. | [configuration-file](/en/total5/configuration-file/) |
| `LOADRESOURCE` | function | Loads a resource (a translation file) from a text or from a URL. | [localization](/en/total5/localization/) |
| `PAUSESERVER` | function | Pauses or resumes the server by name: while paused, requests get a 503 page. | [pause-server](/en/total5/pause-server/) |
| `DEBUG` | boolean | `true` in debug mode, `false` in release mode. | [release-mode-and-debugging](/en/total5/release-mode-and-debugging/) |
| `CONF` | object | The configuration of the application (the `config` file and its defaults). | [configuration-file](/en/total5/configuration-file/) |
| `DEF` | object | Default handlers and settings of the framework (`DEF.onMail`, `DEF.helpers`, `DEF.onCSRFcheck`...). | [view-helpers-and-config](/en/total5/view-helpers-and-config/) |
| `F` | object | The framework object. `Total` is the same object. | [utility-globals](/en/total5/utility-globals/) |
| `Total` | object | The framework object (same as `F`). `Total.run()` starts the application. | [release-mode-and-debugging](/en/total5/release-mode-and-debugging/) |
| `MAIN` | object | An empty object that the framework creates for your own application data. | [utility-globals](/en/total5/utility-globals/) |
| `REPO` | object | An empty object that the framework creates for your own data. | [utility-globals](/en/total5/utility-globals/) |
| `FUNC` | object | An empty object that the framework creates for your own functions. | [utility-globals](/en/total5/utility-globals/) |
| `TEMP` | object | An object for temporary data; the framework replaces it with a new empty object from time to time. | [utility-globals](/en/total5/utility-globals/) |
| `NOW` | object | The current date, refreshed by the framework once a minute and by some calls such as `CACHE`. | [utility-globals](/en/total5/utility-globals/) |
| `EMPTYARRAY` | object | A frozen empty array, to avoid creating new ones. | [utility-globals](/en/total5/utility-globals/) |
| `EMPTYOBJECT` | object | A frozen empty object, to avoid creating new ones. | [utility-globals](/en/total5/utility-globals/) |
| `MODS` | object | The loaded modules of the `modules/` folder, by id. | [utility-globals](/en/total5/utility-globals/) |
| `PLUGINS` | object | The loaded plugins of the `plugins/` folder, by id. | [utility-globals](/en/total5/utility-globals/) |
| `NOOP` | function | A function that does nothing. | [utility-globals](/en/total5/utility-globals/) |
| `print` | function | The same as `console.log`. | [utility-globals](/en/total5/utility-globals/) |
| `REQUIRE` | function | Like `require`, but also looks in the `node_modules` folder of the application and accepts `node:` names. | [utility-globals](/en/total5/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](/en/total5/http-methods/) |
| `NEWACTION` | function | Declares an action with its input, params, query, output and permissions. | [actions-crud](/en/total5/actions-crud/) |
| `NEWSCHEMA` | function | Groups the actions of an entity under one name. | [schemas](/en/total5/schemas/) |
| `ACTION` | function | Runs an action from your own code. | [calling-actions-from-code](/en/total5/calling-actions-from-code/) |
| `EXEC` | function | The same function as `ACTION`. | [calling-actions-from-code](/en/total5/calling-actions-from-code/) |
| `NEWTRANSFORM` | function | Adds a step to a named chain of transformations. | [transforms](/en/total5/transforms/) |
| `TRANSFORM` | function | Runs a value through a chain of transformations. | [transforms](/en/total5/transforms/) |
| `MIDDLEWARE` | function | Registers a middleware to be used in routes with `#name`. | [middleware](/en/total5/middleware/) |
| `NEWMIDDLEWARE` | function | The same function as `MIDDLEWARE`. | [middleware](/en/total5/middleware/) |
| `PROXY` | function | Forwards the requests below a URL prefix to another server. | [proxy](/en/total5/proxy/) |
| `CORS` | function | Sets the origins that may call the application from a browser. | [cors](/en/total5/cors/) |
| `ErrorBuilder` | function | The class that collects validation errors. | [errors-and-audit](/en/total5/errors-and-audit/) |
| `SUCCESS` | function | Returns the object that the framework sends for a successful operation (`{ success: true, value: value }`). | [errors-and-audit](/en/total5/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](/en/total5/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](/en/total5/action-user-and-permissions/) |
| `AUTH` | function | Authenticates every request: a function, or the options of the built-in sessions. | [sessions-with-built-in-auth](/en/total5/sessions-with-built-in-auth/) |
| `BLOCKED` | function | Counts the calls of an IP address and tells when it reached the limit. | [rate-limiting](/en/total5/rate-limiting/) |
| `AUDIT` | function | Appends an audit entry (user, message and type) to a log file in `logs/`. | [errors-and-audit](/en/total5/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](/en/total5/nosql-crud/) |
| `DATA` | object | Database-independent entry to the query builder. | [data-api](/en/total5/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](/en/total5/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](/en/total5/query-builder-db/) |
| `CACHE` | object | An in-memory store with expiration. | [cache](/en/total5/cache/) |
| `FILECACHE` | function | Computes a result once and keeps it in a file for a while. | [filecache](/en/total5/filecache/) |
| `MEMORIZE` | function | A JSON object saved on disk. | [memorize](/en/total5/memorize/) |
| `FILESTORAGE` | function | A storage for uploaded files. | [filestorage](/en/total5/filestorage/) |

## HTTP, WebSocket and messaging clients

| Name | Kind | What it does | Recipe |
|---|---|---|---|
| `REQUEST` | function | Low-level HTTP client. | [request-and-download](/en/total5/request-and-download/) |
| `DOWNLOAD` | function | Saves the response of a URL into a file. | [request-and-download](/en/total5/request-and-download/) |
| `RESTBuilder` | function | Builder for calls to other HTTP APIs. | [restbuilder](/en/total5/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](/en/total5/ajax-requests/) |
| `API` | function | Calls an operation of an external service through its driver: `API('service', 'operation', data).callback($)`. | [api-drivers](/en/total5/api-drivers/) |
| `NEWAPI` | function | Registers the driver `function(options, next)` of a service for `API`, with an optional configuration. | [api-drivers](/en/total5/api-drivers/) |
| `TotalAPI` | function | Calls a Total.js platform service through `API('TAPI', name, model)`. | [remote-service-boundaries](/en/total5/remote-service-boundaries/) |
| `WEBSOCKETCLIENT` | function | A WebSocket client for your application. | [websocket-client](/en/total5/websocket-client/) |
| `TMSCLIENT` | function | A client of the Total Messaging Service. | [tms](/en/total5/tms/) |
| `PUBLISH` | function | Sends a message to the TMS clients that subscribed to it. | [tms](/en/total5/tms/) |
| `NEWPUBLISH` | function | Declares a message that the application publishes. | [tms](/en/total5/tms/) |
| `SUBSCRIBE` | function | Adds a listener for a message that clients send to the application. | [tms](/en/total5/tms/) |
| `UNSUBSCRIBE` | function | Removes the listeners of a TMS message. | [tms](/en/total5/tms/) |
| `NEWSUBSCRIBE` | function | Declares a message that the application receives. | [tms](/en/total5/tms/) |
| `NEWCALL` | function | Declares a function that TMS clients can call. | [tms](/en/total5/tms/) |
| `OPENCLIENT` | function | Connects to OpenPlatform over WebSocket for remote calls, events and shared connections. | [openclient-protocol](/en/total5/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](/en/total5/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](/en/total5/proxy-tunnel/) |
| `LDAP` | function | Connects to an LDAP server (port 389 unless `ldap.port` says otherwise) and calls back with the result. | [ldap-openldap](/en/total5/ldap-openldap/) |
| `MAIL` | function | Sends an email whose body is a view. | [send-email](/en/total5/send-email/) |
| `HTMLMAIL` | function | Sends an email whose body is a string of HTML. | [send-email](/en/total5/send-email/) |
| `LOGMAIL` | function | Sends an email whose body is a text printed in a `<pre>` block (pass the body as a text). | [logmail](/en/total5/logmail/) |
| `Mail` | object | The class behind the email sending (SMTP). | [send-email](/en/total5/send-email/) |
| `AIMODEL` | function | Starts a request for a language model registered with `NEWAIMODEL`: `AIMODEL('name').user('text').callback($.callback())`. | [ai-models](/en/total5/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](/en/total5/ai-models/) |
| `NEWAIMODEL` | function | Registers the driver `function(ai, done)` of one or more AI models for `AIMODEL`, with an optional configuration. | [ai-models](/en/total5/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](/en/total5/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](/en/total5/file-download/) |
| `MERGE` | function | Registers a virtual file made of several files, minified. | [minification](/en/total5/minification/) |
| `TOUCH` | function | Clears the cached minified, temporary and not-found entries of a URL, or of all of them. | [touch-static-cache](/en/total5/touch-static-cache/) |
| `CLEANUP` | function | Destroys a stream when it has finished. | [cleanup-streams](/en/total5/cleanup-streams/) |
| `BACKUP` | function | Packs a directory into one file. | [backup-restore-shell](/en/total5/backup-restore-shell/) |
| `RESTORE` | function | Unpacks a file created with `BACKUP`. | [backup-restore-shell](/en/total5/backup-restore-shell/) |
| `SHELL` | function | Runs a shell command in the folder of the project. | [backup-restore-shell](/en/total5/backup-restore-shell/) |
| `NPMINSTALL` | function | Installs an npm package in the modules folder of the application. | [load-and-npminstall](/en/total5/load-and-npminstall/) |
| `IMPORT` | function | Downloads a JavaScript file from a URL and loads it. | [import-remote-module](/en/total5/import-remote-module/) |
| `Image` | object | Image processing with GraphicsMagick or ImageMagick. | [images](/en/total5/images/) |
| `NEWTHREAD` | function | Starts a worker thread. | [workers-and-threads](/en/total5/workers-and-threads/) |
| `NEWFORK` | function | Starts a child process. | [workers-and-threads](/en/total5/workers-and-threads/) |
| `NEWTHREADPOOL` | function | Creates a pool of workers that jobs borrow one at a time. | [thread-pool](/en/total5/thread-pool/) |
| `CRON` | function | Runs a function on a schedule. | [cron-jobs](/en/total5/cron-jobs/) |
| `setTimeout2` | function | `setTimeout` with an id: calling it again with the same id replaces the previous timer. | [debounce-timers](/en/total5/debounce-timers/) |
| `clearTimeout2` | function | Cancels a timer created with `setTimeout2`. | [debounce-timers](/en/total5/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](/en/total5/flowstream/), [flowstream-component-test](/en/total5/flowstream-component-test/) |
| `FlowStream` | object | The same object as `Flow`. | [flowstream](/en/total5/flowstream/) |
| `NEWMACRO` | function | Compiles a macro from a string. | [macros](/en/total5/macros/) |
| `NEWCOMPONENT` | function | Compiles the HTML of a component. | [native-components](/en/total5/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](/en/total5/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](/en/total5/utilities/) |
| `Utils` | object | The same object as `U`. | [utilities](/en/total5/utilities/) |
| `UID` | function | Creates a short unique id sorted by time. | [unique-ids-and-hashes](/en/total5/unique-ids-and-hashes/) |
| `GUID` | function | Creates a random string of the given length. | [unique-ids-and-hashes](/en/total5/unique-ids-and-hashes/) |
| `HASH` | function | Returns a fast numeric hash (not for passwords). | [unique-ids-and-hashes](/en/total5/unique-ids-and-hashes/) |
| `CLONE` | function | Makes a deep copy of an object. | [utility-globals](/en/total5/utility-globals/) |
| `COPY` | function | Copies the properties of the first object into the second one and returns the second. | [utility-globals](/en/total5/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](/en/total5/diffarr-sync-lists/) |
| `QUERIFY` | function | Builds a URL with a query string from an object. | [utility-globals](/en/total5/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](/en/total5/utility-globals/) |
| `ENCRYPT` | function | Turns a value into an opaque token. | [encrypt-and-decrypt](/en/total5/encrypt-and-decrypt/) |
| `DECRYPT` | function | Reads a value from a token created with `ENCRYPT`. | [encrypt-and-decrypt](/en/total5/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](/en/total5/request-bound-tokens/) |
| `DECRYPTREQ` | function | Reads a value created with `ENCRYPTREQ`; returns nothing when the request does not match. | [request-bound-tokens](/en/total5/request-bound-tokens/) |
| `LOCALIZE` | function | Chooses the language of every request. | [localization](/en/total5/localization/) |
| `TRANSLATE` | function | Translates the `@(...)` texts of a string into a language. | [localization](/en/total5/localization/) |
| `Tangular` | object | The template engine (`Tangular.render()`). | [tangular-templates](/en/total5/tangular-templates/) |
| `Ta` | object | Another name of `Tangular`, the template engine. | [template-files](/en/total5/template-files/) |
| `Thelpers` | object | The helper functions available in Tangular templates. | [tangular-templates](/en/total5/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](/en/total5/template-files/) |

```js controllers/globals.js
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);
}
```
