Documentation
¶
Index ¶
- Constants
- Variables
- func JoinSkippingEmpty(elems []string, sep string) string
- func ParseAsTMIDOrFetchName(idOrName string) (*TMID, *FetchName, error)
- func RelAttachmentsDir(ref AttachmentContainerRef) (string, error)
- type Attachment
- type AttachmentContainer
- type AttachmentContainerKind
- type AttachmentContainerRef
- type CheckResult
- type CheckResultType
- type ErrNotFound
- type FetchName
- type FilterOptions
- type FilterType
- type Filters
- type FoundAttachment
- type FoundEntry
- type FoundSource
- type FoundVersion
- type Index
- func (idx *Index) Delete(id string) (updated bool, deletedName string, err error)
- func (idx *Index) FindAttachmentContainer(ref AttachmentContainerRef) (*AttachmentContainer, *IndexEntry, error)
- func (idx *Index) FindByName(name string) *IndexEntry
- func (idx *Index) FindByTMID(tmID string) *IndexVersion
- func (idx *Index) Insert(ctm *ThingModel) error
- func (idx *Index) InsertAttachments(ref AttachmentContainerRef, atts ...Attachment) error
- func (idx *Index) IsEmpty() bool
- func (idx *Index) Sort()
- type IndexEntry
- type IndexMeta
- type IndexToSearchResultMapper
- func (m *IndexToSearchResultMapper) ToFoundEntry(e *IndexEntry) FoundEntry
- func (m *IndexToSearchResultMapper) ToFoundVersion(v *IndexVersion) FoundVersion
- func (m *IndexToSearchResultMapper) ToFoundVersions(versions []*IndexVersion) []FoundVersion
- func (m *IndexToSearchResultMapper) ToSearchResult(idx Index) SearchResult
- type IndexVersion
- type InventoryResponseToSearchResultMapper
- func (m *InventoryResponseToSearchResultMapper) ToFoundEntries(entries []server.InventoryEntry) []FoundEntry
- func (m *InventoryResponseToSearchResultMapper) ToFoundEntry(e server.InventoryEntry) FoundEntry
- func (m *InventoryResponseToSearchResultMapper) ToFoundVersion(v server.InventoryEntryVersion) FoundVersion
- func (m *InventoryResponseToSearchResultMapper) ToFoundVersionAttachments(al *server.AttachmentsList) []Attachment
- func (m *InventoryResponseToSearchResultMapper) ToFoundVersionLinks(v server.InventoryEntryVersion) map[string]string
- func (m *InventoryResponseToSearchResultMapper) ToFoundVersions(versions []server.InventoryEntryVersion) []FoundVersion
- func (m *InventoryResponseToSearchResultMapper) ToSearchResult(inv server.InventoryResponse) SearchResult
- type Link
- type Links
- type RelType
- type RepoDescription
- type RepoSpec
- type ResourceFilter
- type SchemaAuthor
- type SchemaManufacturer
- type SearchMatch
- type SearchResult
- type TMID
- type TMVersion
- type ThingModel
- type Version
Constants ¶
const ( TMFileExtension = ".tm.json" PseudoVersionTimestampFormat = "20060102150405" )
const ( CheckOK = CheckResultType(iota) CheckErr )
const AttachmentsDir = ".attachments"
const DefaultListSeparator = ","
Variables ¶
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") )
var EmptySpec, _ = NewSpec("", "")
var ErrInvalidFetchName = errors.New("invalid fetch name")
var ErrInvalidSpec = errors.New("illegal repo spec: both local directory and repo name given")
var ErrSearchIndexNotFound = errors.New("search index not found. Use `tmc create-si` to create")
Functions ¶
func JoinSkippingEmpty ¶
func ParseAsTMIDOrFetchName ¶
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 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 ¶
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 (r AttachmentContainerRef) Kind() AttachmentContainerKind
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 ¶
func ParseFetchName ¶
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 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
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 ¶
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 ¶
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
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 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 (m *InventoryResponseToSearchResultMapper) ToFoundEntries(entries []server.InventoryEntry) []FoundEntry
func (*InventoryResponseToSearchResultMapper) ToFoundEntry ¶
func (m *InventoryResponseToSearchResultMapper) ToFoundEntry(e server.InventoryEntry) FoundEntry
func (*InventoryResponseToSearchResultMapper) ToFoundVersion ¶
func (m *InventoryResponseToSearchResultMapper) ToFoundVersion(v server.InventoryEntryVersion) FoundVersion
func (*InventoryResponseToSearchResultMapper) ToFoundVersionAttachments ¶ added in v0.1.3
func (m *InventoryResponseToSearchResultMapper) ToFoundVersionAttachments(al *server.AttachmentsList) []Attachment
func (*InventoryResponseToSearchResultMapper) ToFoundVersionLinks ¶
func (m *InventoryResponseToSearchResultMapper) ToFoundVersionLinks(v server.InventoryEntryVersion) map[string]string
func (*InventoryResponseToSearchResultMapper) ToFoundVersions ¶
func (m *InventoryResponseToSearchResultMapper) ToFoundVersions(versions []server.InventoryEntryVersion) []FoundVersion
func (*InventoryResponseToSearchResultMapper) ToSearchResult ¶
func (m *InventoryResponseToSearchResultMapper) ToSearchResult(inv server.InventoryResponse) SearchResult
type RepoDescription ¶
type RepoSpec ¶
type RepoSpec struct {
// contains filtered or unexported fields
}
func NewDirSpec ¶
func NewRepoSpec ¶
func NewSpecFromFoundSource ¶
func NewSpecFromFoundSource(s FoundSource) RepoSpec
func (RepoSpec) ToFoundSource ¶
func (s RepoSpec) ToFoundSource() FoundSource
type ResourceFilter ¶
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 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 ¶
func MustParseTMID ¶
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)