Skip to content

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

Abstract Class: BasePort<C> ​

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:15

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.

Extended by ​

Type Parameters ​

C ​

C extends IPortConfig = IPortConfig

The configuration type which extends IPortConfig.

Implements ​

Constructors ​

Constructor ​

new BasePort<C>(config): BasePort<C>

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:19

Parameters ​

config ​

C

Returns ​

BasePort<C>

Properties ​

config ​

protected config: C

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:16


value? ​

protected optional value: ExtractValue<C>

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:17

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 ​

IPort.id


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 ​

IPort.key

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 ​

IPort.addConnection


clone() ​

clone(): IPort<C>

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:130

Clones the port instance.

Returns ​

IPort<C>

A new port instance with the same configuration and value.

Implementation of ​

IPort.clone


cloneWithNewId() ​

abstract cloneWithNewId(): IPort<C>

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:231

Clones cloneWithNewId

Returns ​

IPort<C>

Implementation of ​

IPort.cloneWithNewId


deserialize() ​

deserialize(data): IPort<C>

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<C>

Implementation of ​

IPort.deserialize


deserializeConfig() ​

abstract deserializeConfig(data): C

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:221

Deserializes a JSONValue into a configuration object of type C.

Parameters ​

data ​

unknown

Returns ​

C

Implementation of ​

IPort.deserializeConfig


deserializeValue() ​

abstract deserializeValue(data): ExtractValue<C>

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:226

Deserializes a JSONValue into a port value of type T.

Parameters ​

data ​

unknown

Returns ​

ExtractValue<C>

Implementation of ​

IPort.deserializeValue


getConfig() ​

getConfig(): C

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:33

Retrieves the current port configuration.

Returns ​

C

The port configuration of type C.

Implementation of ​

IPort.getConfig


getDefaultValue() ​

abstract getDefaultValue(): ExtractValue<C> | undefined

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:194

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

Returns ​

ExtractValue<C> | undefined

Implementation of ​

IPort.getDefaultValue


getValue() ​

getValue(): ExtractValue<C> | undefined

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:42

Gets the current port value.

Returns ​

ExtractValue<C> | undefined

The port value, or undefined if none is set.

Implementation of ​

IPort.getValue


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 ​

IPort.isSystem


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 ​

IPort.isSystemError


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 ​

IPort.removeConnection


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 ​

IPort.reset


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 ​

IPort.serialize


serializeConfig() ​

abstract serializeConfig(config): unknown

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:211

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

Parameters ​

config ​

C

Returns ​

unknown

Implementation of ​

IPort.serializeConfig


serializeValue() ​

abstract serializeValue(value): unknown

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:216

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

Parameters ​

value ​

ExtractValue<C>

Returns ​

unknown

Implementation of ​

IPort.serializeValue


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 ​

C

New configuration of type C.

Returns ​

void

Implementation of ​

IPort.setConfig


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.

ExtractValue<C> | undefined

Returns ​

void

Implementation of ​

IPort.setValue


unwrap() ​

unwrap(): IPort<C>

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<C>

Implementation of ​

IPort.unwrap


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 ​

IPort.validate


validateConfig() ​

abstract validateConfig(config): boolean

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

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

Parameters ​

config ​

C

Returns ​

boolean

Implementation of ​

IPort.validateConfig


validateValue() ​

abstract validateValue(value): boolean

Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:200

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

Parameters ​

value ​

ExtractValue<C>

Returns ​

boolean

Implementation of ​

IPort.validateValue

Licensed under BUSL-1.1