ChainGraph API Documentation / @badaitech/chaingraph-types / ArrayPort
Class: ArrayPort<Item>
Defined in: packages/chaingraph-types/src/port/instances/ArrayPort.ts:50
Concrete implementation of an Array Port.
This class extends BasePort using ArrayPortConfig and ArrayPortValue. It leverages the ArrayPortPlugin to handle default value resolution, validation, serialization, and deserialization.
Example usage: const config: ArrayPortConfig<StringPortConfig> = { type: 'array', itemConfig: { type: 'string', minLength: 2 }, minLength: 1, maxLength: 5, defaultValue: { type: 'array', value: [{ type: 'string', value: 'hello' }], }, }
const arrayPort = new ArrayPort(config) const valueDefault = arrayPort.getValue()?.value[0].value // => 'hello'
arrayPort.setValue({ type: 'array', value: [ { type: 'string', value: 'one' }, { type: 'string', value: 'two' }, ], })
const value = arrayPort.getValue() console.log(arrayPort.getValue()?.value[0].value) // => 'one'
Extends
BasePort<ArrayPortConfig<Item>>
Type Parameters
Item
Item extends IPortConfig = IPortConfig
Implements
IPort<ArrayPortConfig<Item>>
Constructors
Constructor
new ArrayPort<
Item>(config):ArrayPort<Item>
Defined in: packages/chaingraph-types/src/port/instances/ArrayPort.ts:53
Parameters
config
ArrayPortConfig<Item>
Returns
ArrayPort<Item>
Overrides
Properties
config
protectedconfig:ArrayPortConfig
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:16
Inherited from
value?
protectedoptionalvalue:ArrayPortValue<Item>
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<ArrayPortConfig<Item>>
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:130
Clones the port instance.
Returns
IPort<ArrayPortConfig<Item>>
A new port instance with the same configuration and value.
Implementation of
Inherited from
cloneWithNewId()
cloneWithNewId():
IPort<ArrayPortConfig<Item>>
Defined in: packages/chaingraph-types/src/port/instances/ArrayPort.ts:146
Clones the port with a new ID. Useful for creating copies of the port with a unique identifier.
Returns
IPort<ArrayPortConfig<Item>>
Implementation of
Overrides
deserialize()
deserialize(
data):IPort<ArrayPortConfig<Item>>
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
IPort<ArrayPortConfig<Item>>
Implementation of
Inherited from
deserializeConfig()
deserializeConfig(
data):ArrayPortConfig<Item>
Defined in: packages/chaingraph-types/src/port/instances/ArrayPort.ts:127
Deserializes the provided JSON data into an array port configuration. Delegates deserialization to the ArrayPortPlugin.
Parameters
data
unknown
The JSON data representing the configuration.
Returns
ArrayPortConfig<Item>
The deserialized ArrayPortConfig.
Implementation of
Overrides
deserializeValue()
deserializeValue(
data):ArrayPortValue
Defined in: packages/chaingraph-types/src/port/instances/ArrayPort.ts:138
Deserializes the given JSON data into an array port value. Delegates deserialization to the ArrayPortPlugin.
Parameters
data
unknown
The JSON data representing the value.
Returns
The deserialized ArrayPortValue.
Implementation of
Overrides
getConfig()
getConfig():
ArrayPortConfig
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():
ArrayPortValue<Item>
Defined in: packages/chaingraph-types/src/port/instances/ArrayPort.ts:70
Retrieves the default value from the configuration. If a defaultValue is provided in the config, it is returned; otherwise, undefined is returned.
Returns
ArrayPortValue<Item>
The default ArrayPortValue if specified; otherwise undefined.
Implementation of
Overrides
getValue()
getValue():
ArrayPortValue<Item>
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:42
Gets the current port value.
Returns
ArrayPortValue<Item>
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/ArrayPort.ts:105
Serializes the array port configuration into a JSON-compatible object. Delegates serialization to the ArrayPortPlugin.
Parameters
config
ArrayPortConfig<Item>
The array port configuration to serialize.
Returns
unknown
The serialized configuration as a JSONValue.
Implementation of
Overrides
serializeValue()
serializeValue(
value):unknown
Defined in: packages/chaingraph-types/src/port/instances/ArrayPort.ts:116
Serializes the given array port value into a JSON-compatible object. Delegates serialization logic to the ArrayPortPlugin.
Parameters
value
ArrayPortValue<Item>
The array port value to serialize.
Returns
unknown
The serialized value as a JSONValue.
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
ArrayPortValue<Item>
The new value to set for the port.
Returns
void
Implementation of
Inherited from
unwrap()
unwrap():
IPort<ArrayPortConfig<Item>>
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
IPort<ArrayPortConfig<Item>>
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/ArrayPort.ts:93
Validates the array port configuration. Delegates the configuration validation to the ArrayPortPlugin.
Parameters
config
ArrayPortConfig<Item>
The array port configuration to validate.
Returns
boolean
True if the configuration is valid; otherwise false.
Implementation of
Overrides
validateValue()
validateValue(
value):boolean
Defined in: packages/chaingraph-types/src/port/instances/ArrayPort.ts:81
Validates the given array port value against the current configuration. Delegates validation to the ArrayPortPlugin.
Parameters
value
ArrayPortValue<Item>
The array port value to validate.
Returns
boolean
True if the value is valid; otherwise false.