proposit-core
    Preparing search index...

    Function mergeChangesets

    • Merges two changesets into one, deduplicating entities by id within each bucket (added/modified/removed) with last-write-wins semantics.

      Use this when a single logical operation requires multiple engine calls that each produce a changeset. For example, creating a conclusion premise requires both createPremiseWithId and setConclusionPremise, each returning a changeset — mergeChangesets combines them into one changeset suitable for a single persistence call.

      Type Parameters

      • TExpr extends TCorePropositionalExpression = TCorePropositionalExpression
      • TVar extends
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                claimId: string;
                claimVersion: number;
                id: string;
                symbol: string;
            }
            | {
                argumentId: string;
                argumentVersion: number;
                boundArgumentId: string;
                boundArgumentVersion: number;
                boundPremiseId: string;
                checksum: string;
                id: string;
                symbol: string;
            } =
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                claimId: string;
                claimVersion: number;
                id: string;
                symbol: string;
            }
            | {
                argumentId: string;
                argumentVersion: number;
                boundArgumentId: string;
                boundArgumentVersion: number;
                boundPremiseId: string;
                checksum: string;
                id: string;
                symbol: string;
            }
      • TPremise extends
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                combinedChecksum: string;
                descendantChecksum: string
                | null;
                id: string;
                type: "freeform";
            }
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                combinedChecksum: string;
                derivedClaimId: string;
                descendantChecksum: string
                | null;
                id: string;
                type: "derivation";
            } =
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                combinedChecksum: string;
                descendantChecksum: string
                | null;
                id: string;
                type: "freeform";
            }
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                combinedChecksum: string;
                derivedClaimId: string;
                descendantChecksum: string
                | null;
                id: string;
                type: "derivation";
            }
      • TArg extends {
            checksum: string;
            combinedChecksum: string;
            descendantChecksum: string | null;
            id: string;
            version: number;
        } = {
            checksum: string;
            combinedChecksum: string;
            descendantChecksum: string | null;
            id: string;
            version: number;
        }

      Parameters

      Returns TCoreChangeset<TExpr, TVar, TPremise, TArg>

      A merged changeset. Entity categories that are empty after merge are omitted from the result.

      If any entity ID appears in more than one bucket (added/modified/removed) within the same category after merge. This indicates a logic error in the caller.

      const { changes: createChanges } = engine.createPremiseWithId(premiseId, data)
      const { changes: roleChanges } = engine.setConclusionPremise(premiseId)
      const combined = mergeChangesets(createChanges, roleChanges)
      await persistChangeset(db, combined)