Files
summercms/pact/capabilities.go
Jakub Zych d376b1be2d feat(06-01): grow router verbs, factories, and guard registry
- Add Post/Put/Patch/Delete on pact.Router and surf Router/Group
- Resolve name:param middleware via RegisterMiddlewareFactory
- Add bouncer.Registry with Guard, CredentialGuard, UnauthorizedWriter
- Re-express jwt as NewJWTGuard without changing Middleware bodies
2026-09-19 18:59:12 +02:00

131 lines
4.0 KiB
Go

package pact
import (
"context"
"io/fs"
"net/http"
"git.golem15.com/golem15/summercms/bonfire"
"github.com/go-gormigrate/gormigrate/v2"
)
// HasCommands is implemented by plugins that register console commands.
type HasCommands interface {
Commands() []bonfire.Command
}
// HasConfig is implemented by plugins that ship default YAML configuration.
// ConfigFS should contain files such as config/config.yaml, merged later at
// the plugin ID path.
type HasConfig interface {
ConfigFS() fs.FS
}
// HasMigrations is implemented by plugins that ship an ordered gormigrate
// set. The kernel runs each set in party.Activate order with a separate
// history table per plugin ID.
type HasMigrations interface {
Migrations() []*gormigrate.Migration
}
// Middleware is a named HTTP wrapper registered by a plugin.
type Middleware func(http.Handler) http.Handler
// HasMiddleware is implemented by plugins that register named middleware.
type HasMiddleware interface {
Middlewares() map[string]Middleware
}
// HasMiddlewareFactories is implemented by plugins that register
// parameterized middleware ("name:param"), resolved at wrap time.
type HasMiddlewareFactories interface {
MiddlewareFactories() map[string]func(param string) Middleware
}
// Router is the Laravel-like group builder implemented by surf.
type Router interface {
Group(prefix string, middleware []string, fn func(Router))
Get(path string, handler http.HandlerFunc, middleware ...string)
Post(path string, handler http.HandlerFunc, middleware ...string)
Put(path string, handler http.HandlerFunc, middleware ...string)
Patch(path string, handler http.HandlerFunc, middleware ...string)
Delete(path string, handler http.HandlerFunc, middleware ...string)
Where(param, pattern string)
WhereIn(param string, values ...string)
}
// HasRoutes is implemented by plugins that declare HTTP routes.
type HasRoutes interface {
Routes(Router) error
}
// HasModels is implemented by plugins that expose GORM models.
type HasModels interface {
Models() []any
}
// JobArgs is the typed payload a job worker receives. Kind identifies the
// job so a worker can reject unexpected argument types.
type JobArgs interface {
Kind() string
}
// Job is a unit of background work. Phase 11 adapts this onto River; the
// interface itself must not import River.
type Job interface {
Work(ctx context.Context, args JobArgs) error
}
// HasJobs is implemented by plugins that register background jobs.
type HasJobs interface {
Jobs() []Job
}
// AdminController is the compile-time admin controller contract. Phase 9
// grows the schema pipeline; ID, model name and YAML config directory are
// enough for generated stubs to compile.
type AdminController interface {
ID() string
ModelName() string
ConfigDir() string
}
// HasAdminControllers is implemented by plugins that register admin controllers.
type HasAdminControllers interface {
AdminControllers() []AdminController
}
// HasLang is implemented by plugins that ship embedded translation YAML
// under lang/<locale>/<group>.yaml.
type HasLang interface {
LangFS() fs.FS
}
// HasMailTemplates is implemented by plugins that ship Winter-shaped mail
// templates and layout aliases. MailTemplatesFS contains views/mail assets;
// MailTemplates lists dotted template names; MailLayouts maps a short layout
// name to the full dotted layout name.
type HasMailTemplates interface {
MailTemplatesFS() fs.FS
MailTemplates() []string
MailLayouts() map[string]string
}
// OptionalMessage is a service an optional plugin may publish so other
// plugins can integrate without importing that plugin's package.
type OptionalMessage interface {
Message() string
}
// Future capability families are type-asserted when their first consumer
// packages exist:
//
// HasListeners
// HasNavigation
// HasPermissions
// HasSchedule
//
// The kernel type-asserts HasConfig (party, before Register), HasCommands
// (generated app main, after Boot), HasMigrations (lagoon migrate), and
// HasMiddleware/HasMiddlewareFactories/HasRoutes (surf assemble).