Skip to main content

KindHook

Trait KindHook 

Source
pub trait KindHook:
    Send
    + Sync
    + Debug {
    // Required methods
    fn prepare_create<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        runtime: &'life1 KhiveRuntime,
        args: &'life2 mut Value,
    ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn after_create<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        runtime: &'life1 KhiveRuntime,
        id: Uuid,
        args: &'life2 Value,
    ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn prepare_note_update<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        runtime: &'life1 KhiveRuntime,
        token: &'life2 NamespaceToken,
        note: &'life3 Note,
        args: &'life4 mut Value,
    ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait { ... }
    fn validate_note_update<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        _runtime: &'life1 KhiveRuntime,
        _token: &'life2 NamespaceToken,
        _note: &'life3 Note,
        _properties: Option<&'life4 Value>,
    ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait { ... }
    fn validate_links<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        _runtime: &'life1 KhiveRuntime,
        _token: &'life2 NamespaceToken,
        _links: &'life3 [LinkSpec],
    ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
}
Expand description

Per-kind specialization for shared CRUD.

Packs implement KindHook for kinds they own that need:

  • Defaults filled into create args (e.g. status="inbox" for tasks)
  • Derived properties computed from args (e.g. salience from priority)
  • Side-effect writes after the storage commit (e.g. depends_on edges)
  • Cross-pack validation before shared CRUD mutates an owned kind

Hooks are stateless from the framework’s perspective — they receive the runtime and the current mutation inputs as method parameters. The pack registers them via PackRuntime::kind_hook.

Lifecycle verbs (e.g. gtd’s complete, transition) remain pack-owned verbs. Shared create, note update, and link calls flow through this trait when an endpoint kind has an owning pack hook.

Required Methods§

Source

fn prepare_create<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, runtime: &'life1 KhiveRuntime, args: &'life2 mut Value, ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Mutate args before the storage write. Fill defaults, normalize values, rearrange user-facing fields into the storage shape expected by the shared CRUD handler.

Returning an error aborts the create call (no storage write happens).

Source

fn after_create<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, runtime: &'life1 KhiveRuntime, id: Uuid, args: &'life2 Value, ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Fire side effects after a successful storage write — graph edges, derived observations, etc. The newly created record’s UUID is passed so the hook can attach metadata referencing it.

Errors here are logged but not propagated — the storage write has already succeeded; failing the call would mislead the caller. Implementations should tracing::warn! and return Ok(()) for best-effort side effects.

Provided Methods§

Source

fn prepare_note_update<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, runtime: &'life1 KhiveRuntime, token: &'life2 NamespaceToken, note: &'life3 Note, args: &'life4 mut Value, ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Normalize a shared note update before storage is mutated.

The default preserves the original property-validation contract. A kind-owning pack overrides this when caller-facing note fields mirror owned properties and must be changed together (for example, a task’s searchable content and properties.description).

Source

fn validate_note_update<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, _runtime: &'life1 KhiveRuntime, _token: &'life2 NamespaceToken, _note: &'life3 Note, _properties: Option<&'life4 Value>, ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Validate a shared note-property update before storage is mutated.

The default accepts the update. Kind-owning packs override this when a property has invariants that generic CRUD cannot know about (for example, GTD task dependency acyclicity).

Validate one or more shared graph links before any edge is written.

A batch is supplied as a unit so a hook can reject a cycle formed only by the proposed edges. The default accepts every link.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§