api

package
v2.6.1 Latest Latest
Warning

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

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

Documentation

Overview

Package api defines the shared ConnectRPC workspace service layer.

The Store interface abstracts persistence so both the cloud backend (PostgreSQL) and the offline tld app (SQLite) can serve identical wire APIs. Pro-only features (versioning, etc.) may return errors wrapping ErrUnimplemented from single-tenant deployments.

Package api provides the public APIStore adapter that wraps *app.Store to satisfy the api.Store interface. Wrappers can embed this adapter and override specific methods for multi-tenant or SaaS-specific behavior.

Index

Constants

This section is empty.

Variables

View Source
var ErrMarkdownFileChanged = errors.New("markdown file changed on disk")

ErrMarkdownFileChanged is returned when a save includes a stale file token.

View Source
var ErrUnimplemented = errors.New("not implemented")

ErrUnimplemented is returned by Store methods that are not supported by a particular implementation (e.g. versioning in the offline tld app).

Functions

func BatchConnectorChangesMetadata added in v2.5.4

func BatchConnectorChangesMetadata(planned *diagv1.BatchConnector, current *diagv1.Connector, viewID, sourceID, targetID int32) bool

BatchConnectorChangesMetadata compares a connector patch after resolving refs. Visibility overrides are separate from connector metadata.

func BatchConnectorTags added in v2.6.0

func BatchConnectorTags(planned *diagv1.BatchConnector) []string

BatchConnectorTags preserves omitted tags and represents an explicit clear with a non-nil empty slice, including after protobuf serialization.

func BatchElementChangesMetadata added in v2.5.4

func BatchElementChangesMetadata(planned *diagv1.BatchElement, current *diagv1.Element) bool

BatchElementChangesMetadata compares the effective patch, rather than the serialized messages: omitted optional fields preserve their target values. Owned views and placements are compared separately.

func ConvertTechnologyLinks(links []*diagv1.TechnologyLink) ([]*diagv1.TechnologyLink, error)

ConvertTechnologyLinks validates and converts proto TechnologyLink messages.

func OptStr

func OptStr(s string) *string

OptStr returns nil when s is empty, otherwise returns a pointer to s.

func ResolveWorkspaceID

func ResolveWorkspaceID(ctx interface{ Value(any) any }, msgWorkspaceID string) (uuid.UUID, error)

ResolveWorkspaceID resolves the org_id from a message field or falls back to context. It is used in every RPC that accepts an optional org_id field.

func TechnologyLogoURL added in v2.5.0

func TechnologyLogoURL(links []app.TechnologyConnector) *string

TechnologyLogoURL resolves catalog links consistently for local and hosted adapters. A primary icon wins; otherwise the first valid catalog link wins.

func ValidateFlowRequest added in v2.6.0

func ValidateFlowRequest(req *diagv1.SaveFlowRequest) error

ValidateFlowRequest validates a proposed save without performing any target writes. CLI previews use the same validation as FlowService.SaveFlow.

func ValidateWorkspaceBatchRequest added in v2.6.0

func ValidateWorkspaceBatchRequest(m *diagv1.ApplyWorkspaceBatchRequest) error

ValidateWorkspaceBatchRequest validates batch resource fields without writes.

func WithCollaborationRequestInfo added in v2.3.0

func WithCollaborationRequestInfo(ctx context.Context, info CollaborationRequestInfo) context.Context

func WithWorkspaceID

func WithWorkspaceID(ctx context.Context, id uuid.UUID) context.Context

WithWorkspaceID returns a context carrying the given org ID.

func WorkspaceIDFromCtx

func WorkspaceIDFromCtx(ctx context.Context) uuid.UUID

WorkspaceIDFromCtx extracts the org ID injected by auth middleware or test helpers. Returns uuid.Nil when no org ID is present (tld single-tenant case).

Types

type APIStore added in v2.2.0

type APIStore struct {
	Store *app.Store
	// contains filtered or unexported fields
}

APIStore wraps *app.Store to implement api.Store for both SQLite and PostgreSQL. SaaS wrappers can embed this struct and override methods that need multi-tenant awareness (tags, view layers, markdown, versioning).

func NewAPIStore added in v2.2.0

func NewAPIStore(store *app.Store) *APIStore

NewAPIStore creates a public api.Store implementation backed by *app.Store.

func (*APIStore) AddPlacement added in v2.2.0

func (a *APIStore) AddPlacement(ctx context.Context, viewID, elementID int32, x, y float64) (*diagv1.PlacedElement, error)

func (*APIStore) ApplyBatch added in v2.5.4

func (*APIStore) BunDB added in v2.2.0

func (a *APIStore) BunDB() *bun.DB

BunDB exposes the underlying Bun database for operations that need raw queries.

func (*APIStore) CreateConnector added in v2.2.0

func (a *APIStore) CreateConnector(ctx context.Context, workspaceID uuid.UUID, input ConnectorInput) (*diagv1.Connector, error)

func (*APIStore) CreateElement added in v2.2.0

func (a *APIStore) CreateElement(ctx context.Context, workspaceID uuid.UUID, input ElementInput) (*diagv1.Element, error)

func (*APIStore) CreateView added in v2.2.0

func (a *APIStore) CreateView(ctx context.Context, workspaceID uuid.UUID, ownerElementID *int32, name string, label *string, isRoot bool) (*diagv1.View, error)

func (*APIStore) CreateViewComment added in v2.3.0

func (a *APIStore) CreateViewComment(ctx context.Context, workspaceID uuid.UUID, viewID, threadID int32, authorID, authorUsername, body string) (*diagv1.CommentInfo, error)

func (*APIStore) CreateViewLayer added in v2.2.0

func (a *APIStore) CreateViewLayer(ctx context.Context, viewID int32, name string, tags []string, color string) (*diagv1.ViewLayer, error)

func (*APIStore) CreateViewMarkdown added in v2.2.0

func (a *APIStore) CreateViewMarkdown(ctx context.Context, viewID int32, workspaceID uuid.UUID, fileName *string, initialContent *string, targetKind string, path *string) (*diagv1.View, error)

func (*APIStore) CreateViewThread added in v2.3.0

func (a *APIStore) CreateViewThread(ctx context.Context, workspaceID uuid.UUID, viewID int32, elementID, connectorID *int32, createdBy, createdByUsername string) (*diagv1.ThreadInfo, error)

func (*APIStore) DeleteConnector added in v2.2.0

func (a *APIStore) DeleteConnector(ctx context.Context, id int32, workspaceID uuid.UUID) error

func (*APIStore) DeleteDrawing added in v2.3.0

func (a *APIStore) DeleteDrawing(ctx context.Context, workspaceID uuid.UUID, viewID int32, pathID string) error

func (*APIStore) DeleteElement added in v2.2.0

func (a *APIStore) DeleteElement(ctx context.Context, id int32, workspaceID uuid.UUID) error

func (*APIStore) DeleteFlow added in v2.6.0

func (a *APIStore) DeleteFlow(ctx context.Context, id string, viewID int64, revision int32) error

func (*APIStore) DeleteTag added in v2.2.0

func (a *APIStore) DeleteTag(ctx context.Context, workspaceID uuid.UUID, name string) error

func (*APIStore) DeleteView added in v2.2.0

func (a *APIStore) DeleteView(ctx context.Context, id int32, workspaceID uuid.UUID) error

func (*APIStore) DeleteViewLayer added in v2.2.0

func (a *APIStore) DeleteViewLayer(ctx context.Context, id int32) error

func (*APIStore) GetConnector added in v2.2.0

func (a *APIStore) GetConnector(ctx context.Context, id int32, workspaceID uuid.UUID) (*diagv1.Connector, error)

func (*APIStore) GetElement added in v2.2.0

func (a *APIStore) GetElement(ctx context.Context, id int32, workspaceID uuid.UUID) (*diagv1.Element, error)

func (*APIStore) GetProjectedViewContent added in v2.2.0

func (a *APIStore) GetProjectedViewContent(ctx context.Context, viewID int32, workspaceID uuid.UUID, densityOverride *int32) (*diagv1.ViewContent, error)

func (*APIStore) GetView added in v2.2.0

func (a *APIStore) GetView(ctx context.Context, id int32, workspaceID uuid.UUID) (*diagv1.View, error)

func (*APIStore) GetViewLayer added in v2.2.0

func (a *APIStore) GetViewLayer(ctx context.Context, id int32) (*diagv1.ViewLayer, error)

func (*APIStore) GetViewMarkdown added in v2.2.0

func (a *APIStore) GetViewMarkdown(ctx context.Context, viewID int32, workspaceID uuid.UUID) (*diagv1.ViewMarkdownDocument, string, error)

func (*APIStore) GetViewThread added in v2.3.0

func (a *APIStore) GetViewThread(ctx context.Context, workspaceID uuid.UUID, viewID, threadID int32) (*diagv1.ThreadInfo, error)

func (*APIStore) GetViews added in v2.2.0

func (a *APIStore) GetViews(ctx context.Context, workspaceID uuid.UUID, parentViewID *int32, isRoot *bool, search string, limit, offset int) ([]*diagv1.View, int, error)

func (*APIStore) GetWorkspaceResourceCounts added in v2.2.0

func (a *APIStore) GetWorkspaceResourceCounts(ctx context.Context, workspaceID uuid.UUID) (views, elements, connectors int, err error)

func (*APIStore) LinkViewMarkdown added in v2.2.0

func (a *APIStore) LinkViewMarkdown(ctx context.Context, viewID int32, workspaceID uuid.UUID, path string) (*diagv1.View, error)

func (*APIStore) ListAllConnectors added in v2.2.0

func (a *APIStore) ListAllConnectors(ctx context.Context, workspaceID uuid.UUID) ([]*diagv1.Connector, error)

func (*APIStore) ListAllPlacements added in v2.2.0

func (a *APIStore) ListAllPlacements(ctx context.Context, workspaceID uuid.UUID) ([]*diagv1.PlacedElement, error)

func (*APIStore) ListAllViewLayers added in v2.2.0

func (a *APIStore) ListAllViewLayers(ctx context.Context, workspaceID uuid.UUID) ([]*diagv1.ViewLayer, error)

func (*APIStore) ListConnectors added in v2.2.0

func (a *APIStore) ListConnectors(ctx context.Context, viewID int32, workspaceID uuid.UUID) ([]*diagv1.Connector, error)

func (*APIStore) ListDrawings added in v2.3.0

func (a *APIStore) ListDrawings(ctx context.Context, workspaceID uuid.UUID, viewID int32) ([]RealtimeDrawingInput, error)

func (*APIStore) ListElementNavigations added in v2.2.0

func (a *APIStore) ListElementNavigations(ctx context.Context, workspaceID uuid.UUID, elementID int32) ([]*diagv1.ElementNavigationInfo, error)

func (*APIStore) ListElementPlacements added in v2.2.0

func (a *APIStore) ListElementPlacements(ctx context.Context, elementID int32, workspaceID uuid.UUID) ([]*diagv1.ViewPlacementInfo, error)

func (*APIStore) ListElements added in v2.2.0

func (a *APIStore) ListElements(ctx context.Context, workspaceID uuid.UUID, limit, offset int32, search string) ([]*diagv1.Element, int, error)

func (*APIStore) ListFlows added in v2.6.0

func (a *APIStore) ListFlows(ctx context.Context, viewID int64) ([]app.FlowRecord, error)

func (*APIStore) ListIncomingElementNavigations added in v2.2.0

func (a *APIStore) ListIncomingElementNavigations(ctx context.Context, viewID int32) ([]*diagv1.IncomingElementNavigationInfo, error)

func (*APIStore) ListPlacements added in v2.2.0

func (a *APIStore) ListPlacements(ctx context.Context, viewID int32) ([]*diagv1.PlacedElement, error)

func (*APIStore) ListViewElementReactions added in v2.3.0

func (a *APIStore) ListViewElementReactions(ctx context.Context, workspaceID uuid.UUID, viewID int32, userID string) ([]*diagv1.NodeReactionSummary, error)

func (*APIStore) ListViewLayers added in v2.2.0

func (a *APIStore) ListViewLayers(ctx context.Context, viewID int32) ([]*diagv1.ViewLayer, error)

func (*APIStore) ListViewThreads added in v2.3.0

func (a *APIStore) ListViewThreads(ctx context.Context, workspaceID uuid.UUID, viewID int32, elementID, connectorID *int32) ([]*diagv1.ThreadInfo, error)

func (*APIStore) ListViews added in v2.2.0

func (a *APIStore) ListViews(ctx context.Context, workspaceID uuid.UUID) ([]*diagv1.View, error)

func (*APIStore) RemovePlacement added in v2.2.0

func (a *APIStore) RemovePlacement(ctx context.Context, viewID, elementID int32) error

func (*APIStore) RunInTransaction added in v2.3.2

func (*APIStore) RunInTransaction(_ context.Context, _ func(context.Context, Store) error) error

func (*APIStore) SaveFlow added in v2.6.0

func (a *APIStore) SaveFlow(ctx context.Context, flow app.FlowRecord) (app.FlowRecord, error)

func (*APIStore) SaveViewMarkdown added in v2.2.0

func (a *APIStore) SaveViewMarkdown(ctx context.Context, viewID int32, workspaceID uuid.UUID, content string, expectedFileVersion *string, force bool) (*diagv1.ViewMarkdownDocument, error)

func (*APIStore) SetViewThreadResolved added in v2.3.0

func (a *APIStore) SetViewThreadResolved(ctx context.Context, workspaceID uuid.UUID, viewID, threadID int32, resolved bool) error

func (*APIStore) Tags added in v2.2.0

func (a *APIStore) Tags(ctx context.Context, workspaceID uuid.UUID) (map[string]*diagv1.Tag, error)

func (*APIStore) ToggleElementReaction added in v2.3.0

func (a *APIStore) ToggleElementReaction(ctx context.Context, workspaceID uuid.UUID, viewID, elementID int32, userID, emoji string) (bool, error)

func (*APIStore) UnlinkViewMarkdown added in v2.2.0

func (a *APIStore) UnlinkViewMarkdown(ctx context.Context, viewID int32, workspaceID uuid.UUID, deleteManagedFile bool) (*diagv1.View, error)

func (*APIStore) UpdateConnector added in v2.2.0

func (a *APIStore) UpdateConnector(ctx context.Context, id int32, workspaceID uuid.UUID, input ConnectorInput) (*diagv1.Connector, error)

func (*APIStore) UpdateElement added in v2.2.0

func (a *APIStore) UpdateElement(ctx context.Context, id int32, workspaceID uuid.UUID, input ElementInput) (*diagv1.Element, error)

func (*APIStore) UpdatePlacementPosition added in v2.2.0

func (a *APIStore) UpdatePlacementPosition(ctx context.Context, viewID, elementID int32, x, y float64) error

func (*APIStore) UpdateTag added in v2.2.0

func (a *APIStore) UpdateTag(ctx context.Context, workspaceID uuid.UUID, name, color string, description *string) error

func (*APIStore) UpdateView added in v2.2.0

func (a *APIStore) UpdateView(ctx context.Context, id int32, workspaceID uuid.UUID, name string, description *string, label *string, tags []string) (*diagv1.View, error)

func (*APIStore) UpdateViewLayer added in v2.2.0

func (a *APIStore) UpdateViewLayer(ctx context.Context, id int32, name *string, tags []string, color *string) (*diagv1.ViewLayer, error)

func (*APIStore) UpsertDrawing added in v2.3.0

func (a *APIStore) UpsertDrawing(ctx context.Context, workspaceID uuid.UUID, viewID int32, input RealtimeDrawingInput) error

type CollaborationHub added in v2.3.0

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

func NewCollaborationHub added in v2.3.0

func NewCollaborationHub() *CollaborationHub

func (*CollaborationHub) BroadcastViewEvent added in v2.3.0

func (h *CollaborationHub) BroadcastViewEvent(viewID int32, payload any)

func (*CollaborationHub) BroadcastWorkspaceViewEvent added in v2.3.0

func (h *CollaborationHub) BroadcastWorkspaceViewEvent(workspaceID uuid.UUID, viewID int32, payload any)

func (*CollaborationHub) RefreshViewState added in v2.3.0

func (h *CollaborationHub) RefreshViewState(ctx context.Context, store Store, workspaceID uuid.UUID, viewID int32)

type CollaborationIdentity added in v2.3.0

type CollaborationIdentity struct {
	ClientID string
	UserID   string
	Username string
}

CollaborationIdentity is the per-request/display identity used by core collaboration without creating a user/account system.

type CollaborationIdentityProvider added in v2.3.0

type CollaborationIdentityProvider interface {
	CurrentCollaborationIdentity(ctx context.Context, workspaceID uuid.UUID) (*CollaborationIdentity, bool, error)
}

type CollaborationRealtimeHandler added in v2.3.0

type CollaborationRealtimeHandler struct {
	Store            Store
	Hooks            WorkspaceHooks
	IdentityProvider CollaborationIdentityProvider
	Hub              *CollaborationHub
}

func (*CollaborationRealtimeHandler) WS added in v2.3.0

type CollaborationRequestInfo added in v2.3.0

type CollaborationRequestInfo struct {
	RemoteAddr string
}

type CollaborationService added in v2.3.0

type CollaborationService struct {
	Store            Store
	Hooks            WorkspaceHooks
	IdentityProvider CollaborationIdentityProvider
	Hub              *CollaborationHub

	diagv1connect.UnimplementedCollaborationServiceHandler
}

func (*CollaborationService) AddComment added in v2.3.0

func (*CollaborationService) CreateThread added in v2.3.0

func (*CollaborationService) ListReactions added in v2.3.0

func (*CollaborationService) ListThreads added in v2.3.0

func (*CollaborationService) ResolveThread added in v2.3.0

func (*CollaborationService) ToggleReaction added in v2.3.0

type ConnectorInput

type ConnectorInput struct {
	ViewID       int32
	SourceID     int32
	TargetID     int32
	Label        *string
	Description  *string
	Relationship *string
	Direction    string
	Style        string
	URL          *string
	SourceHandle *string
	TargetHandle *string
	Tags         []string
}

ConnectorInput holds mutable fields for connector create/update.

type DependencyService

type DependencyService struct {
	Store Store
	Hooks WorkspaceHooks
	diagv1connect.UnimplementedDependencyServiceHandler
}

DependencyService implements diagv1connect.DependencyServiceHandler.

func (*DependencyService) ListDependencies

ListDependencies returns all elements and connectors for the organisation.

type ElementInput

type ElementInput struct {
	Name            string
	Description     *string
	Kind            *string
	Technology      *string
	URL             *string
	LogoURL         *string
	TechLinks       []*diagv1.TechnologyLink
	Tags            []string
	Repo            *string
	RepositoryID    *string
	Branch          *string
	Language        *string
	FilePath        *string
	BypassNoiseGate *bool
	HasView         bool
	ViewLabel       *string
}

ElementInput holds mutable fields for element create/update.

type FlowService added in v2.6.0

type FlowService struct {
	diagv1connect.UnimplementedFlowServiceHandler
	Store Store
	Hooks WorkspaceHooks
}

func (*FlowService) DeleteFlow added in v2.6.0

func (*FlowService) ListFlows added in v2.6.0

func (*FlowService) SaveFlow added in v2.6.0

type ImportService

type ImportService struct {
	Store Store
	Hooks WorkspaceHooks
}

ImportService implements import-related RPCs.

func (*ImportService) ImportResources

ImportResources materializes imported elements/connectors through the same granular store mutations used by synchronous commands. Placements without coordinates are auto-laid out server-side.

func (*ImportService) ParseStructurizr

ParseStructurizr parses Structurizr DSL into batch elements and connectors.

type MermaidService added in v2.3.2

type MermaidService struct {
	diagv1connect.UnimplementedMermaidServiceHandler

	Store Store
	Hooks WorkspaceHooks
}

func (*MermaidService) ExportMermaidView added in v2.3.2

func (*MermaidService) ImportMermaidIntoView added in v2.3.2

func (*MermaidService) ParseMermaid added in v2.3.2

type NopWorkspaceHooks

type NopWorkspaceHooks struct{}

NopWorkspaceHooks provides a no-op implementation for the CLI/standalone mode.

func (NopWorkspaceHooks) AfterApplyBatch added in v2.5.4

func (NopWorkspaceHooks) AfterWrite

func (NopWorkspaceHooks) CheckApplyBatch added in v2.5.4

func (NopWorkspaceHooks) CheckRead

func (NopWorkspaceHooks) CheckWrite

type RealtimeDrawingInput added in v2.3.0

type RealtimeDrawingInput struct {
	PathID   string
	UserID   string
	Points   json.RawMessage
	Color    string
	Width    float64
	Text     string
	FontSize float64
}

RealtimeDrawingInput holds durable freehand/text drawing state for a view.

type Store

type Store interface {
	// Flows
	ListFlows(ctx context.Context, viewID int64) ([]app.FlowRecord, error)
	SaveFlow(ctx context.Context, flow app.FlowRecord) (app.FlowRecord, error)
	DeleteFlow(ctx context.Context, id string, viewID int64, revision int32) error

	// Views
	ListViews(ctx context.Context, workspaceID uuid.UUID) ([]*diagv1.View, error)
	GetViews(ctx context.Context, workspaceID uuid.UUID, parentViewID *int32, isRoot *bool, search string, limit, offset int) ([]*diagv1.View, int, error)
	GetView(ctx context.Context, id int32, workspaceID uuid.UUID) (*diagv1.View, error)
	GetProjectedViewContent(ctx context.Context, viewID int32, workspaceID uuid.UUID, densityOverride *int32) (*diagv1.ViewContent, error)
	GetViewMarkdown(ctx context.Context, viewID int32, workspaceID uuid.UUID) (*diagv1.ViewMarkdownDocument, string, error)
	CreateView(ctx context.Context, workspaceID uuid.UUID, ownerElementID *int32, name string, label *string, isRoot bool) (*diagv1.View, error)
	UpdateView(ctx context.Context, id int32, workspaceID uuid.UUID, name string, description *string, label *string, tags []string) (*diagv1.View, error)
	CreateViewMarkdown(ctx context.Context, viewID int32, workspaceID uuid.UUID, fileName *string, initialContent *string, targetKind string, path *string) (*diagv1.View, error)
	LinkViewMarkdown(ctx context.Context, viewID int32, workspaceID uuid.UUID, path string) (*diagv1.View, error)
	SaveViewMarkdown(ctx context.Context, viewID int32, workspaceID uuid.UUID, content string, expectedFileVersion *string, force bool) (*diagv1.ViewMarkdownDocument, error)
	UnlinkViewMarkdown(ctx context.Context, viewID int32, workspaceID uuid.UUID, deleteManagedFile bool) (*diagv1.View, error)
	DeleteView(ctx context.Context, id int32, workspaceID uuid.UUID) error

	// Elements
	ListElements(ctx context.Context, workspaceID uuid.UUID, limit, offset int32, search string) ([]*diagv1.Element, int, error)
	GetElement(ctx context.Context, id int32, workspaceID uuid.UUID) (*diagv1.Element, error)
	CreateElement(ctx context.Context, workspaceID uuid.UUID, input ElementInput) (*diagv1.Element, error)
	UpdateElement(ctx context.Context, id int32, workspaceID uuid.UUID, input ElementInput) (*diagv1.Element, error)
	DeleteElement(ctx context.Context, id int32, workspaceID uuid.UUID) error

	// Placements (view ↔ element positions)
	ListPlacements(ctx context.Context, viewID int32) ([]*diagv1.PlacedElement, error)
	ListAllPlacements(ctx context.Context, workspaceID uuid.UUID) ([]*diagv1.PlacedElement, error)
	ListElementPlacements(ctx context.Context, elementID int32, workspaceID uuid.UUID) ([]*diagv1.ViewPlacementInfo, error)
	AddPlacement(ctx context.Context, viewID, elementID int32, x, y float64) (*diagv1.PlacedElement, error)
	UpdatePlacementPosition(ctx context.Context, viewID, elementID int32, x, y float64) error
	RemovePlacement(ctx context.Context, viewID, elementID int32) error

	// Connectors
	ListConnectors(ctx context.Context, viewID int32, workspaceID uuid.UUID) ([]*diagv1.Connector, error)
	ListAllConnectors(ctx context.Context, workspaceID uuid.UUID) ([]*diagv1.Connector, error)
	GetConnector(ctx context.Context, id int32, workspaceID uuid.UUID) (*diagv1.Connector, error)
	CreateConnector(ctx context.Context, workspaceID uuid.UUID, input ConnectorInput) (*diagv1.Connector, error)
	UpdateConnector(ctx context.Context, id int32, workspaceID uuid.UUID, input ConnectorInput) (*diagv1.Connector, error)
	DeleteConnector(ctx context.Context, id int32, workspaceID uuid.UUID) error

	// Element navigations (derived from owner_element_id relationships)
	ListElementNavigations(ctx context.Context, workspaceID uuid.UUID, elementID int32) ([]*diagv1.ElementNavigationInfo, error)
	ListIncomingElementNavigations(ctx context.Context, viewID int32) ([]*diagv1.IncomingElementNavigationInfo, error)

	// View layers
	ListViewLayers(ctx context.Context, viewID int32) ([]*diagv1.ViewLayer, error)
	ListAllViewLayers(ctx context.Context, workspaceID uuid.UUID) ([]*diagv1.ViewLayer, error)
	GetViewLayer(ctx context.Context, id int32) (*diagv1.ViewLayer, error)
	CreateViewLayer(ctx context.Context, viewID int32, name string, tags []string, color string) (*diagv1.ViewLayer, error)
	UpdateViewLayer(ctx context.Context, id int32, name *string, tags []string, color *string) (*diagv1.ViewLayer, error)
	DeleteViewLayer(ctx context.Context, id int32) error

	// Tags
	Tags(ctx context.Context, workspaceID uuid.UUID) (map[string]*diagv1.Tag, error)
	UpdateTag(ctx context.Context, workspaceID uuid.UUID, name, color string, description *string) error
	DeleteTag(ctx context.Context, workspaceID uuid.UUID, name string) error

	// Collaboration
	ListViewThreads(ctx context.Context, workspaceID uuid.UUID, viewID int32, elementID, connectorID *int32) ([]*diagv1.ThreadInfo, error)
	CreateViewThread(ctx context.Context, workspaceID uuid.UUID, viewID int32, elementID, connectorID *int32, createdBy, createdByUsername string) (*diagv1.ThreadInfo, error)
	GetViewThread(ctx context.Context, workspaceID uuid.UUID, viewID, threadID int32) (*diagv1.ThreadInfo, error)
	SetViewThreadResolved(ctx context.Context, workspaceID uuid.UUID, viewID, threadID int32, resolved bool) error
	CreateViewComment(ctx context.Context, workspaceID uuid.UUID, viewID, threadID int32, authorID, authorUsername, body string) (*diagv1.CommentInfo, error)
	ListViewElementReactions(ctx context.Context, workspaceID uuid.UUID, viewID int32, userID string) ([]*diagv1.NodeReactionSummary, error)
	ToggleElementReaction(ctx context.Context, workspaceID uuid.UUID, viewID, elementID int32, userID, emoji string) (bool, error)
	ListDrawings(ctx context.Context, workspaceID uuid.UUID, viewID int32) ([]RealtimeDrawingInput, error)
	UpsertDrawing(ctx context.Context, workspaceID uuid.UUID, viewID int32, input RealtimeDrawingInput) error
	DeleteDrawing(ctx context.Context, workspaceID uuid.UUID, viewID int32, pathID string) error

	// ApplyBatch atomically applies a CLI workspace batch (create/update elements, views, connectors).
	ApplyBatch(ctx context.Context, workspaceID uuid.UUID, req *diagv1.ApplyWorkspaceBatchRequest) (*diagv1.ApplyWorkspaceBatchResponse, error)

	// GetWorkspaceResourceCounts returns current view/element/connector counts.
	GetWorkspaceResourceCounts(ctx context.Context, workspaceID uuid.UUID) (views, elements, connectors int, err error)
}

Store is the persistence interface for the shared workspace API. Implementations exist for PostgreSQL (backend) and SQLite (tld).

type TransactionalStore added in v2.3.2

type TransactionalStore interface {
	RunInTransaction(ctx context.Context, fn func(context.Context, Store) error) error
}

TransactionalStore is implemented by Store adapters that can run a logical workspace mutation against a transaction-bound store.

type WorkspaceHooks

type WorkspaceHooks interface {
	// CheckRead performs access control before a read operation.
	CheckRead(ctx context.Context, workspaceID uuid.UUID) error

	// CheckWrite performs access control and resource limit checks before a write operation.
	// resourceType identifies the limited resource (e.g., "elements", "views").
	CheckWrite(ctx context.Context, workspaceID uuid.UUID, resourceType string) error

	// AfterWrite provides a hook to perform auditing, notifications, or real-time
	// real-time broadcasts (e.g., WebSockets) after a successful write operation.
	// 'action' is the operation type (e.g., "create", "update", "delete").
	// 'resourceType' is the type of resource (e.g., "element", "view").
	// 'resourceID' is the ID of the resource affected.
	// 'details' contains any additional contextual data for auditing or broadcasting.
	// 'response' contains the optional protobuf response object if further inspection is needed.
	AfterWrite(ctx context.Context, workspaceID uuid.UUID, action string, resourceType string, resourceID string, details map[string]any, response any)

	// CheckApplyBatch allows the SaaS backend to perform resource limit checks
	// specifically for the bulk ApplyBatch operation.
	CheckApplyBatch(ctx context.Context, workspaceID uuid.UUID, req *diagv1.ApplyWorkspaceBatchRequest) error

	// AfterApplyBatch provides a hook to perform layout, versioning, and cache
	// invalidation after a successful bulk ApplyBatch operation.
	AfterApplyBatch(ctx context.Context, workspaceID uuid.UUID, req *diagv1.ApplyWorkspaceBatchRequest, resp *diagv1.ApplyWorkspaceBatchResponse)
}

WorkspaceHooks allows consumers (like the SaaS backend) to inject access control, limit checks, auditing, and real-time update logic into core services.

type WorkspaceService

type WorkspaceService struct {
	Store Store
	Hooks WorkspaceHooks
	diagv1connect.UnimplementedWorkspaceServiceHandler
}

WorkspaceService implements the core workspace ConnectRPC service without any auth, billing, or caching concerns. Both the cloud backend and the offline tld app embed or wrap this service and add their own middleware/interceptors.

func (*WorkspaceService) ApplyWorkspaceBatch added in v2.5.4

func (*WorkspaceService) CreateCustomTechnology added in v2.3.1

func (*WorkspaceService) CreateViewMarkdown added in v2.2.0

func (*WorkspaceService) GetView

func (*WorkspaceService) GetViewMarkdown added in v2.2.0

func (*WorkspaceService) LinkViewMarkdown added in v2.2.0

func (*WorkspaceService) SaveViewMarkdown added in v2.2.0

func (*WorkspaceService) UnlinkViewMarkdown added in v2.2.0

Jump to

Keyboard shortcuts

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