Files
ResolveSpec/pkg/mqttspec/hooks.go
T
warkanum 52d3dca1fa
Tests / Unit Tests (push) Failing after 11s
Tests / Integration Tests (push) Failing after 15s
Build , Vet Test, and Lint / Build (push) Successful in 1m45s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in 2m0s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in 2m0s
Build , Vet Test, and Lint / Lint Code (push) Successful in 2m4s
feat(hooks): add BeforeOp hook and fix BeforeScan row-security gap
Adds a BeforeOp HookType across resolvespec, restheadspec, websocketspec,
mqttspec, and funcspec that fires before every SQL operation (read,
create, update, delete, scan/query) via a new ExecuteBeforeOp helper.

Also closes a row-level-security gap: resolvespec registered a BeforeScan
hook for ApplyRowSecurity but never fired it, and websocketspec/mqttspec
had no BeforeScan hook point at all, so row security was never applied
to their queries. BeforeScan now fires right before the actual scan in
all three, with the (possibly hook-modified) query used for execution.
2026-07-25 11:39:31 +02:00

59 lines
1.8 KiB
Go

package mqttspec
import (
"github.com/bitechdev/ResolveSpec/pkg/websocketspec"
)
// Hook types - aliases to websocketspec for lifecycle hook consistency
type (
// HookType defines the type of lifecycle hook
HookType = websocketspec.HookType
// HookFunc is a function that executes during a lifecycle hook
HookFunc = websocketspec.HookFunc
// HookContext contains all context for hook execution
// Note: For MQTT, the Client is stored in Metadata["mqtt_client"]
HookContext = websocketspec.HookContext
// HookRegistry manages all registered hooks
HookRegistry = websocketspec.HookRegistry
)
// Hook type constants - all lifecycle hooks
const (
// BeforeHandle fires after model resolution, before operation dispatch
BeforeHandle = websocketspec.BeforeHandle
// CRUD operation hooks
BeforeRead = websocketspec.BeforeRead
AfterRead = websocketspec.AfterRead
BeforeCreate = websocketspec.BeforeCreate
AfterCreate = websocketspec.AfterCreate
BeforeUpdate = websocketspec.BeforeUpdate
AfterUpdate = websocketspec.AfterUpdate
BeforeDelete = websocketspec.BeforeDelete
AfterDelete = websocketspec.AfterDelete
BeforeScan = websocketspec.BeforeScan
// Subscription hooks
BeforeSubscribe = websocketspec.BeforeSubscribe
AfterSubscribe = websocketspec.AfterSubscribe
BeforeUnsubscribe = websocketspec.BeforeUnsubscribe
AfterUnsubscribe = websocketspec.AfterUnsubscribe
// Connection hooks
BeforeConnect = websocketspec.BeforeConnect
AfterConnect = websocketspec.AfterConnect
BeforeDisconnect = websocketspec.BeforeDisconnect
AfterDisconnect = websocketspec.AfterDisconnect
// BeforeOp fires immediately before every SQL operation (read, create, update, delete)
BeforeOp = websocketspec.BeforeOp
)
// NewHookRegistry creates a new hook registry
func NewHookRegistry() *HookRegistry {
return websocketspec.NewHookRegistry()
}