projects

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	ProjectDescriptor = "project.yaml"
	DesignDescriptor  = "design.yaml"
)

The two descriptor file names, confined to this package for the reason in the package doc.

View Source
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>/<team>/<project>/<design>/` with one to spare.

Variables

This section is empty.

Functions

func CleanRel

func CleanRel(rel string) string

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 WriteDesign

func WriteDesign(w io.Writer, header, id, title, entry string, companions []string, src Sources) error

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. src.Extends names the design's project, "" for a design in none.

func WriteProject

func WriteProject(w io.Writer, header, id, title string, src Sources) 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.

src names the project's parent and its file tiers, as ParseProject returns them. 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.

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

func NewFSStore(trees ...Tree) *FSStore

NewFSStore returns a store over the given trees, searched in order.

func (*FSStore) Design

func (s *FSStore) Design(ctx context.Context, name string) (*webapi.Design, error)

Design returns one design by resource name, or ErrNotFound.

func (*FSStore) Designs

func (s *FSStore) Designs(ctx context.Context, parent string) ([]*webapi.Design, error)

Designs returns one project's designs, the descriptors that name it in `extends`, ordered by resource name, with a duplicate id rejected on the same reasoning as a duplicate project id. A design may sit anywhere a mount reaches, since its parent is named rather than found above it.

func (*FSStore) Project

func (s *FSStore) Project(ctx context.Context, name string) (*webapi.Project, error)

Project returns one project by resource name, or ErrNotFound.

func (*FSStore) Projects

func (s *FSStore) Projects(context.Context) ([]*webapi.Project, error)

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 the project that design extends. It walks UP from the URI's path to find the design, so the answer costs a few stats however many designs a tree holds. The project is the one the design names, never one found above it.

A miss is (nil, nil, nil), the ordinary state of a mounted folder.

A design that extends nothing 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. A design that extends nothing while a project descriptor sits above it is an error, since that is the shape of a forgotten `extends`, and reading it would run it on the built-in config with nothing said.

type Sources added in v0.3.6

type Sources struct {
	Extends  string
	Profiles []string
	Params   []string
	Symbols  []string
	Lib      []string
	Queries  []string
}

Sources is what a descriptor names outside itself, as written: the descriptor it extends and the files of each tier, each a descriptor-relative path or a mount:// URI. The store resolves them, since only it knows where the descriptor sits, and a source naming nothing is an error there.

func ParseDesign

func ParseDesign(r io.Reader) (id string, d *webapi.Design, src Sources, err error)

ParseDesign reads a `design.yaml`, returning the declared id, the wire message and the sources it names, 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 ParseProject

func ParseProject(r io.Reader) (id string, p *webapi.Project, src Sources, err error)

ParseProject reads a `project.yaml`, returning the declared id, the wire message and the sources it names, which the store resolves.

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. A design's own keys are refused too, naming where they go.

type Tree

type Tree struct {
	// Mount is the name callers address this tree by, and the value that lands in Project.mount.
	Mount string
	FS    fs.FS
}

Tree is one named filesystem the store looks in: a mount on a server, a bounded slice of the local filesystem for the CLI, an embedded FS in a test.

Jump to

Keyboard shortcuts

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