SyncletImplementations
The SyncletImplementations type collects optional async callback functions that customize Synclet behavior at key lifecycle and operational points.
{
onStart?: () => Promise<void>;
onStop?: () => Promise<void>;
onSync?: (address: AnyAddress<Depth>) => Promise<void>;
onSendMessage?: (message: Message, to?: string) => Promise<void>;
onReceiveMessage?: (message: Message, from: string) => Promise<void>;
onSetAtom?: (address: AtomAddress<Depth>) => Promise<void>;
getSendContext?: (receivedContext?: Context) => Promise<Context>;
canReceiveMessage?: (context: Context) => Promise<boolean>;
canReadAtom?: (address: AtomAddress<Depth>, context: Context) => Promise<boolean>;
canWriteAtom?: (address: AtomAddress<Depth>, atom: Atom, context: Context) => Promise<boolean>;
canRemoveAtom?: (address: AtomAddress<Depth>, context: Context) => Promise<boolean>;
filterChildIds?: (address: AnyParentAddress<Depth>, childIds: string[], context: Context) => Promise<string[]>;
getNow?: () => number;
}| Type | Description | |
|---|---|---|
onStart? | () => Promise<void> | The onStart function is called when the synclet starts. |
onStop? | () => Promise<void> | The onStop function is called when the synclet stops. |
onSync? | (address: AnyAddress<Depth>) => Promise<void> | The onSync function is called before syncing the provided address. |
onSendMessage? | (message: Message, to?: string) => Promise<void> | The onSendMessage function is called when a message is sent. |
onReceiveMessage? | (message: Message, from: string) => Promise<void> | The onReceiveMessage function is called when a message is received. |
onSetAtom? | (address: AtomAddress<Depth>) => Promise<void> | The onSetAtom function is called after a local |
getSendContext? | (receivedContext?: Context) => Promise<Context> | The getSendContext callback can be implemented to generate or augment the |
canReceiveMessage? | (context: Context) => Promise<boolean> | The canReceiveMessage callback can be implemented to filter incoming messages based on their |
canReadAtom? | (address: AtomAddress<Depth>, context: Context) => Promise<boolean> | The canReadAtom callback can be implemented to control read access to individual |
canWriteAtom? | (address: AtomAddress<Depth>, atom: Atom, context: Context) => Promise<boolean> | The canWriteAtom callback can be implemented to control write access to individual |
canRemoveAtom? | (address: AtomAddress<Depth>, context: Context) => Promise<boolean> | The canRemoveAtom callback can be implemented to control delete access to individual |
filterChildIds? | (address: AnyParentAddress<Depth>, childIds: string[], context: Context) => Promise<string[]> | The filterChildIds callback can be implemented to selectively hide child IDs from enumeration based on the parent address and request |
getNow? | () => number | The getNow callback can be implemented to provide a custom clock value for timestamp generation. This is primarily useful for deterministic testing where you need reproducible timestamps. If not provided, Date.now() is used. |
These callbacks allow you to inject custom logic for lifecycle events (onStart, onStop), synchronization hooks (onSync, onSetAtom), message handling (onSendMessage, onReceiveMessage, getSendContext), and fine-grained access control (canReceiveMessage, canReadAtom, canWriteAtom, canRemoveAtom, filterChildIds).
All callbacks are optional. The Synclet will use sensible defaults when callbacks are not provided.
Since
v0.0.0