Documentation
¶
Overview ¶
Package projects is the filesystem-backed implementation of service.ProjectStore. It discovers the `project.yaml` / `design.yaml` descriptors that name a design and the set of designs a team shares config across (agni issue 170).
It is ONE implementation of that port. Tree walking, descriptor file names, and design-folder-relative paths are facts about storing projects in directories, which a database-backed store would not share, so the port lives in `service/` and nothing above it imports this package.
The descriptors parse straight into the wire types (`webapi.Project`, `webapi.Design`), with no third Go shape between the YAML and the proto, because the proto is the contract (CONSTRAINTS C2).
Index ¶
- Constants
- func CleanRel(rel string) string
- func ParseDesign(r io.Reader) (id string, d *webapi.Design, err error)
- func WriteDesign(w io.Writer, header, id, title, entry string, companions []string) error
- func WriteProject(w io.Writer, header, id, title string, names *ProjectConfigNames) error
- func WriteProjectExtending(w io.Writer, header, id, title, extends string, names *ProjectConfigNames) error
- type FSStore
- func (s *FSStore) Design(ctx context.Context, name string) (*webapi.Design, error)
- func (s *FSStore) Designs(ctx context.Context, parent string) ([]*webapi.Design, error)
- func (s *FSStore) Project(ctx context.Context, name string) (*webapi.Project, error)
- func (s *FSStore) Projects(context.Context) ([]*webapi.Project, error)
- func (s *FSStore) ResolveDesign(_ context.Context, uri artifact.URI) (*webapi.Design, *webapi.Project, error)
- type ProjectConfigNames
- type Tree
Constants ¶
const ( ProjectDescriptor = "project.yaml" DesignDescriptor = "design.yaml" )
The two descriptor file names, confined to this package for the reason in the package doc.
const MaxDepth = 4
MaxDepth bounds the downward walk that discovers descriptors under a tree, counting the tree root as depth 0. A tree is whatever folder an operator handed the server, possibly a build output or a home directory, so an unbounded walk would stat all of it on every listing. Four levels reaches `<root>/<project>/designs/<design>/`, one deeper than a review project's layout.
Variables ¶
This section is empty.
Functions ¶
func CleanRel ¶
CleanRel normalizes a descriptor-relative file name for comparison (forward slashes, no `./`, no trailing slash). Exported because the store joins on this rule, and a second spelling of "clean" would stop a companion being recognised as one.
func ParseDesign ¶
ParseDesign reads a `design.yaml`, returning the declared id and the wire message, with the same id-separate and strict-field posture as ParseProject.
`entry_uri` and `companion_uris` come back holding DESIGN-FOLDER-RELATIVE NAMES, not URIs. The store turns them into URIs when it locates the design, and nothing outside this package observes the intermediate state.
An entry or companion that escapes the design folder is rejected here rather than where a loader would open it, so the error names the descriptor the operator has to fix.
func WriteDesign ¶
WriteDesign writes a `design.yaml`, the write half of ParseDesign.
entry and companions are descriptor-relative names, cleaned on the way in on the same terms ParseDesign cleans them, so a caller cannot write a descriptor its own parser would reject.
func WriteProject ¶
func WriteProject(w io.Writer, header, id, title string, names *ProjectConfigNames) error
WriteProject writes a `project.yaml`, the write half of ParseProject. It lives here so the descriptor SHAPE has one definition, and TestDescriptorRoundTrip pins the two halves together.
names is optional. Passing nil declares nothing, which suits a scaffolder writing the conventional layout, since the defaults already name `profiles`, `params`, `symbols` and `lib`. The conventions and checklists sections are a scaffolder's to append, since their content is prose an operator edits rather than a value this writer could own.
header is prose written as a YAML comment above the document, "" for none.
func WriteProjectExtending ¶
func WriteProjectExtending(w io.Writer, header, id, title, extends string, names *ProjectConfigNames) error
WriteProjectExtending is WriteProject plus a declared `extends`, for a scaffolder writing a project that inherits shared config. An empty extends writes no key at all.
Types ¶
type FSStore ¶
type FSStore struct {
// contains filtered or unexported fields
}
FSStore is the filesystem-backed service.ProjectStore. Nothing above the port knows it exists, because the tree walking below is only true of keeping projects in directories.
It caches, but every read revalidates against the filesystem before returning, so an operator's edit to a descriptor is visible on the very next request. See cache.go.
func NewFSStore ¶
NewFSStore returns a store over the given trees, searched in order.
func (*FSStore) Designs ¶
Designs returns one project's designs, ordered by resource name, with a duplicate id rejected on the same reasoning as a duplicate project id.
func (*FSStore) Projects ¶
Projects discovers every project across the trees, ordered by resource name.
A duplicate id is an ERROR rather than a first-wins pick, since first-wins would answer a question about project A with project B's designs.
func (*FSStore) ResolveDesign ¶
func (s *FSStore) ResolveDesign(_ context.Context, uri artifact.URI) (*webapi.Design, *webapi.Project, error)
ResolveDesign maps a URI to the design containing it and that design's project. It walks UP from the URI's path, so the answer costs a few stats however many designs a tree holds.
A miss is (nil, nil, nil), the ordinary state of a mounted folder.
A design with no enclosing project is NOT a miss. It comes back with its declaration intact and an EMPTY `name`, since a resource name needs a parent, and the CLI still honours the declaration.
type ProjectConfigNames ¶
type ProjectConfigNames struct {
Profiles string
Params string
Symbols string
Lib string
Queries string
}
ProjectConfigNames is what a parsed project descriptor says its config is called, before anything checks whether those files exist. An empty entry means the project opted OUT of that tier, which is distinct from "not declared, so use the default".
func ParseProject ¶
ParseProject reads a `project.yaml`, returning the declared id and the wire message.
The id comes back SEPARATELY rather than as `Project.name`, because a bare id is not a resource name and only the store knows where the descriptor was reached.
An unknown field is an ERROR, so a misspelled key in a hand-written descriptor fails loudly rather than silently configuring nothing.