Class: PluginBase

PluginBase()

new PluginBase()

Initializes a new instance of a plugin object, which should be a derived class.

Source:

Members

META :Object.<string, module:Core~Node>

The resolved META nodes based on the active namespace. Index by the fully qualified meta node names with the namespace stripped off at the start.

For example, if a project has a library A with a library B. If the project and the libraries all have two meta nodes named a and b. Depending on the namespace the META will have the following keys:

  1. namespace = '' -> ['a', 'b', 'A.a', 'A.b', 'A.B.a', 'A.B.b']
  2. namespace = 'A' -> ['a', 'b', 'B.a', 'B.b']
  3. namespace = 'A.B' -> ['a', 'b']

(N.B. 'a' and 'b' in example 3) are pointing to the meta nodes defined in A.B.)

Type:
Source:

activeNode :module:Core~Node

Type:
Source:

activeSelection :Array.<module:Core~Node>

Type:
Source:

blobClient :BlobClient

Type:
Source:

core :Core

Type:
Source:

gmeConfig :GmeConfig

Type:
Source:

logger :GmeLogger

Type:
Source:

namespace :string

The namespace the META nodes are coming from (set by invoker). The default is the full meta, i.e. the empty string namespace. For example, if a project has a library A with a library B. The possible namespaces are: '', 'A' and 'A.B'.

Type:
Source:

pluginMetadata :PluginMetadata

Type:
  • PluginMetadata
Source:

project :ProjectInterface

Type:
Source:

result :PluginResultBase

Type:
  • PluginResultBase
Source:

rootNode :module:Core~Node

Type:
Source:

Methods

addArtifact(name, files, callbackopt) → {external:Promise}

Adds multiple files to the blob storage and bundles them as an artifact of which the hash is added to the plugin-result.

Parameters:
Name Type Attributes Description
name string

name of the file bundle.

files object.<string, (string|Buffer|ArrayBuffer)>

Keys are file names and values the content.

callback function <optional>

if provided no promise will be returned.

Properties
Name Type Description
err null | Error

status of the call.

metadataHash string

the "id" of the uploaded artifact.

Source:
Returns:

If no callback is given, the result will be provided in a promise.

Type
external:Promise

addCommitToResult(status)

Adds the commit to the results. N.B. if you're using your own save method - make sure to update this.currentHash and this.branchName accordingly before adding the commit.

Parameters:
Name Type Description
status string

Status of the commit 'SYNCED', 'FORKED', 'CANCELED', null.

Source:

addFile(name, data, callbackopt) → {external:Promise}

Adds a file to the blob storage and adds it to the plugin-result.

Parameters:
Name Type Attributes Description
name string

file name.

data string | Buffer | ArrayBuffer

file content.

callback function <optional>

if provided no promise will be returned.

Properties
Name Type Description
err null | Error

status of the call

metadataHash string

the "id" of the uploaded file

Source:
Returns:

If no callback is given, the result will be provided in a promise

Type
external:Promise

baseIsMeta(node) → {boolean}

Returns true if node is a direct instance of a meta-type node (or a meta-type node itself).

Parameters:
Name Type Description
node module:Core~Node

Node to be checked.

Source:
Returns:
Type
boolean

configure(config)

Configures this instance of the plugin for a specific execution. This function is called before the main by the PluginManager. Initializes the result with a new object.

Parameters:
Name Type Description
config object

specific context: project, branch, core, active object and active selection.

Source:

createMessage(node, message, severity)

Creates a new message for the user and adds it to the result.

Parameters:
Name Type Description
node module:Core~Node | object

webgme object which is related to the message

message string

feedback to the user

severity string

severity level of the message: 'debug', 'info' (default), 'warning', 'error'.

Source:

fastForward(callbackopt) → {external:Promise}

If plugin is started from a branch - it will reload the instance's nodes and update the currentHash to the current hash of the branch.

N.B. Use this with caution, for instance manually referenced nodes in a plugin will still be part of the previous commit. Additionally if the namespaces have changed between commits - the this.META might end up being empty.

Parameters:
Name Type Attributes Description
callback function <optional>

the result callback

Properties
Name Type Description
err null | Error

status of the call

didUpdate boolean

true if there was a change and it updated the state to it

Source:
Returns:

If no callback is given, the result will be provided in a promise

Type
external:Promise

getArtifact(metadataHash) → {external:Promise}

Retrieves all the files in the artifact from the blob storage.

Parameters:
Name Type Description
metadataHash string

the "id" of the artifact to retrieve.

callback.err null | Error

status of the call.

callback.files object.<string, string>

Keys are file names, and values the content.

Source:
Returns:

If no callback is given, the result will be provided in a promise.

Type
external:Promise

getBinFile(metadataHash, subpathopt) → {external:Promise}

Retrieves the file from blob storage in binary format.

Parameters:
Name Type Attributes Description
metadataHash string

the "id" of the file to retrieve.

subpath string <optional>

optional file-like path to sub-object if complex blob

callback.err null | Error

status of the call.

callback.content Buffer

the file content.

Source:
Returns:

If no callback is given, the result will be provided in a promise.

Type
external:Promise

getConfigStructure() → {Array.<object>}

Configuration structure with names, descriptions, minimum, maximum values, default values and type definitions.

Example:

[{ "name": "logChildrenNames", "displayName": "Log Children Names", "description": '', "value": true, // this is the 'default config' "valueType": "boolean", "readOnly": false },{ "name": "logLevel", "displayName": "Logger level", "description": '', "value": "info", "valueType": "string", "valueItems": [ "debug", "info", "warn", "error" ], "readOnly": false },{ "name": "maxChildrenToLog", "displayName": "Maximum children to log", "description": 'Set this parameter to blabla', "value": 4, "minValue": 1, "valueType": "number", "readOnly": false }]

Source:
Returns:
Type
Array.<object>

getCurrentConfig() → {PluginConfig}

Gets the current configuration of the plugin that was set by the user and plugin manager.

Source:
Returns:
Type
PluginConfig

getDefaultConfig() → {PluginConfig}

Gets the default configuration based on the configuration structure for this plugin.

Source:
Returns:
Type
PluginConfig

getDescription() → {string}

A detailed description of this plugin and its purpose. It can be one or more sentences.

Source:
Returns:
Type
string

getFile(metadataHash) → {external:Promise}

Retrieves the file from blob storage.

Parameters:
Name Type Description
metadataHash string

the "id" of the file to retrieve.

callback.err null | Error

status of the call.

callback.content string

the file content.

Source:
Returns:

If no callback is given, the result will be provided in a promise.

Type
external:Promise

getId() → {string}

Readable name of this plugin that can contain spaces.

Source:
Returns:
Type
string

getMetaType(node) → {module:Core~Node}

Finds and returns the node object defining the meta type for the given node.

Parameters:
Name Type Description
node module:Core~Node

Node to be checked for type.

Source:
Returns:
  • Node object defining the meta type of node.
Type
module:Core~Node

getMetadata() → {PluginMetaData}

Gets the metadata for the plugin.

Source:
Returns:
Type
PluginMetaData

getName() → {string}

Readable name of this plugin that can contain spaces.

Source:
Returns:
Type
string

getPluginDependencies() → {Array.<string>}

Gets the ids of the directly defined dependencies of the plugin

Source:
Returns:
Type
Array.<string>

getUserId() → {string}

Retrieves the identity of the current user of the opened project (the user who invoked the plugin).

Source:
Returns:

the userId

Type
string

getVersion() → {string}

Current version of this plugin using semantic versioning.

Source:
Returns:
Type
string

initialize(logger, blobClient, gmeConfig)

Initializes the plugin with objects that can be reused within the same plugin instance.

Parameters:
Name Type Description
logger GmeLogger

logging capability to console (or file) based on PluginManager configuration

blobClient BlobClient

virtual file system where files can be generated then saved as a zip file.

gmeConfig GmeConfig

global configuration for webGME.

Source:

invokePlugin(pluginId, contextopt, callbackopt) → {external:Promise}

Initializes and invokes the given plugin (at pluginId). Things to note:

  1. If the invoked plugin calls save - it will not persist nor make a commit. The message will be recorded in the InterPluginResult.
  2. Artifacts and files saved will be added to the blob-storage. Invoked plugins can expose the content by adding it to itself - the instance will be available in the InterPluginResult.
Parameters:
Name Type Attributes Description
pluginId string

Id of plugin that should be invoked

context object <optional>

Optional context for the invoked plugin

Properties
Name Type Attributes Default Description
namespace object <optional>
this.namespace

Namespace (relative this.namespace)

activeNode module:Core~Node <optional>
this.activeNode

Active node of invoked plugin

activeSelection Array.<module:Core~Node> <optional>
this.activeSelection

Active selection of invoked plugin

pluginConfig object <optional>

Specific configuration parameters that should be used for the invocation. If not provided will first check if the currentConfig of this plugin contains this plugin as dependency within the array this._currentConfig._dependencies. Finally it will fall back to the default config of the plugin.

callback function <optional>

the result callback

Properties
Name Type Description
err null | Error

status of the call

result InterPluginResult

result from the invoked plugin

Source:
Returns:

If no callback is given, the result will be provided in a promise

Type
external:Promise

isInvalidActiveNode(pluginId) → {Error}

Checks if the activeNode has registered the plugin.

Parameters:
Name Type Description
pluginId string

Id of plugin

Source:
Returns:
  • returns undefined if valid and an Error if not.
Type
Error

isMetaTypeOf(node, metaNode) → {boolean}

Checks if the given node is of the given meta-type. Usage: self.isMetaTypeOf(aNode, self.META['FCO']);

Parameters:
Name Type Description
node module:Core~Node

Node to be checked for type.

metaNode module:Core~Node

Node object defining the meta type.

Source:
Returns:
  • True if the given object was of the META type.
Type
boolean

loadNodeMap(nodeopt, callbackopt) → {external:Promise}

Loads all the nodes in the subtree starting from node and returns a map from paths to nodes.

Parameters:
Name Type Attributes Default Description
node module:Core~Node <optional>
self.rootNode

Optional node to preload nodes from, by default all will be loaded.

callback function <optional>

the result callback

Properties
Name Type Description
err null | Error

status of the call

nodeMap object

keys are paths and values are nodes

Source:
Returns:

If no callback is given, the result will be provided in a promise

Type
external:Promise

main(callback)

Main function for the plugin to execute. This will perform the execution. Notes:
- Do NOT use console.log use this.logger.[error,warning,info,debug] instead.
- Do NOT put any user interaction logic UI, etc. inside this function.
- callback always have to be called even if error happened.

Parameters:
Name Type Description
callback function

the result callback

Properties
Name Type Description
err null | Error

status of the call

result PluginResult

plugin result

Source:

onAbort()

Aborts the execution of a plugin.

Source:

onMessage(messageType, content)

Can send a message to the plugin.

Parameters:
Name Type Description
messageType string

string identifier of the message.

content object

object that holds arbitrary content of the message.

Source:

save(message, callbackopt) → {external:Promise}

Saves all current changes if there is any to a new commit. If the commit result is either 'FORKED' or 'CANCELED', it creates a new branch.

N.B. This is a utility function for saving/persisting data. The plugin has access to the project and core instances and may persist and make the commit as define its own behavior for e.g. 'FORKED' commits. To report the commits in the PluginResult make sure to invoke this.addCommitToResult with the given status.

Parameters:
Name Type Attributes Description
message string | null

commit message

callback function <optional>

the result callback

Properties
Name Type Description
err null | Error

status of the call

commitResult module:Storage~CommitResult

status of the commit made

Source:
Returns:

If no callback is given, the result will be provided in a promise

Type
external:Promise

sendNotification(message, callbackopt)

Sends a notification back to the invoker of the plugin, can be used to notify about progress.

Parameters:
Name Type Attributes Description
message string | object

Message string or object containing message.

Properties
Name Type Attributes Default Description
message string

If object it must contain a message.

progress number <optional>

Approximate progress (in %) of the plugin at time of sending.

severity string <optional>
'info'

Severity level ('success', 'info', 'warn', 'error')

toBranch boolean <optional>
false

If true, and the plugin is running on the server on a branch - will broadcast to all sockets in the branch room.

callback function <optional>

optional callback invoked when message has been emitted from server.

Properties
Name Type Description
err null | Error

status of the call

Source:

setCurrentConfig(newConfig)

Sets the current configuration of the plugin.

Parameters:
Name Type Description
newConfig PluginConfig

this is the actual configuration and NOT the configuration structure.

Source:

updateMETA(generatedMETA)

WebGME can export the META types as path and this method updates the generated domain specific types with webgme node objects. These can be used to define the base class of new objects created through the webgme API.

Parameters:
Name Type Description
generatedMETA object
Source:

updateSuccess(value, message)

Updates the current success flag with a new value.

NewValue = OldValue && Value

Parameters:
Name Type Description
value boolean

apply this flag on current success value

message string | null

optional detailed message

Source: