registry

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: Apache-2.0, MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Local   = "local"
	Default = "default"
)

Variables

View Source
var (
	ErrStatusCode     = fmt.Errorf("unexpected status code")
	ErrNoTarball      = fmt.Errorf("missing tarball URL")
	ErrBadContentType = fmt.Errorf("unexpected content-type")
	ErrBadContent     = fmt.Errorf("bad content")
)
View Source
var DefaultClient = &Client{
	client: http.DefaultClient,
	url:    "https://packages.simplifier.net",
}

DefaultClient returns a new registry client with the default simplifier registry configured, using a non-authenticated client.

Functions

This section is empty.

Types

type Authentication

type Authentication = auth.Authentication

Authentication is an interface for providing oauth2 authentication to the registry.

func NoAuthentication

func NoAuthentication() Authentication

NoAuthentication returns an Authentication option that provides no real authentication. This is the default behavior if no authentication is specified.

func StaticTokenSource

func StaticTokenSource(token string) Authentication

StaticTokenSource returns an Authentication that always returns the same token.

func TokenSource

func TokenSource(ts oauth2.TokenSource) Authentication

StaticTokenSource returns an Authentication that always returns the same token.

type BaseCacheListener

type BaseCacheListener struct{}

BaseCacheListener is a base implementation of the CacheListener interface.

func (BaseCacheListener) AfterFetch

func (BaseCacheListener) AfterFetch(registry, pkg, version string, err error)

AfterFetch is a no-op implementation of the CacheListener interface.

func (BaseCacheListener) BeforeFetch

func (BaseCacheListener) BeforeFetch(registry, pkg, version string)

BeforeFetch is a no-op implementation of the CacheListener interface.

func (BaseCacheListener) OnCacheHit

func (BaseCacheListener) OnCacheHit(registry, pkg, version string)

OnCacheHit is a no-op implementation of the CacheListener interface.

func (BaseCacheListener) OnDelete

func (BaseCacheListener) OnDelete(registry, pkg, version string)

OnDelete is a no-op implementation of the CacheListener interface.

func (BaseCacheListener) OnFetch

func (BaseCacheListener) OnFetch(registry, pkg, version string, size int64)

OnFetch is a no-op implementation of the CacheListener interface.

func (BaseCacheListener) OnFetchWrite

func (BaseCacheListener) OnFetchWrite(registry, pkg, version string, bytes []byte)

OnFetchWrite is a no-op implementation of the CacheListener interface.

func (BaseCacheListener) OnUnpack

func (BaseCacheListener) OnUnpack(registry, pkg, version, file string, size int64)

OnUnpack is a no-op implementation of the CacheListener interface.

func (BaseCacheListener) OnUnpackWrite

func (BaseCacheListener) OnUnpackWrite(registry, pkg, version, file string, bytes []byte)

OnUnpackWrite is a no-op implementation of the CacheListener interface.

type Cache

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

Cache is a cache of downloaded and used FHIR packages from a given registry.

func DefaultCache

func DefaultCache() *Cache

DefaultCache creates a new cache with the default output path. The behavior can be controlled with the presence of the FHIR_CACHE environment variable.

func NewCache

func NewCache(outputPath string) *Cache

NewCache creates a new cache with the specified output path.

func (*Cache) AddClient

func (c *Cache) AddClient(registry string, client *Client)

AddClient adds a client to the cache.

func (*Cache) AddListener

func (c *Cache) AddListener(listener CacheListener)

AddListener adds a listener to the cache.

func (*Cache) AddLocalPackage

func (c *Cache) AddLocalPackage(pkg, version, path string)

AddLocalPackage adds a local package to the cache that may be referenced later. The package registry is always considered "local".

func (*Cache) CacheDir

func (c *Cache) CacheDir(registry, pkg, version string) string

CacheDir returns the directory where the specified package is cached. If the registry is unknown, or if any parameters are not set, an empty string is returned.

func (*Cache) Contains

func (c *Cache) Contains(registry, pkg, version string) bool

Contains returns true if the cache contains the specified package. Containment does not imply that the package is valid or usable -- just that the contents can be found on disk.

func (*Cache) Delete

func (c *Cache) Delete(registry, pkg, version string) error

Delete removes the specified package from the cache.

func (*Cache) Fetch

func (c *Cache) Fetch(ctx context.Context, registry, pkg, version string) error

Fetch downloads the specified package from the registry.

func (*Cache) ForceFetch

func (c *Cache) ForceFetch(ctx context.Context, registry, pkg, version string) error

ForceFetch forces a download of the specified package from the registry.

func (*Cache) Get

func (c *Cache) Get(registry, pkg, version string) (*Package, error)

Get returns the package from the cache.

func (*Cache) GetOrFetch

func (c *Cache) GetOrFetch(ctx context.Context, registry, pkg, version string) (*Package, error)

GetOrFetch returns the package from the cache, or fetches it if it is not present.

func (*Cache) Root

func (c *Cache) Root() string

Root returns the root directory of the cache.

type CacheListener

type CacheListener interface {

	// BeforeFetch is an event handler invoked before a fetch operation is initiated.
	BeforeFetch(registry, pkg, version string)

	// OnFetch is an event handler invoked when a fetch operation is initiated.
	OnFetch(registry, pkg, version string, size int64)

	// OnFetchWrite is an event handler invoked when bytes written during a fetch
	// operation.
	OnFetchWrite(registry, pkg, version string, bytes []byte)

	// AfterFetch is an event handler invoked after a fetch operation is completed.
	AfterFetch(registry, pkg, version string, err error)

	// OnUnpack is an event handler invoked when a file is unpacked.
	OnUnpack(registry, pkg, version, file string, size int64)

	// OnUnpackWrite is an event handler invoked when bytes written during a
	// file unpack operation.
	OnUnpackWrite(registry, pkg, version, file string, bytes []byte)

	// OnDelete is an event handler invoked when a package is deleted from the
	// cache.
	OnDelete(registry, pkg, version string)

	// OnCacheHit is an event handler invoked when a cache hit occurs.
	OnCacheHit(registry, pkg, version string)
	// contains filtered or unexported methods
}

CacheListener is a listener for events occurring when populating the cache.

type Client

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

Client is a registry client for accessing packages from the registry.

func NewClient

func NewClient(ctx context.Context, opts ...Option) (*Client, error)

NewClient creates a new registry client with the specified options. If no options are provided, the client will be created with the default registry for Simplifier.net, using no authentication.

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, name, version string) (content io.ReadCloser, bytes int64, err error)

Fetch will fetch the given package with the specified version from the connected registry.

type Downloader

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

Downloader is a utility for downloading packages and their dependencies into the Cache.

func NewDownloader

func NewDownloader(dest *Cache) *Downloader

NewDownloader creates a new Downloader.

func (*Downloader) Add

func (d *Downloader) Add(registry, pkg, version string, includeDependencies bool)

Add an explicit package to download from the registry. If includeDependencies is set to true, the downloader will also download the dependencies for the package.

func (*Downloader) Force

func (d *Downloader) Force(b bool) *Downloader

Force forces the downloader to fetch the package from the registry, even if it is already present in the cache.

func (*Downloader) Start

func (d *Downloader) Start(ctx context.Context) error

Start the download process which will load the cache with the downloaded packages and their dependencies.

This function will block until all worker threads have completed downloading the packages and their dependencies. If an error occurs during the download process, the function will return the first encountered error.

func (*Downloader) Workers

func (d *Downloader) Workers(n int) *Downloader

Workers sets the number of worker threads. If it is less than 1, the number of worker threads will be set to the number of CPUs on the system.

type Listeners

type Listeners []CacheListener

Listeners is a collection of [CacheListener]s that itself can be treated as a single listener.

func (Listeners) AfterFetch

func (l Listeners) AfterFetch(registry, pkg, version string, err error)

AfterFetch is an event handler invoked after a fetch operation is completed.

func (Listeners) BeforeFetch

func (l Listeners) BeforeFetch(registry, pkg, version string)

BeforeFetch is an event handler invoked before a fetch operation is initiated.

func (Listeners) OnCacheHit

func (l Listeners) OnCacheHit(registry, pkg, version string)

OnCacheHit is an event handler invoked when a cache hit occurs.

func (Listeners) OnDelete

func (l Listeners) OnDelete(registry, pkg, version string)

OnDelete is an event handler invoked when a package is deleted from the cache.

func (Listeners) OnFetch

func (l Listeners) OnFetch(registry, pkg, version string, size int64)

OnFetch is an event handler invoked when a fetch operation is initiated.

func (Listeners) OnFetchWrite

func (l Listeners) OnFetchWrite(registry, pkg, version string, bytes []byte)

OnFetchWrite is an event handler invoked when bytes written during a fetch operation.

func (Listeners) OnUnpack

func (l Listeners) OnUnpack(registry, pkg, version, file string, size int64)

OnUnpack is an event handler invoked when a file is unpacked.

func (Listeners) OnUnpackWrite

func (l Listeners) OnUnpackWrite(registry, pkg, version, file string, bytes []byte)

OnUnpackWrite is an event handler invoked when bytes written during a file unpack operation.

type Option

type Option interface {
	// contains filtered or unexported methods
}

func Auth

func Auth(auth Authentication) Option

Auth returns an Option that sets the authentication method for the client.

func URL

func URL(url string) Option

URL returns an Option that sets the URL of the registry client. If unspecified, the default registry will be https://packages.simplifier.net

type Package

type Package struct {
	// Path to the location on-disk where the registry has been unpacked to.
	Path string

	// Manifest is the package manifest.
	Manifest *PackageManifest

	// Ref is the reference to the package.
	Ref PackageRef
}

Package represents a FHIR package that has been unpacked on-disk.

func NewPackage

func NewPackage(path string) (*Package, error)

NewPackage creates a new package from the content at the specified file path. The path must contain a package.json content that defines information about the FHIR package.

func (*Package) Canonical

func (p *Package) Canonical() string

Canonical returns the canonical URL for the package.

func (*Package) Dependencies

func (p *Package) Dependencies() map[string]string

Dependencies returns the dependencies for the package.

func (*Package) FHIRVersionList

func (p *Package) FHIRVersionList() []string

FHIRVersionList returns the list of FHIR versions supported by the package.

func (*Package) Files

func (p *Package) Files() ([]string, error)

Files returns the list of files in the package.

func (*Package) Name

func (p *Package) Name() string

Name returns the name of the package.

func (*Package) Version

func (p *Package) Version() string

Version returns the version of the package.

type PackageManifest

type PackageManifest struct {
	Name            string            `json:"name"`
	Version         string            `json:"version"`
	FHIRVersionList []string          `json:"fhir-version-list,omitempty"`
	Type            string            `json:"type"`
	Dependencies    map[string]string `json:"dependencies"`
	License         string            `json:"license"`
	Title           string            `json:"title"`
	Description     string            `json:"description"`
	Author          string            `json:"author"`
	URL             string            `json:"url"`
	ToolsVersion    int               `json:"tools-version"`
	Canonical       string            `json:"canonical"`
	Homepage        string            `json:"homepage"`
}

PackageManifest represents the manifest of a package, in NPM package.json format.

type PackageRef

type PackageRef string

PackageRef is a string that is always in the form of <registry>::<package>@<version>. This is intended for easily passing along package references to other utilities that need this data in some structured manner.

func NewPackageRef

func NewPackageRef(registry, name, version string) PackageRef

func (PackageRef) Name

func (p PackageRef) Name() string

Name returns the name of the package reference.

func (PackageRef) Parts

func (p PackageRef) Parts() (registry, name, version string)

Parts returns the registry, name, and version of the package reference.

func (PackageRef) Registry

func (p PackageRef) Registry() string

Registry returns the registry of the package reference.

func (PackageRef) String

func (p PackageRef) String() string

String returns the string representation of the package reference.

func (PackageRef) Version

func (p PackageRef) Version() string

Version returns the version of the package reference.

Directories

Path Synopsis
internal
Package registrytest provides test-doubles and fakes for the [registry.Client] and other related types.
Package registrytest provides test-doubles and fakes for the [registry.Client] and other related types.

Jump to

Keyboard shortcuts

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