Skip to main content

Application

@webda/core • Readme | API


Class: Application

Map a Webda Application

It allows to:

  • Analyse imported modules
  • Scan code for Modda and generate the webda.config.json
  • Compile and Watch
  • Migrate from old configuration
  • List deployments

Extended by​

Constructors​

new Application(file, logger)​

new Application(file, logger): Application

Parameters​

• file: string

• logger: WorkerOutput= undefined

Returns​

Application

Source​

packages/core/src/application.ts:539

Properties​

_loaded​

protected _loaded: string[] = []

Contains already loaded modules

Source​

packages/core/src/application.ts:473


appModule​

protected appModule: Module

Contains definitions of current application

Source​

packages/core/src/application.ts:457


appPath​

readonly appPath: string

Get Application root path

Source​

packages/core/src/application.ts:444


baseConfiguration​

protected baseConfiguration: Configuration

Base configuration loaded from webda.config.json

Source​

packages/core/src/application.ts:448


configurationFile​

readonly configurationFile: string

Configuration file

Source​

packages/core/src/application.ts:523


currentDeployment​

protected currentDeployment: string

Current deployment

Source​

packages/core/src/application.ts:452


deployers​

protected deployers: Object = {}

Deployers type registry

Index signature​

[key: string]: any

Source​

packages/core/src/application.ts:478


deploymentFile​

deploymentFile: string

Current deployment file

Source​

packages/core/src/application.ts:527


flatHierarchy​

protected flatHierarchy: Object = {}

Direct parent of a model

Index signature​

[key: string]: string

Source​

packages/core/src/application.ts:518


graph​

protected graph: ModelsGraph = {}

Models graph

Source​

packages/core/src/application.ts:493


initTime​

protected initTime: number

When the application got initiated

Source​

packages/core/src/application.ts:513


logger​

protected logger: WorkerOutput

Class Logger

Source​

packages/core/src/application.ts:503


moddas​

protected moddas: Object = {}

Moddas registry

Index signature​

[key: string]: Modda

Source​

packages/core/src/application.ts:483


models​

protected models: Object = {}

Models type registry

Index signature​

[key: string]: CoreModelDefinition

Source​

packages/core/src/application.ts:488


plurals​

protected plurals: Object = {}

Models specific plurals

Index signature​

[key: string]: string

Source​

packages/core/src/application.ts:498


workspacesPath​

protected workspacesPath: string = ""

Detect if running as workspace

Source​

packages/core/src/application.ts:508


active​

static protected active: Application

Current application

Source​

packages/core/src/application.ts:532

Methods​

addDeployer()​

addDeployer(name, model): this

Add a new deployer

Parameters​

• name: string

• model: any

Returns​

this

Source​

packages/core/src/application.ts:990


addModel()​

addModel(name, model, dynamic): this

Add a new model

Parameters​

• name: string

• model: any

• dynamic: boolean= true

Returns​

this

Source​

packages/core/src/application.ts:969


addService()​

addService(name, service): this

Add a new service

Parameters​

• name: string

• service: Modda

Returns​

this

Source​

packages/core/src/application.ts:737


completeNamespace()​

completeNamespace(name): string

Return the full name including namespace

In Webda the ServiceType include namespace Webda/Store or Webda/Test This method will make sure the namespace is present, adding it if no '/' is found in the name

Parameters​

• name: string= ""

Returns​

string

Source​

packages/core/src/application.ts:1234


getAppPath()​

getAppPath(subpath): string

Return the current app path

Parameters​

• subpath: string= undefined

to append to

Returns​

string

Source​

packages/core/src/application.ts:721


getBeans()​

getBeans(): Object

Return all beans of the application

Returns​

Object

Source​

packages/core/src/application.ts:836


getConfiguration()​

getConfiguration(_deployment): Configuration

Get application configuration

Parameters​

• _deployment: string= undefined

Returns​

Configuration

Source​

packages/core/src/application.ts:1128


getCurrentConfiguration()​

getCurrentConfiguration(): Configuration

Return current Configuration of the Application

Same as calling

getConfiguration(this.currentDeployment);

Returns​

Configuration

Source​

packages/core/src/application.ts:1141


getCurrentDeployment()​

getCurrentDeployment(): string

Get current deployment name

Returns​

string

Source​

packages/core/src/application.ts:1110


getDeployers()​

getDeployers(): Object

Return all deployers

Returns​

Object

Source​

packages/core/src/application.ts:959


getFullNameFromPrototype()​

getFullNameFromPrototype(proto): string

Parameters​

• proto: any

Prototype to send

Returns​

string

Source​

packages/core/src/application.ts:605


getGitInformation()​

getGitInformation(_packageName?, _version?): GitInformation

Retrieve Git Repository information

GitInformation for more details on how the information is gathered

Parameters​

• _packageName?: string

• _version?: string

Returns​

GitInformation

the git information

Source​

packages/core/src/application.ts:1012


getGraph()​

getGraph(): ModelsGraph

Get the all graph

Returns​

ModelsGraph

Source​

packages/core/src/application.ts:663


getModda()​

getModda(name): Modda

Get a service based on name

Parameters​

• name: any

Returns​

Modda

Source​

packages/core/src/application.ts:822


getModdas()​

getModdas(): Object

Return all services of the application

Returns​

Object

Source​

packages/core/src/application.ts:829


getModel()​

getModel<T>(name): CoreModelDefinition<T>

Retrieve the model implementation

Type parameters​

• T extends CoreModel = CoreModel

Parameters​

• name: string

model to retrieve

Returns​

CoreModelDefinition<T>

Source​

packages/core/src/application.ts:845


getModelFromConstructor()​

getModelFromConstructor(model): string

Return the model name for a object

Parameters​

• model: Constructor<CoreModel>

Returns​

string

Source​

packages/core/src/application.ts:893


getModelFromInstance()​

getModelFromInstance(object): string

Return the model name for a object

Parameters​

• object: CoreModel

Returns​

string

Source​

packages/core/src/application.ts:885


getModelHierarchy()​

getModelHierarchy(model): Object

Get the model hierarchy

Parameters​

• model: string | CoreModel | Constructor<CoreModel>

Returns​

Object

ancestors​

ancestors: string[]

children​

children: ModelsTree

Source​

packages/core/src/application.ts:918


getModelName()​

getModelName(model): string

Get the model name from a model or a constructor

Parameters​

• model: CoreModel | Constructor<CoreModel>

Returns​

string

longId for a model

Source​

packages/core/src/application.ts:903


getModelPlural()​

getModelPlural(name): string

Get plural of an Id

Parameters​

• name: string

Returns​

string

Source​

packages/core/src/application.ts:760


getModelTypes()​

getModelTypes(model): string[]

Get all model types with the hierarchy

Parameters​

• model: CoreModel

Returns​

string[]

Source​

packages/core/src/application.ts:948


getModels()​

getModels(): Object

Get all models definitions

Returns​

Object

Source​

packages/core/src/application.ts:852


getModules()​

getModules(): CachedModule

Return all application modules merged as one

Used when deployed

Returns​

CachedModule

Source​

packages/core/src/application.ts:1120


getNamespace()​

getNamespace(): string

Return current namespace

Returns​

string

Source​

packages/core/src/application.ts:1250


getPackageDescription()​

getPackageDescription(): PackageDescriptor

Retrieve content of package.json

Returns​

PackageDescriptor

Source​

packages/core/src/application.ts:693


getPackageWebda()​

getPackageWebda(): WebdaPackageDescriptor

Retrieve specific webda conf from package.json

In case of workspaces the object is combined

Returns​

WebdaPackageDescriptor

Source​

packages/core/src/application.ts:683


getRelations()​

getRelations(model): ModelGraph

Get model graph

Parameters​

• model: string | CoreModel | Constructor<CoreModel>

Returns​

ModelGraph

Source​

packages/core/src/application.ts:652


getRootExposedModels()​

getRootExposedModels(): string[]

Return models that do not have parents and are exposed Or specifically set as root via the Expose.root parameter

Returns​

string[]

Source​

packages/core/src/application.ts:871


getRootModels()​

getRootModels(): string[]

Return models that do not have parents

Returns​

string[]

Source​

packages/core/src/application.ts:862


getSchema()​

getSchema(type): JSONSchema7

Get a schema from a type

Schema should be precomputed in the default app

Parameters​

• type: string

Returns​

JSONSchema7

Source​

packages/core/src/application.ts:628


getSchemas()​

getSchemas(): Object

Get schemas

Returns​

Object

Source​

packages/core/src/application.ts:636


getShortId()​

getShortId(name): string

Get short id for a name

Parameters​

• name: string

if name is shortId return longId else return shortId

Returns​

string

Source​

packages/core/src/application.ts:1259


getWebdaObject()​

getWebdaObject(section, name, caseSensitive): any

Parameters​

• section: Section

• name: string

• caseSensitive: boolean= false

Returns​

any

Source​

packages/core/src/application.ts:794


getWebdaVersion()​

getWebdaVersion(): string

Return webda current version

Returns​

string

package version

Since​

0.4.0

Source​

packages/core/src/application.ts:1002


getWorkerOutput()​

getWorkerOutput(): WorkerOutput

Get current logger

Returns​

WorkerOutput

Source​

packages/core/src/application.ts:712


hasSchema()​

hasSchema(type): boolean

Check if a schema exists

Parameters​

• type: string

Returns​

boolean

schema name if it exists

Source​

packages/core/src/application.ts:645


hasWebdaObject()​

hasWebdaObject(section, name, caseSensitive): boolean

Parameters​

• section: Section

• name: string

• caseSensitive: boolean= false

Returns​

boolean

Source​

packages/core/src/application.ts:771


importFile()​

importFile(info, withExport): Promise<any>

Import a file

If the default is set take this or use old format

Parameters​

• info: string

• withExport: boolean= true

Returns​

Promise<any>

Source​

packages/core/src/application.ts:1152


isCached()​

isCached(): boolean

Check if application has cached modules

When deployed the application contains cachedModules in the webda.config.json It allows to avoid the search for webda.module.json inside node_modules and take the schema from the cached modules also

Returns​

boolean

Source​

packages/core/src/application.ts:674


load()​

load(): Promise<Application>

Import all required modules

Returns​

Promise<Application>

Source​

packages/core/src/application.ts:561


loadConfiguration()​

loadConfiguration(file): void

Allow subclass to implement migration

Parameters​

• file: string

Returns​

void

Source​

packages/core/src/application.ts:581


loadLocalModule()​

loadLocalModule(): Promise<void>

Load local module

Returns​

Promise<void>

Source​

packages/core/src/application.ts:1179


log()​

log(level, ...args): void

Log information

Parameters​

• level: WorkerLogLevel

to log for

• ...args: any[]

anything to display same as console.log

Returns​

void

Source​

packages/core/src/application.ts:703


registerSchema()​

registerSchema(name, schema): void

Register a new schema in the application

Parameters​

• name: string

• schema: JSONSchema7

Returns​

void

Source​

packages/core/src/application.ts:748


replaceVariables()​

replaceVariables(object, replacements): any

Allow variable inside object strings

Example

replaceVariables({
myobj: "${test.replace}"
}, {
test: {
replace: 'plop'
}
})

will return

{
myobj: 'plop'
}

By default the replacements map contains

{
git: GitInformation,
package: 'package.json content',
deployment: string,
now: number,
...replacements
}

See: GitInformation

Parameters​

• object: any

a duplicated object with replacement done

• replacements: any= {}

additional replacements to run

Returns​

any

Source​

packages/core/src/application.ts:1092


stringParameter()​

protected stringParameter(templateString, replacements): any

Allow variable inside of string

Parameters​

• templateString: string

to copy

• replacements: any= {}

additional replacements to run

Returns​

any

Source​

packages/core/src/application.ts:1022