menus

package
v0.60.8 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MenuItemTypeItem      = cmsmenus.MenuItemTypeItem
	MenuItemTypeGroup     = cmsmenus.MenuItemTypeGroup
	MenuItemTypeSeparator = cmsmenus.MenuItemTypeSeparator
	MenuStatusDraft       = cmsmenus.MenuStatusDraft
	MenuStatusPublished   = cmsmenus.MenuStatusPublished
)
View Source
const (
	MenuViewModeFull          = "full"
	MenuViewModeTopLevelLimit = "top_level_limit"
	MenuViewModeMaxDepth      = "max_depth"
	MenuViewModeIncludeIDs    = "include_ids"
	MenuViewModeExcludeIDs    = "exclude_ids"
	MenuViewModeComposed      = "composed"

	MenuBindingPolicySingle        = "single"
	MenuBindingPolicyPriorityMulti = "priority_multi"

	MenuContributionDuplicateByURL    = content.NavigationDuplicateByURL
	MenuContributionDuplicateByTarget = content.NavigationDuplicateByTarget
	MenuContributionDuplicateNone     = content.NavigationDuplicateNone
)

Variables

View Source
var (
	ErrMenuCodeRequired                    = errors.New("menus: code is required")
	ErrMenuCodeInvalid                     = errors.New("menus: code must contain only letters, numbers, hyphen, or underscore")
	ErrMenuCodeExists                      = errors.New("menus: code already exists")
	ErrMenuNotFound                        = errors.New("menus: menu not found")
	ErrMenuInUse                           = errors.New("menus: menu is assigned to an active theme")
	ErrMenuItemNotFound                    = errors.New("menus: menu item not found")
	ErrMenuItemParentInvalid               = errors.New("menus: parent menu item invalid")
	ErrMenuItemCycle                       = errors.New("menus: hierarchy creates a cycle")
	ErrMenuItemPosition                    = errors.New("menus: position must be zero or positive")
	ErrMenuItemTargetMissing               = errors.New("menus: target type is required")
	ErrMenuItemTranslations                = errors.New("menus: at least one translation is required")
	ErrMenuItemDuplicateLocale             = errors.New("menus: duplicate translation locale provided")
	ErrMenuItemHasChildren                 = errors.New("menus: menu item has children; enable cascade to delete")
	ErrUnknownLocale                       = errors.New("menus: locale is unknown")
	ErrTranslationExists                   = errors.New("menus: translation already exists for locale")
	ErrTranslationLabelRequired            = errors.New("menus: translation label is required")
	ErrMenuItemPageNotFound                = errors.New("menus: page target not found")
	ErrMenuItemPageSlugRequired            = errors.New("menus: page target requires slug")
	ErrMenuItemTypeInvalid                 = errors.New("menus: menu item type is invalid")
	ErrMenuItemParentUnsupported           = errors.New("menus: parent cannot accept children")
	ErrMenuItemSeparatorFields             = errors.New("menus: separators cannot have targets, children, labels, icons, or badges")
	ErrMenuItemGroupFields                 = errors.New("menus: groups cannot define targets, icons, or badges")
	ErrMenuItemCollapsibleWithoutChildren  = errors.New("menus: collapsible menus require children")
	ErrMenuItemCollapsedWithoutCollapsible = errors.New("menus: collapsed menus must be marked collapsible")
	ErrMenuItemTranslationTextRequired     = errors.New("menus: translation requires label or translation key")
	ErrMenuItemDepthExceeded               = errors.New("menus: hierarchy exceeds maximum depth")
	ErrMenuLocationBindingNotFound         = errors.New("menus: menu location binding not found")
	ErrMenuViewProfileNotFound             = errors.New("menus: menu view profile not found")
	ErrMenuStatusInvalid                   = errors.New("menus: menu status is invalid")
	ErrMenuViewModeInvalid                 = errors.New("menus: menu view profile mode is invalid")
)

Functions

func NewMenuItemRepository

func NewMenuItemRepository(db *bun.DB) repository.Repository[*MenuItem]

NewMenuItemRepository creates a repository for MenuItem entities.

func NewMenuItemTranslationRepository

func NewMenuItemTranslationRepository(db *bun.DB) repository.Repository[*MenuItemTranslation]

NewMenuItemTranslationRepository creates a repository for MenuItemTranslation entities.

func NewMenuLocationBindingRepository added in v0.38.0

func NewMenuLocationBindingRepository(db *bun.DB) repository.Repository[*MenuLocationBinding]

NewMenuLocationBindingRepository creates a repository for MenuLocationBinding entities.

func NewMenuRepository

func NewMenuRepository(db *bun.DB) repository.Repository[*Menu]

NewMenuRepository creates a repository for Menu entities.

func NewMenuViewProfileRepository added in v0.38.0

func NewMenuViewProfileRepository(db *bun.DB) repository.Repository[*MenuViewProfile]

NewMenuViewProfileRepository creates a repository for MenuViewProfile entities.

Types

type AddMenuItemInput

type AddMenuItemInput struct {
	ID       *uuid.UUID
	MenuID   uuid.UUID
	ParentID *uuid.UUID
	// ParentCode allows callers to reference parents using string codes when UUIDs are not available.
	ParentCode   string
	ExternalCode string
	CanonicalKey string
	// Position is a 0-based insertion index among siblings.
	// Values past the end are clamped to append.
	Position    int
	Type        string
	Target      map[string]any
	Icon        string
	Badge       map[string]any
	Permissions []string
	Classes     []string
	Styles      map[string]string
	Collapsible bool
	Collapsed   bool
	Metadata    map[string]any
	CreatedBy   uuid.UUID
	UpdatedBy   uuid.UUID

	Translations             []MenuItemTranslationInput
	AllowMissingTranslations bool
}

AddMenuItemInput captures the data required to register a new menu item.

type AddMenuItemTranslationInput

type AddMenuItemTranslationInput struct {
	ItemID        uuid.UUID
	Locale        string
	Label         string
	LabelKey      string
	GroupTitle    string
	GroupTitleKey string
	URLOverride   *string
}

AddMenuItemTranslationInput adds or updates localized metadata for an item.

type BulkReorderMenuItemsInput added in v0.2.0

type BulkReorderMenuItemsInput struct {
	MenuID uuid.UUID
	Items  []ItemOrder
	// UpdatedBy records the actor requesting the reorder for auditing purposes.
	UpdatedBy uuid.UUID
	// Version optionally captures optimistic-lock metadata for future use.
	Version *int
}

ReorderMenuItemsInput defines a new hierarchical ordering for menu items. BulkReorderMenuItemsInput defines a new hierarchical ordering for menu items.

type BunMenuItemRepository

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

BunMenuItemRepository implements MenuItemRepository with optional caching.

func NewBunMenuItemRepository

func NewBunMenuItemRepository(db *bun.DB) *BunMenuItemRepository

NewBunMenuItemRepository creates a menu item repository without caching.

func NewBunMenuItemRepositoryWithCache

func NewBunMenuItemRepositoryWithCache(db *bun.DB, cacheService cache.CacheService, serializer cache.KeySerializer) *BunMenuItemRepository

NewBunMenuItemRepositoryWithCache creates a menu item repository with caching services.

func (*BunMenuItemRepository) BulkUpdateHierarchy added in v0.2.0

func (r *BunMenuItemRepository) BulkUpdateHierarchy(ctx context.Context, items []*MenuItem) error
func (r *BunMenuItemRepository) BulkUpdateParentLinks(ctx context.Context, items []*MenuItem) error

func (*BunMenuItemRepository) Create

func (r *BunMenuItemRepository) Create(ctx context.Context, item *MenuItem) (*MenuItem, error)

func (*BunMenuItemRepository) Delete added in v0.2.0

func (r *BunMenuItemRepository) Delete(ctx context.Context, id uuid.UUID) error

func (*BunMenuItemRepository) GetByID

func (r *BunMenuItemRepository) GetByID(ctx context.Context, id uuid.UUID) (*MenuItem, error)

func (*BunMenuItemRepository) GetByMenuAndCanonicalKey added in v0.10.0

func (r *BunMenuItemRepository) GetByMenuAndCanonicalKey(ctx context.Context, menuID uuid.UUID, key string) (*MenuItem, error)

func (*BunMenuItemRepository) GetByMenuAndExternalCode added in v0.10.0

func (r *BunMenuItemRepository) GetByMenuAndExternalCode(ctx context.Context, menuID uuid.UUID, code string) (*MenuItem, error)

func (*BunMenuItemRepository) InvalidateCache

func (r *BunMenuItemRepository) InvalidateCache(ctx context.Context) error

func (*BunMenuItemRepository) ListByMenu

func (r *BunMenuItemRepository) ListByMenu(ctx context.Context, menuID uuid.UUID) ([]*MenuItem, error)

func (*BunMenuItemRepository) ListChildren

func (r *BunMenuItemRepository) ListChildren(ctx context.Context, parentID uuid.UUID) ([]*MenuItem, error)

func (*BunMenuItemRepository) ResetMenuContents added in v0.12.0

func (r *BunMenuItemRepository) ResetMenuContents(ctx context.Context, menuID uuid.UUID) (itemsDeleted int, translationsDeleted int, err error)

func (*BunMenuItemRepository) Update

func (r *BunMenuItemRepository) Update(ctx context.Context, item *MenuItem) (*MenuItem, error)

type BunMenuItemTranslationRepository

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

BunMenuItemTranslationRepository implements MenuItemTranslationRepository with optional caching.

func NewBunMenuItemTranslationRepository

func NewBunMenuItemTranslationRepository(db *bun.DB) *BunMenuItemTranslationRepository

NewBunMenuItemTranslationRepository creates a translation repository without caching.

func NewBunMenuItemTranslationRepositoryWithCache

func NewBunMenuItemTranslationRepositoryWithCache(db *bun.DB, cacheService cache.CacheService, serializer cache.KeySerializer) *BunMenuItemTranslationRepository

NewBunMenuItemTranslationRepositoryWithCache creates a translation repository with caching services.

func (*BunMenuItemTranslationRepository) Create

func (*BunMenuItemTranslationRepository) Delete added in v0.2.0

func (*BunMenuItemTranslationRepository) GetByMenuItemAndLocale

func (r *BunMenuItemTranslationRepository) GetByMenuItemAndLocale(ctx context.Context, menuItemID uuid.UUID, localeID uuid.UUID) (*MenuItemTranslation, error)

func (*BunMenuItemTranslationRepository) InvalidateCache

func (r *BunMenuItemTranslationRepository) InvalidateCache(ctx context.Context) error

func (*BunMenuItemTranslationRepository) ListByMenuItem

func (r *BunMenuItemTranslationRepository) ListByMenuItem(ctx context.Context, menuItemID uuid.UUID) ([]*MenuItemTranslation, error)

func (*BunMenuItemTranslationRepository) Update

type BunMenuLocationBindingRepository added in v0.38.0

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

BunMenuLocationBindingRepository implements MenuLocationBindingRepository with optional caching.

func NewBunMenuLocationBindingRepository added in v0.38.0

func NewBunMenuLocationBindingRepository(db *bun.DB) *BunMenuLocationBindingRepository

NewBunMenuLocationBindingRepository creates a location binding repository without caching.

func NewBunMenuLocationBindingRepositoryWithCache added in v0.38.0

func NewBunMenuLocationBindingRepositoryWithCache(db *bun.DB, cacheService cache.CacheService, serializer cache.KeySerializer) *BunMenuLocationBindingRepository

NewBunMenuLocationBindingRepositoryWithCache creates a location binding repository with caching.

func (*BunMenuLocationBindingRepository) Create added in v0.38.0

func (*BunMenuLocationBindingRepository) Delete added in v0.38.0

func (*BunMenuLocationBindingRepository) GetByID added in v0.38.0

func (*BunMenuLocationBindingRepository) InvalidateCache added in v0.38.0

func (r *BunMenuLocationBindingRepository) InvalidateCache(ctx context.Context) error

func (*BunMenuLocationBindingRepository) List added in v0.38.0

func (*BunMenuLocationBindingRepository) ListByLocation added in v0.38.0

func (r *BunMenuLocationBindingRepository) ListByLocation(ctx context.Context, location string, env ...string) ([]*MenuLocationBinding, error)

func (*BunMenuLocationBindingRepository) Update added in v0.38.0

type BunMenuRepository

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

BunMenuRepository implements MenuRepository with optional caching.

func NewBunMenuRepository

func NewBunMenuRepository(db *bun.DB) *BunMenuRepository

NewBunMenuRepository creates a menu repository without caching.

func NewBunMenuRepositoryWithCache

func NewBunMenuRepositoryWithCache(db *bun.DB, cacheService cache.CacheService, serializer cache.KeySerializer) *BunMenuRepository

NewBunMenuRepositoryWithCache creates a menu repository with caching services.

func (*BunMenuRepository) Create

func (r *BunMenuRepository) Create(ctx context.Context, menu *Menu) (*Menu, error)

func (*BunMenuRepository) Delete added in v0.2.0

func (r *BunMenuRepository) Delete(ctx context.Context, id uuid.UUID) error

func (*BunMenuRepository) GetByCode

func (r *BunMenuRepository) GetByCode(ctx context.Context, code string, env ...string) (*Menu, error)

func (*BunMenuRepository) GetByID

func (r *BunMenuRepository) GetByID(ctx context.Context, id uuid.UUID) (*Menu, error)

func (*BunMenuRepository) GetByLocation added in v0.19.0

func (r *BunMenuRepository) GetByLocation(ctx context.Context, location string, env ...string) (*Menu, error)

func (*BunMenuRepository) InvalidateCache

func (r *BunMenuRepository) InvalidateCache(ctx context.Context) error

func (*BunMenuRepository) List

func (r *BunMenuRepository) List(ctx context.Context, env ...string) ([]*Menu, error)

func (*BunMenuRepository) Update

func (r *BunMenuRepository) Update(ctx context.Context, menu *Menu) (*Menu, error)

type BunMenuViewProfileRepository added in v0.38.0

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

BunMenuViewProfileRepository implements MenuViewProfileRepository with optional caching.

func NewBunMenuViewProfileRepository added in v0.38.0

func NewBunMenuViewProfileRepository(db *bun.DB) *BunMenuViewProfileRepository

NewBunMenuViewProfileRepository creates a menu view profile repository without caching.

func NewBunMenuViewProfileRepositoryWithCache added in v0.38.0

func NewBunMenuViewProfileRepositoryWithCache(db *bun.DB, cacheService cache.CacheService, serializer cache.KeySerializer) *BunMenuViewProfileRepository

NewBunMenuViewProfileRepositoryWithCache creates a menu view profile repository with caching.

func (*BunMenuViewProfileRepository) Create added in v0.38.0

func (*BunMenuViewProfileRepository) Delete added in v0.38.0

func (*BunMenuViewProfileRepository) GetByCode added in v0.38.0

func (r *BunMenuViewProfileRepository) GetByCode(ctx context.Context, code string, env ...string) (*MenuViewProfile, error)

func (*BunMenuViewProfileRepository) GetByID added in v0.38.0

func (*BunMenuViewProfileRepository) InvalidateCache added in v0.38.0

func (r *BunMenuViewProfileRepository) InvalidateCache(ctx context.Context) error

func (*BunMenuViewProfileRepository) List added in v0.38.0

func (*BunMenuViewProfileRepository) Update added in v0.38.0

type ContentMenuMembership added in v0.38.0

type ContentMenuMembership struct {
	ContentID       uuid.UUID `json:"content_id"`
	ContentTypeID   uuid.UUID `json:"content_type_id"`
	ContentTypeSlug string    `json:"content_type_slug,omitempty"`
	ContentSlug     string    `json:"content_slug,omitempty"`
	Location        string    `json:"location"`
	Visible         bool      `json:"visible"`
	Origin          string    `json:"origin,omitempty"`
	VisibilityState string    `json:"visibility_state,omitempty"`
	MergeMode       string    `json:"merge_mode,omitempty"`
	DuplicatePolicy string    `json:"duplicate_policy,omitempty"`
	URL             string    `json:"url,omitempty"`
	Label           string    `json:"label,omitempty"`
	SortOrder       *int      `json:"sort_order,omitempty"`
}

ContentMenuMembership reports computed content contribution membership for a location.

type ContentRepository added in v0.38.0

type ContentRepository interface {
	List(ctx context.Context, env ...content.ContentListOption) ([]*content.Content, error)
}

ContentRepository reads content entries used for content-driven menu contributions.

type ContentTypeRepository added in v0.38.0

type ContentTypeRepository interface {
	List(ctx context.Context, env ...string) ([]*content.ContentType, error)
}

ContentTypeRepository reads content type metadata used for navigation capabilities.

type CreateMenuInput

type CreateMenuInput struct {
	Code           string
	Location       string
	Description    *string
	Status         string
	Locale         *string
	TranslationID  *uuid.UUID
	CreatedBy      uuid.UUID
	UpdatedBy      uuid.UUID
	EnvironmentKey string
}

CreateMenuInput captures the information required to register a menu.

type DeleteMenuItemRequest added in v0.2.0

type DeleteMenuItemRequest struct {
	ItemID          uuid.UUID
	DeletedBy       uuid.UUID
	CascadeChildren bool
}

DeleteMenuItemRequest captures the data required to remove a menu item.

type DeleteMenuRequest added in v0.2.0

type DeleteMenuRequest struct {
	MenuID    uuid.UUID
	DeletedBy uuid.UUID
	// Force bypasses guard rails such as theme bindings when true.
	Force bool
}

DeleteMenuRequest captures the data required to remove a menu.

type IDGenerator

type IDGenerator func(AddMenuItemInput) uuid.UUID

IDGenerator produces unique identifiers. It receives the normalized AddMenuItemInput so callers can derive deterministic IDs from payload fields.

type ItemOrder

type ItemOrder struct {
	ItemID   uuid.UUID
	ParentID *uuid.UUID
	Position int
}

ItemOrder describes the desired parent/position for a menu item.

type LocaleRepository

type LocaleRepository interface {
	GetByCode(ctx context.Context, code string) (*content.Locale, error)
}

LocaleRepository resolves locales by code.

type Menu = cmsmenus.Menu
type MenuIDDeriver func(code string) uuid.UUID

MenuIDDeriver produces deterministic menu UUIDs from the stable menu code.

type MenuInUseError struct {
	MenuID   uuid.UUID
	Bindings []MenuUsageBinding
}

MenuInUseError surfaces guard-rail failures for menu deletions.

func (e *MenuInUseError) Error() string
func (e *MenuInUseError) Unwrap() error
type MenuItem = cmsmenus.MenuItem
type MenuItemRepository interface {
	Create(ctx context.Context, item *MenuItem) (*MenuItem, error)
	GetByID(ctx context.Context, id uuid.UUID) (*MenuItem, error)
	GetByMenuAndCanonicalKey(ctx context.Context, menuID uuid.UUID, key string) (*MenuItem, error)
	GetByMenuAndExternalCode(ctx context.Context, menuID uuid.UUID, code string) (*MenuItem, error)
	ListByMenu(ctx context.Context, menuID uuid.UUID) ([]*MenuItem, error)
	ListChildren(ctx context.Context, parentID uuid.UUID) ([]*MenuItem, error)
	Update(ctx context.Context, item *MenuItem) (*MenuItem, error)
	Delete(ctx context.Context, id uuid.UUID) error
	// BulkUpdateHierarchy persists parent/position updates for multiple items atomically.
	BulkUpdateHierarchy(ctx context.Context, items []*MenuItem) error
	// BulkUpdateParentLinks persists parent_id/parent_ref/position updates for multiple items atomically.
	BulkUpdateParentLinks(ctx context.Context, items []*MenuItem) error
}

MenuItemRepository exposes persistence operations for menu items.

func NewMemoryMenuItemRepository

func NewMemoryMenuItemRepository() MenuItemRepository

NewMemoryMenuItemRepository constructs an in-memory repository for menu items.

type MenuItemTranslation = cmsmenus.MenuItemTranslation
type MenuItemTranslationInput struct {
	Locale        string
	Label         string
	LabelKey      string
	GroupTitle    string
	GroupTitleKey string
	URLOverride   *string
}

MenuItemTranslationInput describes localized metadata for a menu item.

type MenuItemTranslationRepository interface {
	Create(ctx context.Context, translation *MenuItemTranslation) (*MenuItemTranslation, error)
	GetByMenuItemAndLocale(ctx context.Context, menuItemID uuid.UUID, localeID uuid.UUID) (*MenuItemTranslation, error)
	ListByMenuItem(ctx context.Context, menuItemID uuid.UUID) ([]*MenuItemTranslation, error)
	Update(ctx context.Context, translation *MenuItemTranslation) (*MenuItemTranslation, error)
	Delete(ctx context.Context, id uuid.UUID) error
}

MenuItemTranslationRepository exposes persistence operations for menu item translations.

func NewMemoryMenuItemTranslationRepository

func NewMemoryMenuItemTranslationRepository() MenuItemTranslationRepository

NewMemoryMenuItemTranslationRepository constructs an in-memory repository for menu item translations.

type MenuLocationBinding = cmsmenus.MenuLocationBinding
type MenuLocationBindingRepository interface {
	Create(ctx context.Context, binding *MenuLocationBinding) (*MenuLocationBinding, error)
	GetByID(ctx context.Context, id uuid.UUID) (*MenuLocationBinding, error)
	ListByLocation(ctx context.Context, location string, env ...string) ([]*MenuLocationBinding, error)
	List(ctx context.Context, env ...string) ([]*MenuLocationBinding, error)
	Update(ctx context.Context, binding *MenuLocationBinding) (*MenuLocationBinding, error)
	Delete(ctx context.Context, id uuid.UUID) error
}

MenuLocationBindingRepository persists menu location binding records.

func NewMemoryMenuLocationBindingRepository added in v0.38.0

func NewMemoryMenuLocationBindingRepository() MenuLocationBindingRepository

NewMemoryMenuLocationBindingRepository constructs an in-memory location binding repository.

type MenuQueryOptions struct {
	IncludeDrafts               bool
	PreviewToken                string
	Status                      string
	ViewProfile                 string
	BindingPolicy               string
	IncludeContributions        *bool
	ContributionMergeMode       string
	ContributionDuplicatePolicy string
}
type MenuRepository interface {
	Create(ctx context.Context, menu *Menu) (*Menu, error)
	GetByID(ctx context.Context, id uuid.UUID) (*Menu, error)
	GetByCode(ctx context.Context, code string, env ...string) (*Menu, error)
	GetByLocation(ctx context.Context, location string, env ...string) (*Menu, error)
	List(ctx context.Context, env ...string) ([]*Menu, error)
	Update(ctx context.Context, menu *Menu) (*Menu, error)
	Delete(ctx context.Context, id uuid.UUID) error
}

MenuRepository exposes persistence operations for menu records.

func NewMemoryMenuRepository

func NewMemoryMenuRepository() MenuRepository

NewMemoryMenuRepository constructs an in-memory repository for menus

type MenuUsageBinding struct {
	ThemeID      uuid.UUID
	ThemeName    string
	LocationCode string
}

MenuUsageBinding describes an active menu reference inside a theme/location pair.

type MenuUsageResolver interface {
	ResolveMenuUsage(ctx context.Context, menuID uuid.UUID) ([]MenuUsageBinding, error)
}

MenuUsageResolver reports whether menus are currently bound to active themes/locations.

type MenuViewProfile = cmsmenus.MenuViewProfile
type MenuViewProfileRepository interface {
	Create(ctx context.Context, profile *MenuViewProfile) (*MenuViewProfile, error)
	GetByID(ctx context.Context, id uuid.UUID) (*MenuViewProfile, error)
	GetByCode(ctx context.Context, code string, env ...string) (*MenuViewProfile, error)
	List(ctx context.Context, env ...string) ([]*MenuViewProfile, error)
	Update(ctx context.Context, profile *MenuViewProfile) (*MenuViewProfile, error)
	Delete(ctx context.Context, id uuid.UUID) error
}

MenuViewProfileRepository persists menu view projection profiles.

func NewMemoryMenuViewProfileRepository added in v0.38.0

func NewMemoryMenuViewProfileRepository() MenuViewProfileRepository

NewMemoryMenuViewProfileRepository constructs an in-memory view profile repository.

type NavigationNode struct {
	ID                 uuid.UUID         `json:"id"`
	Position           int               `json:"position"`
	Type               string            `json:"type,omitempty"`
	Label              string            `json:"label,omitempty"`
	DisplayLabel       string            `json:"display_label,omitempty"`
	LabelKey           string            `json:"label_key,omitempty"`
	GroupTitle         string            `json:"group_title,omitempty"`
	DisplayGroupTitle  string            `json:"display_group_title,omitempty"`
	GroupTitleKey      string            `json:"group_title_key,omitempty"`
	URL                string            `json:"url"`
	Target             map[string]any    `json:"target,omitempty"`
	Icon               string            `json:"icon,omitempty"`
	Badge              map[string]any    `json:"badge,omitempty"`
	Permissions        []string          `json:"permissions,omitempty"`
	Classes            []string          `json:"classes,omitempty"`
	Styles             map[string]string `json:"styles,omitempty"`
	Collapsible        bool              `json:"collapsible,omitempty"`
	Collapsed          bool              `json:"collapsed,omitempty"`
	Metadata           map[string]any    `json:"metadata,omitempty"`
	Contribution       bool              `json:"contribution,omitempty"`
	ContributionOrigin string            `json:"contribution_origin,omitempty"`
	Children           []NavigationNode  `json:"children,omitempty"`
}

NavigationNode represents a localized menu item ready for presentation.

type NotFoundError

type NotFoundError struct {
	Resource string
	Key      string
}

NotFoundError is returned when a menu resource cannot be located.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type PageRepository

type PageRepository interface {
	GetByID(ctx context.Context, id uuid.UUID) (*pages.Page, error)
	GetBySlug(ctx context.Context, slug string, env ...string) (*pages.Page, error)
}

PageRepository looks up pages for menu target validation and navigation resolution.

type ParentResolver added in v0.7.0

type ParentResolver func(ctx context.Context, code string, input AddMenuItemInput) (*uuid.UUID, error)

ParentResolver maps caller-provided parent codes (non-UUID) into UUIDs before validation.

type ReconcileMenuRequest added in v0.10.0

type ReconcileMenuRequest struct {
	MenuID    uuid.UUID
	UpdatedBy uuid.UUID
}

ReconcileMenuRequest triggers a parent-link reconciliation pass for a menu.

type ReconcileResult added in v0.10.0

type ReconcileResult struct {
	Resolved  int
	Remaining int
}

ReconcileResult reports how many items were linked during reconciliation.

type ReorderMenuItemsInput

type ReorderMenuItemsInput = BulkReorderMenuItemsInput

ReorderMenuItemsInput is retained for backward compatibility but mirrors BulkReorderMenuItemsInput. Deprecated: use BulkReorderMenuItemsInput instead.

type ResetMenuCounts added in v0.12.0

type ResetMenuCounts struct {
	ItemsDeleted        int
	TranslationsDeleted int
}

type ResolveRequest

type ResolveRequest struct {
	MenuCode string
	Item     *MenuItem
	Locale   string
	LocaleID uuid.UUID
}

ResolveRequest carries the context required for URL resolvers to build links.

type ResolvedMenu added in v0.38.0

type ResolvedMenu struct {
	Location          string                  `json:"location"`
	RequestedLocale   string                  `json:"requested_locale,omitempty"`
	ResolvedLocale    string                  `json:"resolved_locale,omitempty"`
	Menu              *Menu                   `json:"menu,omitempty"`
	Menus             []*Menu                 `json:"menus,omitempty"`
	Binding           *MenuLocationBinding    `json:"binding,omitempty"`
	Bindings          []*MenuLocationBinding  `json:"bindings,omitempty"`
	ViewProfile       *MenuViewProfile        `json:"view_profile,omitempty"`
	Items             []NavigationNode        `json:"items,omitempty"`
	ContentMembership []ContentMenuMembership `json:"content_membership,omitempty"`
	Preview           ResolvedMenuPreview     `json:"preview"`
	FamilyID          *uuid.UUID              `json:"family_id,omitempty"`
}

type ResolvedMenuPreview added in v0.38.0

type ResolvedMenuPreview struct {
	IncludeDrafts       bool   `json:"include_drafts"`
	PreviewTokenPresent bool   `json:"preview_token_present"`
	MenuStatus          string `json:"menu_status,omitempty"`
	BindingStatus       string `json:"binding_status,omitempty"`
	ViewProfileStatus   string `json:"view_profile_status,omitempty"`
}

type Service

type Service interface {
	CreateMenu(ctx context.Context, input CreateMenuInput) (*Menu, error)
	GetOrCreateMenu(ctx context.Context, input CreateMenuInput) (*Menu, error)
	UpsertMenu(ctx context.Context, input UpsertMenuInput) (*Menu, error)
	MenuByCode(ctx context.Context, code string, locale string, opts MenuQueryOptions, env ...string) (*ResolvedMenu, error)
	MenuByLocation(ctx context.Context, location string, locale string, opts MenuQueryOptions, env ...string) (*ResolvedMenu, error)
	ResolveLocationBinding(ctx context.Context, location, locale string, opts MenuQueryOptions, env ...string) (*MenuLocationBinding, error)
	ApplyViewProfile(ctx context.Context, menu *Menu, profileCode string, opts MenuQueryOptions, env ...string) (*Menu, error)
	UpsertMenuLocationBinding(ctx context.Context, input UpsertMenuLocationBindingInput) (*MenuLocationBinding, error)
	UpsertMenuViewProfile(ctx context.Context, input UpsertMenuViewProfileInput) (*MenuViewProfile, error)
	GetMenu(ctx context.Context, id uuid.UUID) (*Menu, error)
	GetMenuByCode(ctx context.Context, code string, env ...string) (*Menu, error)
	GetMenuByLocation(ctx context.Context, location string, env ...string) (*Menu, error)
	DeleteMenu(ctx context.Context, req DeleteMenuRequest) error
	ResetMenuByCode(ctx context.Context, code string, actor uuid.UUID, force bool, env ...string) error

	AddMenuItem(ctx context.Context, input AddMenuItemInput) (*MenuItem, error)
	UpsertMenuItem(ctx context.Context, input UpsertMenuItemInput) (*MenuItem, error)
	UpdateMenuItem(ctx context.Context, input UpdateMenuItemInput) (*MenuItem, error)
	DeleteMenuItem(ctx context.Context, req DeleteMenuItemRequest) error
	BulkReorderMenuItems(ctx context.Context, input BulkReorderMenuItemsInput) ([]*MenuItem, error)
	ReconcileMenu(ctx context.Context, req ReconcileMenuRequest) (*ReconcileResult, error)

	AddMenuItemTranslation(ctx context.Context, input AddMenuItemTranslationInput) (*MenuItemTranslation, error)
	UpsertMenuItemTranslation(ctx context.Context, input UpsertMenuItemTranslationInput) (*MenuItemTranslation, error)
	GetMenuItemByExternalCode(ctx context.Context, menuCode string, externalCode string, env ...string) (*MenuItem, error)
	ResolveNavigation(ctx context.Context, menuCode string, locale string, env ...string) ([]NavigationNode, error)
	ResolveNavigationByLocation(ctx context.Context, location string, locale string, env ...string) ([]NavigationNode, error)
	InvalidateCache(ctx context.Context) error
}

Service describes menu management capabilities.

func NewService

func NewService(menuRepo MenuRepository, itemRepo MenuItemRepository, trRepo MenuItemTranslationRepository, localeRepo LocaleRepository, opts ...ServiceOption) Service

NewService constructs a menu service instance.

type ServiceOption

type ServiceOption func(*service)

ServiceOption configures menu service behaviour.

func WithActivityEmitter added in v0.5.0

func WithActivityEmitter(emitter *activity.Emitter) ServiceOption

WithActivityEmitter wires the activity emitter used for activity records.

func WithAuditRecorder added in v0.12.0

func WithAuditRecorder(recorder jobs.AuditRecorder) ServiceOption

func WithBindingDuplicatePolicy added in v0.38.0

func WithBindingDuplicatePolicy(policy string) ServiceOption

WithBindingDuplicatePolicy configures how duplicate location bindings are handled.

func WithClock

func WithClock(clock func() time.Time) ServiceOption

WithClock overrides the internal time source.

func WithContentRepository added in v0.38.0

func WithContentRepository(repo ContentRepository) ServiceOption

WithContentRepository wires the content repository used for content-driven contributions.

func WithContentTypeRepository added in v0.38.0

func WithContentTypeRepository(repo ContentTypeRepository) ServiceOption

WithContentTypeRepository wires the content-type repository used for contribution capability lookup.

func WithDefaultEnvironmentKey added in v0.23.1

func WithDefaultEnvironmentKey(key string) ServiceOption

WithDefaultEnvironmentKey overrides the default environment key.

func WithEnvironmentService added in v0.23.1

func WithEnvironmentService(envSvc cmsenv.Service) ServiceOption

WithEnvironmentService wires the environment service for env resolution.

func WithForgivingMenuBootstrap added in v0.10.0

func WithForgivingMenuBootstrap(enabled bool) ServiceOption

WithForgivingMenuBootstrap enables order-independent menu seeding: missing parents are deferred, collapsible flags are tolerated until children exist, and reconciliation runs automatically after writes and before navigation resolution.

func WithIDGenerator

func WithIDGenerator(generator IDGenerator) ServiceOption

WithIDGenerator overrides the ID generator.

func WithMaxMenuDepth added in v0.38.0

func WithMaxMenuDepth(depth int) ServiceOption

WithMaxMenuDepth controls menu hierarchy guard rails. Zero or negative disables depth checks.

func WithMenuIDDeriver added in v0.12.0

func WithMenuIDDeriver(deriver MenuIDDeriver) ServiceOption

WithMenuIDDeriver overrides menu ID derivation so callers can generate stable UUIDs from menu codes.

func WithMenuLocationBindingRepository added in v0.38.0

func WithMenuLocationBindingRepository(repo MenuLocationBindingRepository) ServiceOption

WithMenuLocationBindingRepository wires persistent location bindings used by runtime reads.

func WithMenuUsageResolver added in v0.2.0

func WithMenuUsageResolver(resolver MenuUsageResolver) ServiceOption

WithMenuUsageResolver injects a dependency that reports active menu bindings.

func WithMenuViewProfileRepository added in v0.38.0

func WithMenuViewProfileRepository(repo MenuViewProfileRepository) ServiceOption

WithMenuViewProfileRepository wires persistent view profiles used for menu projections.

func WithPageRepository

func WithPageRepository(repo PageRepository) ServiceOption

WithPageRepository wires the page repository used for target validation and URL resolution.

func WithParentResolver added in v0.7.0

func WithParentResolver(resolver ParentResolver) ServiceOption

WithParentResolver wires a resolver used to translate non-UUID parent references into UUIDs.

func WithReconcileOnResolveNavigation added in v0.10.0

func WithReconcileOnResolveNavigation(enabled bool) ServiceOption

WithReconcileOnResolveNavigation controls whether ResolveNavigation runs reconciliation first.

func WithRecordIDGenerator added in v0.7.0

func WithRecordIDGenerator(generator func() uuid.UUID) ServiceOption

WithRecordIDGenerator overrides the ID generator used for non-menu-item records (menus, translations). Menu item IDs remain governed by WithIDGenerator.

func WithRequireActiveEnvironment added in v0.23.1

func WithRequireActiveEnvironment(required bool) ServiceOption

WithRequireActiveEnvironment blocks operations on inactive environments.

func WithRequireExplicitEnvironment added in v0.23.1

func WithRequireExplicitEnvironment(required bool) ServiceOption

WithRequireExplicitEnvironment enforces explicit environment selection.

func WithRequireTranslations added in v0.2.0

func WithRequireTranslations(required bool) ServiceOption

WithRequireTranslations controls whether menu items must include translations.

func WithTranslationState added in v0.16.0

func WithTranslationState(state *translationconfig.State) ServiceOption

WithTranslationState wires a shared, runtime-configurable translation state.

func WithTranslationsEnabled added in v0.2.0

func WithTranslationsEnabled(enabled bool) ServiceOption

WithTranslationsEnabled toggles translation handling.

func WithURLResolver

func WithURLResolver(resolver URLResolver) ServiceOption

WithURLResolver overrides the default URL resolver used by the menu service.

type URLKitResolver

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

URLKitResolver resolves menu URLs using a go-urlkit RouteManager.

func NewURLKitResolver

func NewURLKitResolver(opts URLKitResolverOptions) *URLKitResolver

NewURLKitResolver constructs a resolver backed by go-urlkit.

func (*URLKitResolver) Resolve

func (r *URLKitResolver) Resolve(ctx context.Context, req ResolveRequest) (string, error)

Resolve builds a URL using the configured route manager.

type URLKitResolverOptions

type URLKitResolverOptions struct {
	Manager       *urlkit.RouteManager
	DefaultGroup  string
	LocaleGroups  map[string]string
	DefaultRoute  string
	SlugParam     string
	LocaleParam   string
	LocaleIDParam string
	RouteField    string
	ParamsField   string
	QueryField    string
}

URLKitResolverOptions configures the go-urlkit backed resolver.

type URLResolver

type URLResolver interface {
	Resolve(ctx context.Context, req ResolveRequest) (string, error)
}

URLResolver allows callers to override how menu URLs are generated.

type UpdateMenuItemInput

type UpdateMenuItemInput struct {
	ItemID      uuid.UUID
	Type        *string
	Target      map[string]any
	Icon        *string
	Badge       map[string]any
	Permissions []string
	Classes     []string
	Styles      map[string]string
	Collapsible *bool
	Collapsed   *bool
	Metadata    map[string]any
	// Position is a 0-based insertion index among siblings.
	// Values past the end are clamped to append. Nil leaves the current position unchanged.
	Position  *int
	ParentID  *uuid.UUID
	UpdatedBy uuid.UUID
}

UpdateMenuItemInput captures mutable fields for a menu item.

type UpsertMenuInput added in v0.10.0

type UpsertMenuInput struct {
	Code           string
	Location       string
	Description    *string
	Status         string
	Locale         *string
	TranslationID  *uuid.UUID
	Actor          uuid.UUID
	EnvironmentKey string
}

UpsertMenuInput captures the information required to create or update a menu by code.

type UpsertMenuItemInput added in v0.10.0

type UpsertMenuItemInput struct {
	MenuID          *uuid.UUID
	MenuCode        string
	MenuDescription *string
	EnvironmentKey  string

	// ExternalCode is a stable human-friendly identifier used for both dedupe and parent linking.
	ExternalCode string
	// CanonicalKey optionally overrides the dedupe key; when empty, it is derived from ExternalCode or the target.
	CanonicalKey string

	ParentID   *uuid.UUID
	ParentCode string
	// Position is a 0-based insertion index among siblings.
	// When nil, new items default to append (clamped to sibling length).
	Position *int

	Type        string
	Target      map[string]any
	Icon        string
	Badge       map[string]any
	Permissions []string
	Classes     []string
	Styles      map[string]string
	Collapsible bool
	Collapsed   bool
	Metadata    map[string]any

	Actor uuid.UUID

	Translations             []MenuItemTranslationInput
	AllowMissingTranslations bool
}

UpsertMenuItemInput upserts a menu item by canonical identity. It supports resolving the target menu by code and deferring parent links when enabled.

type UpsertMenuItemTranslationInput added in v0.12.0

type UpsertMenuItemTranslationInput = AddMenuItemTranslationInput

UpsertMenuItemTranslationInput adds or updates localized metadata for an item.

type UpsertMenuLocationBindingInput added in v0.38.0

type UpsertMenuLocationBindingInput struct {
	ID              *uuid.UUID
	Location        string
	MenuCode        string
	ViewProfileCode *string
	Locale          *string
	Priority        int
	Status          string
	Actor           uuid.UUID
	EnvironmentKey  string
}

type UpsertMenuViewProfileInput added in v0.38.0

type UpsertMenuViewProfileInput struct {
	ID             *uuid.UUID
	Code           string
	Name           string
	Mode           string
	MaxTopLevel    *int
	MaxDepth       *int
	IncludeItemIDs []string
	ExcludeItemIDs []string
	Status         string
	Actor          uuid.UUID
	EnvironmentKey string
}

Jump to

Keyboard shortcuts

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