Skip to content

ChainGraph API Documentation / @badaitech/chaingraph-types / IPort

Interface: IPort<C> ​

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:30

IPort interface

Represents a generic port that holds a configuration and a value. The type parameter C must extend IPortConfig and defines the shape of the configuration.

Each port instance implements several methods:

  • getConfig: Returns the current configuration.
  • setConfig: Updates the configuration.
  • getValue: Retrieves the current port value.
  • setValue: Sets or updates the port value.
  • reset: Resets the port’s value, typically to a default state.
  • serialize: Serializes the port (both config and value) to a JSON-compatible value.
  • deserialize: Deserializes a JSON value into the port’s configuration and value.
  • validate: Validates both the configuration and the current value.

Type Parameters ​

C ​

C extends IPortConfig = IPortConfig

The configuration type which extends IPortConfig.

Properties ​

addConnection() ​

addConnection: (nodeId, portId) => void

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:140

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


clone() ​

clone: () => IPort<C>

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:108

Clones the port instance.

Returns ​

IPort<C>

A new port instance with the same configuration and value.


cloneWithNewId() ​

cloneWithNewId: () => IPort<C>

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:117

Clones the port instance with a new unique identifier.

This is useful for creating a copy of the port that can be used independently.

Returns ​

IPort<C>

A new port instance with the same configuration and value, but a new ID.


deserialize() ​

deserialize: (data) => IPort<C>

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:94

Deserializes the given JSON data and updates the port’s configuration and value.

The input data is expected to contain a serialized representation of the port.

Parameters ​

data ​

unknown

A JSONValue that holds serialized port data.

Returns ​

IPort<C>

A port instance (of type IPort<C>) with updated configuration and value.


deserializeConfig() ​

deserializeConfig: (data) => C

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:181

Deserializes a JSONValue into a configuration object of type C.

Parameters ​

data ​

unknown

Returns ​

C


deserializeValue() ​

deserializeValue: (data) => ExtractValue<C>

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:186

Deserializes a JSONValue into a port value of type T.

Parameters ​

data ​

unknown

Returns ​

ExtractValue<C>


getConfig() ​

getConfig: () => C

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:46

Retrieves the current port configuration.

Returns ​

C

The port configuration of type C.


getDefaultValue() ​

getDefaultValue: () => ExtractValue<C> | undefined

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:154

Returns the default value. Concrete implementations can use a default provided by the configuration.

Returns ​

ExtractValue<C> | undefined


getValue() ​

getValue: () => ExtractValue<C> | undefined

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:60

Gets the current port value.

Returns ​

ExtractValue<C> | undefined

The port value, or undefined if none is set.


isSystem() ​

isSystem: () => boolean

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:124

Check if the port is a system port.

Returns ​

boolean

True if the port is a system port, otherwise false.


isSystemError() ​

isSystemError: () => boolean

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:131

Check if the port is a system error port.

Returns ​

boolean

True if the port is a system error port, otherwise false.


removeConnection() ​

removeConnection: (nodeId, portId) => void

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:148

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


reset() ​

reset: () => void

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:75

Resets the port’s current value.

In typical implementations, this resets the value to a default (if available).

Returns ​

void


serialize() ​

serialize: () => unknown

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:84

Serializes the port’s configuration and value.

The returned JSONValue should be a JSON-serializable representation of the port.

Returns ​

unknown

A JSON value representing the port’s state.


serializeConfig() ​

serializeConfig: (config) => unknown

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:171

Serializes the configuration (of type C) to a JSONValue.

Parameters ​

config ​

C

Returns ​

unknown


serializeValue() ​

serializeValue: (value) => unknown

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:176

Serializes the port value (of type T) to a JSONValue.

Parameters ​

value ​

ExtractValue<C>

Returns ​

unknown


setConfig() ​

setConfig: (newConfig) => void

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:53

Updates the port configuration with a new configuration object.

Parameters ​

newConfig ​

C

New configuration of type C.

Returns ​

void


setValue() ​

setValue: (newValue) => void

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:68

Sets or updates the port value. The value must be validated before being accepted.

Parameters ​

newValue ​

ExtractValue<C>

The new value to set for the port.

Returns ​

void


unwrap() ​

unwrap: () => IPort<C>

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:206

Unwrap to get underlying port instance

For storage-backed ports (WrappedPort): returns inner port For regular ports: returns this

Use when you need access to port-type-specific methods or when you need instanceof checks to work correctly

Returns ​

IPort<C>

Underlying port instance

Example ​

ts
const port = node.getPort('config')  // Returns WrappedPort
if (port.unwrap() instanceof ObjectPort) {
  const objPort = port.unwrap() as ObjectPort
  objPort.addField('newField', config)  // ObjectPort-specific method
}

validate() ​

validate: () => boolean

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:101

Validates the current port configuration and value.

Returns ​

boolean

True if the port is valid, otherwise false.


validateConfig() ​

validateConfig: (config) => boolean

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:166

Validates the port configuration. Must return true if the configuration is valid, false otherwise.

Parameters ​

config ​

C

Returns ​

boolean


validateValue() ​

validateValue: (value) => boolean

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:160

Validates the port value. Must return true if the value is valid, false otherwise.

Parameters ​

value ​

ExtractValue<C>

Returns ​

boolean

Accessors ​

id ​

Get Signature ​

get id(): string

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:34

The unique identifier of the port.

Returns ​

string


key ​

Get Signature ​

get key(): string

Defined in: packages/chaingraph-types/src/port/base/IPort.ts:39

The key of the port.

Returns ​

string

Licensed under BUSL-1.1