ChainGraph API Documentation / @badaitech/chaingraph-types / ObjectPort
Class: ObjectPort<S>
Defined in: packages/chaingraph-types/src/port/instances/ObjectPort.ts:79
Concrete implementation of an Object Port.
This class extends BasePort using ObjectPortConfig<S> and ObjectPortValue<S>. It leverages the ObjectPortPlugin to handle default value resolution, validation, serialization, and deserialization.
The port is generic over S (which extends ObjectSchema) so that the types of nested properties can be inferred. When using the helper functions below, your IDE will provide full autocompletion for the nested values.
Example usage:
// Using the helper functions to build a schema and config: const userSchema = createObjectSchema({ name: { type: 'string', minLength: 2 }, age: { type: 'number', min: 21 }, address: { type: 'object', schema: createObjectSchema({ street: { type: 'string' }, city: { type: 'string' }, state: { type: 'string' }, }), }, })
const userConfig = createObjectPortConfig({ type: 'object', schema: userSchema, defaultValue: { type: 'object', value: { name: { type: 'string', value: 'Alice' }, age: { type: 'number', value: 30 }, address: { type: 'object', value: { street: { type: 'string', value: '123 Main St' }, city: { type: 'string', value: 'Springfield' }, state: { type: 'string', value: 'IL' }, }, }, }, }, })
const userPort = new ObjectPort(userConfig) // The IDE now knows that userPort.getValue() returns an object // whose "value" property has both "name" and "age" with proper types. console.log(userPort.getValue()?.value.name.value) // 'Alice' console.log(userPort.getValue()?.value.address.value.state.value) // 'IL'
Extends
Type Parameters
S
S extends IObjectSchema = IObjectSchema
The object schema type (extending ObjectSchema) used in the configuration.
Implements
Constructors
Constructor
new ObjectPort<
S>(config):ObjectPort<S>
Defined in: packages/chaingraph-types/src/port/instances/ObjectPort.ts:82
Parameters
config
Returns
ObjectPort<S>
Overrides
Properties
config
protectedconfig:ObjectPortConfig
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:16
Inherited from
value?
protectedoptionalvalue:ObjectPortValue<S>
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
addField()
addField(
field,config):void
Defined in: packages/chaingraph-types/src/port/instances/ObjectPort.ts:268
Adds a new field to the object schema and updates the default and current values.
Parameters
field
string
config
Returns
void
clone()
clone():
IPort<ObjectPortConfig<S>>
Defined in: packages/chaingraph-types/src/port/base/BasePort.ts:130
Clones the port instance.
Returns
A new port instance with the same configuration and value.
Implementation of
Inherited from
cloneWithNewId()
cloneWithNewId():
IPort<ObjectPortConfig<S>>
Defined in: packages/chaingraph-types/src/port/instances/ObjectPort.ts:328
Clones the port with a new ID. Useful for creating copies of the port with a unique identifier.
Returns
Implementation of
Overrides
deserialize()
deserialize(
data):IPort<ObjectPortConfig<S>>
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
Implementation of
Inherited from
deserializeConfig()
deserializeConfig(
data):ObjectPortConfig<S>
Defined in: packages/chaingraph-types/src/port/instances/ObjectPort.ts:249
Deserializes JSON data into an ObjectPortConfig. Delegates to ObjectPortPlugin.deserializeConfig.
Parameters
data
unknown
The JSON data.
Returns
The deserialized configuration.
Implementation of
Overrides
deserializeValue()
deserializeValue(
data):ObjectPortValue<S>
Defined in: packages/chaingraph-types/src/port/instances/ObjectPort.ts:259
Deserializes JSON data into an ObjectPortValue. Delegates to ObjectPortPlugin.deserializeValue.
Parameters
data
unknown
The JSON data.
Returns
The deserialized port value.
Implementation of
Overrides
getConfig()
getConfig():
ObjectPortConfig
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():
ObjectPortValue<S>
Defined in: packages/chaingraph-types/src/port/instances/ObjectPort.ts:96
Retrieves the default value from the configuration.
Returns
The default ObjectPortValue if specified; otherwise undefined.
Implementation of
Overrides
getValue()
getValue():
ObjectPortValue<S>
Defined in: packages/chaingraph-types/src/port/instances/ObjectPort.ts:104
Optionally, override getValue() to indicate that it returns a fully typed ObjectPortValue.
Returns
The current 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
removeField()
removeField(
field):void
Defined in: packages/chaingraph-types/src/port/instances/ObjectPort.ts:307
Remove a field from the object schema and updates the default and current values.
Parameters
field
string
Returns
void
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/ObjectPort.ts:229
Serializes the object port configuration. Delegates to ObjectPortPlugin.serializeConfig.
Parameters
config
The object port configuration.
Returns
unknown
The serialized configuration.
Implementation of
Overrides
serializeValue()
serializeValue(
value):unknown
Defined in: packages/chaingraph-types/src/port/instances/ObjectPort.ts:239
Serializes the object port value. Delegates to ObjectPortPlugin.serializeValue.
Parameters
value
The object 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/instances/ObjectPort.ts:108
Sets or updates the port value. The value must be validated before being accepted.
Parameters
newValue
The new value to set for the port.
Returns
void
Implementation of
Overrides
unwrap()
unwrap():
IPort<ObjectPortConfig<S>>
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
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/ObjectPort.ts:218
Validates the object port configuration. Delegates to ObjectPortPlugin.validateConfig.
Parameters
config
The object port configuration.
Returns
boolean
True if valid; otherwise false.
Implementation of
Overrides
validateValue()
validateValue(
value):boolean
Defined in: packages/chaingraph-types/src/port/instances/ObjectPort.ts:207
Validates the object port value. Delegates to ObjectPortPlugin.validateValue.
Parameters
value
The object port value.
Returns
boolean
True if valid; otherwise false.