ChainGraph API Documentation / @badaitech/chaingraph-types / EnumPort
Class: EnumPort
Defined in: packages/chaingraph-types/src/port/instances/EnumPort.ts:40
Concrete implementation of an Enum Port.
This class extends BasePort using EnumPortConfig and EnumPortValue. It leverages the EnumPortPlugin to handle validation, serialization, and deserialization.
The Enum port allows selecting one option from a list of possible options, where each option is a valid port configuration. The selected value is stored as the id of the chosen option.
Example usage: const config: EnumPortConfig = { type: 'enum', options: [ { type: 'string', id: 'opt1', name: 'Option 1' }, { type: 'number', id: 'opt2', name: 'Option 2' }, ], defaultValue: { type: 'enum', value: 'opt1' }, }
const enumPort = new EnumPort(config) enumPort.setValue({ type: 'enum', value: 'opt2' }) console.log(enumPort.getValue()) // => { type: 'enum', value: 'opt2' }
Extends
Implements
Constructors
Constructor
new EnumPort(
config):EnumPort
Defined in: packages/chaingraph-types/src/port/instances/EnumPort.ts:43
Parameters
config
Returns
EnumPort
Overrides
Properties
config
protectedconfig:EnumPortConfig
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:16
Inherited from
value?
protectedoptionalvalue:string
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:17
Inherited from
Accessors
id
Get Signature
get id():
string
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:25
The unique identifier of the port.
Returns
string
Implementation of
Inherited from
key
Get Signature
get key():
string
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:29
The key of the port.
Returns
string
Implementation of
Inherited from
Methods
addConnection()
addConnection(
nodeId,portId):void
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:153
Adds a connection to the port metadata.
Parameters
nodeId
string
The ID of the node to connect to.
portId
string
The ID of the port to connect to.
Returns
void
Implementation of
Inherited from
clone()
clone():
IPort<EnumPortConfig>
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:130
Clones the port instance.
Returns
A new port instance with the same configuration and value.
Implementation of
Inherited from
cloneWithNewId()
cloneWithNewId():
IPort<EnumPortConfig>
Defined in: packages/chaingraph-types/src/port/instances/EnumPort.ts:127
Clones the port with a new ID. Useful for creating copies of the port with a unique identifier.
Returns
Implementation of
Overrides
deserialize()
deserialize(
data):IPort<EnumPortConfig>
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:79
Deserializes the given JSONValue (expected to hold { config, value }) and updates both the config and current value.
Parameters
data
unknown
Returns
Implementation of
Inherited from
deserializeConfig()
deserializeConfig(
data):EnumPortConfig
Defined in: packages/chaingraph-types/src/port/instances/EnumPort.ts:109
Deserializes JSON data into an EnumPortConfig. Delegates to EnumPortPlugin.deserializeConfig.
Parameters
data
unknown
The JSON data.
Returns
The deserialized configuration.
Implementation of
Overrides
deserializeValue()
deserializeValue(
data):string
Defined in: packages/chaingraph-types/src/port/instances/EnumPort.ts:119
Deserializes JSON data into an EnumPortValue. Delegates to EnumPortPlugin.deserializeValue.
Parameters
data
unknown
The JSON data.
Returns
string
The deserialized port value.
Implementation of
Overrides
getConfig()
getConfig():
EnumPortConfig
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:33
Retrieves the current port configuration.
Returns
The port configuration of type C.
Implementation of
Inherited from
getDefaultValue()
getDefaultValue():
string|undefined
Defined in: packages/chaingraph-types/src/port/instances/EnumPort.ts:57
Returns the default value from the configuration.
Returns
string | undefined
The default EnumPortValue if specified; otherwise undefined.
Implementation of
Overrides
getValue()
getValue():
string|undefined
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:42
Gets the current port value.
Returns
string | undefined
The port value, or undefined if none is set.
Implementation of
Inherited from
isSystem()
isSystem():
boolean
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:138
Check if the port is a system port.
Returns
boolean
True if the port is a system port, otherwise false.
Implementation of
Inherited from
isSystemError()
isSystemError():
boolean
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:142
Check if the port is a system error port.
Returns
boolean
True if the port is a system error port, otherwise false.
Implementation of
Inherited from
removeConnection()
removeConnection(
nodeId,portId):void
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:179
Removes a connection from the port metadata.
Parameters
nodeId
string
The ID of the node to disconnect from.
portId
string
The ID of the port to disconnect from.
Returns
void
Implementation of
Inherited from
reset()
reset():
void
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:50
Resets the port’s current value.
In typical implementations, this resets the value to a default (if available).
Returns
void
Implementation of
Inherited from
serialize()
serialize():
unknown
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:59
Serializes both config and value into a JSONValue–compatible object. It calls the abstract serializeConfig and serializeValue methods.
Returns
unknown
Implementation of
Inherited from
serializeConfig()
serializeConfig(
config):unknown
Defined in: packages/chaingraph-types/src/port/instances/EnumPort.ts:89
Serializes the enum port configuration. Delegates to EnumPortPlugin.serializeConfig.
Parameters
config
The enum port configuration.
Returns
unknown
The serialized configuration.
Implementation of
Overrides
serializeValue()
serializeValue(
value):unknown
Defined in: packages/chaingraph-types/src/port/instances/EnumPort.ts:99
Serializes the enum port value. Delegates to EnumPortPlugin.serializeValue.
Parameters
value
string
The enum port value.
Returns
unknown
The serialized value.
Implementation of
Overrides
setConfig()
setConfig(
newConfig):void
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:37
Updates the port configuration with a new configuration object.
Parameters
newConfig
New configuration of type C.
Returns
void
Implementation of
Inherited from
setValue()
setValue(
newValue):void
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:46
Sets or updates the port value. The value must be validated before being accepted.
Parameters
newValue
The new value to set for the port.
string | undefined
Returns
void
Implementation of
Inherited from
unwrap()
unwrap():
IPort<EnumPortConfig>
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:237
Unwrap to get underlying port instance For regular ports, returns this (already unwrapped)
Returns
Implementation of
Inherited from
validate()
validate():
boolean
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:118
Validates both the current configuration and value. It defers to the abstract validateConfig and validateValue methods.
Returns
boolean
Implementation of
Inherited from
validateConfig()
validateConfig(
config):boolean
Defined in: packages/chaingraph-types/src/port/instances/EnumPort.ts:78
Validates the enum port configuration. Delegates to EnumPortPlugin.validateConfig.
Parameters
config
The enum port configuration.
Returns
boolean
True if valid; otherwise false.
Implementation of
Overrides
validateValue()
validateValue(
value):boolean
Defined in: packages/chaingraph-types/src/port/instances/EnumPort.ts:67
Validates the enum port value. Delegates to EnumPortPlugin.validateValue.
Parameters
value
string
The enum port value to validate.
Returns
boolean
True if valid; otherwise false.