workspace

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package workspace is the domain of where flags live: projects, their environments, and the unit types and attributes their targeting refers to. Other contexts refer to a project or an environment by the identifier types declared here, so every context means the same entity by the same type.

Index

Constants

View Source
const MaxEnvironments = 20

MaxEnvironments is how many environments a project has at most: every flag holds a configuration in each, and every SDK key reads one.

Variables

View Source
var ErrDeclarationKeyTaken = apperrors.Conflict("already_exists", "a unit type or attribute of the project already has this key")

ErrDeclarationKeyTaken refuses a unit type or attribute whose key the project's unit types or attributes already use: a rule names either by its key alone, so one key must mean one thing.

Functions

func CanDeleteEnvironment

func CanDeleteEnvironment(e Environment, count int) error

CanDeleteEnvironment refuses to delete e, one of its project's count environments, when it is the last, since a project always has somewhere to serve its flags from, or while it is protected. Deleting an environment removes its configurations and SDK keys and closes the change requests proposed for it, so a protected environment would otherwise lose everything its protection guards without any approval; it has to be unprotected first, which takes a permission of its own. The last environment is judged first: unprotecting it would not let it go.

func CheckEnvironmentCount added in v0.5.0

func CheckEnvironmentCount(existing int) error

CheckEnvironmentCount refuses adding an environment to a project that already has existing, which is the most it may.

func DiscoverableAttributeKey

func DiscoverableAttributeKey(key string) bool

DiscoverableAttributeKey reports whether key could be declared as an attribute: a key of the workspace, not the reserved one. Only such keys are worth showing as discovered, since nothing else can be declared.

Types

type Attribute

type Attribute struct {
	ID          AttributeID
	Project     ProjectID
	Key         string
	Name        string
	Description string
	Type        AttributeType
	// Standard attributes are predeclared in every project, so SDKs can rely
	// on them.
	Standard  bool
	CreatedAt time.Time
	UpdatedAt time.Time
	// Version counts the attribute's accepted changes, from 1.
	Version int64
}

Attribute is one named, typed value of a context a project declares.

func NewAttribute

func NewAttribute(attributeID AttributeID, project ProjectID, key, name, description string, typ AttributeType, now time.Time) (Attribute, error)

NewAttribute returns an attribute of project, declared rather than standard.

func StandardAttributesOf added in v0.3.0

func StandardAttributesOf(p Project, ids IDs) []Attribute

StandardAttributesOf returns the standard attributes p is created with, whatever else it is created with.

func (Attribute) CanDelete

func (a Attribute) CanDelete() error

CanDelete refuses to delete a standard attribute, which SDKs rely on finding in every project.

func (Attribute) Change

func (a Attribute) Change(c AttributeChange, now time.Time) (Attribute, bool, error)

Change returns the attribute with c applied at now, and whether anything changed. A standard attribute is renamed like any other and stays standard.

type AttributeChange

type AttributeChange struct {
	// Key and Type are refused whatever their value: rules written against
	// the attribute rely on both.
	Key         *string
	Type        *AttributeType
	Name        *string
	Description *string
}

AttributeChange is a change to an attribute; a nil field is left as it is.

type AttributeID

type AttributeID = id.Of[Attribute]

AttributeID identifies an attribute.

type AttributeType

type AttributeType string

AttributeType is the type of an attribute's values.

const (
	TypeString  AttributeType = "string"
	TypeNumber  AttributeType = "number"
	TypeBoolean AttributeType = "boolean"
	// TypeSemver is a semantic version, compared as one.
	TypeSemver AttributeType = "semver"
	TypeDate   AttributeType = "date"
	TypeList   AttributeType = "list"
)

The attribute types.

func AttributeTypes

func AttributeTypes() []AttributeType

AttributeTypes returns every attribute type.

func StandardAttributeType added in v0.3.0

func StandardAttributeType(key string) (AttributeType, bool)

StandardAttributeType returns the type of the standard attribute keyed key, and whether there is one.

type Draft

type Draft struct {
	Key, Name, Description string
	Type                   AttributeType
}

Draft is what a project is created with besides itself: the key and name of a default environment, unit type or standard attribute, and its description or type where it has one.

type Environment

type Environment struct {
	ID      EnvironmentID
	Project ProjectID
	// Key names the environment in SDK calls and never changes.
	Key  string
	Name string
	// SortOrder places the environment among its project's, the first
	// created first.
	SortOrder int
	CreatedAt time.Time
	UpdatedAt time.Time
	// Version counts the environment's accepted changes, from 1.
	Version int64
	// Protected marks an environment whose ruleset changes only through an
	// approved change request; SDKs ignore local overrides in it.
	Protected bool
}

Environment is one of a project's environments, such as production.

func NewEnvironment

func NewEnvironment(environmentID EnvironmentID, project ProjectID, key, name string, sortOrder int, now time.Time) (Environment, error)

NewEnvironment returns an environment of project placed at sortOrder.

func (Environment) Change

Change returns the environment with c applied at now, and whether anything changed.

func (Environment) Protect added in v0.2.0

func (e Environment) Protect(protected bool, now time.Time) (Environment, bool)

Protect returns the environment protected or not as protected says, at now, and whether that changed anything.

type EnvironmentChange

type EnvironmentChange struct {
	// Key is refused whatever its value, since a key never changes.
	Key  *string
	Name *string
}

EnvironmentChange is a change to an environment; a nil field is left as it is.

type EnvironmentID

type EnvironmentID = id.Of[Environment]

EnvironmentID identifies an environment.

type IDs

type IDs interface {
	Environment() EnvironmentID
	UnitType() UnitTypeID
	Attribute() AttributeID
}

IDs mints the identifiers of a new project's defaults.

type Project

type Project struct {
	ID ProjectID
	// Key names the project in URLs and SDK calls, and never changes.
	Key         string
	Name        string
	Description string
	CreatedAt   time.Time
	UpdatedAt   time.Time
	// Version counts the project's accepted changes, from 1, so a write can
	// name the one it was based on.
	Version int64
}

Project is a project: the flags, segments, experiments and environments of one product, and the grants of the members working on it.

func NewProject

func NewProject(projectID ProjectID, key, name, description string, now time.Time) (Project, error)

NewProject returns a project with key, name and description, created at now.

func (Project) Change

func (p Project) Change(c ProjectChange, now time.Time) (Project, bool, error)

Change returns the project with c applied at now, and whether anything changed: a change to the values it already has is none.

type ProjectChange

type ProjectChange struct {
	// Key is refused whatever its value, since a key never changes.
	Key         *string
	Name        *string
	Description *string
}

ProjectChange is a change to a project; a nil field is left as it is.

type ProjectDefaults

type ProjectDefaults struct {
	Environments []Environment
	UnitTypes    []UnitType
	Attributes   []Attribute
}

ProjectDefaults is what a new project is created with.

func DefaultsOf

func DefaultsOf(p Project, ids IDs) ProjectDefaults

DefaultsOf returns what p is created with, at its creation time: development, staging and production environments in that order, production protected, the user and anonymous unit types, and the standard attributes.

type ProjectID

type ProjectID = id.Of[Project]

ProjectID identifies a project.

type UnitType

type UnitType struct {
	ID          UnitTypeID
	Project     ProjectID
	Key         string
	Name        string
	Description string
	CreatedAt   time.Time
	UpdatedAt   time.Time
	// Version counts the unit type's accepted changes, from 1.
	Version int64
}

UnitType is one declared kind of unit in a project, such as user.

func NewUnitType

func NewUnitType(unitTypeID UnitTypeID, project ProjectID, key, name, description string, now time.Time) (UnitType, error)

NewUnitType returns a unit type of project.

func (UnitType) Change

func (u UnitType) Change(c UnitTypeChange, now time.Time) (UnitType, bool, error)

Change returns the unit type with c applied at now, and whether anything changed.

type UnitTypeChange

type UnitTypeChange struct {
	// Key is refused whatever its value, since a key never changes.
	Key         *string
	Name        *string
	Description *string
}

UnitTypeChange is a change to a unit type; a nil field is left as it is.

type UnitTypeID

type UnitTypeID = id.Of[UnitType]

UnitTypeID identifies a unit type.

Jump to

Keyboard shortcuts

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