model

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TMFileExtension              = ".tm.json"
	PseudoVersionTimestampFormat = "20060102150405"
)
View Source
const (
	CheckOK = CheckResultType(iota)
	CheckErr
)
View Source
const AttachmentsDir = ".attachments"
View Source
const DefaultListSeparator = ","

Variables

View Source
var (
	ErrInvalidVersion       = errors.New("invalid version string")
	ErrInvalidPseudoVersion = errors.New("no valid pseudo-version found")
	ErrInvalidId            = errors.New("TM id invalid")
	ErrInvalidIdOrName      = errors.New("id or name invalid")
)
View Source
var EmptySpec, _ = NewSpec("", "")
View Source
var ErrInvalidFetchName = errors.New("invalid fetch name")
View Source
var ErrInvalidSpec = errors.New("illegal repo spec: both local directory and repo name given")
View Source
var ErrSearchIndexNotFound = errors.New("search index not found. Use `tmc create-si` to create")

Functions

func JoinSkippingEmpty

func JoinSkippingEmpty(elems []string, sep string) string

func ParseAsTMIDOrFetchName

func ParseAsTMIDOrFetchName(idOrName string) (*TMID, *FetchName, error)

ParseAsTMIDOrFetchName parses idOrName as model.TMID. If that fails, parses it as FetchName. Returns error is idOrName is not valid as either. Only one of returned pointers may be not nil

func RelAttachmentsDir

func RelAttachmentsDir(ref AttachmentContainerRef) (string, error)

RelAttachmentsDir is a helper function which calculates the relative path of the attachments directory for given attachment container. That is, e.g. 'author/manufacturer/mpn/.attachments' for a TMName ref and 'author/manufacturer/mpn/.attachments/v1.0.0-20240108112117-2cd14601ef09' for a TMID ref

Types

type Attachment

type Attachment struct {
	Name      string `json:"name"`
	MediaType string `json:"mediaType,omitempty"`
}

type AttachmentContainer

type AttachmentContainer struct {
	Attachments []Attachment `json:"attachments,omitempty"`
}

func (*AttachmentContainer) FindAttachment

func (ac *AttachmentContainer) FindAttachment(name string) (att Attachment, found bool)

type AttachmentContainerKind

type AttachmentContainerKind byte
const (
	AttachmentContainerKindInvalid AttachmentContainerKind = iota
	AttachmentContainerKindTMName
	AttachmentContainerKindTMID
)

type AttachmentContainerRef

type AttachmentContainerRef struct {
	TMName string
	TMID   string
}

AttachmentContainerRef contains a reference to an entity which can have file attachments Either TMName field must be not empty, or TMID. Never both and never none.

func NewTMIDAttachmentContainerRef

func NewTMIDAttachmentContainerRef(tmid string) AttachmentContainerRef

func NewTMNameAttachmentContainerRef

func NewTMNameAttachmentContainerRef(tmName string) AttachmentContainerRef

func (AttachmentContainerRef) Kind

func (AttachmentContainerRef) String

func (r AttachmentContainerRef) String() string

type CheckResult added in v0.1.3

type CheckResult struct {
	Typ          CheckResultType `json:"type"`
	ResourceName string          `json:"resource"`
	Message      string          `json:"message,omitempty"`
}

func (CheckResult) String added in v0.1.3

func (r CheckResult) String() string

type CheckResultType added in v0.1.3

type CheckResultType int

func (CheckResultType) MarshalJSON added in v0.1.3

func (t CheckResultType) MarshalJSON() ([]byte, error)

func (CheckResultType) String added in v0.1.3

func (t CheckResultType) String() string

type ErrNotFound

type ErrNotFound struct {
	Subject string
}
var (
	ErrTMNotFound         *ErrNotFound
	ErrTMNameNotFound     *ErrNotFound
	ErrAttachmentNotFound *ErrNotFound
)

func NewErrNotFound

func NewErrNotFound(subject string) *ErrNotFound

func (*ErrNotFound) Code

func (e *ErrNotFound) Code() string

func (*ErrNotFound) Error

func (e *ErrNotFound) Error() string

type FetchName

type FetchName struct {
	Name   string
	Semver string
}

func ParseFetchName

func ParseFetchName(fetchName string) (FetchName, error)

type FilterOptions added in v0.1.3

type FilterOptions struct {
	// NameFilterType specifies whether Filters. Name must match a prefix or the full length of a TM name
	// Note that using FullMatch effectively limits the search result to at most one FoundEntry
	NameFilterType FilterType
}

type FilterType

type FilterType byte
const (
	FullMatch FilterType = iota
	PrefixMatch
)

type Filters added in v0.1.3

type Filters struct {
	Author       []string
	Manufacturer []string
	Mpn          []string
	Protocol     []string
	Name         string
	Options      FilterOptions
}

func ToFilters added in v0.1.3

func ToFilters(author, manufacturer, mpn, protocol, name *string, opts *FilterOptions) *Filters

func (*Filters) Sanitize added in v0.1.3

func (p *Filters) Sanitize()

type FoundAttachment

type FoundAttachment struct {
	Attachment
	FoundIn FoundSource `json:"repo"`
}

type FoundEntry

type FoundEntry struct {
	Name         string
	Manufacturer SchemaManufacturer
	Mpn          string
	Author       SchemaAuthor
	Versions     []FoundVersion
	FoundIn      FoundSource
	AttachmentContainer
}

type FoundSource

type FoundSource struct {
	Directory string
	RepoName  string
}

func (FoundSource) MarshalJSON added in v0.1.3

func (s FoundSource) MarshalJSON() ([]byte, error)

func (FoundSource) String

func (s FoundSource) String() string

type FoundVersion

type FoundVersion struct {
	*IndexVersion
	FoundIn FoundSource
}

func MergeFoundVersions

func MergeFoundVersions(vs1, vs2 []FoundVersion) []FoundVersion

type Index

type Index struct {
	Meta IndexMeta     `json:"meta"`
	Data []*IndexEntry `json:"data"`
	// contains filtered or unexported fields
}

func (*Index) Delete

func (idx *Index) Delete(id string) (updated bool, deletedName string, err error)

Delete deletes the record for the given id. Returns TM name to be removed from names file if no more versions are left

func (*Index) FindAttachmentContainer

func (idx *Index) FindAttachmentContainer(ref AttachmentContainerRef) (*AttachmentContainer, *IndexEntry, error)

func (*Index) FindByName

func (idx *Index) FindByName(name string) *IndexEntry

FindByName searches by TM name and returns a pointer to the IndexEntry if found

func (*Index) FindByTMID

func (idx *Index) FindByTMID(tmID string) *IndexVersion

FindByTMID searches by TM name and returns a pointer to the IndexVersion if found. returns nil if tmID is not valid or not found in

func (*Index) Insert

func (idx *Index) Insert(ctm *ThingModel) error

Insert uses ThingModel to add a version, either to an existing entry or as a new entry.

func (*Index) InsertAttachments

func (idx *Index) InsertAttachments(ref AttachmentContainerRef, atts ...Attachment) error

func (*Index) IsEmpty

func (idx *Index) IsEmpty() bool

func (*Index) Sort

func (idx *Index) Sort()

type IndexEntry

type IndexEntry struct {
	Name         string             `json:"name"`
	Manufacturer SchemaManufacturer `json:"schema:manufacturer" validate:"required"`
	Mpn          string             `json:"schema:mpn" validate:"required"`
	Author       SchemaAuthor       `json:"schema:author" validate:"required"`
	Versions     []*IndexVersion    `json:"versions"`
	AttachmentContainer
}

type IndexMeta

type IndexMeta struct {
	Created time.Time `json:"created"`
}

type IndexToSearchResultMapper

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

func NewIndexToFoundMapper

func NewIndexToFoundMapper(s FoundSource) *IndexToSearchResultMapper

func (*IndexToSearchResultMapper) ToFoundEntry

func (m *IndexToSearchResultMapper) ToFoundEntry(e *IndexEntry) FoundEntry

func (*IndexToSearchResultMapper) ToFoundVersion

func (m *IndexToSearchResultMapper) ToFoundVersion(v *IndexVersion) FoundVersion

func (*IndexToSearchResultMapper) ToFoundVersions

func (m *IndexToSearchResultMapper) ToFoundVersions(versions []*IndexVersion) []FoundVersion

func (*IndexToSearchResultMapper) ToSearchResult

func (m *IndexToSearchResultMapper) ToSearchResult(idx Index) SearchResult

type IndexVersion

type IndexVersion struct {
	Description string            `json:"description"`
	Version     Version           `json:"version"`
	Links       map[string]string `json:"links"`
	TMID        string            `json:"tmID"`
	Digest      string            `json:"digest"`
	TimeStamp   string            `json:"timestamp,omitempty"`
	ExternalID  string            `json:"externalID"`
	Protocols   []string          `json:"protocols,omitempty"`
	SearchMatch *SearchMatch      `json:"searchMatch,omitempty"`
	AttachmentContainer
}

type InventoryResponseToSearchResultMapper

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

func NewInventoryResponseToSearchResultMapper

func NewInventoryResponseToSearchResultMapper(s FoundSource, linksMapper func(links server.InventoryEntryVersion) map[string]string) *InventoryResponseToSearchResultMapper

func (*InventoryResponseToSearchResultMapper) ToFoundEntries

func (*InventoryResponseToSearchResultMapper) ToFoundEntry

func (*InventoryResponseToSearchResultMapper) ToFoundVersion

func (*InventoryResponseToSearchResultMapper) ToFoundVersionAttachments added in v0.1.3

func (m *InventoryResponseToSearchResultMapper) ToFoundVersionAttachments(al *server.AttachmentsList) []Attachment

func (*InventoryResponseToSearchResultMapper) ToFoundVersions

func (*InventoryResponseToSearchResultMapper) ToSearchResult

type Link struct {
	Rel  RelType `json:"rel"`
	HRef string  `json:"href"`
}
type Links []Link
func (links *Links) FindLink(rel RelType) *Link

type RelType

type RelType string

type RepoDescription

type RepoDescription struct {
	Name        string
	Type        string
	Description string
}

type RepoSpec

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

func NewDirSpec

func NewDirSpec(dir string) RepoSpec

func NewRepoSpec

func NewRepoSpec(repoName string) RepoSpec

func NewSpec

func NewSpec(repoName, dir string) (RepoSpec, error)

func NewSpecFromFoundSource

func NewSpecFromFoundSource(s FoundSource) RepoSpec

func (RepoSpec) Dir

func (s RepoSpec) Dir() string

func (RepoSpec) IsEmpty added in v0.1.3

func (s RepoSpec) IsEmpty() bool

func (RepoSpec) RepoName

func (s RepoSpec) RepoName() string

func (RepoSpec) String

func (s RepoSpec) String() string

func (RepoSpec) ToFoundSource

func (s RepoSpec) ToFoundSource() FoundSource

type ResourceFilter

type ResourceFilter func(string) bool

ResourceFilter is a function which determines whether a named resource should be processed or not

type SchemaAuthor

type SchemaAuthor struct {
	Name string `json:"schema:name" validate:"required"`
}

type SchemaManufacturer

type SchemaManufacturer struct {
	Name string `json:"schema:name" validate:"required"`
}

type SearchMatch added in v0.1.3

type SearchMatch struct {
	Score     float32  `json:"score,omitempty"`
	Locations []string `json:"locations,omitempty"`
}

type SearchResult

type SearchResult struct {
	LastUpdated time.Time
	Entries     []FoundEntry
}

func (*SearchResult) Filter added in v0.1.3

func (sr *SearchResult) Filter(filters *Filters) error

Filter deletes all entries from this SearchResult that don't match the filters

func (*SearchResult) FilterByQuery added in v0.1.3

func (sr *SearchResult) FilterByQuery(query, indexPath string) error

FilterByQuery deletes all versions from this SearchResult that don't match the search query. The entries that remain are extended with information on matches' locations.

func (*SearchResult) Merge

func (sr *SearchResult) Merge(other *SearchResult)

type TMID

type TMID struct {
	Name    string
	Version TMVersion
}

func MustParseTMID

func MustParseTMID(s string) TMID

func NewTMID

func NewTMID(author, manufacturer, mpn, optPath string, version TMVersion) TMID

func ParseTMID

func ParseTMID(s string) (TMID, error)

func (TMID) Equals

func (id TMID) Equals(other TMID) bool

func (TMID) String

func (id TMID) String() string

type TMVersion

type TMVersion struct {
	Base      *semver.Version
	Timestamp string
	Hash      string
}

func ParseTMVersion

func ParseTMVersion(s string) (TMVersion, error)

func TMVersionFromOriginal

func TMVersionFromOriginal(ver string) TMVersion

func (TMVersion) BaseString

func (v TMVersion) BaseString() string

func (TMVersion) Compare added in v0.1.3

func (v TMVersion) Compare(other TMVersion) int

func (TMVersion) String

func (v TMVersion) String() string

type ThingModel

type ThingModel struct {
	ID           string             `json:"id,omitempty"`
	Description  string             `json:"description"`
	Manufacturer SchemaManufacturer `json:"schema:manufacturer" validate:"required"`
	Mpn          string             `json:"schema:mpn" validate:"required"`
	Author       SchemaAuthor       `json:"schema:author" validate:"required"`
	Version      Version            `json:"version"`

	Links `json:"links"`
	// contains filtered or unexported fields
}

ThingModel is a model for unmarshalling a Thing Model to be imported. It contains only the fields required to be accepted into the catalog.

func ParseThingModel added in v0.1.3

func ParseThingModel(data []byte) (*ThingModel, error)

type Version

type Version struct {
	Model string `json:"model"`
}

Jump to

Keyboard shortcuts

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