Sync / foldkit-sync/journal

ServerJournal

interface · packages/sync/src/serverJournal.ts:235

interface ServerJournal<ServerOnly, R> {
  readonly appendAsServer: (
    message: ServerOnly,
    options: {
      readonly key: string
    },
  ) => Effect.Effect<
    AppendResult<Operation>,
    AppendError | ServerKeyReusedError
  >
  readonly react: Effect.Effect<Option.Option<Duration.Duration>, never, R>
  readonly follow: Effect.Effect<never, never, R>
  readonly settledThrough: Effect.Effect<Cursor, JournalError>
  readonly parked: Effect.Effect<ReadonlyArray<Parked>, JournalError>
  readonly retry: (parked: Parked) => Effect.Effect<void, unknown, R>
  readonly dismiss: (parked: Parked) => Effect.Effect<void, JournalError>
}

Members

ServerJournal.appendAsServer

property · packages/sync/src/serverJournal.ts:243

readonly appendAsServer: (
  message: ServerOnly,
  options: {
    readonly key: string
  },
) => Effect.Effect<
  AppendResult<Operation>,
  AppendError | ServerKeyReusedError
>

Appends a server-only Message as the server. key names the fact (a webhook event's id, absorbed/<through>): a repeat with the same key and Message is answered from history, and one with another Message fails with ServerKeyReusedError. A key is a non-empty string of at most 200 characters; another is an InvalidOperationError.

ServerJournal.react

property · packages/sync/src/serverJournal.ts:255

readonly react: Effect.Effect<Option.Option<Duration.Duration>, never, R>

Runs every reaction from its stored cursor, a page at a time. Never fails: a failed run is reported, and the answer is how long to wait before running again; none when every reaction has caught up. Safe to call at any time, from anywhere in this process: passes of one serverJournal run one at a time. Two instances over one store (two isolates over one D1) do not wait for each other.

ServerJournal.follow

property · packages/sync/src/serverJournal.ts:261

readonly follow: Effect.Effect<never, never, R>

Runs react now, after every commit to the document this journal instance hears of, and after the delay react answers, until interrupted: a long-lived process's loop. Fork it.

ServerJournal.settledThrough

property · packages/sync/src/serverJournal.ts:263

readonly settledThrough: Effect.Effect<Cursor, JournalError>

The lowest cursor of the declared reactions: compact no further than this.

ServerJournal.parked

property · packages/sync/src/serverJournal.ts:265

readonly parked: Effect.Effect<ReadonlyArray<Parked>, JournalError>

The runs set aside, for a person to look at.

ServerJournal.retry

property · packages/sync/src/serverJournal.ts:272

readonly retry: (parked: Parked) => Effect.Effect<void, unknown, R>

Runs a parked run again, out of order; it leaves the list when it succeeds, and stays, failing, when it does not. A recorded answer is reused, so a refused append retried after the rule changed makes no second external call. A stale one fails with StaleParkedRunError.

ServerJournal.dismiss

property · packages/sync/src/serverJournal.ts:274

readonly dismiss: (parked: Parked) => Effect.Effect<void, JournalError>

Forgets a parked run: its reaction never happens.