type_bridge.crud.hooks¶
hooks
¶
Lifecycle hook system for CRUD operations.
Hooks are duck-typed classes that implement only the methods they care about.
Register them on a manager instance via manager.add_hook(hook).
Pre-hooks run in registration order and may raise HookCancelled to abort.
Post-hooks run in reverse registration order; errors are logged, not propagated.
CrudEvent
¶
Bases: Enum
CRUD lifecycle events.
HookCancelled
¶
Bases: Exception
Raise in a pre-hook to abort the operation.
Attributes:
| Name | Type | Description |
|---|---|---|
reason |
Human-readable explanation. |
|
event |
The event that was cancelled (set by HookRunner). |
|
hook |
The hook instance that raised the cancellation (set by HookRunner). |
Source code in type_bridge/crud/hooks.py
CrudHook
¶
Bases: Protocol
Protocol for CRUD lifecycle hooks.
Implement only the methods you need. All methods are optional —
HookRunner uses hasattr / getattr to discover them.
HookRunner
¶
Manages hook registration and execution.
Pre-hooks run in registration order. Post-hooks run in reverse registration order (middleware unwinding).
Source code in type_bridge/crud/hooks.py
add
¶
remove
¶
run_pre
¶
Run pre-hooks in registration order.
Raises HookCancelled if any hook cancels the operation.
Source code in type_bridge/crud/hooks.py
run_post
¶
Run post-hooks in reverse registration order.
Errors are logged but do not propagate.