ChainGraph API Documentation / @badaitech/chaingraph-nodes / TokenBalanceFormatter
Class: TokenBalanceFormatter
Defined in: packages/chaingraph-nodes/src/nodes/converters/token-balance-formatter.node.ts:90
Extends
Constructors
Constructor
new TokenBalanceFormatter(
id,_metadata?):TokenBalanceFormatter
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:32
Parameters
id
string
_metadata?
Returns
TokenBalanceFormatter
Inherited from
Properties
_id
protectedreadonly_id:string
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:20
Inherited from
_metadata
protected_metadata:NodeMetadata
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:21
Inherited from
_status
protected_status:NodeStatus
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:22
Inherited from
rawBalances
rawBalances:
RawBalanceInput[] =[]
Defined in: packages/chaingraph-nodes/src/nodes/converters/token-balance-formatter.node.ts:101
tokenBalances
tokenBalances:
TokenBalance[] =[]
Defined in: packages/chaingraph-nodes/src/nodes/converters/token-balance-formatter.node.ts:129
tokens
tokens:
Token[] =[]
Defined in: packages/chaingraph-nodes/src/nodes/converters/token-balance-formatter.node.ts:118
Accessors
id
Get Signature
get id():
string
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:46
Unique identifier of the node
Returns
string
Inherited from
metadata
Get Signature
get metadata():
NodeMetadata
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:47
Metadata describing the node
Returns
Inherited from
ports
Get Signature
get ports():
Map<string,IPort<IPortConfig>>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:65
Get all ports of the node
Returns
Map<string, IPort<IPortConfig>>
Inherited from
status
Get Signature
get status():
NodeStatus
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:48
Current execution status of the node
Returns
Inherited from
storage
Get Signature
get storage():
UnifiedPortStorage
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:52
Access to unified storage (for advanced usage and debugging)
Returns
UnifiedPortStorage
Inherited from
Methods
addObjectProperties()
addObjectProperties(
objectPort,properties,useParentUI?):Promise<IPort<IPortConfig>[]>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:203
Parameters
objectPort
properties
useParentUI?
boolean
Returns
Promise<IPort<IPortConfig>[]>
Deprecated
Use AddFieldsOperation instead
Inherited from
addObjectProperty()
addObjectProperty(
objectPort,key,portConfig,useParentUI?):Promise<IPort<IPortConfig>>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:199
Add a new property to an object port
Parameters
objectPort
The parent object port
key
string
The property key
portConfig
The port configuration for the new property
useParentUI?
boolean
indicates whether we want to use the parents UI
Returns
Promise<IPort<IPortConfig>>
Inherited from
appendArrayItem()
appendArrayItem(
arrayPort,value):Promise<number>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:217
Add an item to an array port
Parameters
arrayPort
The array port
value
any
The value to append
Returns
Promise<number>
The index of the new item
Inherited from
bindPortBindings()
bindPortBindings():
void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:172
Rebind all port properties to storage
Returns
void
Inherited from
bindPortToNodeProperty()
bindPortToNodeProperty(
targetObject,port):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:168
Bind a port to a node property
Parameters
targetObject
any
port
Returns
void
Deprecated
Use bindProperty instead
Inherited from
BaseNode.bindPortToNodeProperty
clone()
clone():
INodeComposite
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:250
Create a deep clone of the node
Returns
INodeComposite
A new node instance with the same state
Inherited from
cloneWithNewId()
cloneWithNewId():
this
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:258
Create a deep clone of the node with new unique identifiers This method recursively clones all ports with new IDs while preserving the port hierarchy, values, and metadata
Returns
this
A result object containing the cloned node and ID mappings
Inherited from
commitBatchUpdate()
commitBatchUpdate(
eventContext?):Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:163
Commit all collected port updates and emit events
Parameters
eventContext?
EventContext
Optional context to be added to all emitted events
Returns
Promise<void>
Inherited from
copyObjectSchemaTo()
copyObjectSchemaTo(
sourceNode,sourceObjectPort,targetObjectPort,useParentUI?):Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:101
Copy the schema (properties) from a source ObjectPort to a target ObjectPort
Parameters
sourceNode
INodeComposite
The node containing the source port
sourceObjectPort
The source ObjectPort to copy from
ObjectPort<IObjectSchema<Record<string, IPortConfig>>> | AnyPort
targetObjectPort
The target ObjectPort to copy to
ObjectPort<IObjectSchema<Record<string, IPortConfig>>> | AnyPort
useParentUI?
boolean
Whether to use parent UI settings for the new properties
Returns
Promise<void>
Promise that resolves when copying is complete
Inherited from
createEvent()
createEvent<
T>(type,data):EventReturnType<T>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:269
Type Parameters
T
T extends NodeEventType
Parameters
type
T
data
Returns
Inherited from
deserialize()
deserialize(
data):INodeComposite
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:249
Deserialize from JSON data
Parameters
data
unknown
The serialized data
Returns
INodeComposite
The deserialized instance
Inherited from
dispose()
dispose():
Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:64
Release resources and prepare the node for garbage collection
Returns
Promise<void>
Inherited from
emit()
emit<
T>(event):Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:127
Emit an event to all subscribers
Type Parameters
T
T extends NodeEvent
Parameters
event
T
The event to emit
Returns
Promise<void>
Inherited from
execute()
execute(
context):Promise<NodeExecutionResult>
Defined in: packages/chaingraph-nodes/src/nodes/converters/token-balance-formatter.node.ts:131
Abstract method that must be implemented by concrete nodes We'll wrap this with logic for default port handling
Parameters
context
Returns
Promise<NodeExecutionResult>
Overrides
executeOperation()
executeOperation<
P,R>(operation):Promise<OperationResult<R>>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:153
Execute an operation on this node
This is the new primary API for node manipulation. Operations provide:
- Type-safe parameters and results
- Automatic event emission
- Traceability (operation IDs, context)
- Validation before execution
Type Parameters
P
P
R
R
Parameters
operation
IOperation<P, R>
Operation to execute
Returns
Promise<OperationResult<R>>
Operation result with success/error and events
Example
const op = new SetValueOperation(
{ portPath: 'prompt', value: 'Hello' },
{ userId: 'user123', source: 'ui' }
)
const result = await node.executeOperation(op)
if (result.success) {
console.log('Value set:', result.data.newValue)
}Inherited from
executeWithSystemPorts()
executeWithSystemPorts(
context):Promise<NodeExecutionResult>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:45
Runtime execute that wraps the abstract execute to handle system ports. This is an internal method used by the execution engine.
Parameters
context
The execution context
Returns
Promise<NodeExecutionResult>
The execution result
Inherited from
BaseNode.executeWithSystemPorts
findPort()
findPort(
predicate):IPort<IPortConfig> |undefined
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:102
Find a port by a predicate function
Parameters
predicate
(port) => boolean
Predicate function to match the port
Returns
IPort<IPortConfig> | undefined
The port if found, undefined otherwise
Inherited from
findPortByKey()
findPortByKey(
key):IPort<IPortConfig> |undefined
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:126
Find a port by its key
Parameters
key
string
The key of the port to find
Returns
IPort<IPortConfig> | undefined
The port if found, undefined otherwise
Inherited from
findPortByPath()
findPortByPath(
path):IPort<IPortConfig> |undefined
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:74
Find a port by following a path of property names from the node root
Parameters
path
string[]
Path segments (property names or array indices)
Returns
IPort<IPortConfig> | undefined
The port if found, undefined otherwise
Inherited from
findPorts()
findPorts(
predicate):IPort<IPortConfig>[]
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:103
Find all ports by a predicate function
Parameters
predicate
(port) => boolean
Predicate function to match the port
Returns
IPort<IPortConfig>[]
Array of ports that match the predicate
Inherited from
getChildPorts()
getChildPorts(
parentPort):IPort<IPortConfig>[]
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:75
Get all direct child ports of a parent port
Parameters
parentPort
The parent port
Returns
IPort<IPortConfig>[]
Array of child ports
Inherited from
getDefaultPorts()
getDefaultPorts():
IPort<IPortConfig>[]
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:259
Get all default ports based on the node's flow configuration
Returns
IPort<IPortConfig>[]
Inherited from
getErrorMessagePort()
getErrorMessagePort():
IPort<IPortConfig> |undefined
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:265
Get error message port
Returns
IPort<IPortConfig> | undefined
Inherited from
getErrorPort()
getErrorPort():
IPort<IPortConfig> |undefined
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:264
Get error port
Returns
IPort<IPortConfig> | undefined
Inherited from
getFlowInPort()
getFlowInPort():
IPort<IPortConfig> |undefined
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:262
Get flow in port
Returns
IPort<IPortConfig> | undefined
Inherited from
getFlowOutPort()
getFlowOutPort():
IPort<IPortConfig> |undefined
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:263
Get flow out port
Returns
IPort<IPortConfig> | undefined
Inherited from
getInputs()
getInputs():
IPort<IPortConfig>[]
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:68
Get all input ports
Returns
IPort<IPortConfig>[]
Array of input ports
Inherited from
getNestedPorts()
getNestedPorts(
parentPort):IPort<IPortConfig>[]
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:76
Get all nested ports of a parent port, including its children and their children recursively
Parameters
parentPort
The parent port
Returns
IPort<IPortConfig>[]
Array of all nested ports
Inherited from
getOutputs()
getOutputs():
IPort<IPortConfig>[]
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:69
Get all output ports
Returns
IPort<IPortConfig>[]
Array of output ports
Inherited from
getParentshipChain()
getParentshipChain(
port):IPort<IPortConfig>[]
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:77
Get the full parentship chain of a port, from the port up to the root
Parameters
port
The port to get the chain for
Returns
IPort<IPortConfig>[]
Array of ports in the chain, starting from the given port up to the root
Inherited from
getPort()
getPort(
portId):IPort<IPortConfig> |undefined
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:66
Get a port by its ID
Parameters
portId
string
The port ID
Returns
IPort<IPortConfig> | undefined
The port if found, undefined otherwise
Inherited from
getPortByPath()
getPortByPath(
pathString):IPort<IPortConfig> |undefined
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:104
Get a port by its path string (e.g., "port.subport.array[0].field")
Parameters
pathString
string
The path string to the port
Returns
IPort<IPortConfig> | undefined
The port if found, undefined otherwise
Inherited from
getPortPath()
getPortPath(
portId):string|undefined
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:105
Get the full path string for a given port
Parameters
portId
string
The ID of the port
Returns
string | undefined
The path string (e.g., "port.subport.field") or undefined if port not found
Inherited from
getPortPathForPort()
getPortPathForPort(
port):string
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:106
Get the full path string for a given port instance
Parameters
port
The port instance
Returns
string
The path string (e.g., "port.subport.field")
Inherited from
getRootPort()
getRootPort(
port):IPort
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:78
Get the root port of a given port by traversing up the parentship chain
Parameters
port
The port to find the root for
Returns
The root port
Inherited from
getSystemPortConfigs()
getSystemPortConfigs():
IPortConfig[]
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:260
Get system port configurations
Returns
Inherited from
getUI()
getUI():
NodeUIMetadata|undefined
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:236
Get the node's UI metadata
Returns
NodeUIMetadata | undefined
Node UI metadata or undefined if not set
Inherited from
getVersion()
getVersion():
number
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:242
Get the current version number
Returns
number
The current version
Inherited from
hasPort()
hasPort(
portId):boolean
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:67
Check if a port with the given ID exists
Parameters
portId
string
The port ID
Returns
boolean
True if the port exists, false otherwise
Inherited from
incrementVersion()
incrementVersion():
number
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:241
Increment the node's version number
Returns
number
The new version number
Inherited from
initialize()
initialize(
portsConfig?):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:268
Initialize the node with port configurations
Parameters
portsConfig?
Map<string, IPortConfig>
Optional map of port configurations
Returns
void
Inherited from
initializePortsFromConfigs()
initializePortsFromConfigs(
portsConfigs,syncValuesToStorage?):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:176
Initialize ports from configs
Parameters
portsConfigs
Map<string, IPortConfig>
syncValuesToStorage?
boolean
Returns
void
Inherited from
BaseNode.initializePortsFromConfigs
isDefaultPort()
isDefaultPort(
portId):boolean
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:261
Check if a port is a system default port
Parameters
portId
string
Returns
boolean
Inherited from
on()
on<
T>(eventType,handler): () =>void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:107
Subscribe to node events of a specific type
Type Parameters
T
T extends NodeEvent
Parameters
eventType
T["type"]
The type of event to subscribe to
handler
(event) => void | Promise<void>
The event handler function
Returns
A function to unsubscribe
():
void
Returns
void
Inherited from
onAll()
onAll(
handler): () =>void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:108
Subscribe to all node events
Parameters
handler
(event) => void | Promise<void>
The event handler function
Returns
A function to unsubscribe
():
void
Returns
void
Inherited from
onEvent()
onEvent(
_event):Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:115
Event handler for the node This is the key method that derived classes can override to handle events
Parameters
_event
The event to handle
Returns
Promise<void>
Inherited from
processPortConfig()
processPortConfig(
config,context):IPortConfig
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:230
Parameters
config
context
nodeId
string
parentPortConfig
IPortConfig | null
propertyKey
string
propertyValue
any
Returns
Deprecated
Internal method - should not be called externally
Inherited from
removeArrayItem()
removeArrayItem(
arrayPort,index):Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:222
Parameters
arrayPort
index
number
Returns
Promise<void>
Deprecated
Use RemoveItemOperation instead
Example
await node.executeOperation(new RemoveItemOperation({ arrayPath, index }))Inherited from
removeArrayItems()
removeArrayItems(
arrayPort,indices):Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:226
Parameters
arrayPort
indices
number[]
Returns
Promise<void>
Deprecated
Use multiple RemoveItemOperation calls or batch operation
Inherited from
removeObjectProperties()
removeObjectProperties(
objectPort,keys):Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:207
Parameters
objectPort
keys
string[]
Returns
Promise<void>
Deprecated
Use RemoveFieldsOperation instead
Inherited from
BaseNode.removeObjectProperties
removeObjectProperty()
removeObjectProperty(
objectPort,key):Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:212
Parameters
objectPort
key
string
Returns
Promise<void>
Deprecated
Use RemoveFieldOperation instead
Example
await node.executeOperation(new RemoveFieldOperation({ parentPath, key }))Inherited from
removePort()
removePort(
portId):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:72
Remove a port by its ID
Parameters
portId
string
The ID of the port to remove
Returns
void
Inherited from
removePorts()
removePorts(
portIds):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:73
Remove multiple ports by their IDs
Parameters
portIds
string[]
Array of port IDs to remove
Returns
void
Inherited from
replaceStorage()
replaceStorage(
newStorage):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:59
Internal
Replace the unified storage with a new instance Used during cloning to set up the cloned node's storage
Parameters
newStorage
UnifiedPortStorage
Returns
void
Inherited from
reset()
reset():
Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:63
Reset the node to its initial state
Returns
Promise<void>
Inherited from
serialize()
serialize():
unknown
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:248
Serialize the node to a JSON-compatible format
Returns
unknown
The serialized node
Inherited from
setDimensions()
setDimensions(
dimensions,emitEvent?):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:239
Update the node's dimensions
Parameters
dimensions
New dimensions
emitEvent?
boolean
Whether to emit a dimensions change event
Returns
void
Inherited from
setMetadata()
setMetadata(
metadata):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:60
Set the node metadata
Parameters
metadata
New metadata
Returns
void
Inherited from
setNodeParent()
setNodeParent(
position,parentNodeId?,emitEvent?):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:240
Update the node's parent and position
Parameters
position
New position coordinates
parentNodeId?
string
ID of the parent node or undefined to remove parent
emitEvent?
boolean
Whether to emit a parent change event
Returns
void
Inherited from
setPort()
setPort(
port):IPort
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:70
Add or update a port
Parameters
port
The port to set
Returns
The added/updated port
Inherited from
setPorts()
setPorts(
ports):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:71
Set all ports at once
Parameters
ports
Map<string, IPort<IPortConfig>>
Map of ports to set
Returns
void
Inherited from
setPosition()
setPosition(
position,emitEvent?):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:238
Update the node's position
Parameters
position
New position coordinates
emitEvent?
boolean
Whether to emit a position change event
Returns
void
Inherited from
setStatus()
setStatus(
status,emitEvent?):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:61
Set the node status
Parameters
status
New status
emitEvent?
boolean
Whether to emit a status change event
Returns
void
Inherited from
setUI()
setUI(
ui,emitEvent?):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:237
Update the node's UI metadata
Parameters
ui
New UI metadata
emitEvent?
boolean
Whether to emit a UI change event
Returns
void
Inherited from
setVersion()
setVersion(
version):void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:247
Set the node version
Parameters
version
number
The new version
Returns
void
Inherited from
shouldExecute()
shouldExecute(
context):boolean
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:266
Determine if node should execute based on flow ports
Parameters
context
Returns
boolean
Inherited from
startBatchUpdate()
startBatchUpdate():
void
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:158
Start collecting port updates without emitting events immediately Used for batch operations where multiple ports are updated
Returns
void
Inherited from
updateArrayItemConfig()
updateArrayItemConfig(
arrayPort):Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:216
Parameters
arrayPort
Returns
Promise<void>
Deprecated
Array item config updates should be handled via UpdateConfigOperation
Inherited from
BaseNode.updateArrayItemConfig
updatePort()
updatePort(
port,eventContext?):Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:85
Update a port and emit a port update event This is a critical method that triggers port-related events
Parameters
port
The port to update
eventContext?
EventContext
Optional event context for additional metadata
Returns
Promise<void>
Inherited from
updatePorts()
updatePorts(
ports,eventContext?):Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:92
Update multiple ports at once This is useful for batch updates
Parameters
ports
IPort<IPortConfig>[]
Array of ports to update
eventContext?
EventContext
Optional event context for additional metadata
Returns
Promise<void>
Inherited from
updatePortsAfterExecution()
updatePortsAfterExecution(
success,errorMessage?):Promise<void>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:267
Update flow ports after execution
Parameters
success
boolean
errorMessage?
string
Returns
Promise<void>
Inherited from
BaseNode.updatePortsAfterExecution
validate()
validate():
Promise<NodeValidationResult>
Defined in: packages/chaingraph-types/dist/node/base-node-compositional.d.ts:62
Validate the node configuration
Returns
Promise<NodeValidationResult>
A promise resolving to the validation result