Skip to main content

Application

@webda/core


Class: Application

Defined in: packages/core/src/application/application.ts:135

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​

Constructor​

new Application(file, logger?): Application

Defined in: packages/core/src/application/application.ts:223

Create a new Application

Parameters​

file​

string | UnpackedConfiguration

file path or unpacked configuration to load from

logger?​

WorkerOutput = undefined

the logger instance

Returns​

Application

Properties​

applicationPath​

readonly applicationPath: string

Defined in: packages/core/src/application/application.ts:139

Get Application root path


appModule​

protected appModule: WebdaModule

Defined in: packages/core/src/application/application.ts:158

Contains definitions of current application


baseConfiguration​

protected baseConfiguration: Configuration

Defined in: packages/core/src/application/application.ts:143

Base configuration loaded from webda.config.json


beans​

protected beans: object = {}

Defined in: packages/core/src/application/application.ts:182

Beans registry

Index Signature​

[key: string]: Modda


behaviors​

protected behaviors: object = {}

Defined in: packages/core/src/application/application.ts:197

Behaviors registry

Populated by loadModule from the top-level behaviors map of every loaded webda.module.json. Each entry holds the metadata blob emitted by the compiler so downstream consumers (DomainService, REST transport, etc.) can introspect the Behavior's declared actions and shape.

The Behavior class itself is NOT loaded at runtime: the per-model __hydrateBehaviors method emitted at compile time by @webda/content-mapper holds a static import to the class, so the runtime never needs to look it up by identifier.

Index Signature​

[key: string]: object


configurationFile​

readonly configurationFile: string

Defined in: packages/core/src/application/application.ts:212

Configuration file


currentDeployment​

protected currentDeployment: string

Defined in: packages/core/src/application/application.ts:149

Current deployment

Defaults to the WEBDA_DEPLOYMENT environment variable


deployers​

protected deployers: object = {}

Defined in: packages/core/src/application/application.ts:167

Deployers type registry

Index Signature​

[key: string]: any


deployment​

protected deployment: Deployment

Defined in: packages/core/src/application/application.ts:153

Definition of the current deployment, once loaded


deploymentFile​

deploymentFile: string

Defined in: packages/core/src/application/application.ts:216

Current deployment file


logger​

protected logger: WorkerOutput

Defined in: packages/core/src/application/application.ts:202

Class Logger


moddas​

protected moddas: object = {}

Defined in: packages/core/src/application/application.ts:172

Moddas registry

Index Signature​

[key: string]: Modda


models​

protected models: object = {}

Defined in: packages/core/src/application/application.ts:177

Models type registry

Index Signature​

[key: string]: ModelDefinition


workspacesPath​

protected workspacesPath: string = ""

Defined in: packages/core/src/application/application.ts:207

Detect if running as workspace


_runner​

static _runner: (app) => Promise<void>

Defined in: packages/core/src/application/application.ts:260

Internal

Pluggable runner — set by runner.ts to avoid circular dependency with Core.

Parameters​

app​

Application

Returns​

Promise<void>

Methods​

addModda()​

addModda(name, service): this

Defined in: packages/core/src/application/application.ts:451

Add a new service

Parameters​

name​

string

the name to use

service​

Modda

the service instance

Returns​

this

this for chaining


addModel()​

addModel(name, model, metadata?): this

Defined in: packages/core/src/application/application.ts:642

Add a new model The stored type resolver is rebuilt.

Parameters​

name​

string

the name to use

model​

any

the model to use

metadata?​

ModelMetadata = ...

the model metadata

Returns​

this

this for chaining


applyCurrentDeployment()​

protected applyCurrentDeployment(): void

Defined in: packages/core/src/application/application.ts:305

Apply the current deployment parameters and services on the configuration

A packaged application already contains its deployment: the file is only required when the deployment differs from the packaged one

Returns​

void


completeNamespace()​

completeNamespace(name?): string

Defined in: packages/core/src/application/application.ts:945

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 = ""

the name to use

Returns​

string

the result string


getBehaviorMetadata()​

getBehaviorMetadata(identifier): BehaviorMetadata

Defined in: packages/core/src/application/application.ts:576

Return the metadata blob (Identifier, Actions, etc.) for a Behavior loaded from webda.module.json.

Parameters​

identifier​

string

fully qualified Behavior id (e.g. Webda/MFA)

Returns​

BehaviorMetadata

the metadata, or undefined if no Behavior with that id is registered


getBehaviors()​

getBehaviors(): object

Defined in: packages/core/src/application/application.ts:586

Return all loaded Behaviors keyed by identifier.

Each entry exposes the original metadata blob emitted by the compiler.

Returns​

object

the result


getConfiguration()​

getConfiguration(_deployment?): Configuration

Defined in: packages/core/src/application/application.ts:755

Get application configuration

Parameters​

_deployment?​

string = undefined

the deployment name

Returns​

Configuration

the result


getCurrentConfiguration()​

getCurrentConfiguration(): Configuration

Defined in: packages/core/src/application/application.ts:769

Return current Configuration of the Application

Same as calling

getConfiguration(this.currentDeployment);

Returns​

Configuration

the result


getCurrentDeployment()​

getCurrentDeployment(): string

Defined in: packages/core/src/application/application.ts:736

Get current deployment name

Returns​

string

the result string


getDeployers()​

getDeployers(): object

Defined in: packages/core/src/application/application.ts:628

Return all deployers

Returns​

object

the result


getDeployment()​

getDeployment(): Deployment

Defined in: packages/core/src/application/application.ts:295

Get the definition of the current deployment

It includes the units and resources that are not part of the application configuration

Returns​

Deployment

the deployment or undefined if no deployment is selected


getGitInformation()​

getGitInformation(_packageName?, _version?): GitInformation

Defined in: packages/core/src/application/application.ts:720

Retrieve Git Repository information

GitInformation for more details on how the information is gathered

Parameters​

_packageName?​

string

the package name

_version?​

string

the version string

Returns​

GitInformation

the git information


getImplementations()​

getImplementations<T>(object): object

Defined in: packages/core/src/application/application.ts:822

Get implementations of a class

Type Parameters​

T​

T extends Service<ServiceParameters, { }>

Parameters​

object​

T

the target object

Returns​

object

the result


getModda()​

getModda(name): Modda

Defined in: packages/core/src/application/application.ts:528

Get a service based on name

Parameters​

name​

string

the name to use

Returns​

Modda

the result


getModdas()​

getModdas(): object

Defined in: packages/core/src/application/application.ts:545

Return all services of the application

Returns​

object

the result


getModel()​

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

Defined in: packages/core/src/application/application.ts:555

Retrieve the model implementation

Type Parameters​

T​

T extends Model = Model

Parameters​

name​

string

model to retrieve

Returns​

ModelDefinition<T>

the result


getModelFromConstructor()​

getModelFromConstructor(model): string

Defined in: packages/core/src/application/application.ts:605

Return the model name for a object

Parameters​

model​

ModelClass

the model to use

Returns​

string

the result


getModelFromInstance()​

getModelFromInstance(object): string

Defined in: packages/core/src/application/application.ts:595

Return the model name for a object

Parameters​

object​

Storable

the target object

Returns​

string

the result


getModelId()​

getModelId(model): string

Defined in: packages/core/src/application/application.ts:617

Get the model name from a model or a constructor

Parameters​

model​

Storable<any, any> | ModelClass<Storable<any, any>>

the model to use

Returns​

string

longId for a model

Paramn​

full if true always include the namespace, default is false e.g Webda/


getModels()​

getModels(): object

Defined in: packages/core/src/application/application.ts:563

Get all models definitions

Returns​

object

the result


getModuleFilePath()​

protected getModuleFilePath(parent, info): string

Defined in: packages/core/src/application/application.ts:838

Path of a file referenced by a module, see resolveModuleFile

Parameters​

parent​

string

the module folder

info​

string

the path:export descriptor of the module

Returns​

string

the descriptor with the path resolved


getModules()​

getModules(): CachedModule

Defined in: packages/core/src/application/application.ts:746

Return all application modules merged as one

Used when deployed

Returns​

CachedModule

the result


getNamespace()​

getNamespace(): string

Defined in: packages/core/src/application/application.ts:957

Return current namespace

Returns​

string

the result string


getPackageDescription()​

getPackageDescription(): PackageDescriptor

Defined in: packages/core/src/application/application.ts:406

Retrieve content of package.json

Returns​

PackageDescriptor

the result


getPackageWebda()​

getPackageWebda(): WebdaPackageDescriptor

Defined in: packages/core/src/application/application.ts:395

Retrieve specific webda conf from package.json

In case of workspaces the object is combined

Returns​

WebdaPackageDescriptor

the result


getPath()​

getPath(subpath?): string

Defined in: packages/core/src/application/application.ts:434

Return the current app path

Parameters​

subpath?​

string = undefined

to append to

Returns​

string

the result string


getProjectInfo()​

getProjectInfo(): ProjectInformation

Defined in: packages/core/src/application/application.ts:728

Retrieve the project information

Returns​

ProjectInformation

the result


getSchema()​

getSchema(type): JSONSchema7

Defined in: packages/core/src/application/application.ts:354

Get a schema from a type

Schema should be precomputed in the default app

Parameters​

type​

string

the type to look up

Returns​

JSONSchema7

the result


getSchemas()​

getSchemas(): object

Defined in: packages/core/src/application/application.ts:373

Get schemas

Returns​

object

the result


getWebdaObject()​

getWebdaObject(section, name): any

Defined in: packages/core/src/application/application.ts:504

Parameters​

section​

Section

the section name

name​

string

the name to use

Returns​

any

the result


getWebdaVersion()​

getWebdaVersion(): string

Defined in: packages/core/src/application/application.ts:707

Return webda current version

Returns​

string

package version

Since​

0.4.0


getWorkerOutput()​

getWorkerOutput(): WorkerOutput

Defined in: packages/core/src/application/application.ts:424

Get current logger

Returns​

WorkerOutput

the result


hasWebdaObject()​

hasWebdaObject(section, name): boolean

Defined in: packages/core/src/application/application.ts:464

Parameters​

section​

Section

the section name

name​

string

the name to use

Returns​

boolean

true if the condition is met


importFile()​

protected importFile(info, withExport?): Promise<any>

Defined in: packages/core/src/application/application.ts:782

Import a file

If the default is set take this or use old format

Parameters​

info​

string

the information object

withExport?​

boolean = true

whether to include exports

Returns​

Promise<any>

the result


isCached()​

isCached(): boolean

Defined in: packages/core/src/application/application.ts:385

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

true if the condition is met


isFinalModel()​

isFinalModel(model): boolean

Defined in: packages/core/src/application/application.ts:486

Return true if model is the one that wins when consumers look up the short name in the current namespace. Used by transports (REST, GraphQL, gRPC) so only one model gets exposed at a given URL / type when the app overrides a framework-provided class — e.g. WebdaSample/User shadowing Webda/User at /users.

A model is "final" when either:

  • it is the one resolved by completeNamespace(shortName), or
  • no other model exists with the same short name in the current namespace.

Parameters​

model​

string

the fully-qualified model identifier (e.g. "Webda/User")

Returns​

boolean

true when model should be treated as the canonical version


load()​

load(): Promise<Application>

Defined in: packages/core/src/application/application.ts:268

Import all required modules

Returns​

Promise<Application>

the result


loadConfiguration()​

loadConfiguration(file): Promise<void>

Defined in: packages/core/src/application/application.ts:329

Allow subclass to implement migration

Parameters​

file​

string

the file path

Returns​

Promise<void>

the result


loadLocalModule()​

loadLocalModule(): Promise<void>

Defined in: packages/core/src/application/application.ts:810

Load local module

Returns​

Promise<void>


log()​

log(level, ...args): void

Defined in: packages/core/src/application/application.ts:416

Log information

Parameters​

level​

WorkerLogLevel

to log for

args​

...any[]

anything to display same as console.log

Returns​

void


run()​

run(): Promise<void>

Defined in: packages/core/src/application/application.ts:252

Run the application

Returns​

Promise<void>

the result


setCurrentDeployment()​

setCurrentDeployment(name): this

Defined in: packages/core/src/application/application.ts:283

Select the deployment to apply on the configuration

Must be called before load

Parameters​

name​

string

deployment name, a deployments/<name> file of the application

Returns​

this

this


setModelMetadata()​

protected setModelMetadata(info): void

Defined in: packages/core/src/application/application.ts:911

Set object Metadata Need to be done after all models are loaded to resolve Ancestors and Subclasses

Parameters​

info​

{[key: string]: ModelMetadata; }

the information object

Returns​

void


toJSON()​

toJSON(): object

Defined in: packages/core/src/application/application.ts:693

Serialize the application state to a plain object

Returns​

object

the result

appModule​

appModule: WebdaModule

baseConfiguration​

baseConfiguration: Configuration

currentDeployment​

currentDeployment: string


deserialize()​

static deserialize<T>(this, json): T

Defined in: packages/core/src/application/application.ts:681

Type Parameters​

T​

T extends Application

Parameters​

this​

new (...args) => T

the constructor

json​

any

the JSON data

Returns​

T

the result