Synclets logoSynclets

DataConnectorImplementations

The DataConnectorImplementations type lists the async functions required to read and write Atoms.

{
  connect?: (syncChangedAtoms: (...address: AtomAddress<Depth>[]) => Promise<void>) => Promise<void>;
  disconnect?: () => Promise<void>;
  readAtom: (address: AtomAddress<Depth>) => Promise<Atom | undefined>;
  writeAtom: (address: AtomAddress<Depth>, atom: Atom) => Promise<void>;
  removeAtom: (address: AtomAddress<Depth>) => Promise<void>;
  readChildIds: (address: AnyParentAddress<Depth>) => Promise<string[]>;
}
TypeDescription
connect?(syncChangedAtoms: (...address: AtomAddress<Depth>[]) => Promise<void>) => Promise<void>

The connect callback is invoked when the Synclet starts. It receives a syncChangedAtoms function that should be called whenever external changes occur in the underlying storage (e.g., from another process). This enables the Synclet to detect and propagate changes from outside sources. The callback can also perform one-time initialization like creating database tables or opening file handles.

disconnect?() => Promise<void>

The disconnect callback is invoked when the Synclet is destroyed. It should clean up any resources allocated during connect, such as closing file handles, database connections, or removing event listeners. The connector will not be used after this callback returns.

readAtom(address: AtomAddress<Depth>) => Promise<Atom | undefined>

The readAtom callback must retrieve the Atom value stored at the specified address. Return the Atom if it exists, or undefined if the address contains no value. This callback is called frequently during sync operations, so efficient implementations are important for performance.

writeAtom(address: AtomAddress<Depth>, atom: Atom) => Promise<void>

The writeAtom callback must persist the provided Atom value at the specified address, overwriting any existing value. The callback should handle all Atom types (string, number, boolean, null, and the UNDEFINED constant). Ensure the write is atomic to prevent partial updates during concurrent access.

removeAtom(address: AtomAddress<Depth>) => Promise<void>

The removeAtom callback must delete the Atom value at the specified address. If no value exists at the address, the operation should succeed silently without error. Ensure the deletion is atomic to prevent partial updates during concurrent access.

readChildIds(address: AnyParentAddress<Depth>) => Promise<string[]>

The readChildIds callback must return an array of child ID strings that exist under the specified parent address. For Atoms addresses, this returns the IDs of Atoms in the parent collection. For deeper tree nodes, this returns the IDs of child branches. Return an empty array if the address has no children.

Since

v0.0.0