Skip to content

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

Class: WrappedPort<C> ​

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:39

WrappedPort intercepts all port operations and integrates with UnifiedPortStorage

Key features:

  • getValue()/setValue() read/write from unified storage
  • getConfig() builds dynamic proxy trees for complex types
  • setConfig() writes to storage, automatically syncs everywhere
  • All other methods delegate to inner port instance

This wrapper makes the unified storage system transparent to external code. Users can call port.setConfig() and the change automatically propagates to:

  • The flat config storage
  • Parent port schemas
  • All proxy references
  • All watchers

Type Parameters ​

C ​

C extends IPortConfig = IPortConfig

Implements ​

Constructors ​

Constructor ​

new WrappedPort<C>(inner, storage, path): WrappedPort<C>

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:40

Parameters ​

inner ​

IPort<C>

storage ​

UnifiedPortStorage

path ​

string

Returns ​

WrappedPort<C>

Accessors ​

id ​

Get Signature ​

get id(): string

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:52

Get port ID

Returns ​

string

Implementation of ​

IPort.id


key ​

Get Signature ​

get key(): string

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:59

Get port key

Returns ​

string

Implementation of ​

IPort.key

Methods ​

addConnection() ​

addConnection(nodeId, portId): void

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:464

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/instances/WrappedPort.ts:448

Clones the port instance.

Returns ​

IPort<C>

A new port instance with the same configuration and value.

Implementation of ​

IPort.clone


cloneWithNewId() ​

cloneWithNewId(): IPort<C>

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:452

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.

Implementation of ​

IPort.cloneWithNewId


deserialize() ​

deserialize(data): IPort<C>

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:440

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.

Implementation of ​

IPort.deserialize


deserializeConfig() ​

deserializeConfig(data): C

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:529

Deserializes a JSONValue into a configuration object of type C.

Parameters ​

data ​

unknown

Returns ​

C

Implementation of ​

IPort.deserializeConfig


deserializeValue() ​

deserializeValue(data): ExtractValue<C>

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:533

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/instances/WrappedPort.ts:70

Get configuration - builds dynamic proxy tree for complex types This is where the magic happens!

CRITICAL: Resolves $ref before building proxies. Reference configs don't have type/schema/itemConfig until resolved!

Returns ​

C

Implementation of ​

IPort.getConfig


getDefaultValue() ​

getDefaultValue(): ExtractValue<C> | undefined

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:509

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/instances/WrappedPort.ts:228

Get value - reads from unified storage

Returns ​

ExtractValue<C> | undefined

Implementation of ​

IPort.getValue


isSystem() ​

isSystem(): boolean

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:456

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/instances/WrappedPort.ts:460

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/instances/WrappedPort.ts:489

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/instances/WrappedPort.ts:432

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/instances/WrappedPort.ts:436

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.

Implementation of ​

IPort.serialize


serializeConfig() ​

serializeConfig(config): unknown

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:521

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

Parameters ​

config ​

C

Returns ​

unknown

Implementation of ​

IPort.serializeConfig


serializeValue() ​

serializeValue(value): unknown

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:525

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/instances/WrappedPort.ts:107

Set configuration - writes to storage, auto-syncs everywhere

IMPORTANT: For array/stream ports, also syncs itemConfig to template. This enables dynamic type mutation (any → string, any → object, etc.)

Parameters ​

newConfig ​

C

Returns ​

void

Implementation of ​

IPort.setConfig


setUnderlyingType() ​

setUnderlyingType(underlyingType): void

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:200

Set underlying type for Any ports (storage-centric)

CRITICAL: This method intercepts setUnderlyingType() calls from transfer rules and persists changes to storage. Without this, underlyingType changes are lost!

Transfer rules call this when connecting ports:

  • string → any: Sets underlyingType to string config
  • object → any: Sets underlyingType to object config
  • etc.

Parameters ​

underlyingType ​

IPortConfig | undefined

Returns ​

void


setValue() ​

setValue(newValue): void

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:235

Set value - writes to unified storage

Parameters ​

newValue ​

ExtractValue<C>

Returns ​

void

Implementation of ​

IPort.setValue


unwrap() ​

unwrap(): IPort<C>

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:548

Unwrap to get underlying port instance Returns the inner port (not the wrapper)

Returns ​

IPort<C>

Example ​

ts
const wrapped = node.getPort('config')  // WrappedPort<ObjectPortConfig>
const inner = wrapped.unwrap()          // ObjectPort
if (inner instanceof ObjectPort) {
  inner.addField('field', config)       // Works!
}

Implementation of ​

IPort.unwrap


validate() ​

validate(): boolean

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:444

Validates the current port configuration and value.

Returns ​

boolean

True if the port is valid, otherwise false.

Implementation of ​

IPort.validate


validateConfig() ​

validateConfig(config): boolean

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:517

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

Parameters ​

config ​

C

Returns ​

boolean

Implementation of ​

IPort.validateConfig


validateValue() ​

validateValue(value): boolean

Defined in: packages/chaingraph-types/src/port/instances/WrappedPort.ts:513

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