authoritiesvc

package
v0.167.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package authoritiesvc is the local-authority editing service (tasks/046): CRUD over authority grains for a deployment's own headings, authority merge with corpus-wide reference rewrite, and the on-save auto-linker that turns string subjects into moderated linking suggestions. It is SKOS-native Koha-authorities: cross-references are altLabel (used-for) and broader/ narrower/related; global heading update is free because bibs reference terms by URI, so a relabel propagates at projection.

Index

Constants

View Source
const LocalScheme = "local"

LocalScheme is the vocabulary key local authority terms live under: their statements land in the authority:local named graph and the vocab index serves them beside imported schemes.

Variables

View Source
var ErrValidation = errors.New("authoritiesvc: invalid term")

ErrValidation reports a term description that cannot be saved.

View Source
var IDPattern = regexp.MustCompile(`^a[0-9a-v]{6,20}$`)

IDPattern matches a minted local-authority id (identity.Mint "a" prefix).

Functions

This section is empty.

Types

type MergeResult

type MergeResult struct {
	Loser  string `json:"loser"`
	Winner string `json:"winner"`
	// Rewritten counts the Work grains repointed at the winner. On a failure it
	// is what the pass managed before it stopped, and it is meaningful: the works
	// it counts really are repointed (tasks/305).
	Rewritten int `json:"rewritten"`
	// Carriers is how many Works named the loser when the pass began. Rewritten <
	// Carriers means the merge did not finish and the heading is still live; the
	// same request run again resumes, because the loop skips works that no longer
	// name the loser.
	Carriers int `json:"carriers"`
	// Complete reports that every carrier was rewritten AND the loser was retired.
	// It distinguishes the two ways Merge can return an error with work behind it:
	// a rewrite that stopped partway (Complete false, retry to finish) from a
	// finished merge whose index reload failed (Complete true, nothing to redo).
	Complete bool `json:"complete"`
}

MergeResult summarizes one authority merge.

type Service

type Service struct {
	Blob  blob.Store
	Vocab *vocab.Index
	// Queue, when set, receives audit entries and the auto-linker's
	// PIPELINE suggestions.
	Queue *suggest.Service
	// Trigger, when set, gets one grains-changed event per merge rewrite.
	Trigger trigger.Notifier
	// Prefix is the grain tree root in the blob store ("" = repo-layout
	// paths straight from bibframe paths).
	Prefix string
	// AuthoritiesPrefix is the vocab reload scan prefix; empty means
	// Prefix + "data/authorities/".
	AuthoritiesPrefix string
	// Schemes filters the vocab reload (nil = every authority graph).
	Schemes []string
	// SchemesFn, when set, supersedes Schemes -- the tasks/067 seam: installed
	// vocabulary snapshots widen the effective filter at reload time, so an
	// authority edit's reload never drops an installed scheme.
	SchemesFn func(context.Context) ([]string, error)
	// Summaries, when set, is the shared maintained summary source
	// (workindex, tasks/109) merge rewrites scan instead of a per-run
	// corpus walk; nil falls back to ScanSummaries.
	Summaries ingest.SummarySource
	Logger    *slog.Logger
}

Service edits local authority grains and keeps the shared vocab index fresh. All writes go through the store's optimistic concurrency.

func (s *Service) AutoLink(ctx context.Context, workID string, grain []byte) (int, error)

AutoLink matches a just-saved Work's uncontrolled string subjects against the authority labels of every loaded scheme and lands whole-heading matches in the moderation queue as PIPELINE suggestions -- never writing the link itself (tasks/046). Returns the number of candidate links handed to the queue; the queue is create-only and tombstone-aware, so re-running on every save never duplicates, and a tag whose term the Work already carries as a controlled subject produces no candidate.

func (*Service) Create

func (s *Service) Create(ctx context.Context, term bibframe.AuthorityTerm, actor string) (id, etag string, err error)

Create mints a local authority id, writes the term's grain, and refreshes the index. The term's URI field is assigned, never client-chosen.

func (*Service) Get

Get reads one local authority term and its concurrency token.

func (*Service) Merge

func (s *Service) Merge(ctx context.Context, loserID string, winner vocab.TermRef, actor string) (MergeResult, error)

Merge retires the local term loserID into winner: lcat:mergedInto lands in the loser's grain, and every Work grain referencing the loser is rewritten to the winner in one batch pass (references live in the editorial graph, so the rewrite is a global heading update, not a feed mutation). The winner may belong to any loaded scheme -- merging a local heading into an established vocabulary term is the expected promotion path.

func (*Service) Reload

func (s *Service) Reload(ctx context.Context) error

Reload rebuilds the shared vocab index from the authorities tree so edits are searchable immediately.

func (*Service) Update

func (s *Service) Update(ctx context.Context, id string, term bibframe.AuthorityTerm, ifMatch, actor string) (string, error)

Update replaces a term's description under the client's If-Match token (blob.ErrPreconditionFailed on a concurrent write, blob.ErrNotFound if the term does not exist). A recorded merge retirement survives the edit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL