injectable

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultInjectorTimeout is the default timeout for injectors.
	DefaultInjectorTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

func NewInjectableService

func NewInjectableService(
	injectableRepo port.InjectableRepository,
	systemInjectableRepo port.SystemInjectableRepository,
	injectorRegistry port.InjectorRegistry,
	workspaceRepo port.WorkspaceRepository,
	tenantRepo port.TenantRepository,
	workspaceProvider port.WorkspaceInjectableProvider,
) injectableuc.InjectableUseCase

NewInjectableService creates a new injectable service.

func NewSystemInjectableService

func NewSystemInjectableService(
	repo port.SystemInjectableRepository,
	registry port.InjectorRegistry,
) injectableuc.SystemInjectableUseCase

NewSystemInjectableService creates a new system injectable service.

func NewWorkspaceInjectableService

NewWorkspaceInjectableService creates a new workspace injectable service.

Types

type DependencyGraph

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

DependencyGraph is a directed acyclic graph (DAG) that manages dependencies between injectors for determining execution order.

Purpose: When resolving injectable values, injectors may depend on the results of other injectors. The DependencyGraph ensures injectors are executed in the correct order by performing topological sorting.

How it works:

  1. Each injector is a node in the graph
  2. An edge from A to B means "A depends on B" (B must execute before A)
  3. TopologicalSort groups nodes into levels where: - Level 0: nodes with no dependencies (can run in parallel) - Level 1: nodes depending only on level 0 (can run in parallel) - And so on...

Example:

Injectors: client_name, calculated_price (depends on base_price), base_price

Graph:
  calculated_price -> base_price
  client_name (no dependencies)
  base_price (no dependencies)

Levels after TopologicalSort:
  Level 0: [client_name, base_price] - run in parallel
  Level 1: [calculated_price] - runs after level 0

Cycle Detection: If a dependency cycle is detected (A -> B -> C -> A), TopologicalSort returns an error with the cycle path for debugging.

func NewDependencyGraph

func NewDependencyGraph() *DependencyGraph

NewDependencyGraph creates a new dependency graph.

func (*DependencyGraph) AddEdge

func (g *DependencyGraph) AddEdge(from, to string)

AddEdge adds a dependency: 'from' depends on 'to'. This means 'to' must execute before 'from'.

func (*DependencyGraph) AddNode

func (g *DependencyGraph) AddNode(code string)

AddNode adds a node to the graph.

func (*DependencyGraph) BuildFromInjectors

func (g *DependencyGraph) BuildFromInjectors(
	getInjector func(code string) (dependencies []string, exists bool),
	referencedCodes []string,
) error

BuildFromInjectors builds the dependency graph from injectors. Only includes injectors whose codes are in referencedCodes.

func (*DependencyGraph) TopologicalSort

func (g *DependencyGraph) TopologicalSort() ([][]string, error)

TopologicalSort returns the nodes ordered by dependency levels. Each level contains nodes that can be executed in parallel. Returns an error if cycles are detected.

type InjectableResolverService

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

InjectableResolverService resolves injector values.

func NewInjectableResolverService

func NewInjectableResolverService(
	registry port.InjectorRegistry,
	workspaceProvider port.WorkspaceInjectableProvider,
) *InjectableResolverService

NewInjectableResolverService creates a new resolution service.

func (*InjectableResolverService) MergeWithPayloadValues

func (s *InjectableResolverService) MergeWithPayloadValues(
	resolved *ResolveResult,
	payloadValues map[string]entity.InjectableValue,
) map[string]any

MergeWithPayloadValues combines injector values with values extracted from the payload. Payload values have priority (they overwrite injector values).

func (*InjectableResolverService) Resolve

func (s *InjectableResolverService) Resolve(
	ctx context.Context,
	injCtx *entity.InjectorContext,
	referencedCodes []string,
) (*ResolveResult, error)

Resolve resolves the values of the referenced injectors. Executes Init() GLOBAL first, then resolves registry injectors by dependency levels, then resolves provider injectors in batch.

type InjectableService

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

InjectableService implements injectable definition business logic. Note: Injectables are read-only - they are managed via database migrations/seeds.

func (*InjectableService) GetInjectable

GetInjectable retrieves an injectable definition by ID.

func (*InjectableService) ListInjectables

ListInjectables lists all injectable definitions for a workspace (including global, system, and provider).

type ResolveResult

type ResolveResult struct {

	// Values contains the resolved values (code -> value).
	Values map[string]entity.InjectableValue

	// Errors contains errors from non-critical injectors.
	Errors map[string]error

	// Metadata contains additional metadata per injector.
	Metadata map[string]map[string]any
	// contains filtered or unexported fields
}

ResolveResult contains the results of injector resolution.

type SystemInjectableService

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

SystemInjectableService implements system injectable management business logic.

func (*SystemInjectableService) Activate

func (s *SystemInjectableService) Activate(ctx context.Context, key string) error

Activate enables a system injectable globally.

func (*SystemInjectableService) BulkActivate

BulkActivate activates multiple system injectables globally.

func (*SystemInjectableService) BulkCreateAssignments

BulkCreateAssignments creates scoped assignments for multiple injectable keys. Keys that already have assignments at the given scope are considered successful (idempotent).

func (*SystemInjectableService) BulkDeactivate

BulkDeactivate deactivates multiple system injectables globally.

func (*SystemInjectableService) BulkDeleteAssignments

BulkDeleteAssignments deletes scoped assignments for multiple injectable keys. Keys that don't have assignments at the given scope are considered successful (idempotent).

func (*SystemInjectableService) CreateAssignment

CreateAssignment creates a new assignment for a system injectable.

func (*SystemInjectableService) Deactivate

func (s *SystemInjectableService) Deactivate(ctx context.Context, key string) error

Deactivate disables a system injectable globally.

func (*SystemInjectableService) DeleteAssignment

func (s *SystemInjectableService) DeleteAssignment(ctx context.Context, key, assignmentID string) error

DeleteAssignment removes an assignment.

func (*SystemInjectableService) ExcludeAssignment

func (s *SystemInjectableService) ExcludeAssignment(ctx context.Context, key, assignmentID string) error

ExcludeAssignment sets an assignment's is_active to false (exclusion).

func (*SystemInjectableService) IncludeAssignment

func (s *SystemInjectableService) IncludeAssignment(ctx context.Context, key, assignmentID string) error

IncludeAssignment sets an assignment's is_active to true (undo exclusion).

func (*SystemInjectableService) ListAll

ListAll returns all system injectors from the registry with their active state.

func (*SystemInjectableService) ListAssignments

ListAssignments returns all assignments for a given system injectable key.

type WorkspaceInjectableService

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

WorkspaceInjectableService implements workspace injectable business logic.

func (*WorkspaceInjectableService) ActivateInjectable

func (s *WorkspaceInjectableService) ActivateInjectable(ctx context.Context, id, workspaceID string) (*entity.InjectableDefinition, error)

ActivateInjectable sets is_active=true for an injectable.

func (*WorkspaceInjectableService) CreateInjectable

CreateInjectable creates a new TEXT type injectable for the workspace.

func (*WorkspaceInjectableService) DeactivateInjectable

func (s *WorkspaceInjectableService) DeactivateInjectable(ctx context.Context, id, workspaceID string) (*entity.InjectableDefinition, error)

DeactivateInjectable sets is_active=false for an injectable.

func (*WorkspaceInjectableService) DeleteInjectable

func (s *WorkspaceInjectableService) DeleteInjectable(ctx context.Context, id, workspaceID string) error

DeleteInjectable soft-deletes an injectable.

func (*WorkspaceInjectableService) GetInjectable

func (s *WorkspaceInjectableService) GetInjectable(ctx context.Context, id, workspaceID string) (*entity.InjectableDefinition, error)

GetInjectable retrieves an injectable by ID.

func (*WorkspaceInjectableService) ListInjectables

func (s *WorkspaceInjectableService) ListInjectables(ctx context.Context, workspaceID string) ([]*entity.InjectableDefinition, error)

ListInjectables lists all injectables owned by the workspace.

func (*WorkspaceInjectableService) UpdateInjectable

UpdateInjectable updates a workspace-owned injectable.

Jump to

Keyboard shortcuts

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