Files
self f050f58e85
CI / Test (push) Failing after 16s
feat: add Kobold commit chunks
Model dynamic dataset edits as synced commit chunks with bookmarks while keeping record projections as the local read model.\n\nPrivate/public visibility now only controls external tribe access; dataset metadata, resource definitions, and commits still publish through AshNostrSync for cluster-wide distribution.
2026-05-29 01:22:47 +02:00

143 lines
2.7 KiB
Elixir

defmodule TribeOne.TribesPlugin.Kobold.Commit do
@moduledoc false
use Ash.Resource,
otp_app: :tribe_one_kobold,
domain: TribeOne.TribesPlugin.Kobold,
data_layer: AshPostgres.DataLayer,
extensions: [AshNostrSync]
import Ash.Expr
postgres do
table("kobold_commits")
repo(Tribes.Repo)
custom_indexes do
index([:dataset_id])
index([:run_id])
index([:change_id])
index([:dataset_id, :inserted_at])
end
end
nostr_sync do
namespace("plugins.kobold.commit")
lane(:bulk)
publish?(true)
consume?(true)
end
actions do
defaults([:read])
read :by_dataset do
argument :dataset_id, :uuid do
allow_nil?(false)
end
prepare(build(filter: expr(dataset_id == ^arg(:dataset_id)), sort: [inserted_at: :asc]))
end
read :by_run do
argument :run_id, :string do
allow_nil?(false)
end
prepare(build(filter: expr(run_id == ^arg(:run_id)), sort: [inserted_at: :asc]))
end
create :create do
accept([
:id,
:dataset_id,
:run_id,
:change_id,
:parent_commit_ids,
:message,
:operations,
:metadata,
:author_pubkey
])
change(TribeOne.TribesPlugin.Kobold.Changes.ProjectCommit)
change(AshNostrSync.PublishChange)
end
create :sync_upsert do
accept([
:id,
:dataset_id,
:run_id,
:change_id,
:parent_commit_ids,
:message,
:operations,
:metadata,
:author_pubkey
])
upsert?(true)
change(TribeOne.TribesPlugin.Kobold.Changes.ProjectCommit)
end
destroy :destroy do
require_atomic?(false)
end
end
attributes do
attribute :id, :uuid do
allow_nil?(false)
primary_key?(true)
public?(true)
writable?(true)
default(&Ash.UUID.generate/0)
end
attribute :dataset_id, :uuid do
allow_nil?(false)
public?(true)
end
attribute :run_id, :string do
public?(true)
end
attribute :change_id, :uuid do
allow_nil?(false)
public?(true)
writable?(true)
default(&Ash.UUID.generate/0)
end
attribute :parent_commit_ids, {:array, :uuid} do
allow_nil?(false)
default([])
public?(true)
end
attribute :message, :string do
public?(true)
end
attribute :operations, {:array, :map} do
allow_nil?(false)
default([])
public?(true)
end
attribute :metadata, :map do
allow_nil?(false)
default(%{})
public?(true)
end
attribute :author_pubkey, :string do
public?(true)
end
timestamps(type: :utc_datetime)
end
end