Class: Modules
moralis-monorepo / @moralisweb3/common-core / Modules
Class: Modules
@moralisweb3/common-core.Modules
MoralisModues handles all registered modules. Any package that is used in Moralis, should register itself via this class. This allows cross-communication between modules and easy management of the modules
This class is responsible for:
- registering new modules
- removing modules (in theory possible for exotic usecases, but might break the app if done after initialisation)
- getting individual modules by name, type or everything
Table of contents
Constructors
Methods
Constructors
constructor
• new Modules()
Methods
get
▸ get<CurrentModule
>(name
): CurrentModule
Returns the module with the given name.
This module should have been registered with register
Throws
a CoreError if no module with the given name has been registered
Type parameters
Name | Type |
---|---|
CurrentModule | extends Module <CurrentModule > = Module |
Parameters
Name | Type | Description |
---|---|---|
name | string | the module name |
Returns
CurrentModule
a valid BaseModule
getApi
▸ getApi(name
): ApiModule
Returns the network module with the provided name.
Throws
a CoreError if no network module with the given name has been registered
Parameters
Name | Type | Description |
---|---|---|
name | string | the module name |
Returns
a valid ApiModule
has
▸ has(name
): boolean
Parameters
Name | Type |
---|---|
name | string |
Returns
boolean
list
▸ list(): Module
[]
List all the registered modules
Returns
Module
[]
an array of BaseModule that have been registered
listApis
▸ listApis(): ApiModule
[]
List all the registered api modules (eg. modules with the type CoreModuleType.API)
Returns
listNames
▸ listNames(): string
[]
Returns the names of all registered modules
Returns
string
[]
register
▸ register(module
): void
Register and setup a new module by providing a module that is extended from BaseClass. This will throw an error if the name is not unique
Parameters
Name | Type | Description |
---|---|---|
module | AnyBaseClass | the module that needs to be registered |
Returns
void
remove
▸ remove(name
): void
Remove the module with the provided name, if it has been registered,
Throws
a CoreError if the module cannot be found.
Parameters
Name | Type | Description |
---|---|---|
name | string | the module name |
Returns
void
tryGet
▸ tryGet(name
): null
| Module
Tries to return the module with the given name if exist. Otherwise returns null.
Parameters
Name | Type | Description |
---|---|---|
name | string | the module name |
Returns
null
| Module
a valid BaseModule or null