projects

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 20 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>/<project>/designs/<design>/`, one deeper than a review project's layout.

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 ParseDesign

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

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

func WriteDesign(w io.Writer, header, id, title, entry string, companions []string) 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.

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

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, ordered by resource name, with a duplicate id rejected on the same reasoning as a duplicate project id.

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

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

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.

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