resource

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package resource is the kernel resource registry and the thin tenant mirror that lets kernel services (authz record-scope, comments, documents, workflow, relationships) address any module row uniformly. A module owns its business table; on write it upserts a matching row into the kernel `resources` table (same id) via a Registrar, declaring the resource type. See blueprint 01 §3, 03 §2, 04 §2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidTypeKey

func ValidTypeKey(key string) bool

ValidTypeKey reports whether key is a legal resource type key.

Types

type PgRegistrar

type PgRegistrar struct{}

PgRegistrar is the Postgres-backed resource Registrar factory. It carries no state of its own: a Registrar must run inside the caller's tenant transaction so the mirror row and the business write commit atomically, and the tx's TenantDB is only available per unit of work. Bind supplies that db and yields a Registrar bound to it.

func NewRegistrar

func NewRegistrar() *PgRegistrar

NewRegistrar returns the Postgres resource registrar factory.

func (*PgRegistrar) Bind

func (r *PgRegistrar) Bind(db database.TenantDB) Registrar

Bind returns a Registrar that writes the resources mirror through db (the caller's open tenant transaction). Module code obtains db from the TxManager and binds the registrar for the duration of the write.

type Ref

type Ref struct {
	Type string    `json:"type"` // registered resource_types.key, e.g. "requests.request"
	ID   uuid.UUID `json:"id"`
}

Ref is a kernel-wide pointer to any domain object: its registered type key plus id. It is the currency of authz targets, relationships, comments, and attachments.

func (Ref) IsZero

func (r Ref) IsZero() bool

IsZero reports whether the ref is unset.

type Registrar

type Registrar interface {
	// Upsert writes (or updates) the resources row: same id as the module row,
	// its resource type, optional org, a human label, and status.
	Upsert(ctx context.Context, ref Ref, orgID *uuid.UUID, label, status string) error
}

Registrar upserts the kernel resources mirror row for a module aggregate, inside the caller's tenant transaction so the mirror and the business write commit atomically. The concrete implementation lives beside the DB layer and receives the TenantDB; this port keeps module code off the raw pool.

type Registry

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

Registry accumulates resource type declarations during module registration and is synced to the resource_types table at boot. Duplicate keys and keys whose module prefix does not match the registering module are errors.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty registry.

func (*Registry) Err

func (r *Registry) Err() error

Err returns accumulated registration errors joined, or nil.

func (*Registry) Register

func (r *Registry) Register(module string, spec TypeSpec)

Register adds a resource type for the given module. The key must be "<module>.<name>"; a mismatch or duplicate records an error surfaced by Err.

func (*Registry) Specs

func (r *Registry) Specs() map[string]TypeSpec

Specs returns the registered specs keyed by type key.

type TypeSpec

type TypeSpec struct {
	Key         string // "requests.request"
	Description string
}

TypeSpec describes a resource type a module registers. Module is derived from the key prefix and validated against the registering module.

Jump to

Keyboard shortcuts

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