API reference › @evolu/common › local‑first/Protocol › createProtocolUploadFromCrdtMessages

function createProtocolUploadFromCrdtMessages(
  deps: RandomBytesDep & XChaCha20Poly1305Dep,
): (
  owner: Owner,
  messages: readonly [CrdtMessage, CrdtMessage],
  maxSize?: number &
    Brand<"NonNaN"> &
    Brand<"Finite"> &
    Brand<"Int"> &
    Brand<"Between1000000-100000000">,
) => ProtocolUpload;

Defined in: packages/common/src/local-first/Protocol.ts:656

Creates the ProtocolUpload of CRDT messages.

The message holds the leading CRDT messages that fit maxSize, by default defaultProtocolMessageMaxSize, measured exactly. When one does not fit, it and the rest are left out, and the message ends with a range that makes the non-initiator answer with ranges. Sync then sends them in later rounds, even over unidirectional and stateless transports, because every change within maxMutationSize fits an empty message. isComplete tells whether the message holds every CRDT message, so its sender knows whether only its later rounds send the rest.

Example

import {
  assertSame,
  createId,
  createXChaCha20Poly1305,
  testCreateDeps,
} from "@evolu/common";
import {
  createProtocolUploadFromCrdtMessages,
  testAppOwner,
  testCreateCrdtMessage,
} from "@evolu/common/local-first";

const deps = {
  ...testCreateDeps(),
  xChaCha20Poly1305: createXChaCha20Poly1305(),
};
const upload = createProtocolUploadFromCrdtMessages(deps)(testAppOwner, [
  testCreateCrdtMessage(createId(deps), 1, "Ada"),
]);
assertSame(upload.isComplete, true);