OT.Server v0.3.1 OT.Server View Source
A safe API for interacting with operations and the data they operate against.
Link to this section Summary
Types
A map containing OT-related information
A piece of information that can uniquely identify a datum/0
A list of units of work performed against a single piece of data (a
datum/0
)
A tuple representing an operation/0
and its version/0
Link to this section Types
datum() :: %{:type => String.t, :version => non_neg_integer, :content => any, optional(any) => any}
A map containing OT-related information.
This map must contain at least three keys:
type
: A string representing the OT type, which will be used to find the appropriate OT module.version
: A non-negative integer representing the currentversion/0
of the datum.content
: The contents of the datum thatoperation/0
s will be applied to.
A piece of information that can uniquely identify a datum/0
.
A list of units of work performed against a single piece of data (a
datum/0
).
A tuple representing an operation/0
and its version/0
.
A non-negative integer representing an operation or datum/0
version.
Link to this section Functions
get_datum(pid, any) :: {:ok, any} | {:error, any}
Get a datum.
This will call the configured adapter’s OT.Server.Adapter.get_datum/1
function and return that value.
Example
iex> {:ok, pid} = OT.Server.start_link([])
iex> :ets.insert(:ot_data, {"id", %{id: "id"}})
iex> OT.Server.get_datum(pid, "id")
{:ok, %{id: "id"}}
If the datum is found, it will be returned. Otherwise, an error is returned.
Also, note that this function does get called in a worker, so shares worker
bandwidth with submit_operation/3
.
submit_operation(pid, any, {OT.Operation.t, pos_integer}, any) :: {:ok, {OT.Operation.t, pos_integer}} | {:error, any}
Submit an operation.
Example
iex> {:ok, pid} = OT.Server.start_link([])
iex> :ets.insert(:ot_data,
...> {"id", %{id: "id", content: "Hllo, ", type: "text", version: 0}})
iex> OT.Server.submit_operation(pid, "id", {[1, %{i: "e"}], 1})
iex> OT.Server.submit_operation(pid, "id", {[6, %{i: "world."}], 1})
{:ok, {[7, %{i: "world."}], 2}}
iex> OT.Server.get_datum(pid, "id")
{:ok, %{id: "id", content: "Hello, world.", type: "text", version: 2}}
If the operation succeeds, a tuple will be returned with the operation and its version. Otherwise, an error will be returned.