framework

package
v1.801.450 Latest Latest
Warning

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

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

Documentation

Overview

Package framework is document types you define: describe a record once, then create, list, submit and cancel documents against it.

The DocType routes live at /v1/framework and are per org, with the engine's own permission calculus deciding every access.

The engine itself is github.com/hanzoai/framework, built on the metadata model github.com/hanzoai/doctype. Neither knows what HTTP is. This package is the ADAPTER — the "place" in the engine's layering:

doctype    the VALUE  — schema, coercion, naming, permission calculus.
framework  the ENGINE — store, hooks, leases, operations. No transport.
this pkg   the PLACE  — /v1/framework/* over zip, cek-encrypted storage,
                        principal-derived tenancy, engine Code → HTTP status.

It does four things and nothing else:

  1. opens the engine with cloud's storage policy (cek, encrypted at rest);
  2. turns a validated request principal into an engine Caller;
  3. binds each engine operation to a TYPED OP and maps the error Code;
  4. re-exports the engine vocabulary so the app lanes (cms, erp, help, knowledge, content, guide) keep ONE import and compile unchanged.

(3) is a typed op — zip.Get[In, Out] and friends — for every route but the two document WRITES: one registry entry, and the REST route, the OpenAPI operation, the MCP tool, the CLI command and the generated SDK method all follow from it. The two exceptions are in Mount, with the reason.

The engine enforces permissions itself, so there is no authorization logic here — a second copy would be a second answer.

Index

Constants

View Source
const (
	FieldData     = doctype.FieldData
	FieldInt      = doctype.FieldInt
	FieldFloat    = doctype.FieldFloat
	FieldCurrency = doctype.FieldCurrency
	FieldCheck    = doctype.FieldCheck
	FieldDate     = doctype.FieldDate
	FieldDatetime = doctype.FieldDatetime
	FieldText     = doctype.FieldText
	FieldSmall    = doctype.FieldSmall
	FieldLong     = doctype.FieldLong
	FieldRichText = doctype.FieldRichText
	FieldSelect   = doctype.FieldSelect
	FieldLink     = doctype.FieldLink
	FieldTable    = doctype.FieldTable
	FieldAttach   = doctype.FieldAttach
	FieldJSON     = doctype.FieldJSON
	FieldPassword = doctype.FieldPassword
)

The closed fieldtype set.

View Source
const (
	RoleSystemManager = doctype.RoleSystemManager
	RoleAll           = doctype.RoleAll
)

Roles.

View Source
const (
	ActionBeforeInsert = engine.ActionBeforeInsert
	ActionBeforeSave   = engine.ActionBeforeSave
	ActionAfterSave    = engine.ActionAfterSave
	ActionOnSubmit     = engine.ActionOnSubmit
	ActionOnCancel     = engine.ActionOnCancel
	ActionOnTrash      = engine.ActionOnTrash
)

Lifecycle hook actions.

Variables

View Source
var (
	ErrNotFound = engine.ErrNotFound
	ErrConflict = engine.ErrConflict
	ErrBadRef   = engine.ErrBadRef
)

Error sentinels an in-process caller classifies with errors.Is.

View Source
var (
	// RegisterModule declares the DocType fixtures a module installs.
	RegisterModule = doctype.RegisterModule
	// MarkAlwaysOn makes a module's fixtures resolve for every org with no
	// per-org install step.
	MarkAlwaysOn = doctype.MarkAlwaysOn
	// RegisteredModules is the sorted set of registered module names.
	RegisteredModules = doctype.RegisteredModules
	// AlwaysOnModules is the sorted set of modules marked always-on.
	AlwaysOnModules = doctype.AlwaysOnModules
	// RegisterHook attaches a lifecycle handler to (doctype, action).
	RegisterHook = engine.RegisterHook
	// RegisteredHookCount is the number of (doctype, action) keys carrying a
	// hook — the composition root's link-guard asserts the lanes are compiled in.
	RegisteredHookCount = engine.RegisteredHookCount
)

Registration entry points. An app lane calls these from a package init() to declare its content model and attach behaviour — the ONE way a lane extends the engine.

Functions

func Delete

func Delete(ctx context.Context, org, doctype, name string) error

Delete removes a document after running the on_trash gate hooks.

func FindByField

func FindByField(ctx context.Context, org, doctype, field, value string) (string, error)

FindByField returns the name of the first document whose `field` equals `value`, or "" if none.

func Installed

func Installed(ctx context.Context, org, doctype string) bool

Installed reports whether `doctype` exists in `org`.

func IsValidationError

func IsValidationError(err error) bool

IsValidationError reports whether err is a document-schema violation.

func ModuleInstalled

func ModuleInstalled(ctx context.Context, org, module string) bool

ModuleInstalled reports whether a module's content model resolves for `org`.

func Mount

func Mount(app cloud.Router, deps cloud.Deps) error

Mount wires the framework surface onto app per HIP-0106.

func Shutdown

func Shutdown() error

Shutdown closes the engine. Idempotent.

func UpdateData

func UpdateData(ctx context.Context, org, doctype, name string, data map[string]any) error

UpdateData replaces an existing draft document's data, running before_save + after_save — the in-process twin of the HTTP PUT.

Types

type DocField

type DocField = doctype.DocField

DocField is one field in a DocType.

type DocPerm

type DocPerm = doctype.DocPerm

DocPerm is a role's rights on a DocType.

type DocType

type DocType = doctype.DocType

DocType is a metadata definition.

type Document

type Document = engine.Document

Document is a stored record: validated field data plus its lifecycle state.

func Get

func Get(ctx context.Context, org, doctype, name string) (Document, error)

Get returns one document by name in (org, doctype).

func Search(ctx context.Context, org, doctype string, filters map[string]string, limit int) ([]Document, error)

Search is the in-process, org-scoped document list.

type Event

type Event = engine.Event

Event is the value that flows through a lifecycle Hook.

type Hook

type Hook = engine.Hook

Hook is a server-side lifecycle handler.

type Ingested

type Ingested = engine.Ingested

Ingested is the result of an in-process create.

func Ingest

func Ingest(ctx context.Context, org, doctype string, data map[string]any, requestedName string) (Ingested, error)

Ingest creates a document from already-trusted field data, running the full validate + lifecycle-hook pipeline.

type Lease

type Lease = engine.Lease

Lease is an acquired exclusive claim on (org, key).

func AcquireLease

func AcquireLease(ctx context.Context, org, key string, ttl, wait time.Duration) (*Lease, bool, error)

AcquireLease takes an exclusive, TTL-bounded lease on (org, key) — the cross-process interlock a non-idempotent side effect (the content lane's channel fan-out) serializes on.

type ListOpts

type ListOpts = engine.ListOpts

ListOpts is a parsed, validated list query.

type Role

type Role = engine.Role

Role is a (user, role) assignment within an org.

type Store

type Store = engine.Store

Store is the engine's per-org data access, reached by hooks via Event.Store.

Jump to

Keyboard shortcuts

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