base

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: GPL-3.0 Imports: 29 Imported by: 1

Documentation

Overview

Package base defines business that operates on local data. it's main job is to composing APIs from the lower half of our tech stack, providing uniform functions for higher up packages, mainly p2p and lib. p2p and lib use base as the only way of operate on the local repo Here's some ascii art to clarify the stack:

┌───────────────┐ ┌───────────────┐
│      cmd      │ │     api       │
└───────────────┘ └───────────────┘
┌─────────────────────────────────┐
│               lib               │
└─────────────────────────────────┘
┌───────────────────────┐
│          p2p          │
└───────────────────────┘
┌─────────────────────────────────┐
│              base               │  <-- you are here
└─────────────────────────────────┘
┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐
│ repo │ │ dsfs │ │ qfs  │ │ ...  │
└──────┘ └──────┘ └──────┘ └──────┘

There are packages omitted from this diagram, but these are the vitals. base functions mainly work with repo.Repo instances, using repo interface methods and related packages to do their work. This is part of a larger pattern of having lib rely on lower level interfaces wherever possible to enhance configurability

Index

Constants

View Source
const TimeoutDuration = 100 * time.Millisecond

TimeoutDuration is the duration allowed for a datasetLog lookup before it times out

Variables

View Source
var DefaultTemplate = `` /* 249-byte string literal not displayed */

DefaultTemplate is the template that render will fall back to should no template be available

View Source
var ErrDatasetLogTimeout = fmt.Errorf("datasetLog: timeout")

ErrDatasetLogTimeout is an error for when getting the datasetLog times out

View Source
var ErrNameTaken = fmt.Errorf("name already in use")

ErrNameTaken is an error for when a name for a new dataset is already being used

View Source
var ErrNoBodyToInline = fmt.Errorf("no body to inline")

ErrNoBodyToInline is an error returned when a dataset has no body for inlining

View Source
var ErrUnlistableReferences = errors.New("Warning: Some datasets could not be listed, because of invalid state. These datasets still exist in your repository, but have references that cannot be resolved. This will be fixed in a future version. You can see all datasets by using `qri list --raw`")

ErrUnlistableReferences is an error for when listing references encounters some problem, but these problems are non-fatal

View Source
var (

	// OpenFileTimeoutDuration determines the maximium amount of time to wait for
	// a Filestore to open a file. Some filestores (like IPFS) fallback to a
	// network request when it can't find a file locally. Setting a short timeout
	// prevents waiting for a slow network response, at the expense of leaving
	// files unresolved.
	// TODO (b5) - allow -1 duration as a sentinel value for no timeout
	OpenFileTimeoutDuration = time.Millisecond * 250
)

Functions

func ApplyPath

func ApplyPath(ds *dataset.Dataset, path string) (interface{}, error)

ApplyPath gets a dataset value by applying a case.Sensitve.dot.separated.path ApplyPath cannot select file fields TODO(ramfox): consider replacing this with base.GetPathValue

func CloseDataset added in v0.7.0

func CloseDataset(ds *dataset.Dataset) (err error)

CloseDataset ensures all open dataset files are closed

func ConvertBodyFormat added in v0.6.1

func ConvertBodyFormat(bodyFile qfs.File, fromSt, toSt *dataset.Structure) (qfs.File, error)

ConvertBodyFormat rewrites a body from a source format to a destination format. TODO (b5): Combine this with ConvertBodyFile, update callers.

func CreateDataset

func CreateDataset(ctx context.Context, r repo.Repo, writeDest qfs.Filesystem, ds, dsPrev *dataset.Dataset, sw SaveSwitches) (res *dataset.Dataset, err error)

CreateDataset uses dsfs to add a dataset to a repo's store, updating the refstore

func DatasetLog

func DatasetLog(ctx context.Context, r repo.Repo, ref dsref.Ref, limit, offset int, loadDatasets bool) ([]dsref.VersionInfo, error)

DatasetLog fetches the change version history of a dataset

func Drop added in v0.9.9

func Drop(ds *dataset.Dataset, revStr string) error

Drop sets named components to nil from a revision string

func GenerateAvailableName added in v0.9.3

func GenerateAvailableName(ctx context.Context, pro *profile.Profile, resolver dsref.Resolver, prefix string) string

GenerateAvailableName creates a name for the dataset that is not currently in use. Generated names start with _2, implying the "_1" file is the original no-suffix name.

func GetBody added in v0.10.0

func GetBody(ds *dataset.Dataset, limit, offset int, all bool) (interface{}, error)

GetBody takes returns the Body as a go-native structure, using limit, offset, and all parameters to determine what part of the Body to return

func InLocalNamespace

func InLocalNamespace(ctx context.Context, r repo.Repo, ref dsref.Ref) bool

InLocalNamespace checks if a dataset ref is local, assumes the reference is already resolved

func InferValues

func InferValues(pro *profile.Profile, ds *dataset.Dataset) error

InferValues populates any missing fields that must exist to create a snapshot

func InlineJSONBody added in v0.7.2

func InlineJSONBody(ds *dataset.Dataset) error

InlineJSONBody reads the contents dataset.BodyFile() into a json.RawMessage, assigning the result to dataset.Body

func ListDatasets

func ListDatasets(ctx context.Context, r repo.Repo, term, profileID string, offset, limit int, publishedOnly, showVersions bool) ([]dsref.VersionInfo, error)

ListDatasets lists datasets from a repo

func LoadRevs

func LoadRevs(ctx context.Context, fs qfs.Filesystem, ref dsref.Ref, revs []*dsref.Rev) (res *dataset.Dataset, err error)

LoadRevs grabs a component of a dataset that exists <n>th generation ancestor of the referenced version, where presence of a component in a previous snapshot constitutes ancestry

func MaybeAddDefaultViz added in v0.8.0

func MaybeAddDefaultViz(ds *dataset.Dataset)

MaybeAddDefaultViz sets a dataset viz component and template if none exists TODO(dlong): This is deprecated and should be removed.

func ModifyRepoUsername added in v0.9.4

func ModifyRepoUsername(ctx context.Context, r repo.Repo, book *logbook.Book, from, to string) error

ModifyRepoUsername performs all tasks necessary to switch a username (formerly: peername) for a local repo, and must be called when a username is changed TODO (b5) - make this transactional

func NewTestDatasetLoader added in v0.10.0

func NewTestDatasetLoader(fs qfs.Filesystem, resolver dsref.Resolver) dsref.Loader

NewTestDatasetLoader constructs a loader that is useful for tests since they only need a simplified version of resolution and loading

func OpenDataset added in v0.7.0

func OpenDataset(ctx context.Context, fsys qfs.Filesystem, ds *dataset.Dataset) (err error)

OpenDataset prepares a dataset for use, checking each component for populated Path or Byte suffixed fields, consuming those fields to set File handlers that are ready for reading

func PrepareSaveRef added in v0.9.10

func PrepareSaveRef(
	ctx context.Context,
	pro *profile.Profile,
	book *logbook.Book,
	resolver dsref.Resolver,
	refStr string,
	bodyPathNameHint string,
	wantNewName bool,
) (dsref.Ref, bool, error)

PrepareSaveRef works out a dataset reference for saving a dataset version. When a dataset exists, resolve the initID & path. When no dataset with that name exists, ensure a locally-unique dataset name and create a new logbook history & InitID to write to. PrepareSaveRef returns a true boolean value if an initID was created successful calls to PrepareSaveRef always have an InitID, and will have the Path of the current version, if one exists

func RawDatasetRefs added in v0.9.3

func RawDatasetRefs(ctx context.Context, r repo.Repo) (string, error)

RawDatasetRefs converts the dataset refs to a string

func ReadBodyBytes added in v0.10.0

func ReadBodyBytes(ds *dataset.Dataset, format dataset.DataFormat, fcfg dataset.FormatConfig, limit, offset int, all bool) (data []byte, err error)

ReadBodyBytes grabs some or all of a dataset's body, writing an output in the desired format

func ReadDataset

func ReadDataset(ctx context.Context, r repo.Repo, path string) (ds *dataset.Dataset, err error)

ReadDataset grabs a dataset from the store

Deprecated - use LoadDataset instead

func ReadEntries added in v0.7.1

func ReadEntries(reader dsio.EntryReader) (interface{}, error)

ReadEntries reads entries and returns them as a native go array or map

func RemoveEntireDataset added in v0.9.5

func RemoveEntireDataset(ctx context.Context, r repo.Repo, ref dsref.Ref, history []dsref.VersionInfo) (didRemove string, removeErr error)

RemoveEntireDataset removes all of the information in the repository about a dataset. It will continue on even if some error occurs, returning a comma-separated list of what locations data was removed from, as well the last error that occurred, if any. Note that in particular, FSI is not handled at all by this function. Callers should also call any relevent FSI operations.

func RemoveNVersionsFromStore added in v0.9.1

func RemoveNVersionsFromStore(ctx context.Context, r repo.Repo, curr dsref.Ref, n int) (*dsref.VersionInfo, error)

RemoveNVersionsFromStore removes n versions of a dataset from the store starting with the most recent version when n == -1, remove all versions does not remove the dataset reference

func RenameDatasetRef added in v0.9.9

func RenameDatasetRef(ctx context.Context, r repo.Repo, ref dsref.Ref, newName string) (*dsref.VersionInfo, error)

RenameDatasetRef changes a dataset's pretty name by modifying the ref in the repository refstore, and returns a versionInfo describing the resulting dataset reference.

func Render

func Render(ctx context.Context, r repo.Repo, ds *dataset.Dataset, tmplData []byte) ([]byte, error)

Render executes a template for a dataset, returning a slice of HTML Render uses go's html/template package to generate html documents from an input dataset. It's API has been adjusted to use lowerCamelCase instead of UpperCamelCase naming conventions

func RenderReadme added in v0.9.1

func RenderReadme(ctx context.Context, file qfs.File) ([]byte, error)

RenderReadme converts the markdown from the file into html.

func ReplaceRefIfMoreRecent added in v0.9.1

func ReplaceRefIfMoreRecent(r repo.Repo, prev, curr *reporef.DatasetRef) error

ReplaceRefIfMoreRecent replaces the given ref in the ref store, if it is more recent then the ref currently in the refstore

func RewindDatasetRef added in v0.9.9

func RewindDatasetRef(ctx context.Context, r repo.Repo, curr, next dsref.Ref) (*dsref.VersionInfo, error)

RewindDatasetRef changes a dsref in the repository refstore, by setting the path back to an older value, and returns a versionInfo describing the resulting dataset reference.

func SaveDataset added in v0.9.1

func SaveDataset(
	ctx context.Context,
	r repo.Repo,
	writeDest qfs.Filesystem,
	initID string,
	prevPath string,
	changes *dataset.Dataset,
	runState *run.State,
	sw SaveSwitches,
) (ds *dataset.Dataset, err error)

SaveDataset saves a version of the dataset for the given initID at the current path

func Select

func Select(ctx context.Context, fs qfs.Filesystem, ref dsref.Ref, valuePath string) (interface{}, error)

Select loads a dataset value specified by case.Sensitve.dot.separated.paths

func SetPublishStatus

func SetPublishStatus(ctx context.Context, r repo.Repo, ref dsref.Ref, published bool) error

SetPublishStatus updates the Published field of a dataset ref

func StoredHistoricalDatasets added in v0.9.9

func StoredHistoricalDatasets(ctx context.Context, r repo.Repo, headPath string, offset, limit int, loadDatasets bool) (log []*dataset.Dataset, err error)

StoredHistoricalDatasets fetches the history of changes to a dataset by walking backwards through dataset commits. if loadDatasets is true, dataset information will be populated

func Validate added in v0.9.1

func Validate(ctx context.Context, r repo.Repo, body qfs.File, st *dataset.Structure) ([]jsonschema.KeyError, error)

Validate checks a dataset body for errors based on the structure's schema

func ValidateDataset

func ValidateDataset(ds *dataset.Dataset) (err error)

ValidateDataset checks that a dataset is semantically valid

Types

type SaveSwitches added in v0.9.8

type SaveSwitches = dsfs.SaveSwitches

SaveSwitches is an alias for the switches that control how saves happen

Directories

Path Synopsis
Package archive creates and consumes high-fidelity conversions of dataset documents for export & import
Package archive creates and consumes high-fidelity conversions of dataset documents for export & import
Package dsfs glues datsets to cafs (content-addressed-file-system)
Package dsfs glues datsets to cafs (content-addressed-file-system)
dstest
Package dstest defines an interface for reading test cases from static files leveraging directories of test dataset input files & expected output files
Package dstest defines an interface for reading test cases from static files leveraging directories of test dataset input files & expected output files
Package fill assigns arbitrary values to struct fields using reflection.
Package fill assigns arbitrary values to struct fields using reflection.

Jump to

Keyboard shortcuts

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