model

package
v0.0.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TMFileExtension              = ".tm.json"
	PseudoVersionTimestampFormat = "20060102150405"
)
View Source
const DefaultListSeparator = ","
View Source
const TMLinkRel = "content"

Variables

View Source
var (
	ErrInvalidVersion       = errors.New("invalid version string")
	ErrInvalidPseudoVersion = errors.New("no valid pseudo-version found")
	ErrInvalidId            = errors.New("TM id invalid")
	ErrVersionDiffers       = errors.New("id has a differing version from given ThingModel")
)
View Source
var EmptySpec, _ = NewSpec("", "")
View Source
var ErrInvalidSpec = errors.New("illegal repo spec: both local directory and repo name given")

Functions

func JoinSkippingEmpty

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

Types

type FilterType

type FilterType byte
const (
	FullMatch FilterType = iota
	PrefixMatch
)

type FoundEntry

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

func (FoundEntry) Merge

func (r FoundEntry) Merge(other FoundEntry) FoundEntry

type FoundSource

type FoundSource struct {
	Directory string
	RepoName  string
}

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"`
}

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) Filter

func (idx *Index) Filter(search *SearchParams)

func (*Index) Insert

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

Insert uses CatalogThingModel to add a version, either to an existing entry or as a new entry. Returns the TMID of the inserted entry

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"`
}

func (*IndexEntry) MatchesSearchText

func (e *IndexEntry) MatchesSearchText(searchQuery string) bool

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) 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"`
}

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) ToFoundEntry

func (*InventoryResponseToSearchResultMapper) ToFoundVersions

func (*InventoryResponseToSearchResultMapper) ToSearchResult

type Link struct {
	Rel  RelType `json:"rel"`
	HRef string  `json:"href"`
}

type LinkType

type LinkType string
type Links []Link
func (links *Links) FindLink(rel RelType) *Link

type RelType

type RelType string
const (
	RelContent RelType = "content"
)

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 (r RepoSpec) Dir() string

func (RepoSpec) RepoName

func (r RepoSpec) RepoName() string

func (RepoSpec) String

func (r RepoSpec) String() string

func (RepoSpec) ToFoundSource

func (r RepoSpec) ToFoundSource() FoundSource

type Resource

type Resource struct {
	Name    string
	RelPath string
	Typ     ResourceType
	Raw     []byte
}

type ResourceFilter

type ResourceFilter struct {
	Types []ResourceType
	Names []string
}

type ResourceType

type ResourceType int
const (
	ResTypeUnknown ResourceType = iota
	ResTypeTM
)

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 SearchOptions

type SearchOptions struct {
	// NameFilterType specifies whether SearchParams.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 SearchParams

type SearchParams struct {
	Author       []string
	Manufacturer []string
	Mpn          []string
	Name         string
	Query        string
	Options      SearchOptions
}

func ToSearchParams

func ToSearchParams(author, manufacturer, mpn, name, query *string, opts *SearchOptions) *SearchParams

func (*SearchParams) Sanitize

func (p *SearchParams) Sanitize()

type SearchResult

type SearchResult struct {
	Entries []FoundEntry
}

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) 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"`
}

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

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