service

package
v0.0.0-...-ca9423e Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package service defines a service that maintains the state of a dependency graph. It is compatible with the github.com/creachadair/jrpc2 package, but can also be used independently.

Index

Constants

This section is empty.

Variables

View Source
var KeyNotFound = code.Register(404, "key not found")

KeyNotFound is the error code returned when a requested key is not found in the database.

Functions

This section is empty.

Types

type MatchReq

type MatchReq struct {
	// Match rows for this package. If package ends with "/...", any row with
	// that prefix is matched.
	Package string `json:"package"`

	// Match rows with this repository URL.
	Repository string `json:"repository"`

	// Only count the number of matching rows; do not emit them.
	CountOnly bool `json:"countOnly"`

	// Whether to include source file paths.
	IncludeFiles bool `json:"includeFiles"`

	// Whether to exclude direct dependencies.
	ExcludeDirects bool `json:"excludeDirects"`

	// Return at most this many rows (0 uses a reasonable default).
	Limit int `json:"limit"`

	// Resume reading from this page key.
	PageKey []byte `json:"pageKey"`
}

MatchReq is the request parameter to the Match method.

type MatchRsp

type MatchRsp struct {
	// The number of rows processed to obtain this result. If countOnly was true
	// in the request, this is the total number of matching rows.
	NumRows int `json:"numRows"`

	Rows     []*graph.Row `json:"rows,omitempty"`
	NextPage []byte       `json:"nextPage,omitempty"`
}

MatchRsp is the response from a successful Match query.

type Options

type Options struct {
	RepoDB  string // path of repository state database (required)
	GraphDB string // path of graph database (required)
	WorkDir string // working directory for update clones

	// The minimum polling interval for repository scans.
	MinPollInterval time.Duration

	// The maximum number of times a repository update may fail before that
	// repository is removed from the database.
	ErrorLimit int

	// Default sampling rate for scans (0..1); zero means 1.0.
	SampleRate float64

	// Default scale factor for ranking; zero means 4.
	RankScale int

	// Default damping factor for ranking; zero means 0.85.
	RankDamping float64

	// Default iteration count for ranking; zero means 10.
	RankIterations int

	// The maximum number of concurrent workers that may be processing updates.
	// A value less that or equal to zero means 1.
	Concurrency int

	// If set, this callback is invoked to deliver streaming logs from scan
	// operations. The server ensures that at most one goroutine is active in
	// this callback at once.
	StreamLog func(ctx context.Context, key string, value interface{}) error

	// The default page size for paginated responses (0 means 100).
	DefaultPageSize int

	// Open read-only, disallow updates.
	ReadOnly bool

	// Default package loader options.
	deps.Options
}

Options control the behaviour of a Server.

type RankReq

type RankReq struct {
	// Number of iterations to compute; > 0 required.
	Iterations int `json:"iterations"`

	// Damping factor (0..1).
	Damping float64 `json:"damping"`

	// Scale values to this number of significant figures (0 means don't scale).
	Scale int `json:"scale"`

	// Write the updated rankings back to the database.
	Update bool `json:"update"`

	LogProgress bool `json:"logProgress"` // push progress notifications
	LogUpdates  bool `json:"logUpdates"`  // push update notifications
}

RankReq is the request parameter to the Rank method.

type RankRsp

type RankRsp struct {
	NumRows  int `json:"numRows"`  // total count of rows examined
	NumRanks int `json:"numRanks"` // number of rankings updated

	Elapsed time.Duration `json:"elapsed"`
}

RankRsp is the response from a successful Rank query.

type RemoveReq

type RemoveReq struct {
	Repository   StringList `json:"repository"`
	Package      StringList `json:"package"`
	KeepPackages bool       `json:"keepPackages"`
	LogErrors    bool       `json:"logErrors"`
}

RemoveReq is the request parameter to the Remove method.

type RemoveRsp

type RemoveRsp struct {
	Repositories []string `json:"repositories,omitempty"` // repositories removed
	Packages     []string `json:"packages,omitempty"`     // packages removed
}

RemoveRsp is the result from a successful Remove call.

type RepoStatusReq

type RepoStatusReq struct {
	Repository string `json:"repository"`
}

RepoStatusReq is the request parameter to the RepoStatus method.

type RepoStatusRsp

type RepoStatusRsp struct {
	Status []*poll.Status `json:"status,omitempty"`
}

RepoStatusRsp is the response message from a successful RepoStatus call.

type ResolveReq

type ResolveReq struct {
	Package string `json:"package"`
}

ResolveReq is the request parameter to the Resolve method.

type ResolveRsp

type ResolveRsp struct {
	Repository string `json:"repository"`
	Prefix     string `json:"prefix"`
	ImportPath string `json:"importPath"`
}

ResolveRsp is the response value from a successful Resolve call.

func ResolveRepository

func ResolveRepository(ctx context.Context, req *ResolveReq) (*ResolveRsp, error)

ResolveRepository attempts to resolve the URL of the repository containing the specified import path, using the HTTP metadata protocol used by "go get". Unlike "go get", this resolver only considers Git targets.

type ReverseDep

type ReverseDep struct {
	Target string `json:"target"` // the target (imported) package

	Source string     `json:"source,omitempty"` // the source (importing) package
	Row    *graph.Row `json:"row,omitempty"`    // same, but the full row
}

A ReverseDep encodes a single reverse direct dependency relationship. The source package directly imports the target package.

type ReverseReq

type ReverseReq struct {
	// Find reverse dependencies for this package. If package ends with "/...",
	// any row with that prefix is matched.
	Package StringList `json:"package"`

	// Only count the number of matching rows; do not emit them.
	CountOnly bool `json:"countOnly"`

	// Filter out dependencies from packages in the same repository as the
	// target package or packages.
	FilterSameRepo bool `json:"filterSameRepo"`

	// If set, select only reverse dependencies matching this regexp.
	Matching string `json:"matching"`

	// If true, return the complete row for each dependendent package, rather
	// than only the import path.
	Complete bool `json:"complete"`

	// Return at most this many rows (0 uses a reasonable default).
	Limit int `json:"limit"`

	// Resume reading from this page key.
	PageKey []byte `json:"pageKey"`
}

ReverseReq is the request parameter to the Reverse method.

type ReverseRsp

type ReverseRsp struct {
	NumImports int           `json:"numImports"`
	Imports    []*ReverseDep `json:"imports,omitempty"`
	NextPage   []byte        `json:"nextPage,omitempty"`
}

ReverseRsp is the response from a successful Reverse query. If additional results are available, NextPage will contain an opaque page key that can be passed to retrieve the next chunk of results.

type ScanReq

type ScanReq struct {
	SampleRate    float64 `json:"sampleRate"`    // sampling rate, 0..1; 0 for default
	LogUpdates    bool    `json:"logUpdates"`    // push update notifications
	LogErrors     bool    `json:"logErrors"`     // push error notifications
	LogNonUpdates bool    `json:"logNonUpdates"` // push non-update notifications
}

ScanReq is the request parameter to the Scan method.

type ScanRsp

type ScanRsp struct {
	NumScanned  int `json:"numScanned"`        // number of repositories scanned
	NumDups     int `json:"numDups,omitempty"` // number of duplicates discarded
	NumSamples  int `json:"numSamples"`        // number of samples selected
	NumUpdates  int `json:"numUpdates"`        // number of repositories updated
	NumPackages int `json:"numPackages"`       // number of packages updated

	Elapsed time.Duration `json:"elapsed"` // time elapsed during the scan
}

ScanRsp is the final result from a successful Scan call.

type Server

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

A Server manages reads and updates to a database of dependencies.

func New

func New(opts Options) (*Server, error)

New constructs a new Server from the specified options. As long as the server is open, it holds a lock on the databases assigned to it. The caller must call Close when the server is no longer in use.

func (*Server) Close

func (u *Server) Close() error

Close shuts down the server and closes its underlying data stores.

func (*Server) Match

func (u *Server) Match(ctx context.Context, req *MatchReq) (*MatchRsp, error)

Match enumerates the rows of the graph matching the specified query. If more rows are available than the limit requested, the response will indicate the next offset of a matching row.

func (*Server) Methods

func (u *Server) Methods() handler.Map

Methods returns a method assigner for u.

func (*Server) Rank

func (u *Server) Rank(ctx context.Context, req *RankReq) (*RankRsp, error)

Rank computes pagerank for the nodes of the graph.

func (*Server) Remove

func (u *Server) Remove(ctx context.Context, req *RemoveReq) (*RemoveRsp, error)

Remove removes package and repositories from the database.

func (*Server) RepoStatus

func (u *Server) RepoStatus(ctx context.Context, req *RepoStatusReq) (*RepoStatusRsp, error)

RepoStatus reports the current status of the specified repository.

func (*Server) Resolve

func (*Server) Resolve(ctx context.Context, req *ResolveReq) (*ResolveRsp, error)

Resolve attempts to resolve the URL of the repository containing the specified import path, using the HTTP metadata protocol used by "go get". Unlike "go get", this resolver only considers Git targets.

func (*Server) Reverse

func (u *Server) Reverse(ctx context.Context, req *ReverseReq) (*ReverseRsp, error)

Reverse enumerates the reverse dependencies of one or more packages. The order of results is unspecified but deterministic.

func (*Server) Scan

func (u *Server) Scan(ctx context.Context, req *ScanReq) (*ScanRsp, error)

Scan performs a scan over all the repositories known to the repo database updating each one. Only one scanner is allowed at a time; concurrent calls to scan will report an error.

func (*Server) Update

func (u *Server) Update(ctx context.Context, req *UpdateReq) (*UpdateRsp, error)

Update processes a single update request. An error has concrete type *jrpc2.Error and errors during the update phase have a partial response attached as a data value.

type StringList

type StringList []string

A StringList is a slice of strings that can be decoded from JSON as either an array or a single string.

func (*StringList) UnmarshalJSON

func (s *StringList) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a StringList from JSON, accepting either a string value (corresponding to a single-element slice) or an array of strings.

type UpdateReq

type UpdateReq struct {
	// The URL of the repository to update, must be non-empty.
	Repository string `json:"repository"`

	// The storage tag for this snapshot of the repository (optional).
	Tag string `json:"tag"`

	// The reference name to update (optional).
	Reference string `json:"reference"`

	// The package prefix to attribute to packages in this repository.
	Prefix string `json:"prefix"`

	// If true, only check the repository state, do not update.
	CheckOnly bool `json:"checkOnly"`

	// If true, remove any packages currently attributed to this repository
	// before updating.
	Reset bool `json:"reset"`

	// If true, force an update even if one is not needed.
	Force bool `json:"force"`

	// Options for the package loader (if unset, service defaults are used).
	Options *deps.Options `json:"options"`
}

UpdateReq is the request parameter to the Update method.

type UpdateRsp

type UpdateRsp struct {
	Repository  string `json:"repository"`    // the fetch URL of the repository
	Tag         string `json:"tag,omitempty"` // the storage tag, if set.
	NeedsUpdate bool   `json:"needsUpdate"`   // whether an update was needed
	Reference   string `json:"reference"`     // the name of the target reference
	Digest      string `json:"digest"`        // the SHA-1 digest (hex) at the reference

	NumPackages int  `json:"numPackages,omitempty"` // the number of packages updated
	Errors      int  `json:"errors,omitempty"`      // number of consecutive update failures
	Removed     bool `json:"removed,omitempty"`     // true if removed due to the error limit
}

UpdateRsp is the response from a successful Update call.

Jump to

Keyboard shortcuts

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