ForgeDocumentation
en

Documentation

Global names of Total.js 5

Total.js 5 · total5@0.0.19 referenceglobals Executed against 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.

NameKindWhat it doesRecipe
ONfunctionRegisters a listener for an application event.events
ONCEfunctionLike ON, but the listener runs only for the first event.events
OFFfunctionRemoves a listener registered with ON.events
EMITfunctionEmits an event with up to seven arguments.events
LOADfunctionLoads the files of the project (controllers, definitions...); the framework calls it for you at start.load-and-npminstall
LOADCONFIGfunctionParses a text in the config format and applies it to CONF.configuration-file
LOADRESOURCEfunctionLoads a resource (a translation file) from a text or from a URL.localization
PAUSESERVERfunctionPauses or resumes the server by name: while paused, requests get a 503 page.pause-server
DEBUGbooleantrue in debug mode, false in release mode.release-mode-and-debugging
CONFobjectThe configuration of the application (the config file and its defaults).configuration-file
DEFobjectDefault handlers and settings of the framework (DEF.onMail, DEF.helpers, DEF.onCSRFcheck...).view-helpers-and-config
FobjectThe framework object. Total is the same object.utility-globals
TotalobjectThe framework object (same as F). Total.run() starts the application.release-mode-and-debugging
MAINobjectAn empty object that the framework creates for your own application data.utility-globals
REPOobjectAn empty object that the framework creates for your own data.utility-globals
FUNCobjectAn empty object that the framework creates for your own functions.utility-globals
TEMPobjectAn object for temporary data; the framework replaces it with a new empty object from time to time.utility-globals
NOWobjectThe current date, refreshed by the framework once a minute and by some calls such as CACHE.utility-globals
EMPTYARRAYobjectA frozen empty array, to avoid creating new ones.utility-globals
EMPTYOBJECTobjectA frozen empty object, to avoid creating new ones.utility-globals
MODSobjectThe loaded modules of the modules/ folder, by id.utility-globals
PLUGINSobjectThe loaded plugins of the plugins/ folder, by id.utility-globals
NOOPfunctionA function that does nothing.utility-globals
printfunctionThe same as console.log.utility-globals
REQUIREfunctionLike require, but also looks in the node_modules folder of the application and accepts node: names.utility-globals

Routing, actions and middleware

NameKindWhat it doesRecipe
ROUTEfunctionDeclares a route (HTTP, SOCKET, FILE, API or a fallback such as #404).http-methods
NEWACTIONfunctionDeclares an action with its input, params, query, output and permissions.actions-crud
NEWSCHEMAfunctionGroups the actions of an entity under one name.schemas
ACTIONfunctionRuns an action from your own code.calling-actions-from-code
EXECfunctionThe same function as ACTION.calling-actions-from-code
NEWTRANSFORMfunctionAdds a step to a named chain of transformations.transforms
TRANSFORMfunctionRuns a value through a chain of transformations.transforms
MIDDLEWAREfunctionRegisters a middleware to be used in routes with #name.middleware
NEWMIDDLEWAREfunctionThe same function as MIDDLEWARE.middleware
PROXYfunctionForwards the requests below a URL prefix to another server.proxy
CORSfunctionSets the origins that may call the application from a browser.cors
ErrorBuilderfunctionThe class that collects validation errors.errors-and-audit
SUCCESSfunctionReturns the object that the framework sends for a successful operation ({ success: true, value: value }).errors-and-audit
ERRORfunctionERROR(name) returns a callback that logs the error it receives under that name; ERROR() returns the default error callback.errors-and-audit
UNAUTHORIZEDfunctionUNAUTHORIZED($, ...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
AUTHfunctionAuthenticates every request: a function, or the options of the built-in sessions.sessions-with-built-in-auth
BLOCKEDfunctionCounts the calls of an IP address and tells when it reached the limit.rate-limiting
AUDITfunctionAppends an audit entry (user, message and type) to a log file in logs/.errors-and-audit

Data and cache

NameKindWhat it doesRecipe
NOSQLfunctionOpens a table of the built-in NoSQL database.nosql-crud
DATAobjectDatabase-independent entry to the query builder.data-api
DBfunctionStarts a query with the query builder (DB().find('table').where(...).callback($)); the query is run by the driver registered with NEWDB.query-builder-db
NEWDBfunctionRegisters a database driver function(options, callback) for the query builder: the default one, or a named one with NEWDB('name', fn).query-builder-db
CACHEobjectAn in-memory store with expiration.cache
FILECACHEfunctionComputes a result once and keeps it in a file for a while.filecache
MEMORIZEfunctionA JSON object saved on disk.memorize
FILESTORAGEfunctionA storage for uploaded files.filestorage

HTTP, WebSocket and messaging clients

NameKindWhat it doesRecipe
REQUESTfunctionLow-level HTTP client.request-and-download
DOWNLOADfunctionSaves the response of a URL into a file.request-and-download
RESTBuilderfunctionBuilder for calls to other HTTP APIs.restbuilder
AJAXfunctionAJAX('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
APIfunctionCalls an operation of an external service through its driver: API('service', 'operation', data).callback($).api-drivers
NEWAPIfunctionRegisters the driver function(options, next) of a service for API, with an optional configuration.api-drivers
TotalAPIfunctionCalls a Total.js platform service through API('TAPI', name, model).remote-service-boundaries
WEBSOCKETCLIENTfunctionA WebSocket client for your application.websocket-client
TMSCLIENTfunctionA client of the Total Messaging Service.tms
PUBLISHfunctionSends a message to the TMS clients that subscribed to it.tms
NEWPUBLISHfunctionDeclares a message that the application publishes.tms
SUBSCRIBEfunctionAdds a listener for a message that clients send to the application.tms
UNSUBSCRIBEfunctionRemoves the listeners of a TMS message.tms
NEWSUBSCRIBEfunctionDeclares a message that the application receives.tms
NEWCALLfunctionDeclares a function that TMS clients can call.tms
OPENCLIENTfunctionConnects to OpenPlatform over WebSocket for remote calls, events and shared connections.openclient-protocol
PROXYCLIENTfunctionConnects to a PROXYSERVER over WebSocket and answers its requests with a local server (a port or ip:port).proxy-tunnel
PROXYSERVERfunctionTurns the application into a tunnel server: the HTTP requests of an endpoint are sent through a WebSocket route to a PROXYCLIENT.proxy-tunnel
LDAPfunctionConnects to an LDAP server (port 389 unless ldap.port says otherwise) and calls back with the result.ldap-openldap
MAILfunctionSends an email whose body is a view.send-email
HTMLMAILfunctionSends an email whose body is a string of HTML.send-email
LOGMAILfunctionSends an email whose body is a text printed in a <pre> block (pass the body as a text).logmail
MailobjectThe class behind the email sending (SMTP).send-email
AIMODELfunctionStarts a request for a language model registered with NEWAIMODEL: AIMODEL('name').user('text').callback($.callback()).ai-models
AIPARSERfunctionCreates 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
NEWAIMODELfunctionRegisters the driver function(ai, done) of one or more AI models for AIMODEL, with an optional configuration.ai-models
PYPELINEfunctionRuns 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

NameKindWhat it doesRecipe
PATHobjectHelpers that build paths in the project folders (PATH.root(), PATH.public(), PATH.tmp()...).file-download
MERGEfunctionRegisters a virtual file made of several files, minified.minification
TOUCHfunctionClears the cached minified, temporary and not-found entries of a URL, or of all of them.touch-static-cache
CLEANUPfunctionDestroys a stream when it has finished.cleanup-streams
BACKUPfunctionPacks a directory into one file.backup-restore-shell
RESTOREfunctionUnpacks a file created with BACKUP.backup-restore-shell
SHELLfunctionRuns a shell command in the folder of the project.backup-restore-shell
NPMINSTALLfunctionInstalls an npm package in the modules folder of the application.load-and-npminstall
IMPORTfunctionDownloads a JavaScript file from a URL and loads it.import-remote-module
ImageobjectImage processing with GraphicsMagick or ImageMagick.images
NEWTHREADfunctionStarts a worker thread.workers-and-threads
NEWFORKfunctionStarts a child process.workers-and-threads
NEWTHREADPOOLfunctionCreates a pool of workers that jobs borrow one at a time.thread-pool
CRONfunctionRuns a function on a schedule.cron-jobs
setTimeout2functionsetTimeout with an id: calling it again with the same id replaces the previous timer.debounce-timers
clearTimeout2functionCancels a timer created with setTimeout2.debounce-timers
FlowobjectThe 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
FlowStreamobjectThe same object as Flow.flowstream
NEWMACROfunctionCompiles a macro from a string.macros
NEWCOMPONENTfunctionCompiles the HTML of a component.native-components
COMPONENTATORfunctionDownloads 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

NameKindWhat it doesRecipe
UobjectThe utility object of the framework (U.extend(), U.clone()...).utilities
UtilsobjectThe same object as U.utilities
UIDfunctionCreates a short unique id sorted by time.unique-ids-and-hashes
GUIDfunctionCreates a random string of the given length.unique-ids-and-hashes
HASHfunctionReturns a fast numeric hash (not for passwords).unique-ids-and-hashes
CLONEfunctionMakes a deep copy of an object.utility-globals
COPYfunctionCopies the properties of the first object into the second one and returns the second.utility-globals
DIFFARRfunctionCompares 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
QUERIFYfunctionBuilds a URL with a query string from an object.utility-globals
PROMISIFYfunctionPROMISIFY(fn, a, b, c) calls a function that takes a callback as the last argument and returns a promise.utility-globals
ENCRYPTfunctionTurns a value into an opaque token.encrypt-and-decrypt
DECRYPTfunctionReads a value from a token created with ENCRYPT.encrypt-and-decrypt
ENCRYPTREQfunctionEncrypts a value together with the user agent of a request (and its IP address when strict).request-bound-tokens
DECRYPTREQfunctionReads a value created with ENCRYPTREQ; returns nothing when the request does not match.request-bound-tokens
LOCALIZEfunctionChooses the language of every request.localization
TRANSLATEfunctionTranslates the @(...) texts of a string into a language.localization
TangularobjectThe template engine (Tangular.render()).tangular-templates
TaobjectAnother name of Tangular, the template engine.template-files
ThelpersobjectThe helper functions available in Tangular templates.tangular-templates
TEMPLATEfunctionRenders 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
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);
}