linker

package
v0.0.0-...-ac441f4 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FromRemoteResult

type FromRemoteResult struct {
	// Remote entity from target.
	RemoteEntity RemoteEntity

	// Linked RemoteEntity.
	Linked Linked
}

type Linkables

type Linkables interface {
	// Link entity with remote.
	CreateLink(context.Context, shared.EntityID, *shared.RemoteID) (Linked, error)

	// Example: get linked spotify artist by artist entity.
	LinkedEntity(shared.EntityID) (Linked, error)

	// Example: get linked spotify artist by its ID on Spotify.
	LinkedRemoteID(shared.RemoteID) (Linked, error)
}

Remote in DB.

type Linked

type Linked interface {
	// Parent entity.
	EntityID() shared.EntityID

	// Example: Spotify artist ID.
	//
	// Nil if not exists in remote.
	RemoteID() *shared.RemoteID

	// Example: set Spotify artist ID.
	//
	// Nil if not exists in remote.
	SetRemoteID(*shared.RemoteID) error

	// Date when link created/modified.
	ModifiedAt() time.Time
}

type Remote

type Remote interface {
	// Unique name.
	//
	// Example: "Spotify".
	Name() shared.RemoteName

	// Find entity from another remote in current.
	Match(context.Context, RemoteEntity) (RemoteEntity, error)

	// Get entity by ID.
	RemoteEntity(context.Context, shared.RemoteID) (RemoteEntity, error)

	// DB ops for linked entities.
	Linkables() Linkables
}

Links global entities like artists, tracks, albums.

type RemoteEntity

type RemoteEntity interface {
	// Example: Spotify.
	RemoteName() shared.RemoteName

	// Example: Spotify artist ID.
	ID() shared.RemoteID

	// Example: Spotify artist name.
	Name() string
}

type Repository

type Repository interface {
	CreateEntity() (shared.EntityID, error)

	// 1. Delete entities that not linked with any remote.
	//
	// 2. Delete entities that linked, but have NULL RemoteID on all remotes.
	DeleteNotLinked() error

	// Delete all entities.
	DeleteAll() error
}

Repository of remote-independent entity.

Example: artist repository.

type RepositoryShareable

type RepositoryShareable interface {
	Repository
}

Can import/export links.

type Static

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

Links global entities.

Example: track, artist, album.

func NewStatic

func NewStatic(repo Repository, remotes map[shared.RemoteName]Remote) *Static

func (Static) FromRemote

func (e Static) FromRemote(ctx context.Context, source RemoteEntity, target shared.RemoteName) (FromRemoteResult, error)

From remote entity to linked.

func (Static) ToRemote

func (e Static) ToRemote(ctx context.Context, sourceLinked Linked, source, target shared.RemoteName) (ToRemoteResult, error)

From source linked entity to target linked entity.

type ToRemoteResult

type ToRemoteResult struct {
	// Missing on remote before but now present?
	MissingBefore,

	MissingNow,

	NewLink bool

	// Entity linked with target remote.
	//
	// Can be nil.
	Linked Linked
}

Jump to

Keyboard shortcuts

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