Help us shape the future of Go! Take the 2026 Go Developer Survey

store

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package store loads collections from disk, resolves diagnostic positions, produces canonical formatting changes and writes files atomically.

Index

Constants

View Source
const GeneratedAsyncDescription = descriptionsDir + "/requests.asyncapi.yaml"

GeneratedAsyncDescription is the collection-relative path of the AsyncAPI description Flowi derives from the collection's async requests; it exists only while the collection has one.

View Source
const GeneratedDescription = descriptionsDir + "/requests.openapi.yaml"

GeneratedDescription is the collection-relative path of the OpenAPI description Flowi derives from the collection's requests.

Variables

View Source
var (
	ErrNotCollection     = errors.New("directory is not a collection (no flowi.yaml)")
	ErrAlreadyCollection = errors.New("directory already contains flowi.yaml")
)

Errors returned by the store.

Functions

func Apply

func Apply(changes []FileChange) error

Apply writes each change atomically: the new content goes to a temporary file in the same directory, which then replaces the target. Existing files keep their permissions; new files get 0644.

func RepairRefs

func RepairRefs(c model.Collection, resolve RefResolver) model.Collection

RepairRefs returns a copy of c with every reference's path hint replaced by the resolver's answer. The input is not modified.

func Watch

func Watch(ctx context.Context, roots []string) (<-chan Change, error)

Watch reports changes to collection files under roots. Roots must be absolute with symlinks resolved, as Load returns them.

Goroutine ownership: Watch starts one goroutine that owns the fsnotify watcher and the returned channel. It exits, closing the channel, when ctx is done or the watcher fails (after sending a Change with Err set).

Types

type Change

type Change struct {
	Root string
	File string
	Op   ChangeOp
	Err  error
}

Change reports that a collection file changed. When Err is set the watcher has stopped because of it and the channel closes next.

type ChangeOp

type ChangeOp int

ChangeOp says what happened to a file.

const (
	ChangeCreated ChangeOp = iota + 1
	ChangeModified
	ChangeRemoved
	// ChangeRescan means events were lost: reload the whole collection at
	// Root (File equals Root).
	ChangeRescan
)

Change operations.

type Codec

type Codec interface {
	DecodeManifest(file string, data []byte) (model.Manifest, diag.List)
	DecodeFolder(file, dir string, data []byte) (model.Folder, diag.List)
	DecodeEnvironment(file string, data []byte) (model.Environment, diag.List)
	DecodeRequest(file, path string, data []byte) (model.Request, diag.List)
	DecodeFlow(file, path string, data []byte) (model.Flow, diag.List)
	DecodeBlueprint(file, path string, data []byte) (model.Blueprint, diag.List)
	EncodeManifest(model.Manifest) ([]byte, error)
	EncodeFolder(model.Folder) ([]byte, error)
	EncodeEnvironment(model.Environment) ([]byte, error)
	EncodeRequest(model.Request) ([]byte, error)
	EncodeFlow(model.Flow) ([]byte, error)
	EncodeBlueprint(model.Blueprint) ([]byte, error)
	Locate(data []byte, yamlPath string) (diag.Position, bool)
	HasComments(data []byte) bool
}

Codec converts collection files to and from the model.

type FileChange

type FileChange struct {
	File          string
	Old           []byte
	New           []byte
	DropsComments bool
}

FileChange is a file whose canonical content differs from disk. Old is nil for a new file. DropsComments is set when Old has comments, which the canonical form does not keep.

type RefResolver

type RefResolver func(model.Ref) (string, bool)

RefResolver returns the current path of a referenced entity, or false when it cannot be resolved (the hint is then left unchanged).

func LocalResolver

func LocalResolver(c model.Collection) RefResolver

LocalResolver resolves references within c itself.

type Store

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

Store reads and writes collections. It remembers the bytes of every file it loaded so diagnostics can be positioned and formatting compared without re-reading the disk.

func New

func New(c Codec) *Store

New returns a store using codec.

func (*Store) DecodeEnvironment

func (s *Store) DecodeEnvironment(file string, data []byte) (model.Environment, diag.List)

DecodeEnvironment reads the content of an environment file.

func (*Store) DecodeFlowBody

func (s *Store) DecodeFlowBody(file, path string, data []byte) (model.Flow, diag.List)

DecodeFlowBody reads the text EncodeFlowBody wrote; diagnostics are positioned in data.

func (*Store) EncodeBlueprint

func (s *Store) EncodeBlueprint(b model.Blueprint) ([]byte, error)

EncodeBlueprint is the canonical file content of b.

func (*Store) EncodeEnvironment

func (s *Store) EncodeEnvironment(e model.Environment) ([]byte, error)

EncodeEnvironment is the canonical file content of e. A name equal to the file stem is left out, as Load derives it.

func (*Store) EncodeFlow

func (s *Store) EncodeFlow(c model.Collection, f model.Flow) ([]byte, error)

EncodeFlow is the canonical file content of f: an Arazzo document whose steps name c's requests by operationId (see EncodeFlow in package arazzo).

func (*Store) EncodeFlowBody

func (s *Store) EncodeFlowBody(f model.Flow) ([]byte, error)

EncodeFlowBody is the flow's own data in canonical form: the text kept in the Arazzo file's x-flowi-flow, and what the editor's code view shows.

func (*Store) EncodeFolder

func (s *Store) EncodeFolder(f model.Folder) ([]byte, error)

EncodeFolder is the canonical _folder.yaml for f.

func (*Store) EncodeManifest

func (s *Store) EncodeManifest(m model.Manifest) ([]byte, error)

EncodeManifest encodes a collection's flowi.yaml.

func (*Store) EncodeOverlay

func (s *Store) EncodeOverlay(o model.Overlay) ([]byte, error)

EncodeOverlay encodes a flowi overlay as its file.

func (*Store) EncodeRequest

func (s *Store) EncodeRequest(r model.Request) ([]byte, error)

EncodeRequest is the canonical file content of r.

func (*Store) Format

func (s *Store) Format(c model.Collection) ([]FileChange, error)

Format returns the files of c whose canonical encoding differs from what was loaded, after repairing path hints within the collection. It writes nothing; pass the result to Apply.

func (*Store) HasComments

func (s *Store) HasComments(data []byte) bool

HasComments reports whether file content has comments, which the canonical encoding does not keep.

func (*Store) Init

func (s *Store) Init(dir string, m model.Manifest) error

Init creates a new collection in dir: flowi.yaml plus the requests and flows directories. It refuses a directory that already holds a collection.

func (*Store) Load

func (s *Store) Load(root string) (model.Collection, diag.List, error)

Load reads the collection at root. User problems are returned as diagnostics; the error is reserved for I/O failures and ErrNotCollection.

func (*Store) LoadEnvironments

func (s *Store) LoadEnvironments(dir string, scope model.ID) ([]model.Environment, diag.List, error)

LoadEnvironments reads the global environment files in dir (one <name>.yaml each). A missing dir means there are none. Every environment is stamped with scope, the vault scope of its secrets. Problems are diagnostics; a broken file does not hide the others.

func (*Store) Locate

func (s *Store) Locate(d diag.Diagnostic) diag.Diagnostic

Locate fills in the position of a diagnostic (and its related locations) from its YAML path, when the position is not already known.

func (*Store) ReloadFile

func (s *Store) ReloadFile(c model.Collection, file string) (model.Collection, diag.List, error)

ReloadFile re-reads one file and returns a new collection with that file's entity replaced, added or (if the file is gone) removed.

Jump to

Keyboard shortcuts

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