Class: Modules

moralis-monorepo / @moralisweb3/core / Modules

Class: Modules

@moralisweb3/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

Methods

Methods

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

NameTypeDescription
moduleAnyBaseClassthe module that needs to be registered

Returns

void


get

get<CurrentModule>(name): CurrentModule

Returns the module with the given name.
This module should have been registered with register

Throws

a MoralisCoreError if no module with the given name has been registered

Type parameters

NameType
CurrentModuleextends Module<any, CurrentModule> = Module<any>

Parameters

NameTypeDescription
namestringthe module name

Returns

CurrentModule

a valid BaseModule


tryGet

tryGet(name): null | Module<any>

Tries to return the module with the given name if exist. Otherwise returns null.

Parameters

NameTypeDescription
namestringthe module name

Returns

null | Module<any>

a valid BaseModule or null


getApi

getApi(name): ApiModule<any>

Returns the network module with the provided name.

Throws

a MoralisCoreError if no network module with the given name has been registered

Parameters

NameTypeDescription
namestringthe module name

Returns

ApiModule<any>

a valid ApiModule


remove

remove(name): void

Remove the module with the provided name, if it has been registered,

Throws

a MoralisCoreError if the module cannot be found.

Parameters

NameTypeDescription
namestringthe module name

Returns

void


list

list(): Module<any>[]

List all the registered modules

Returns

Module<any>[]

an array of BaseModule that have been registered


listNames

listNames(): string[]

Returns the names of all registered modules

Returns

string[]


listApis

listApis(): ApiModule<any>[]

List all the registered api modules (eg. modules with the type CoreModuleType.API)

Returns

ApiModule<any>[]


Did this page help you?