user

package
v1.0.0-alpha.21 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Schema = database.NewSchema(map[domain.UserField]database.FieldBinding[domain.User]{
	domain.UserFieldProjectID: {
		SQLName:  "project_id",
		Accessor: func(u *domain.User) any { return u.ProjectID },
		Coerce:   database.CoerceString,
	},
	domain.UserFieldID: {
		SQLName:  "id",
		Accessor: func(u *domain.User) any { return u.ID },
		Coerce:   database.CoerceString,
	},
	domain.UserFieldSchemaURL: {
		SQLName:  "schema_url",
		Accessor: func(u *domain.User) any { return u.SchemaURL },
		Coerce:   database.CoerceString,
	},
	domain.UserFieldLifecycleOwnerTeamID: {
		SQLName:  "lifecycle_owner_team_id",
		Accessor: func(u *domain.User) any { return database.NullableValue(u.LifecycleOwnerTeamID) },
		Coerce:   database.CoerceString,
		Nullable: true,
	},
	domain.UserFieldStatus: {
		SQLName:  "status",
		Accessor: func(u *domain.User) any { return u.Metadata.Status.String() },
		Coerce:   coerceUserStatus,
	},
	domain.UserFieldCreatedAt: {
		SQLName:  "created_at",
		Accessor: func(u *domain.User) any { return u.Metadata.CreatedAt },
		Coerce:   database.CoerceTime,
	},
	domain.UserFieldUpdatedAt: {
		SQLName:  "updated_at",
		Accessor: func(u *domain.User) any { return u.Metadata.UpdatedAt },
		Coerce:   database.CoerceTime,
	},
})

Schema binds user list/filter/order fields for both dialects.

Functions

func ApplyCursor

ApplyCursor adds a keyset cursor predicate to filter when page.Cursor is set.

func EnsureListOptions

EnsureListOptions returns opts with the default CreatedAt+ID ASC order when OrderBy is unset. A nil opts becomes an empty ListOptions.

func MembershipStatusStrings

func MembershipStatusStrings() []string

MembershipStatusStrings are the states an embedded membership list serves, as the strings the column stores. It is domain.RosterMembershipStatuses rendered once here so the three dialects cannot drift from each other or from the paginated ListUserTeams read.

func NextCursor

func NextCursor(users []*domain.User, page database.Page[domain.UserField]) []byte

NextCursor returns a marshaled keyset cursor when the page is full; otherwise nil.

Types

type OwnerTeamCollector

type OwnerTeamCollector struct {
	// contains filtered or unexported fields
}

OwnerTeamCollector places lifecycle owner teams on the users they own.

Unlike an embedded collection this needs no cap: each user has at most one owner, so the second read is bounded by the page's distinct owner ids rather than by anything the data can grow.

func NewOwnerTeamCollector

func NewOwnerTeamCollector(group ProjectGroup) *OwnerTeamCollector

NewOwnerTeamCollector indexes group's users by the team that owns them. Self-owned users are absent from the index and keep a nil owner.

Every user in the group is marked loaded up front, the way NewTeamCollector gives each one an empty list: the read was asked for the owner, so a self-owned user must serialize as null rather than as absent.

func (*OwnerTeamCollector) Add

func (c *OwnerTeamCollector) Add(team domain.Team)

Add places one team on every user it owns. A team no user in the page is owned by is ignored.

func (*OwnerTeamCollector) TeamIDs

func (c *OwnerTeamCollector) TeamIDs() []string

TeamIDs are the distinct owner team ids the page refers to, in page order. Empty means every user in the group is self-owned and no second query is worth running.

type ProjectGroup

type ProjectGroup struct {
	ProjectID string
	IDs       []string
	ByID      map[string]*domain.User
}

ProjectGroup is one project's users prepared for attribute hydration.

func GroupByProject

func GroupByProject(users []*domain.User) []ProjectGroup

GroupByProject clears Attributes and groups users by ProjectID for hydration.

type TeamCollector

type TeamCollector struct {
	// contains filtered or unexported fields
}

TeamCollector places membership rows on the users they belong to, capping each user's list and flagging the ones that were cut.

The dialects hand over every current membership of the page's users, in user-then-team-name order; the cap lives here rather than in the query because bounding it per user needs a window function the Spanner emulator rejects. Rows arriving past the cap set the truncation flag and are dropped.

func NewTeamCollector

func NewTeamCollector(group ProjectGroup, limit int) *TeamCollector

NewTeamCollector prepares collection into group, which must be the same group the membership query was keyed on. Every user in it starts with an empty, non-nil slice: the read was asked for teams, so "no teams" must serialize as [] rather than as absent.

func (*TeamCollector) Add

func (c *TeamCollector) Add(userID string, team domain.UserTeam)

Add places one membership row. Rows past the cap are dropped and mark the user truncated. Rows for a user outside the page are ignored.

Jump to

Keyboard shortcuts

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