projects

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 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` and `design.yaml` descriptors (agni issue 170). A `design.yaml` names a design, and a `project.yaml` holds the config a team shares across a set of designs.

It is ONE implementation of that port. Tree walking, descriptor file names and design-folder-relative paths are facts about storing projects in directories. A database-backed store would not share them. 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. The tree root is depth 0. An operator can hand the server any folder as a tree, such as 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). It is exported because the store joins on this rule. A second definition 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. WriteDesign checks and cleans them as ParseDesign does, so a caller cannot write a descriptor that ParseDesign 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. A scaffolder appends the conventions and checklists sections. Their content is prose for an operator to edit, and this writer has no value of its own to put there.

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. 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. A design belongs to the project when its descriptor names that project in `extends`. A duplicate design id is rejected, for the same reason as a duplicate project id. A design may sit anywhere a mount reaches, since it names its parent and is not found under 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. A first-wins pick could 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 design names its project, and ResolveDesign never takes 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. Suppose instead that a project descriptor sits above a design that extends nothing. The author most likely forgot the `extends`, and reading the design would run it on the built-in config with nothing said. So that case is an error.

type Sources added in v0.3.6

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

Sources holds a descriptor's references outside itself, as written. They are the descriptor it extends and the files of each tier, each a descriptor-relative path or a mount:// URI. Only the store knows where the descriptor sits, so the store resolves them, and there a source naming nothing is an error.

func ParseDesign

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

ParseDesign reads a `design.yaml`. It returns the declared id, the wire message and the design's sources. Like ParseProject, it returns the id separately and refuses an unknown field.

`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, not where a loader would open it. The error then names the descriptor, and the operator knows which file to fix.

func ParseProject

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

ParseProject reads a `project.yaml`. It returns the declared id, the wire message and the project's sources, and the store resolves those sources.

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 use to address this tree. It is also the value of Project.mount.
	Mount string
	FS    fs.FS
}

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

Jump to

Keyboard shortcuts

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