Expand description
KG change-set op-list model and NDJSON-delta codec. See README.md.
Structs§
- Change
Set - A staged change-set: envelope metadata plus an ordered list of operations.
- Create
Op - Create a new entity or note.
idis minted at stage time and is stable across however long the change-set sits before it is applied. - Delete
Op - Remove an existing entity, note, or edge.
preimagecaptures the full prior record state at stage time — required, not optional, so adeleteop without a captured preimage is unrepresentable.target_idis validated against the embedded preimage’s own record id at deserialize time; a mismatched pair is a parse error, not a silently-accepted op. - Edge
Patch weight, when present, must be finite and in[0.0, 1.0]— the same invariantLinkOp/khive_types::Linkenforce, so a staged edge update can never target a weight the live graph would itself reject.- Edge
Preimage - Prior value of exactly the fields an
UpdateOp’s patch touches; mirrorsEdgePatchthe same wayEntityPreimagemirrorsEntityPatch. A capturedweightvalue, when present, must satisfy the same finite/[0.0, 1.0]invariantEdgePatch/LinkOp/khive_types::Linkenforce on a live edge weight. - Entity
Create Fields - Entity
Patch - Absent field = unchanged.
descriptiondistinguishes explicit-null (clear) from absent (unchanged) viaOption<Option<String>>. - Entity
Preimage - Prior value of exactly the fields an
UpdateOp’s patch touches, captured at stage time. MirrorsEntityPatch’s field shape one-to-one: a populated preimage field means “the patch touches this field, and this was its value before the patch”; an absent preimage field means “the patch leaves this field unchanged.”UpdateOp’s customDeserializeenforces that this field set exactly equalsEntityPatch’s touched-field set. - Envelope
- Change-set-level metadata block. Carries producer identity and model family; individual ops never reference it and stay producer-agnostic.
- LinkOp
- Create a new directed, typed edge.
idis minted at stage time;sourceandtargetmay resolve to another op’s stage-timeidin the same or a different change-set. - MergeOp
- Merge two entities.
preimagecaptures both prior entities and the incident edges the merge will rewire — required, not optional, so amergeop without a captured preimage is unrepresentable.into_id/from_idare validated againstpreimage.into/preimage.from’s own record ids, and every incident edge is validated to actually touch one of the two merge participants, at deserialize time. - Merge
Preimage - Note
Create Fields - Note
Patch - Note
Preimage - Prior value of exactly the fields an
UpdateOp’s patch touches; mirrorsNotePatchthe same wayEntityPreimagemirrorsEntityPatch. A capturedsalience/decay_factorvalue, when present, must satisfy the same finite/range invariantkhive_types::Note::is_validenforces on a live note — a prior value outside that range could never have been real. - Update
Op - Patch an existing entity, note, or edge’s mutable fields, carrying a
stage-time preimage scoped to exactly the fields the patch touches.
preimage’s populated fields must equalpatch’s touched fields — every field the patch sets or explicitly clears to null, and no field the patch leaves unchanged — enforced at deserialize time, the same disciplineDeleteOpandMergeOpapply to their own preimages below. AnUpdateOpwhose preimage and patch disagree on which fields changed is unrepresentable — both the checked constructor andDeserializeenforce the same congruence validation, so there is no construction path that bypasses it.
Enums§
- Change
SetError - Errors from NDJSON-delta encode/decode. No variant touches the filesystem or performs any I/O — every value here is constructed from in-memory input.
- Create
Target - The substrate a
createop targets, with its own field surface. - Delete
Preimage - Op
- One staged mutation. Tagged internally by
"op"so every NDJSON-delta line self-describes its kind without a wrapping envelope. - Update
Patch - Update
Preimage - The field-scoped preimage for one
UpdateOp, tagged by the sametargetdiscriminantUpdatePatchuses so a preimage’s substrate is self-describing on the wire.
Constants§
- CURRENT_
SCHEMA_ VERSION - The NDJSON-delta schema version this crate currently emits and accepts.
Functions§
- from_
ndjson - Decode NDJSON-delta text into a
ChangeSet. Line 1 must parse as the envelope; every subsequent non-empty line must parse as oneOp, in stage order. Rejects an envelope whoseschema_versionthis crate does not recognize, and rejects any line carrying an unknown field (fail-loud, matching thedeny_unknown_fieldsposture the rest of the codebase uses for configuration surfaces). - to_
ndjson - Encode a
ChangeSetas NDJSON-delta: the envelope as line 1, then one line per op in stage order. No filesystem access — returns an in-memoryString; the caller decides what to do with it.