@hyperfrontend/network-protocol/node/channelchannel
Node-side channel factories pre-wired with the Node.js sender and receiver implementations.
Overview
A channel is a named, bidirectional, queue-backed conduit between two endpoints. This entry point composes the runtime-agnostic channel logic from lib/channel with the Node-specific sender (/node/sender) and receiver (/node/receiver), so the resulting createChannel factory only needs a label, send/receive transport callbacks, and a ProtocolProvider.
Usage
import { createChannel, createChannelStore } from '@hyperfrontend/network-protocol/node/channel'
import { createProtocol } from '@hyperfrontend/network-protocol/node/v1'
import { createLogger } from '@hyperfrontend/logging'
const protocolProvider = createProtocol(createLogger({ level: 'info' }), 60)
const channel = createChannel(
'parent-to-worker',
(packet) => process.send?.(packet),
(handler) => process.on('message', handler),
protocolProvider
)
const store = createChannelStore()
store.add(channel)
Notes
createChannelStoreproduces a registry for managing multiple channels by label or UUID, with stop/resume controls applied across all entries.- Validation helpers (
isValidChannel,isValidLabel,isValidReceiver,isValidSender,getFirstInvalidProtocolProperty) are re-exported for upstream guards. - Works over any Node transport (IPC, sockets,
process.send, message ports); the browser counterpart lives at/browser/channel.
API Reference
ƒ Functions
Identifies the first invalid property in a protocol object.
Parameters
| Name | Type | Description |
|---|---|---|
§protocol | unknown | The protocol object to validate |
Returns
"" | unknownThe name of the first invalid protocol property, or an empty string if all properties are valid
Example
Detecting invalid protocol properties
getFirstInvalidProtocolProperty({ send: () => {}, receive: null })
// => 'receive'
getFirstInvalidProtocolProperty(validProtocol)
// => ''Validates whether a channel meets the required structure with send/receive methods and inbound/outbound queues.
Parameters
| Name | Type | Description |
|---|---|---|
§channel | unknown | The channel object to validate |
Returns
booleanTrue if the channel is valid, false otherwise
Example
Validating channel structure
isValidChannel(channel) // => true
isValidChannel({}) // => falseValidates whether a label meets the required criteria of being a non-empty string.
Parameters
| Name | Type | Description |
|---|---|---|
§label | string | The label string to validate |
Returns
booleanTrue if the label is valid, false otherwise
Example
Validating channel labels
isValidLabel('channel-1') // => true
isValidLabel('') // => falseValidates whether a receiver meets the required criteria of being a function.
Parameters
| Name | Type | Description |
|---|---|---|
§receiver | unknown | The receiver to validate |
Returns
booleanTrue if the receiver is valid, false otherwise
Example
Validating receiver functions
isValidReceiver((packet) => handlePacket(packet)) // => true
isValidReceiver('not-a-function') // => falseValidates whether a sender meets the required criteria of being a function.
Parameters
| Name | Type | Description |
|---|---|---|
§sender | unknown | The sender to validate |
Returns
booleanTrue if the sender is valid, false otherwise
Example
Validating sender functions
isValidSender((packet) => transmit(packet)) // => true
isValidSender(null) // => false◈ Interfaces
Secure communication channel with inbound and outbound queues
Properties
Entry in a channel store with metadata
Store for managing multiple channels
Properties
§
readonly create:(label: string, send: SendPacketFn, receive: ReceivePacketFn, protocol: ProtocolProvider<T>) => Channel<T>— Creates and returns a new channel
Protocol instance with encryption, decryption, and message transport
Properties
◆ Types
Factory function for creating channels
type ChannelCreater = (label: string, send: SendPacketFn, receive: ReceivePacketFn, protocol: ProtocolProvider<T>) => Channel<T>Factory function that creates a protocol from send/receive functions
type ProtocolProvider = (send: SendPacketFn, receive: ReceivePacketFn<T>) => Protocol<T>