resolver

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package resolver handles reference resolution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AliasCollision

type AliasCollision struct {
	Alias         string   // The alias that collides
	ObjectIDs     []string // Object IDs that share this alias (if multiple objects use same alias)
	ConflictsWith string   // What it conflicts with: "alias", "short_name", or "object_id"
}

AliasCollision represents a collision where an alias conflicts with something else.

type IDCollision

type IDCollision struct {
	ShortName string   // The short name that collides (e.g., "freya")
	ObjectIDs []string // The full object IDs that share this short name
}

IDCollision represents a collision between object IDs with the same short name.

type Options

type Options struct {
	// DailyDirectory is the directory for daily notes (default: "daily").
	DailyDirectory string

	// Aliases maps alias strings to their target object IDs.
	// For example: {"The Queen": "people/freya"}
	Aliases map[string]string

	// NameFieldMap maps name_field values to object IDs for semantic resolution.
	// Values are multi-mapped to preserve ambiguity when multiple objects share
	// the same display name.
	// For example: {"The Prose Edda": {"books/the-prose-edda"}}
	NameFieldMap map[string][]string
}

Options configures the resolver.

type ResolveResult

type ResolveResult struct {
	// TargetID is the resolved target object ID (empty if unresolved).
	TargetID string

	// Ambiguous is true if the reference matches multiple objects.
	Ambiguous bool

	// Matches contains all matching IDs (for ambiguous refs).
	Matches []string

	// MatchSources maps matched IDs to their match source.
	MatchSources map[string]string

	// Error message if resolution failed.
	Error string
}

ResolveResult represents the result of a reference resolution.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver resolves short references to full object IDs.

func New

func New(objectIDs []string, opts Options) *Resolver

New creates a new Resolver with the given object IDs and options.

func (*Resolver) AllObjectIDs

func (r *Resolver) AllObjectIDs() []string

AllObjectIDs returns a slice of all known object IDs.

func (*Resolver) Exists

func (r *Resolver) Exists(id string) bool

Exists checks if an object ID exists.

func (*Resolver) FindAliasCollisions

func (r *Resolver) FindAliasCollisions() []AliasCollision

FindAliasCollisions finds alias conflicts: 1. Multiple objects using the same alias 2. An alias that matches an existing object's short name 3. An alias that matches an existing object ID

func (*Resolver) FindCollisions

func (r *Resolver) FindCollisions() []IDCollision

FindCollisions finds object IDs that share the same short name. This is useful for `rvn check` to warn about potential reference ambiguity.

Note: Collisions between a file and sections within that same file are NOT reported, since these resolve unambiguously (the file takes precedence). For example, `people/freya` and `people/freya#freya` sharing short name "freya" is fine - [[freya]] resolves to the file.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ref string) ResolveResult

Resolve resolves a reference to its target object ID. If a reference matches multiple things (alias + object, alias + short name, etc.), it is treated as ambiguous and returns an error.

Resolution priority:

  1. Aliases (exact match)
  2. Name field values (semantic match by display name)
  3. Date references (YYYY-MM-DD)
  4. Object IDs (exact path match)
  5. Short names (filename match)

func (*Resolver) ResolveAll

func (r *Resolver) ResolveAll(refs []string) map[string]ResolveResult

ResolveAll resolves all references and returns a map from raw ref to result.

Jump to

Keyboard shortcuts

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