Documentation
¶
Index ¶
- Constants
- Variables
- func Add(name, typ, confStr string, confFile []byte, descr string) error
- func AsRepoConfig(bytes []byte) (map[string]any, error)
- func Remove(name string) error
- func Rename(oldName, newName string) error
- func SetConfig(name, typ, confStr string, confFile []byte, descr string) error
- func ToggleEnabled(name string) error
- type CodedError
- type Config
- type ErrTMIDConflict
- type FileRepo
- func (f *FileRepo) AnalyzeIndex(ctx context.Context) error
- func (f *FileRepo) Delete(ctx context.Context, id string) error
- func (f *FileRepo) DeleteAttachment(ctx context.Context, ref model.AttachmentContainerRef, attachmentName string) error
- func (f *FileRepo) Fetch(ctx context.Context, id string) (string, []byte, error)
- func (f *FileRepo) FetchAttachment(ctx context.Context, ref model.AttachmentContainerRef, attachmentName string) ([]byte, error)
- func (f *FileRepo) GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, error)
- func (f *FileRepo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
- func (f *FileRepo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) error
- func (f *FileRepo) Index(ctx context.Context, ids ...string) error
- func (f *FileRepo) List(ctx context.Context, search *model.SearchParams) (model.SearchResult, error)
- func (f *FileRepo) ListCompletions(ctx context.Context, kind string, args []string, toComplete string) ([]string, error)
- func (f *FileRepo) RangeResources(ctx context.Context, filter model.ResourceFilter, ...) error
- func (f *FileRepo) Spec() model.RepoSpec
- func (f *FileRepo) Versions(ctx context.Context, name string) ([]model.FoundVersion, error)
- type HttpRepo
- func (h *HttpRepo) AnalyzeIndex(context.Context) error
- func (h *HttpRepo) Delete(ctx context.Context, id string) error
- func (h *HttpRepo) DeleteAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) error
- func (h *HttpRepo) Fetch(ctx context.Context, id string) (string, []byte, error)
- func (h *HttpRepo) FetchAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) ([]byte, error)
- func (h *HttpRepo) GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, error)
- func (h *HttpRepo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
- func (h *HttpRepo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) error
- func (h *HttpRepo) Index(context.Context, ...string) error
- func (h *HttpRepo) List(ctx context.Context, search *model.SearchParams) (model.SearchResult, error)
- func (h *HttpRepo) ListCompletions(ctx context.Context, kind string, args []string, toComplete string) ([]string, error)
- func (h *HttpRepo) RangeResources(context.Context, model.ResourceFilter, func(model.Resource, error) bool) error
- func (h *HttpRepo) Spec() model.RepoSpec
- func (h *HttpRepo) Versions(ctx context.Context, name string) ([]model.FoundVersion, error)
- type IdConflictType
- type ImportOptions
- type ImportResult
- type ImportResultType
- type Repo
- type RepoAccessError
- type TmcRepo
- func (t *TmcRepo) AnalyzeIndex(context.Context) error
- func (t *TmcRepo) Delete(ctx context.Context, id string) error
- func (t *TmcRepo) DeleteAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) error
- func (t *TmcRepo) Fetch(ctx context.Context, id string) (string, []byte, error)
- func (t *TmcRepo) FetchAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) ([]byte, error)
- func (t *TmcRepo) GetSubRepos(ctx context.Context) ([]model.RepoDescription, error)
- func (t *TmcRepo) GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, error)
- func (t *TmcRepo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
- func (t *TmcRepo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) error
- func (t *TmcRepo) Index(context.Context, ...string) error
- func (t *TmcRepo) List(ctx context.Context, search *model.SearchParams) (model.SearchResult, error)
- func (t *TmcRepo) ListCompletions(ctx context.Context, kind string, args []string, toComplete string) ([]string, error)
- func (t *TmcRepo) RangeResources(context.Context, model.ResourceFilter, func(model.Resource, error) bool) error
- func (t *TmcRepo) Spec() model.RepoSpec
- func (t *TmcRepo) Versions(ctx context.Context, name string) ([]model.FoundVersion, error)
- type Union
- func (u *Union) Fetch(ctx context.Context, id string) (string, []byte, error, []*RepoAccessError)
- func (u *Union) GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, []*RepoAccessError)
- func (u *Union) List(ctx context.Context, search *model.SearchParams) (model.SearchResult, []*RepoAccessError)
- func (u *Union) ListCompletions(ctx context.Context, kind string, args []string, toComplete string) []string
- func (u *Union) Versions(ctx context.Context, name string) ([]model.FoundVersion, []*RepoAccessError)
Constants ¶
View Source
const ( IdConflictSameContent = iota + 1 IdConflictSameTimestamp )
View Source
const ( KeyRepos = "repos" KeyRepoType = "type" KeyRepoLoc = "loc" KeyRepoAuth = "auth" KeyRepoEnabled = "enabled" KeyRepoDescription = "description" RepoTypeFile = "file" RepoTypeHttp = "http" RepoTypeTmc = "tmc" CompletionKindNames = "names" CompletionKindFetchNames = "fetchNames" CompletionKindNamesOrIds = "namesOrIds" CompletionKindAttachments = "attachments" RepoConfDir = ".tmc" IndexFilename = "tm-catalog.toc.json" TmNamesFile = "tmnames.txt" )
View Source
const ( ImportResultOK = ImportResultType(iota + 1) ImportResultWarning // imported but with warning ImportResultError // not imported because of error )
View Source
const RelFileUriPlaceholder = "{{ID}}"
View Source
const (
TMExt = ".tm.json"
)
Variables ¶
View Source
var ( ErrAmbiguous = errors.New("multiple repos configured, but target repo not specified") ErrRepoNotFound = errors.New("repo not found") ErrInvalidRepoName = errors.New("invalid repo name") ErrRepoExists = errors.New("named repo already exists") ErrAttachmentExists = errors.New("attachment already exists") ErrInvalidErrorCode = errors.New("invalid error code") ErrInvalidCompletionParams = errors.New("invalid completion parameters") ErrNotSupported = errors.New("method not supported") ErrResourceAccess = errors.New("cannot access resource") ErrResourceInvalid = errors.New("invalid resource name") ErrResourceNotExists = errors.New("resource does not exist") ErrIndexMismatch = errors.New("index does not reflect repository content, maybe needs rebuild") ErrNoIndex = errors.New("no table of contents found. Run `index` for this repo") )
View Source
var All = func() ([]Repo, error) { conf, err := ReadConfig() if err != nil { return nil, err } var rs []Repo for n, rc := range conf { en := utils.JsGetBool(rc, KeyRepoEnabled) if en != nil && !*en { continue } r, err := createRepo(rc, model.NewRepoSpec(n)) if err != nil { return rs, err } rs = append(rs, r) } return rs, err }
View Source
var ErrIndexLocked = errors.New("could not acquire lock on index file")
View Source
var ErrRootInvalid = errors.New("root is not a directory")
View Source
var Get = func(spec model.RepoSpec) (Repo, error) { if spec.Dir() != "" { if spec.RepoName() != "" { return nil, model.ErrInvalidSpec } return NewFileRepo(map[string]any{KeyRepoType: "file", KeyRepoLoc: spec.Dir()}, spec) } repos, err := ReadConfig() if err != nil { return nil, err } repos = filterEnabled(repos) parent, child := splitRepoName(spec.RepoName()) spec = model.NewRepoSpec(parent) rc, ok := repos[parent] if parent == "" { switch len(repos) { case 0: return nil, ErrRepoNotFound case 1: for n, v := range repos { rc = v spec = model.NewRepoSpec(n) } default: return nil, ErrAmbiguous } } else { if !ok { return nil, ErrRepoNotFound } } if child != "" { rc[keySubRepo] = child } return createRepo(rc, spec) }
View Source
var GetDescriptions = func(ctx context.Context, spec model.RepoSpec) ([]model.RepoDescription, error) { if spec.Dir() != "" { return nil, nil } conf, err := ReadConfig() if err != nil { return nil, err } var rs []model.RepoDescription for n, rc := range conf { en := utils.JsGetBool(rc, KeyRepoEnabled) if en != nil && !*en { continue } if spec.RepoName() == "" || n == spec.RepoName() { ds, _ := rc[KeyRepoDescription].(string) r := model.RepoDescription{ Name: n, Type: fmt.Sprintf("%v", rc[KeyRepoType]), Description: ds, } rs = append(rs, r) } } rs, err = expandTmcRepos(ctx, rs) return rs, err }
GetDescriptions returns the list of descriptions of repositories that could be used as targets for write operations or be returned as "found-in" sources when reading from catalog
View Source
var SupportedTypes = []string{RepoTypeFile, RepoTypeHttp, RepoTypeTmc}
View Source
var ValidRepoNameRegex = regexp.MustCompile("^[a-zA-Z0-9][\\w\\-_:]*$")
Functions ¶
func ToggleEnabled ¶
Types ¶
type CodedError ¶
type CodedError interface {
Code() string
}
type Config ¶
func ReadConfig ¶
type ErrTMIDConflict ¶
type ErrTMIDConflict struct { Type IdConflictType ExistingId string }
func ParseErrTMIDConflict ¶
func ParseErrTMIDConflict(errCode string) (*ErrTMIDConflict, error)
func (*ErrTMIDConflict) Code ¶
func (e *ErrTMIDConflict) Code() string
Code returns a machine-readable string error code, which can be parsed by ParseErrTMIDConflict
func (*ErrTMIDConflict) Error ¶
func (e *ErrTMIDConflict) Error() string
type FileRepo ¶
type FileRepo struct {
// contains filtered or unexported fields
}
FileRepo implements a Repo TM repository backed by a file system
func (*FileRepo) DeleteAttachment ¶
func (*FileRepo) FetchAttachment ¶
func (*FileRepo) GetTMMetadata ¶
func (*FileRepo) Import ¶
func (f *FileRepo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
func (*FileRepo) ImportAttachment ¶
func (f *FileRepo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, attachment model.Attachment, content []byte, force bool) error
func (*FileRepo) List ¶
func (f *FileRepo) List(ctx context.Context, search *model.SearchParams) (model.SearchResult, error)
func (*FileRepo) ListCompletions ¶
func (*FileRepo) RangeResources ¶
type HttpRepo ¶
type HttpRepo struct {
// contains filtered or unexported fields
}
HttpRepo implements a Repo backed by a http server. It does not allow writing to the repository and is thus a read-only view
func (*HttpRepo) DeleteAttachment ¶
func (*HttpRepo) FetchAttachment ¶
func (*HttpRepo) GetTMMetadata ¶
func (*HttpRepo) Import ¶
func (h *HttpRepo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
func (*HttpRepo) ImportAttachment ¶
func (h *HttpRepo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, attachment model.Attachment, content []byte, force bool) error
func (*HttpRepo) List ¶
func (h *HttpRepo) List(ctx context.Context, search *model.SearchParams) (model.SearchResult, error)
func (*HttpRepo) ListCompletions ¶
func (*HttpRepo) RangeResources ¶
type IdConflictType ¶
type IdConflictType int
func (IdConflictType) String ¶
func (t IdConflictType) String() string
type ImportOptions ¶
type ImportResult ¶
type ImportResult struct { Type ImportResultType // TmID is not empty when the result is successful, i.e. Type is OK or Warning TmID string Message string // Err is not nil when there was an ID conflict or another error during import, i.e. Type is TMExists or Warning or Error Err error }
func ImportResultFromError ¶
func ImportResultFromError(err error) (ImportResult, error)
func (ImportResult) IsSuccessful ¶
func (r ImportResult) IsSuccessful() bool
func (ImportResult) String ¶
func (r ImportResult) String() string
type ImportResultType ¶
type ImportResultType int
func (ImportResultType) String ¶
func (t ImportResultType) String() string
type Repo ¶
type Repo interface { // Import writes the Thing Model file into the path under root that corresponds to id. // Returns ErrTMIDConflict if the same file is already stored with a different timestamp or // there is a file with the same semantic version and timestamp but different content Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error) // Fetch retrieves the Thing Model file from repo // Returns the actual id of the retrieved Thing Model (it may differ in the timestamp from the id requested), the file contents, and an error Fetch(ctx context.Context, id string) (string, []byte, error) // Index updates repository's index file with data from given TM files. For ids that refer to non-existing files, // removes those from index. Performs a full update if no updatedIds given Index(ctx context.Context, updatedIds ...string) error // AnalyzeIndex checks the index for consistency. AnalyzeIndex(ctx context.Context) error // List searches the catalog for TMs matching search parameters List(ctx context.Context, search *model.SearchParams) (model.SearchResult, error) // Versions lists versions of a TM with given name Versions(ctx context.Context, name string) ([]model.FoundVersion, error) // Spec returns the spec this Repo has been created from Spec() model.RepoSpec // Delete deletes the TM with given id from repo. Returns ErrTMNotFound if TM does not exist Delete(ctx context.Context, id string) error // RangeResources iterates over resources within this Repo. // Iteration can be narrowed down by a ResourceFilter. Each iteration calls the visit function. RangeResources(ctx context.Context, filter model.ResourceFilter, visit func(res model.Resource, err error) bool) error ListCompletions(ctx context.Context, kind string, args []string, toComplete string) ([]string, error) GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, error) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, attachment model.Attachment, content []byte, force bool) error FetchAttachment(ctx context.Context, container model.AttachmentContainerRef, attachmentName string) ([]byte, error) DeleteAttachment(ctx context.Context, container model.AttachmentContainerRef, attachmentName string) error }
type RepoAccessError ¶
type RepoAccessError struct {
// contains filtered or unexported fields
}
func NewRepoAccessError ¶
func NewRepoAccessError(spec model.RepoSpec, err error) *RepoAccessError
func (*RepoAccessError) Error ¶
func (e *RepoAccessError) Error() string
func (*RepoAccessError) Unwrap ¶
func (e *RepoAccessError) Unwrap() error
type TmcRepo ¶
type TmcRepo struct {
// contains filtered or unexported fields
}
TmcRepo implements a Repo TM repository backed by an instance of TM catalog REST API server
func (*TmcRepo) DeleteAttachment ¶
func (*TmcRepo) FetchAttachment ¶
func (*TmcRepo) GetSubRepos ¶
func (*TmcRepo) GetTMMetadata ¶
func (*TmcRepo) Import ¶
func (t *TmcRepo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
func (*TmcRepo) ImportAttachment ¶
func (t *TmcRepo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, attachment model.Attachment, content []byte, force bool) error
func (*TmcRepo) List ¶
func (t *TmcRepo) List(ctx context.Context, search *model.SearchParams) (model.SearchResult, error)
func (*TmcRepo) ListCompletions ¶
func (*TmcRepo) RangeResources ¶
type Union ¶
type Union struct {
// contains filtered or unexported fields
}
func GetSpecdOrAll ¶
GetSpecdOrAll returns a union containing the repo specified by spec, or union of all repo, if the spec is empty
func (*Union) GetTMMetadata ¶
func (u *Union) GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, []*RepoAccessError)
func (*Union) List ¶
func (u *Union) List(ctx context.Context, search *model.SearchParams) (model.SearchResult, []*RepoAccessError)
func (*Union) ListCompletions ¶
func (*Union) Versions ¶
func (u *Union) Versions(ctx context.Context, name string) ([]model.FoundVersion, []*RepoAccessError)
Click to show internal directories.
Click to hide internal directories.