base

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2020 License: GPL-3.0 Imports: 35 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 MaxNumDatasetRowsInPreview = 100

MaxNumDatasetRowsInPreview is the highest number of rows a dataset preview can contain

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 (

	// 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

func CloseDataset added in v0.7.0

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

CloseDataset ensures all open dataset files are closed

func ConvertBodyFile added in v0.7.2

func ConvertBodyFile(file qfs.File, in, out *dataset.Structure, limit, offset int, all bool) (data []byte, err error)

ConvertBodyFile takes an input file & structure, and converts a specified selection to the structure specified by out

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, streams ioes.IOStreams, ds, dsPrev *dataset.Dataset, sw SaveSwitches) (ref reporef.DatasetRef, err error)

CreateDataset uses dsfs to add a dataset to a repo's store, updating all references within the repo if successful

func CreatePreview added in v0.9.5

func CreatePreview(ctx context.Context, r repo.Repo, ref dsref.Ref) (ds *dataset.Dataset, err error)

CreatePreview generates a preview for a dataset version

func DatasetBodyFile added in v0.7.0

func DatasetBodyFile(ctx context.Context, store cafs.Filestore, ds *dataset.Dataset) (qfs.File, error)

DatasetBodyFile creates a streaming data file from a Dataset using the following precedence: * ds.BodyBytes not being nil (requires ds.Structure.Format be set to know data format) * ds.BodyPath being a url * ds.BodyPath being a path on the local filesystem

func DatasetLogFromHistory added in v0.9.1

func DatasetLogFromHistory(ctx context.Context, r repo.Repo, ref reporef.DatasetRef, offset, limit int, loadDatasets bool) (rlog []reporef.DatasetRef, err error)

DatasetLogFromHistory fetches the history of changes to a dataset by walking backwards through dataset commits. if loadDatasets is true, dataset information will be populated TODO(dlong): Convert to use dsref.Ref (for input) and dsref.VersionInfo (for output)

func FetchDataset

func FetchDataset(ctx context.Context, r repo.Repo, ref *reporef.DatasetRef, pin, load bool) (err error)

FetchDataset grabs a dataset from a remote source

func GenerateAvailableName added in v0.9.3

func GenerateAvailableName(r repo.Repo, peername, prefix string) string

GenerateAvailableName creates a name for the dataset that is not currently in use

func InLocalNamespace

func InLocalNamespace(r repo.Repo, ref *reporef.DatasetRef) bool

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

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 string, limit, offset int, RPC, publishedOnly, showVersions bool) (res []reporef.DatasetRef, err error)

ListDatasets lists datasets from a repo

func LoadRevs

func LoadRevs(ctx context.Context, r repo.Repo, ref reporef.DatasetRef, 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 MaybeInferName added in v0.9.3

func MaybeInferName(ds *dataset.Dataset) bool

MaybeInferName infer a name for the dataset if none is set

func ModifyDatasetRef added in v0.9.1

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

ModifyDatasetRef changes a dsref in the repository refstore, either name or path, and returns a versionInfo describing the resulting dataset reference. Use for renaming a dataset's pretty name or for rewinding to before some recent number of commits.

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 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 PinDataset

func PinDataset(ctx context.Context, r repo.Repo, ref reporef.DatasetRef) error

PinDataset marks a dataset for retention in a store

func PrepareDatasetSave

func PrepareDatasetSave(ctx context.Context, r repo.Repo, peername, name string) (prev, mutable *dataset.Dataset, prevPath string, err error)

PrepareDatasetSave prepares a save by loading the previous commit, opening the body file, and constructing a mutable version that has no transform or commit.

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 ReadBody added in v0.9.1

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

ReadBody 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, ref *reporef.DatasetRef) (err error)

ReadDataset grabs a dataset from the store

func ReadDatasetPath added in v0.7.0

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

ReadDatasetPath takes a path string, parses, canonicalizes, loads a dataset pointer, and opens the file The medium-term goal here is to obfuscate use of reporef.DatasetRef, which we're hoping to deprecate

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 Recall added in v0.9.1

func Recall(ctx context.Context, r repo.Repo, str string, ref reporef.DatasetRef) (*dataset.Dataset, error)

Recall loads revisions of a dataset from history

func RemoveEntireDataset added in v0.9.5

func RemoveEntireDataset(ctx context.Context, r repo.Repo, ref dsref.Ref, history []DatasetLogItem) (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 occured, 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.Ref, 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 Render

func Render(ctx context.Context, r repo.Repo, ref reporef.DatasetRef, 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) (string, 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 SaveDataset added in v0.9.1

func SaveDataset(ctx context.Context, r repo.Repo, str ioes.IOStreams, changes *dataset.Dataset, secrets map[string]string, scriptOut io.Writer, sw SaveSwitches) (ref reporef.DatasetRef, err error)

SaveDataset initializes a dataset from a dataset pointer and data file

func Select

func Select(ctx context.Context, r repo.Repo, ref reporef.DatasetRef, path string) (interface{}, error)

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

func SetFileHidden added in v0.9.2

func SetFileHidden(path string) error

SetFileHidden ensures the filename begins with a dot. Other OSes may do more

func SetPublishStatus

func SetPublishStatus(r repo.Repo, ref *reporef.DatasetRef, published bool) error

SetPublishStatus updates the Published field of a dataset ref

func ToDatasetRef added in v0.9.0

func ToDatasetRef(path string, r repo.Repo, _ bool) (*reporef.DatasetRef, error)

ToDatasetRef parses the dataset ref and looks it up in the refstore, allows refs with no history TODO(dustmop): In a future change, remove the third parameter from this function

func UnpinDataset

func UnpinDataset(ctx context.Context, r repo.Repo, ref reporef.DatasetRef) error

UnpinDataset unmarks a dataset for retention in a store

func Validate added in v0.9.1

func Validate(ctx context.Context, r repo.Repo, body qfs.File, st *dataset.Structure) ([]jsonschema.ValError, 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

func WriteHiddenFile added in v0.9.4

func WriteHiddenFile(path, content string) error

WriteHiddenFile ensures the filename begins with a dot, and writes content to it. Other Operating Systems may do more

Types

type DatasetLogItem added in v0.9.1

type DatasetLogItem = logbook.DatasetLogItem

DatasetLogItem aliases the type from logbook

func DatasetLog

func DatasetLog(ctx context.Context, r repo.Repo, ref reporef.DatasetRef, limit, offset int, loadDatasets bool) ([]DatasetLogItem, error)

DatasetLog fetches the change version history of a dataset

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