Documentation
¶
Overview ¶
Package store loads collections from disk, resolves diagnostic positions, produces canonical formatting changes and writes files atomically.
Index ¶
- Constants
- Variables
- func Apply(changes []FileChange) error
- func RepairRefs(c model.Collection, resolve RefResolver) model.Collection
- func Watch(ctx context.Context, roots []string) (<-chan Change, error)
- type Change
- type ChangeOp
- type Codec
- type FileChange
- type RefResolver
- type Store
- func (s *Store) DecodeFlowBody(file, path string, data []byte) (model.Flow, diag.List)
- func (s *Store) EncodeBlueprint(b model.Blueprint) ([]byte, error)
- func (s *Store) EncodeEnvironment(e model.Environment) ([]byte, error)
- func (s *Store) EncodeFlow(c model.Collection, f model.Flow) ([]byte, error)
- func (s *Store) EncodeFlowBody(f model.Flow) ([]byte, error)
- func (s *Store) EncodeFolder(f model.Folder) ([]byte, error)
- func (s *Store) EncodeRequest(r model.Request) ([]byte, error)
- func (s *Store) Format(c model.Collection) ([]FileChange, error)
- func (s *Store) HasComments(data []byte) bool
- func (s *Store) Init(dir string, m model.Manifest) error
- func (s *Store) Load(root string) (model.Collection, diag.List, error)
- func (s *Store) LoadEnvironments(dir string, scope model.ID) ([]model.Environment, diag.List, error)
- func (s *Store) Locate(d diag.Diagnostic) diag.Diagnostic
- func (s *Store) ReloadFile(c model.Collection, file string) (model.Collection, diag.List, error)
Constants ¶
const GeneratedAsyncDescription = descriptionsDir + "/requests.asyncapi.yaml"
GeneratedAsyncDescription is the collection-relative path of the AsyncAPI description Flow-I derives from the collection's async requests; it exists only while the collection has one.
const GeneratedDescription = descriptionsDir + "/requests.openapi.yaml"
GeneratedDescription is the collection-relative path of the OpenAPI description Flow-I derives from the collection's requests.
Variables ¶
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 ¶
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 ¶
Change reports that a collection file changed. When Err is set the watcher has stopped because of it and the channel closes next.
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 ¶
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 ¶
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 (*Store) DecodeFlowBody ¶
DecodeFlowBody reads the text EncodeFlowBody wrote; diagnostics are positioned in data.
func (*Store) EncodeBlueprint ¶
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 ¶
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 ¶
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 ¶
EncodeFolder is the canonical _folder.yaml for f.
func (*Store) EncodeRequest ¶
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 ¶
HasComments reports whether file content has comments, which the canonical encoding does not keep.
func (*Store) Init ¶
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 ¶
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.