Published foldkit API declarations for port.
./port
@wsagency/wseffect-foldkit · MIT · source · MIT license · WS-AGENCY-NOTICE · THIRD-PARTY-NOTICES
This entry point is published in @wsagency/wseffect-foldkit@0.1.0-rc.1. Import it from the package subpath shown below; the signatures and documentation are read from the installed package declarations.
import * as Wseffect from '@wsagency/wseffect-foldkit/port'
Exported declarations
emit
Emits a value on an outbound Port. The value is encoded against the Port's
Schema and delivered to every host listener subscribed through the
`EmbedHandle`. Compose it into the app's own Commands like any other
Effect:
```ts
const ReportCount = Command.define('ReportCount', {
args: { count: Schema.Number },
messages: [CompletedReportCount],
execute: ({ count }) =>
Port.emit(ports.outbound.countChanged, count).pipe(
Effect.as(CompletedReportCount()),
),
})
```
When the program runs without an embed handle (started with `Runtime.run`),
emitting is a no-op.
emit: <Value, Encoded>(port: Outbound<Value, Encoded>, value: Value) => Effect.Effect<void>
inbound
Declares an inbound Port carrying values of the given Schema. The host
sends values in the Schema's Encoded form; they are validated by decoding
at the boundary, so only well-formed `Value`s ever reach the app.
inbound: <Value, Encoded>(schema: Schema.Codec<Value, Encoded>) => Inbound<Value, Encoded>
Inbound
A typed channel for values flowing from the host into the app. The app
consumes the decoded values as a Subscription source via `Port.stream` or
`Port.subscriptionEntry`; the host pushes encoded values through the
`EmbedHandle` returned by `Runtime.embed`. Create with `Port.inbound`.
export interface Inbound<Value, Encoded> {
readonly [InboundTypeId]: InboundTypeId;
readonly schema: Schema.Codec<Value, Encoded>;
}
InboundTypeId
Type-level brand for inbound Port values.
export type InboundTypeId = typeof InboundTypeId;
InboundTypeId
Type-level brand for inbound Port values.
InboundTypeId: unique symbol
outbound
Declares an outbound Port carrying values of the given Schema. The app
emits `Value`s with `Port.emit`; they are encoded at the boundary, so host
listeners receive the Schema's Encoded form.
outbound: <Value, Encoded>(schema: Schema.Codec<Value, Encoded>) => Outbound<Value, Encoded>
Outbound
A typed channel for values flowing from the app out to the host. The app
emits values with `Port.emit` inside its own Commands; the host listens
through the `EmbedHandle` returned by `Runtime.embed`. Create with
`Port.outbound`.
export interface Outbound<Value, Encoded> {
readonly [OutboundTypeId]: OutboundTypeId;
readonly schema: Schema.Codec<Value, Encoded>;
}
OutboundTypeId
Type-level brand for outbound Port values.
export type OutboundTypeId = typeof OutboundTypeId;
OutboundTypeId
Type-level brand for outbound Port values.
OutboundTypeId: unique symbol
Ports
The Ports record passed to `makeApplication` or `makeElement` via the
`ports` config field. Record keys name the ports; the names appear on the
`EmbedHandle` and in boundary error messages.
export type Ports = Readonly<{
inbound?: Readonly<Record<string, Inbound<any, any>>>;
outbound?: Readonly<Record<string, Outbound<any, any>>>;
}>;
stream
The decoded values arriving on an inbound Port, as a Stream. This is the
atomic primitive for consuming a Port inside a Subscription entry; reach
for `Port.subscriptionEntry` when you want the common always-on form. Values
sent while no Stream for the Port is running are dropped, except for
values sent before the first Stream attaches, which are buffered and
delivered to it in order (so host sends issued right after `Runtime.embed`
are not lost during startup).
stream: <Value, Encoded>(port: Inbound<Value, Encoded>) => Stream.Stream<Value>
subscriptionEntry
Builds a Subscription entry that wraps every decoded value arriving on an
inbound Port into a Message. The entry has no Model dependencies of its own,
though a parent can gate it when lifting the Subscription. Pass it as an
entry value inside `Subscription.make`. For an entry gated by its own Model,
build one from `Port.stream`.
subscriptionEntry: <Value, Encoded, Message>(port: Inbound<Value, Encoded>, toMessage: (value: Value) => Message) => import("../subscription/subscription.js").EntryWithoutKeepAlive<unknown, Message, Record<string, never>, never>