Sync / foldkit-sync/journal

serverJournal

function · packages/sync/src/serverJournal.ts:393

function serverJournal<
  AppModel,
  Fields extends Schema.Struct.Fields,
  Message,
  Ms extends readonly unknown[],
  ContractPrincipal,
  Authorized extends boolean,
  SMs extends readonly unknown[],
  Principal,
  const Reactions extends ReadonlyArray<
    Reaction<
      DefinedSync<
        AppModel,
        Fields,
        Message,
        Ms,
        ContractPrincipal,
        Authorized,
        SMs
      >,
      any
    >
  > = [],
>(
  options: ServerJournalOptions<
    DefinedSync<
      AppModel,
      Fields,
      Message,
      Ms,
      ContractPrincipal,
      Authorized,
      SMs
    >,
    Principal,
    Schema.Struct.Type<Fields>,
    Reactions
  >,
): Effect.Effect<
  ServerJournal<ServerMsgOf<SMs>, Requires<Reactions>>,
  JournalError
>

The server's side of one document: appendAsServer, and the declared reactions with what runs them. Registers each reaction's cursor at the journal's current cursor before it answers, so make it before the journal serves its first exchange: a reaction sees every commit made after this. Throws for a reaction of another contract, two of one name, or a cycle.