Constructor
new UtilityUnit(app_rootopt)
Instantiate the unit.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
app_root |
string |
<optional> |
'./app' | path to the 'app' folder |
- Source:
Extends
Members
(static) name
Gets the name of the service provided by this unit: 'utility'
- Source:
(static) provides
Array of additional service names provided by this unit.
- Source:
(static) services
Defines the services required by this unit.
- Source:
(private) _di_allow_defer :boolean
If true, the injector will defer the class if the class requests any services that the container is missing. These services are filled in later and added to the prototype and any instances. True by default.
- boolean
- Overrides:
- Source:
(private) _di_deferred_instances :Array.<module:flitter-di/src/Injectable~Injectable>
Collection of instances of this class that need to have the deferred service instances injected into them when the deferred services are finally provided.
- Source:
(private) _di_deferred_services :Array.<string>
List of services that were deferred and not provided at the time of injection.
- Array.<string>
- Source:
directory :Promise.<void>|Promise.<string>
Fully-qualified path to the 'app' folder.
- Promise.<void> | Promise.<string>
- Source:
services_dir :Promise.<void>|Promise.<string>
Fully-qualified path to the 'app/services' folder.
- Promise.<void> | Promise.<string>
- Source:
Methods
(async) cleanup(app) → {Promise.<void>}
Cleans up the unit's resources before Flitter closes.
Name | Type | Description |
---|---|---|
app |
module:libflitter/app/FlitterApp~FlitterApp | the Flitter app |
- Overrides:
- Source:
- Type
- Promise.<void>
deep_copy(item) → {Object}
Make a deep copy of some item. If item is primitive, return it. It item is an array, create a new array with deep copies of each array item. If item is an object, create a new object with key-values such that the keys are the same, but the values are deep copies of the keys.
Assumes items can eventually be resolved to primitive types, and that they contain no circular structure.
Name | Type | Description |
---|---|---|
item |
- Type
- Object
deep_merge(obj1, obj2) → {*}
Deep merges object 2 into object 1, recursively. This mutates object 1.
Name | Type | Description |
---|---|---|
obj1 |
||
obj2 |
- Type
- *
directives() → {Object}
Get the directives provided by this unit.
- Type
- Object
directories() → {Object}
Get the directories managed by this unit. Includes 'root' for the application root.
- Overrides:
- Type
- Object
env(name, default_value) → {string|null|boolean|number}
Grabs an environment variable by name and tries to infer its type.
Name | Type | Description |
---|---|---|
name |
string | |
default_value |
- Type
- string | null | boolean | number
(async) go(app, context) → {Promise.<void>}
Loads the unit. Binds the application root and global logging function to the appropriate contexts.
Name | Type | Description |
---|---|---|
app |
module:libflitter/app/FlitterApp~FlitterApp | the Flitter app |
context |
module:libflitter/Context~Context | the unit's context |
- Overrides:
- Source:
- Type
- Promise.<void>
infer(val) → {boolean|null|*|number|undefined}
Attempt to infer the variable type of a string's data.
Name | Type | Description |
---|---|---|
val |
string |
- Type
- boolean | null | * | number | undefined
is_json(string) → {boolean}
Checks if a string is valid JSON.
Name | Type | Description |
---|---|---|
string |
- true if the string is valid JSON
- Type
- boolean
is_linux() → {boolean}
Returns true if the application is running on Linux.
- Type
- boolean
is_mac() → {boolean}
Returns true if the application is running on macOS.
- Type
- boolean
is_windows() → {boolean}
Returns true if the application is running on Windows.
- Type
- boolean
migrations() → {string}
Get the unit's migrations.
- Type
- string
name() → {String}
Get the name of the unit. Should be a lowercase, alphanum/dash/underscore string.
- Overrides:
- Source:
- Type
- String
path(…segments)
Resolve the absolute path to a file, relative to the root directory of the Flitter app. This is equivalent to path.resolve(UtilityUnit.path(), ...segments)
Name | Type | Attributes | Description |
---|---|---|---|
segments |
<repeatable> |
- Source:
root() → {string}
Get the fully-qualified path to the root folder of the Flitter application.
- Source:
- Type
- string
status(setopt) → {string}
Get or set the unit's current status.
Name | Type | Attributes | Description |
---|---|---|---|
set |
string |
<optional> |
if provided, set the status of the unit |
- Overrides:
- Source:
- current status of the unit
- Type
- string