ChainGraph API Documentation / @badaitech/chaingraph-types / StreamPort
Class: StreamPort<Item>
Defined in: packages/chaingraph-types/src/port/instances/StreamPort.ts:52
Concrete implementation of a Stream Port.
This class extends BasePort using StreamPortConfig and StreamPortValue. It leverages the StreamPortPlugin to handle default value resolution, validation, serialization, and deserialization.
In a Stream Port, the value represents a channel (typically implemented by MultiChannel) that holds port values. When you serialize the port, the channel’s buffer and its closed-state get serialized and later restored on deserialization.
Example usage:
// Create a stream port configuration. Assume that a stream is used to push a series of // port values (for example, strings or numbers). The "itemConfig" defines the type of // items allowed on this stream.
const streamConfig = createStreamPortConfig({ type: 'stream', itemConfig: { type: 'string', minLength: 2 }, // Optionally, you might include a default value that represents the initial channel state. })
// Create the stream port: const streamPort = new StreamPort(streamConfig)
// Later, obtain the stream channel (the port value) and subscribe to values: const channel = streamPort.getValue()?.value if (channel) { for await (const item of channel) { console.log(item) } }
Extends
BasePort<StreamPortConfig<Item>>
Type Parameters
Item
Item extends IPortConfig = IPortConfig
Implements
IPort<StreamPortConfig<Item>>
Constructors
Constructor
new StreamPort<
Item>(config):StreamPort<Item>
Defined in: packages/chaingraph-types/src/port/instances/StreamPort.ts:55
Parameters
config
StreamPortConfig<Item>
Returns
StreamPort<Item>
Overrides
Properties
config
protectedconfig:StreamPortConfig
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:16
Inherited from
value?
protectedoptionalvalue:StreamPortValue<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<StreamPortConfig<Item>>
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:130
Clones the port instance.
Returns
IPort<StreamPortConfig<Item>>
A new port instance with the same configuration and value.
Implementation of
Inherited from
cloneWithNewId()
cloneWithNewId():
IPort<StreamPortConfig<Item>>
Defined in: packages/chaingraph-types/src/port/instances/StreamPort.ts:157
Clones the port with a new ID. Useful for creating copies of the port with a unique identifier.
Returns
IPort<StreamPortConfig<Item>>
Implementation of
Overrides
deserialize()
deserialize(
data):IPort<StreamPortConfig<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<StreamPortConfig<Item>>
Implementation of
Inherited from
deserializeConfig()
deserializeConfig(
data):StreamPortConfig<Item>
Defined in: packages/chaingraph-types/src/port/instances/StreamPort.ts:138
Deserializes the provided JSON data into a stream port configuration. Delegates to StreamPortPlugin.deserializeConfig.
Parameters
data
unknown
The JSON data representing the configuration.
Returns
StreamPortConfig<Item>
The deserialized configuration.
Implementation of
Overrides
deserializeValue()
deserializeValue(
data):StreamPortValue<Item>
Defined in: packages/chaingraph-types/src/port/instances/StreamPort.ts:149
Deserializes the provided JSON data into a stream port value. Delegates to StreamPortPlugin.deserializeValue.
Parameters
data
unknown
The JSON data representing the port value.
Returns
StreamPortValue<Item>
The deserialized port value.
Implementation of
Overrides
getConfig()
getConfig():
StreamPortConfig
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():
StreamPortValue<Item> |undefined
Defined in: packages/chaingraph-types/src/port/instances/StreamPort.ts:72
Retrieves the default value from the configuration. If a defaultValue is provided in config, it is returned; otherwise, undefined is returned.
Returns
StreamPortValue<Item> | undefined
The default StreamPortValue, if specified.
Implementation of
Overrides
getValue()
getValue():
StreamPortValue<Item> |undefined
Defined in: packages/chaingraph-types/src/port/instances/StreamPort.ts:81
Optionally override getValue() so that the returned type is StreamPortValue.
Returns
StreamPortValue<Item> | undefined
The current stream port value.
Implementation of
Overrides
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/StreamPort.ts:116
Serializes the stream port configuration to a JSON-compatible object. Delegates serialization to StreamPortPlugin.serializeConfig.
Parameters
config
StreamPortConfig<Item>
The stream port configuration.
Returns
unknown
The serialized configuration.
Implementation of
Overrides
serializeValue()
serializeValue(
value):unknown
Defined in: packages/chaingraph-types/src/port/instances/StreamPort.ts:127
Serializes the stream port value into a JSON-compatible object. Delegates serialization to StreamPortPlugin.serializeValue.
Parameters
value
StreamPortValue<Item>
The stream 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.
StreamPortValue<Item> | undefined
Returns
void
Implementation of
Inherited from
unwrap()
unwrap():
IPort<StreamPortConfig<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<StreamPortConfig<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/StreamPort.ts:104
Validates the stream port configuration. Delegates to StreamPortPlugin.validateConfig.
Parameters
config
StreamPortConfig<Item>
The stream port configuration.
Returns
boolean
True if valid; otherwise false.
Implementation of
Overrides
validateValue()
validateValue(
value):boolean
Defined in: packages/chaingraph-types/src/port/instances/StreamPort.ts:92
Validates the provided stream port value against the configuration. Delegates validation logic to StreamPortPlugin.validateValue.
Parameters
value
StreamPortValue<Item>
The stream port value to validate.
Returns
boolean
True if valid; otherwise false.