Gno.EffectiveChangeset (Gno v0.1.0)

Copy Markdown View Source

A changeset containing only the minimal changes needed to achieve the desired state.

Unlike Gno.Changeset, an effective changeset is computed by querying the current repository state. Statements that already exist are removed from :add/:update/:replace, and statements that don't exist are removed from :remove.

The :overwrite Field

When :update or :replace actions take effect, existing statements are implicitly removed. The :overwrite field makes these removals explicit:

  • :update overwrites at property level: existing values for the same subject+predicate combinations are captured as overwrites
  • :replace overwrites at subject level: all existing statements about the same subjects are captured as overwrites

This tracking enables reliable inversion via invert/1 - without knowing what was overwritten, the original state cannot be reconstructed.

Summary

Functions

Returns a combined graph of all statements that will be deleted by the changeset.

Creates the empty changeset.

Returns if the given changeset is empty.

Extracts a Gno.EffectiveChangeset from the given keywords and returns it with the remaining unprocessed keywords.

Deserializes an effective changeset from an RDF.Dataset.

Returns a combined graph of all statements that will be inserted by the changeset.

Inverts the changeset.

Limits the changeset to the given scope.

Merge the changes of a list of Gno.EffectiveChangesets into one.

Merge the changes of two Gno.EffectiveChangesets into one.

Creates a new valid changeset.

Creates a new valid changeset.

Serializes the effective changeset to an RDF.Dataset.

Validates the given changeset structure.

Types

t()

@type t() :: %Gno.EffectiveChangeset{
  add: RDF.Graph.t() | nil,
  overwrite: RDF.Graph.t() | nil,
  remove: RDF.Graph.t() | nil,
  replace: RDF.Graph.t() | nil,
  update: RDF.Graph.t() | nil
}

Functions

deletes(effective_changeset)

Returns a combined graph of all statements that will be deleted by the changeset.

empty()

@spec empty() :: t()

Creates the empty changeset.

empty?(effective_changeset)

Returns if the given changeset is empty.

extract(keywords)

Extracts a Gno.EffectiveChangeset from the given keywords and returns it with the remaining unprocessed keywords.

from_rdf(dataset, opts \\ [])

Deserializes an effective changeset from an RDF.Dataset.

inserts(changeset)

Returns a combined graph of all statements that will be inserted by the changeset.

invert(changeset)

Inverts the changeset.

limit(changeset, arg2, resource)

Limits the changeset to the given scope.

The scope can be one of :dataset, or :resource. For :resource the scope can be given as a list of resources.

merge(list)

Merge the changes of a list of Gno.EffectiveChangesets into one.

Warning

This function can be used to collapse the changes of multiple consecutive EffectiveChangesets from a changeset sequence into one and relies on the fact that these consist of complete effective changes incl. overwrites, which might lead to surprising results and limits its general applicability. E.g. a single merged replace does not remove the statements with only matching subjects from the other actions, but only the fully matching statements, since we rely on the fact that a complete EffectiveChangeset includes also the overwrites of these statements, leading to the removals of these statements during the merge.

merge(changeset, changes)

Merge the changes of two Gno.EffectiveChangesets into one.

Warning

This function can be used to collapse the changes of multiple consecutive EffectiveChangesets from a changeset sequence into one and relies on the fact that these consist of complete effective changes incl. overwrites, which might lead to surprising results and limits its general applicability. E.g. a single merged replace does not remove the statements with only matching subjects from the other actions, but only the fully matching statements, since we rely on the fact that a complete EffectiveChangeset includes also the overwrites of these statements, leading to the removals of these statements during the merge.

new(changes, opts \\ [])

@spec new(Gno.Changeset.Action.changes(), opts :: keyword()) ::
  {:ok, t()} | {:error, any()}

Creates a new valid changeset.

new!(args, opts \\ [])

@spec new!(Gno.Changeset.Action.changes(), opts :: keyword()) :: t()

Creates a new valid changeset.

As opposed to new/1 this function fails in error cases.

to_rdf(changeset, opts \\ [])

Serializes the effective changeset to an RDF.Dataset.

validate(changeset, opts \\ [])

Validates the given changeset structure.

If valid, the given structure is returned unchanged in an :ok tuple. Otherwise, an :error tuple is returned.