Class: Application
The application: the root module, created and launched by the static fluent API. Application.run() gives its options (its identity and its components, providers, objects and bootstrap); the other static calls set its environment variables, path aliases and lifecycle handlers. The application launches once, in the turn of the event loop following the first calls; the calls made once its launch started only add their handlers (env(), alias() and run() have no effect then):
- the environment variables are set, the aliases registered (
@runtimebeing the working directory); - the options are read (from the getter given to
run(), which may be async) and validated, the identity applied (process.titleis the application ID, the time zone and the mode set); - the application is created in a new root container: its objects are registered and its bootstrap runs in order;
- the
onLaunched()handlers and the objects'launched()hooks run.
A failure of steps 1 to 3 is a fatal exception: the onFatalException() handler runs (or the error is logged), then the process exits (code 1 by default). The application ends by app.exit() or a shutdown signal (shutdownSignals option): the onDone() handlers run, the objects are destroyed, then the process exits.
The objects of the application are reached with @Inject, or with app.getObject().
Example
import {Application, Component} from 'lakutata'
class Greeter extends Component {
public greet(name: string): string {
return `Hello, ${name}`
}
}
Application
.env({TZ_NAME: 'Asia/Shanghai'})
.alias({'@data': './data'}, true)
.run(() => ({
id: 'greeter.app',
name: 'Greeter',
components: {
greeter: {class: Greeter}
},
bootstrap: ['greeter']
}))
.onLaunched(async (app, logger): Promise<void> => {
const greeter: Greeter = await app.getObject<Greeter>('greeter')
logger.info(greeter.greet(app.appName))
})
.onDone((app, logger, reason): void => logger.info('Exiting with the code %d', reason.code))
.onFatalException((error, logger): number => {
logger.error(error)
return 2
})Extends
Indexable
[
key:symbol]:Object
Constructors
Constructor
new Application(
cradleProxy):Application
Called by the container only: a module is created through a container, never with new.
Parameters
cradleProxy
Record<string | symbol, any>
The container's resolution proxy.
Returns
Application
Inherited from
Properties
constructor
constructor:
Function
The initial value of Object.prototype.constructor is the standard built-in Object constructor.
Inherited from
Module.constructor
Accessors
$id
Get Signature
get $id():
string|symbol
The name the object was registered under (its key in the module options), or a symbol of its class for an object registered by its class or built without registration.
Returns
string | symbol
Inherited from
$symbol
Get Signature
get $symbol():
symbol
A symbol unique to the instance (made from its $uuid), created on first read.
Returns
symbol
Inherited from
$uuid
Get Signature
get $uuid():
string
A random UUID identifying the instance.
Returns
string
Inherited from
alias
Get Signature
get alias():
Alias
The path alias manager, shared by the process: resolve() replaces the aliases in a path, get(), set(), has() and list() manage them.
Returns
Alias
appId
Get Signature
get
staticappId():string
The ID of the application (its id option), readable before the application is created; "Unknown" until its options are loaded.
Returns
string
appId
Get Signature
get appId():
string
The ID of the application (its id option).
Returns
string
appName
Get Signature
get
staticappName():string
The name of the application (its name option), readable before the application is created; "Unknown" until its options are loaded.
Returns
string
appName
Get Signature
get appName():
string
The name of the application (its name option).
Returns
string
className
Get Signature
get
staticclassName():string
The name of the class.
Returns
string
Inherited from
className
Get Signature
get className():
string
The name of the object's class.
Returns
string
Inherited from
timezone
Get Signature
get timezone():
string
The time zone of the application: its timezone option, or the system's (auto); the TZ environment variable.
Returns
string
uptime
Get Signature
get uptime():
number
The time the process has been running, in seconds (rounded down).
Returns
number
Methods
[asyncDispose]()
[asyncDispose]():
Promise<void>
Dispose the object at the end of an await using block, as BaseObject.dispose.
Returns
Promise<void>
Resolves once the object is destroyed.
Inherited from
acceptsOption()
staticacceptsOption(name,value):boolean
Whether the class accepts an option which is not one of its @Configurable properties (an option it reads with getConfigurableRecords()): the modules check the options of the objects they declare and warn of the options the classes do not accept. Override it in the classes reading options without configurable properties.
Parameters
name
string
The option name.
value
unknown
The option value.
Returns
boolean
true when the option is accepted; false by default.
Inherited from
addListener()
addListener(
event,listener):this
Add a listener called synchronously, at the emitting, after the event's other listeners. Unlike on(), its listener runs before emit() returns.
Parameters
event
string | symbol | event[]
The event: a name ('order.paid', the parts separated by dots, with the wildcards * for one part and ** for any parts) or the parts as an array (['order', 'paid']). A symbol is an event of its own (matched by the wildcard * as a name of one part).
listener
ListenerFn
The function called with the event's values.
Returns
this
The component, for chaining.
Inherited from
alias()
staticalias(alias,createIfNotExist?): typeofApplication
Register path aliases at launch: an alias (@data) in a path given to path.resolve() of Node.js or to app.alias.resolve() is replaced with its path. The alias @runtime (the working directory) is registered by the application. An invalid alias name (@ followed by letters and digits only) or an alias registered twice fails the launch (a fatal exception). Each call adds to the previous ones.
Parameters
alias
Record<string, string>
The paths, by alias name ({'@data': '/var/lib/app'}).
createIfNotExist?
boolean
Create the directories of the aliases which do not exist; false by default.
Returns
typeof Application
The application class, to chain the other calls.
Throws
When a path is not a string.
assign()
Call Signature
staticassign<T,U>(target,source):T&U
Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.
Type Parameters
T
T extends object
U
U
Parameters
target
T
The target object to copy to.
source
U
The source object from which to copy properties.
Returns
T & U
Inherited from
Call Signature
staticassign<T,U,V>(target,source1,source2):T&U&V
Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.
Type Parameters
T
T extends object
U
U
V
V
Parameters
target
T
The target object to copy to.
source1
U
The first source object from which to copy properties.
source2
V
The second source object from which to copy properties.
Returns
T & U & V
Inherited from
Call Signature
staticassign<T,U,V,W>(target,source1,source2,source3):T&U&V&W
Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.
Type Parameters
T
T extends object
U
U
V
V
W
W
Parameters
target
T
The target object to copy to.
source1
U
The first source object from which to copy properties.
source2
V
The second source object from which to copy properties.
source3
W
The third source object from which to copy properties.
Returns
T & U & V & W
Inherited from
Call Signature
staticassign(target, ...sources):any
Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.
Parameters
target
object
The target object to copy to.
sources
...any[]
One or more source objects from which to copy properties
Returns
any
Inherited from
create()
Call Signature
staticcreate(o):any
Creates an object that has the specified prototype or that has null prototype.
Parameters
o
object | null
Object to use as a prototype. May be null.
Returns
any
Inherited from
Call Signature
staticcreate(o,properties):any
Creates an object that has the specified prototype, and that optionally contains specified properties.
Parameters
o
object | null
Object to use as a prototype. May be null
properties
PropertyDescriptorMap & ThisType<any>
JavaScript object that contains one or more property descriptors.
Returns
any
Inherited from
defineProperties()
staticdefineProperties<T>(o,properties):T
Adds one or more properties to an object, and/or modifies attributes of existing properties.
Type Parameters
T
T
Parameters
o
T
Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object.
properties
PropertyDescriptorMap & ThisType<any>
JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property.
Returns
T
Inherited from
defineProperty()
staticdefineProperty<T>(o,p,attributes):T
Adds a property to an object, or modifies attributes of an existing property.
Type Parameters
T
T
Parameters
o
T
Object on which to add or modify the property. This can be a native JavaScript object (that is, a user-defined object or a built in object) or a DOM object.
p
PropertyKey
The property name.
attributes
PropertyDescriptor & ThisType<any>
Descriptor for the property. It can be for a data property or an accessor property.
Returns
T
Inherited from
dispose()
dispose():
Promise<void>
Destroy the object: its beforeDestroy(), the objects it created, then its destroy(). Calling it more than once destroys once. A disposed singleton or scoped object is dropped from its container, which creates a new one on the next request. Using a destroyed object (getObject(), buildObject()) throws an ObjectDestroyedException.
Returns
Promise<void>
Resolves once the object is destroyed.
Throws
The error of the object's own beforeDestroy() or destroy() (an AggregateError when several fail); the errors of the objects it created are reported through the application's logger instead.
Inherited from
emit()
emit(
event, ...values):boolean
Emit an event: the listeners added by addListener() and onAny() are called now, in order; the ones added by on(), once(), many() and their prepended forms are scheduled (an error they throw is an unhandled rejection). Use emitRequest() to wait for the listeners and their results.
Parameters
event
string | symbol | event[]
The event: a name ('order.paid', the parts separated by dots, with the wildcards * for one part and ** for any parts) or the parts as an array (['order', 'paid']). A symbol is an event of its own (matched by the wildcard * as a name of one part).
values
...any[]
The values passed to the listeners.
Returns
boolean
true when the event has listeners.
Throws
The error emitted as an 'error' event which has no listener.
Inherited from
emitRequest()
emitRequest(
event, ...values):Promise<any[]>
Emit an event and wait for its listeners (the asynchronous ones included).
Parameters
event
string | symbol | event[]
The event: a name ('order.paid', the parts separated by dots, with the wildcards * for one part and ** for any parts) or the parts as an array (['order', 'paid']). A symbol is an event of its own (matched by the wildcard * as a name of one part).
values
...any[]
The values passed to the listeners.
Returns
Promise<any[]>
The results of the listeners, in their order (an empty array without listener).
Throws
The first error thrown by a listener, or the error emitted as an 'error' event which has no listener.
Inherited from
entries()
Call Signature
staticentries<T>(o): [string,T][]
Returns an array of key/values of the enumerable own properties of an object
Type Parameters
T
T
Parameters
o
{[s: string]: T; } | ArrayLike<T>
Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
Returns
[string, T][]
Inherited from
Call Signature
staticentries(o): [string,any][]
Returns an array of key/values of the enumerable own properties of an object
Parameters
o
{ }
Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
Returns
[string, any][]
Inherited from
env()
staticenv(env): typeofApplication
Set environment variables, written to process.env at launch, before the options getter given to run() is called (it may read them). Each call adds to the previous ones.
Parameters
env
Record<string, string>
The variables, by name; the values are strings.
Returns
typeof Application
The application class, to chain the other calls.
Throws
When a value is not a string.
eventNames()
eventNames(
nsAsArray?): (string|symbol|event[])[]
The events having listeners, in no guaranteed order.
Parameters
nsAsArray?
boolean
Return each namespaced event as the array of its parts (['order', 'paid']) instead of its name ('order.paid'); false by default.
Returns
(string | symbol | event[])[]
The events.
Inherited from
exit()
Call Signature
exit(
exitCode):void
Exit the application gracefully: the onDone() handlers run, the entrypoints stop (the requests running complete), the objects are destroyed, then the process exits with the code. Returns at once.
Parameters
exitCode
number
The exit code of the process (0 for success).
Returns
void
Call Signature
exit(
force):void
Exit the process at once with the code 2, without the done handlers nor the teardown of the objects.
Parameters
force
true
true.
Returns
void
freeze()
Call Signature
staticfreeze<T>(f):T
Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
Type Parameters
T
T extends Function
Parameters
f
T
Object on which to lock the attributes.
Returns
T
Inherited from
Call Signature
staticfreeze<T,U>(o):Readonly<T>
Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
Type Parameters
T
T extends object
U
U extends string | number | bigint | boolean | symbol
Parameters
o
T
Object on which to lock the attributes.
Returns
Readonly<T>
Inherited from
Call Signature
staticfreeze<T>(o):Readonly<T>
Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
Type Parameters
T
T
Parameters
o
T
Object on which to lock the attributes.
Returns
Readonly<T>
Inherited from
fromEntries()
Call Signature
staticfromEntries<T>(entries):object
Returns an object created by key-value entries for properties and methods
Type Parameters
T
T = any
Parameters
entries
Iterable<readonly [PropertyKey, T]>
An iterable object that contains key-value entries for properties and methods.
Returns
object
Inherited from
Call Signature
staticfromEntries(entries):any
Returns an object created by key-value entries for properties and methods
Parameters
entries
Iterable<readonly any[]>
An iterable object that contains key-value entries for properties and methods.
Returns
any
Inherited from
getMaxListeners()
getMaxListeners():
number
The number of listeners of one event above which a possible memory leak is warned of.
Returns
number
The number, 0 for no warning.
Inherited from
getMethod()
getMethod(
name,throwExceptionIfNotFound?): (...args) =>any
Get a method bound to the object, to call it by name.
Parameters
name
string | symbol
The method name or symbol.
throwExceptionIfNotFound?
boolean
Throw when the method does not exist, instead of returning a function doing nothing; false by default.
Returns
The bound method, or a function doing nothing (returning undefined) when it does not exist.
(...args) => any
Throws
When the method does not exist and throwExceptionIfNotFound is true.
Inherited from
getObject()
Call Signature
getObject<
T>(constructor,configurableRecords?):Promise<T>
Get an object registered by its class, from the module's container or its parents, as Container.get.
Type Parameters
T
T extends BaseObject
Parameters
constructor
The class the object was registered with (or an @Autoload class).
configurableRecords?
Record<string, any>
The options of the object, merged over the ones it was declared with. Ignored, with a warning outside production, when the cached singleton or scoped instance already exists; a scoped object requested with options is a new instance owned by the module.
Returns
Promise<T>
The object, once created and initialized.
Throws
When the module has been destroyed.
Throws
When nothing is registered under it, or the object fails to be created.
Inherited from
Call Signature
getObject<
T>(name,configurableRecords?):Promise<T>
Get an object registered under a name (its key in the module options), as Module.getObject by class.
Type Parameters
T
T extends BaseObject
Parameters
name
string
The registration name.
configurableRecords?
Record<string, any>
The options of the object, merged over the ones it was declared with. Ignored, with a warning outside production, when the cached singleton or scoped instance already exists; a scoped object requested with options is a new instance owned by the module.
Returns
Promise<T>
The object, once created and initialized.
Throws
When the module has been destroyed.
Throws
When nothing is registered under it, or the object fails to be created.
Inherited from
Call Signature
getObject<
T>(name,configurableRecords?):Promise<T>
Get an object registered under a symbol, as Module.getObject by class.
Type Parameters
T
T extends BaseObject
Parameters
name
symbol
The registration symbol.
configurableRecords?
Record<string, any>
The options of the object, merged over the ones it was declared with. Ignored, with a warning outside production, when the cached singleton or scoped instance already exists; a scoped object requested with options is a new instance owned by the module.
Returns
Promise<T>
The object, once created and initialized.
Throws
When the module has been destroyed.
Throws
When nothing is registered under it, or the object fails to be created.
Inherited from
Call Signature
getObject<
T>(name,configurableRecords?):Promise<T>
Get an object registered under a name or a symbol, as Module.getObject by class.
Type Parameters
T
T extends BaseObject
Parameters
name
string | symbol
The registration name or symbol.
configurableRecords?
Record<string, any>
The options of the object, merged over the ones it was declared with. Ignored, with a warning outside production, when the cached singleton or scoped instance already exists; a scoped object requested with options is a new instance owned by the module.
Returns
Promise<T>
The object, once created and initialized.
Throws
When the module has been destroyed.
Throws
When nothing is registered under it, or the object fails to be created.
Inherited from
Call Signature
getObject<
T>(nameOrConstructor,configurableRecords?):Promise<T>
Get an object registered under a name, a symbol or by its class, as Module.getObject by class.
Type Parameters
T
T extends BaseObject
Parameters
nameOrConstructor
string | symbol | IBaseObjectConstructor<T>
The registration name, symbol or class.
configurableRecords?
Record<string, any>
The options of the object, merged over the ones it was declared with. Ignored, with a warning outside production, when the cached singleton or scoped instance already exists; a scoped object requested with options is a new instance owned by the module.
Returns
Promise<T>
The object, once created and initialized.
Throws
When the module has been destroyed.
Throws
When nothing is registered under it, or the object fails to be created.
Inherited from
getOwnPropertyDescriptor()
staticgetOwnPropertyDescriptor(o,p):PropertyDescriptor|undefined
Gets the own property descriptor of the specified object. An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype.
Parameters
o
any
Object that contains the property.
p
PropertyKey
Name of the property.
Returns
PropertyDescriptor | undefined
Inherited from
Module.getOwnPropertyDescriptor
getOwnPropertyDescriptors()
staticgetOwnPropertyDescriptors<T>(o): { [P in string | number | symbol]: TypedPropertyDescriptor<T[P]> } &object
Returns an object containing all own property descriptors of an object
Type Parameters
T
T
Parameters
o
T
Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
Returns
{ [P in string | number | symbol]: TypedPropertyDescriptor<T[P]> } & object
Inherited from
Module.getOwnPropertyDescriptors
getOwnPropertyNames()
staticgetOwnPropertyNames(o):string[]
Returns the names of the own properties of an object. The own properties of an object are those that are defined directly on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions.
Parameters
o
any
Object that contains the own properties.
Returns
string[]
Inherited from
getOwnPropertySymbols()
staticgetOwnPropertySymbols(o):symbol[]
Returns an array of all symbol properties found directly on object o.
Parameters
o
any
Object to retrieve the symbols from.
Returns
symbol[]
Inherited from
getProperty()
getProperty<
T>(propertyKey,defaultValue?):T
Read an own property of the object.
Type Parameters
T
T = any
Parameters
propertyKey
string
The property name.
defaultValue?
T
The value returned when the object has no own property of this name.
Returns
T
The property value, or the default value.
Inherited from
getPrototypeOf()
staticgetPrototypeOf(o):any
Returns the prototype of an object.
Parameters
o
any
The object that references the prototype.
Returns
any
Inherited from
hasListeners()
hasListeners(
event?):boolean
Whether an event has listeners (the wildcard listeners matching it included; the listeners of onAny() excluded).
Parameters
event?
string | symbol | event[]
The event name, its parts as an array, or a symbol; any event when omitted.
Returns
boolean
true when there are listeners.
Inherited from
hasMethod()
hasMethod(
name):boolean
Whether the object has a method of this name or symbol (a function of its class, not an own property).
Parameters
name
string | symbol
The method name or symbol.
Returns
boolean
true when the method exists.
Inherited from
hasOwn()
statichasOwn(o,v):boolean
Determines whether an object has a property with the specified name.
Parameters
o
object
An object.
v
PropertyKey
A property name.
Returns
boolean
Inherited from
hasOwnProperty()
hasOwnProperty(
v):boolean
Determines whether an object has a property with the specified name.
Parameters
v
PropertyKey
A property name.
Returns
boolean
Inherited from
hasProperty()
hasProperty(
propertyKey):boolean
Whether the object has an own property (not a method or accessor of its class) of this name or symbol.
Parameters
propertyKey
string | symbol
The property name or symbol.
Returns
boolean
true when the property exists.
Inherited from
is()
staticis(value1,value2):boolean
Returns true if the values are the same value, false otherwise.
Parameters
value1
any
The first value.
value2
any
The second value.
Returns
boolean
Inherited from
isExtensible()
staticisExtensible(o):boolean
Returns a value that indicates whether new properties can be added to an object.
Parameters
o
any
Object to test.
Returns
boolean
Inherited from
isFrozen()
staticisFrozen(o):boolean
Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object.
Parameters
o
any
Object to test.
Returns
boolean
Inherited from
isPrototypeOf()
isPrototypeOf(
v):boolean
Determines whether an object exists in another object's prototype chain.
Parameters
v
Object
Another object whose prototype chain is to be checked.
Returns
boolean
Inherited from
isSealed()
staticisSealed(o):boolean
Returns true if existing property attributes cannot be modified in an object and new properties cannot be added to the object.
Parameters
o
any
Object to test.
Returns
boolean
Inherited from
keys()
Call Signature
statickeys(o):string[]
Returns the names of the enumerable string properties and methods of an object.
Parameters
o
object
Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
Returns
string[]
Inherited from
Call Signature
statickeys(o):string[]
Returns the names of the enumerable string properties and methods of an object.
Parameters
o
{ }
Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
Returns
string[]
Inherited from
listenerCount()
listenerCount(
event?):number
The number of listeners of an event (the wildcard listeners matching it included), or of every event (the listeners of onAny() excluded).
Parameters
event?
string | symbol | event[]
The event name or its parts as an array; every event when omitted.
Returns
number
The number of listeners.
Inherited from
listeners()
listeners(
event?):ListenerFn[]
The listeners of an event, or of every event.
Parameters
event?
string | symbol | event[]
The event name (the wildcard listeners matching it included), its parts as an array, or a symbol; every event when omitted (the listeners of onAny() excluded).
Returns
ListenerFn[]
A copy of the listeners; changing it does not change the listeners.
Inherited from
listenersAny()
listenersAny():
ListenerFn[]
The listeners of every event, added by onAny() and prependAny().
Returns
ListenerFn[]
A copy of these listeners; changing it does not change the listeners.
Inherited from
many()
many(
event,timesToListen,listener):this
Add a listener called for the event's next emittings, then removed.
Parameters
event
string | symbol | event[]
The event: a name ('order.paid', the parts separated by dots, with the wildcards * for one part and ** for any parts) or the parts as an array (['order', 'paid']). A symbol is an event of its own (matched by the wildcard * as a name of one part).
timesToListen
number
The number of emittings the listener is called for.
listener
ListenerFn
The function called with the event's values, asynchronously after the emitting (in a later turn of the event loop); its result (or the promise it returns) is collected by emitRequest().
Returns
this
The component, for chaining.
Inherited from
mode()
mode():
"development"|"production"
The mode the application runs in: the MODE environment variable, else NODE_ENV, when it is development or production; development otherwise.
Returns
"development" | "production"
The mode.
Inherited from
off()
off(
event,listener):this
Remove a listener of an event; nothing happens when it was not added.
Parameters
event
string | symbol | event[]
The event the listener was added for.
listener
ListenerFn
The listener to remove.
Returns
this
The component, for chaining.
Inherited from
offAny()
offAny(
listener):this
Remove a listener of every event added by onAny() or prependAny().
Parameters
listener
ListenerFn
The listener to remove.
Returns
this
The component, for chaining.
Inherited from
on()
on(
event,listener):this
Add a listener, after the event's other listeners.
Parameters
event
string | symbol | event[]
The event: a name ('order.paid', the parts separated by dots, with the wildcards * for one part and ** for any parts) or the parts as an array (['order', 'paid']). A symbol is an event of its own (matched by the wildcard * as a name of one part).
listener
ListenerFn
The function called with the event's values, asynchronously after the emitting (in a later turn of the event loop); its result (or the promise it returns) is collected by emitRequest().
Returns
this
The component, for chaining.
Inherited from
onAny()
onAny(
listener):this
Add a listener of every event, called synchronously at the emitting, before the event's own listeners.
Parameters
listener
EventAndListener
The function called with the event name, then the event's values.
Returns
this
The component, for chaining.
Inherited from
once()
once(
event,listener):this
Add a listener called for the event's next emitting only, then removed.
Parameters
event
string | symbol | event[]
The event: a name ('order.paid', the parts separated by dots, with the wildcards * for one part and ** for any parts) or the parts as an array (['order', 'paid']). A symbol is an event of its own (matched by the wildcard * as a name of one part).
listener
ListenerFn
The function called with the event's values, asynchronously after the emitting (in a later turn of the event loop); its result (or the promise it returns) is collected by emitRequest().
Returns
this
The component, for chaining.
Inherited from
onDone()
staticonDone(handler): typeofApplication
Add a handler called when the application exits (app.exit(), a shutdown signal): it runs, awaited, before the entrypoints stop and the objects are destroyed, the application still working. A handler failing makes the process exit with the code 1.
Parameters
handler
(app, logger, reason) => void | Promise<void>
The function called with the application, its logger and why it exits (its exit code, the signal ending it).
Returns
typeof Application
The application class, to chain the other calls.
onFatalException()
staticonFatalException(handler): typeofApplication
Set the handler of a fatal exception: an error stopping the launch (invalid options or aliases, an object failing to initialize, a bootstrap step failing). The process exits after it, with the code it returns (1 when it returns none). Without handler, the error is logged and the process exits with the code 1. Only the first handler added is called.
Parameters
handler
(error, logger) => number | void | Promise<number | void | undefined> | undefined
The function called with the error and the logger, returning the exit code.
Returns
typeof Application
The application class, to chain the other calls.
onLaunched()
staticonLaunched(handler): typeofApplication
Add a handler called once the application has launched (its bootstrap completed), or at once when it has launched already. An async handler is not awaited; its rejection is an unhandled rejection.
Parameters
handler
(app, logger) => void | Promise<void>
The function called with the application and its logger.
Returns
typeof Application
The application class, to chain the other calls.
onUncaughtException()
staticonUncaughtException(handler): typeofApplication
Add a handler of the process' uncaught exceptions (process.on('uncaughtException')), the application keeping running. Without handler, the exception is logged as a warning. Every handler added is called.
Parameters
handler
(error, logger) => void | Promise<void>
The function called with the error and the logger.
Returns
typeof Application
The application class, to chain the other calls.
prependAny()
prependAny(
listener):this
Add a listener of every event, before the other listeners of every event, called synchronously at the emitting.
Parameters
listener
EventAndListener
The function called with the event name, then the event's values.
Returns
this
The component, for chaining.
Inherited from
prependListener()
prependListener(
event,listener):this
Add a listener before the event's other listeners.
Parameters
event
string | symbol | event[]
The event: a name ('order.paid', the parts separated by dots, with the wildcards * for one part and ** for any parts) or the parts as an array (['order', 'paid']). A symbol is an event of its own (matched by the wildcard * as a name of one part).
listener
ListenerFn
The function called with the event's values, asynchronously after the emitting (in a later turn of the event loop); its result (or the promise it returns) is collected by emitRequest().
Returns
this
The component, for chaining.
Inherited from
prependMany()
prependMany(
event,timesToListen,listener):this
Add a listener called for the event's next emittings, then removed; it is placed before the event's other listeners.
Parameters
event
string | symbol | event[]
The event: a name ('order.paid', the parts separated by dots, with the wildcards * for one part and ** for any parts) or the parts as an array (['order', 'paid']). A symbol is an event of its own (matched by the wildcard * as a name of one part).
timesToListen
number
The number of emittings the listener is called for.
listener
ListenerFn
The function called with the event's values, asynchronously after the emitting (in a later turn of the event loop); its result (or the promise it returns) is collected by emitRequest().
Returns
this
The component, for chaining.
Inherited from
prependOnceListener()
prependOnceListener(
event,listener):this
Add a listener called for the event's next emitting only, then removed; it is placed before the event's other listeners.
Parameters
event
string | symbol | event[]
The event: a name ('order.paid', the parts separated by dots, with the wildcards * for one part and ** for any parts) or the parts as an array (['order', 'paid']). A symbol is an event of its own (matched by the wildcard * as a name of one part).
listener
ListenerFn
The function called with the event's values, asynchronously after the emitting (in a later turn of the event loop); its result (or the promise it returns) is collected by emitRequest().
Returns
this
The component, for chaining.
Inherited from
preset()
staticpreset(options): typeofApplication
Preset the options of the applications, before they run: the packages assembling the framework preset their components (the lakutata package presets its Logger as log and its Entrypoint as entrypoint). An object given to run() under a preset name replaces the preset one when it gives its class, or completes its options when it gives none (log: {level: 'debug'}); the preset bootstrap steps run first. Each call adds to the preset: its components, providers and named objects replace the preset ones of the same name, its anonymous objects and bootstrap steps are appended. Does not launch the application.
Parameters
options
The objects and bootstrap steps to preset.
Returns
typeof Application
The application class, to chain the other calls.
Example
import {Application, Component} from 'lakutata'
class Metrics extends Component {
}
//Every application of this process gets the "metrics" component, started at launch
Application.preset({
components: {
metrics: {class: Metrics}
},
bootstrap: ['metrics']
})preventExtensions()
staticpreventExtensions<T>(o):T
Prevents the addition of new properties to an object.
Type Parameters
T
T
Parameters
o
T
Object to make non-extensible.
Returns
T
Inherited from
propertyIsEnumerable()
propertyIsEnumerable(
v):boolean
Determines whether a specified property is enumerable.
Parameters
v
PropertyKey
A property name.
Returns
boolean
Inherited from
propertyNames()
propertyNames():
string[]
The names of the object's own properties (not its class's methods and accessors).
Returns
string[]
The names.
Inherited from
propertySymbols()
propertySymbols():
symbol[]
The symbols of the object's own properties.
Returns
symbol[]
The symbols.
Inherited from
reload()
reload():
Promise<void>
Destroy the module with its objects and initialize it again (same instance): its objects are registered again and its bootstrap runs again.
Returns
Promise<void>
Resolves once the module is initialized again.
Throws
When its parent has been destroyed.
Throws
The error of its teardown or of its initialization.
Inherited from
removeAllListeners()
removeAllListeners(
event?):this
Remove the listeners of an event, or all the listeners.
Parameters
event?
string | symbol | event[]
The event whose listeners are removed; all the listeners when omitted.
Returns
this
The component, for chaining.
Inherited from
removeListener()
removeListener(
event,listener):this
Remove a listener of an event, as off().
Parameters
event
string | symbol | event[]
The event the listener was added for.
listener
ListenerFn
The listener to remove.
Returns
this
The component, for chaining.
Inherited from
run()
Call Signature
staticrun(options): typeofApplication
Give the application options and launch it (in the next turn of the event loop, once the chain of calls is complete). The options are validated at launch: invalid options are a fatal exception.
Parameters
options
The application's identity (id, name), its objects and its bootstrap.
Returns
typeof Application
The application class, to chain the other calls.
Call Signature
staticrun(optionsGetter): typeofApplication
Give the function returning the application options, called at launch once the environment variables and the aliases are set, and launch the application (in the next turn of the event loop). A getter failing, or invalid options, are a fatal exception.
Parameters
optionsGetter
() => ApplicationOptions | Promise<ApplicationOptions>
The function returning the options, or their promise.
Returns
typeof Application
The application class, to chain the other calls.
seal()
staticseal<T>(o):T
Prevents the modification of attributes of existing properties, and prevents the addition of new properties.
Type Parameters
T
T
Parameters
o
T
Object on which to lock the attributes.
Returns
T
Inherited from
setMaxListeners()
setMaxListeners(
n):void
Set the number of listeners of one event above which a possible memory leak is warned of (the maxListeners option, 11 by default); the listeners are never limited.
Parameters
n
number
The number, 0 for no warning.
Returns
void
Inherited from
setProperty()
setProperty(
propertyKey,value):void
Set a property of the object; the value is not validated, even for a @Configurable property.
Parameters
propertyKey
string
The property name.
value
any
The value.
Returns
void
Inherited from
setPrototypeOf()
staticsetPrototypeOf(o,proto):any
Sets the prototype of a specified object o to object proto or null. Returns the object o.
Parameters
o
any
The object to change its prototype.
proto
object | null
The value of the new prototype or null.
Returns
any
Inherited from
toLocaleString()
toLocaleString():
string
Returns a date converted to a string using the current locale.
Returns
string
Inherited from
toString()
toString():
string
Returns a string representation of an object.
Returns
string
Inherited from
valueOf()
valueOf():
Object
Returns the primitive value of the specified object.
Returns
Object
Inherited from
values()
Call Signature
staticvalues<T>(o):T[]
Returns an array of values of the enumerable own properties of an object
Type Parameters
T
T
Parameters
o
{[s: string]: T; } | ArrayLike<T>
Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
Returns
T[]
Inherited from
Call Signature
staticvalues(o):any[]
Returns an array of values of the enumerable own properties of an object
Parameters
o
{ }
Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
Returns
any[]