Documentation
¶
Index ¶
- type EventSchemaValidator
- type JSONSchemaValidator
- type MemorySchemaCache
- type MemorySchemaStore
- func (mss *MemorySchemaStore) Close(ctx context.Context) error
- func (mss *MemorySchemaStore) DeleteSchema(ctx context.Context, schemaID string) error
- func (mss *MemorySchemaStore) GetLatestSchema(ctx context.Context, eventType string) (*Schema, error)
- func (mss *MemorySchemaStore) GetSchema(ctx context.Context, eventType string, version int) (*Schema, error)
- func (mss *MemorySchemaStore) GetSchemaByID(ctx context.Context, schemaID string) (*Schema, error)
- func (mss *MemorySchemaStore) GetSchemaVersions(ctx context.Context, eventType string) ([]*Schema, error)
- func (mss *MemorySchemaStore) ListEventTypes(ctx context.Context) ([]string, error)
- func (mss *MemorySchemaStore) SaveSchema(ctx context.Context, schema *Schema) error
- type Property
- type RegexValidator
- type RegistryConfig
- type Schema
- type SchemaCache
- type SchemaChange
- type SchemaEvolution
- type SchemaRegistry
- func (sr *SchemaRegistry) DeleteSchema(ctx context.Context, eventType string, version int) error
- func (sr *SchemaRegistry) GetLatestSchema(eventType string) (*Schema, error)
- func (sr *SchemaRegistry) GetSchema(eventType string, version int) (*Schema, error)
- func (sr *SchemaRegistry) GetSchemaByID(schemaID string) (*Schema, error)
- func (sr *SchemaRegistry) GetSchemaVersions(eventType string) ([]*Schema, error)
- func (sr *SchemaRegistry) GetStats() map[string]any
- func (sr *SchemaRegistry) ListEventTypes() []string
- func (sr *SchemaRegistry) RegisterSchema(ctx context.Context, schema *Schema) error
- func (sr *SchemaRegistry) UpdateSchema(ctx context.Context, schema *Schema) error
- type SchemaStore
- type StructValidator
- type TransformationRule
- type ValidationConfig
- type ValidationError
- type ValidationResult
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventSchemaValidator ¶
type EventSchemaValidator struct {
// contains filtered or unexported fields
}
EventSchemaValidator validates events against registered schemas.
func NewEventSchemaValidator ¶
func NewEventSchemaValidator(registry *SchemaRegistry, config *ValidationConfig, logger forge.Logger, metrics forge.Metrics) *EventSchemaValidator
NewEventSchemaValidator creates a new event schema validator.
func (*EventSchemaValidator) AddValidator ¶
func (esv *EventSchemaValidator) AddValidator(schemaID string, validator Validator)
AddValidator adds a custom validator.
func (*EventSchemaValidator) GetStats ¶
func (esv *EventSchemaValidator) GetStats() map[string]any
GetStats returns validation statistics.
func (*EventSchemaValidator) RemoveValidator ¶
func (esv *EventSchemaValidator) RemoveValidator(schemaID string)
RemoveValidator removes a validator.
func (*EventSchemaValidator) ValidateEvent ¶
func (esv *EventSchemaValidator) ValidateEvent(event *eventscore.Event) *ValidationResult
ValidateEvent validates an event against its schema.
type JSONSchemaValidator ¶
type JSONSchemaValidator struct {
// contains filtered or unexported fields
}
JSONSchemaValidator validates against JSON Schema.
func NewJSONSchemaValidator ¶
func NewJSONSchemaValidator(schema *Schema) (*JSONSchemaValidator, error)
NewJSONSchemaValidator creates a new JSON schema validator.
func (*JSONSchemaValidator) GetSchema ¶
func (jsv *JSONSchemaValidator) GetSchema() *Schema
GetSchema implements Validator.
func (*JSONSchemaValidator) GetType ¶
func (jsv *JSONSchemaValidator) GetType() string
GetType implements Validator.
func (*JSONSchemaValidator) Validate ¶
func (jsv *JSONSchemaValidator) Validate(data any) error
Validate implements Validator.
type MemorySchemaCache ¶
type MemorySchemaCache struct {
// contains filtered or unexported fields
}
MemorySchemaCache implements SchemaCache using in-memory storage.
func NewMemorySchemaCache ¶
func NewMemorySchemaCache() *MemorySchemaCache
NewMemorySchemaCache creates a new in-memory schema cache.
func (*MemorySchemaCache) Clear ¶
func (msc *MemorySchemaCache) Clear()
Clear implements SchemaCache.
func (*MemorySchemaCache) Delete ¶
func (msc *MemorySchemaCache) Delete(key string)
Delete implements SchemaCache.
func (*MemorySchemaCache) Get ¶
func (msc *MemorySchemaCache) Get(key string) (*Schema, bool)
Get implements SchemaCache.
func (*MemorySchemaCache) Set ¶
func (msc *MemorySchemaCache) Set(key string, schema *Schema, ttl time.Duration)
Set implements SchemaCache.
func (*MemorySchemaCache) Stats ¶
func (msc *MemorySchemaCache) Stats() map[string]any
Stats implements SchemaCache.
type MemorySchemaStore ¶
type MemorySchemaStore struct {
// contains filtered or unexported fields
}
MemorySchemaStore implements SchemaStore using in-memory storage.
func NewMemorySchemaStore ¶
func NewMemorySchemaStore() *MemorySchemaStore
NewMemorySchemaStore creates a new in-memory schema store.
func (*MemorySchemaStore) Close ¶
func (mss *MemorySchemaStore) Close(ctx context.Context) error
Close implements SchemaStore.
func (*MemorySchemaStore) DeleteSchema ¶
func (mss *MemorySchemaStore) DeleteSchema(ctx context.Context, schemaID string) error
DeleteSchema implements SchemaStore.
func (*MemorySchemaStore) GetLatestSchema ¶
func (mss *MemorySchemaStore) GetLatestSchema(ctx context.Context, eventType string) (*Schema, error)
GetLatestSchema implements SchemaStore.
func (*MemorySchemaStore) GetSchema ¶
func (mss *MemorySchemaStore) GetSchema(ctx context.Context, eventType string, version int) (*Schema, error)
GetSchema implements SchemaStore.
func (*MemorySchemaStore) GetSchemaByID ¶
GetSchemaByID implements SchemaStore.
func (*MemorySchemaStore) GetSchemaVersions ¶
func (mss *MemorySchemaStore) GetSchemaVersions(ctx context.Context, eventType string) ([]*Schema, error)
GetSchemaVersions implements SchemaStore.
func (*MemorySchemaStore) ListEventTypes ¶
func (mss *MemorySchemaStore) ListEventTypes(ctx context.Context) ([]string, error)
ListEventTypes implements SchemaStore.
func (*MemorySchemaStore) SaveSchema ¶
func (mss *MemorySchemaStore) SaveSchema(ctx context.Context, schema *Schema) error
SaveSchema implements SchemaStore.
type Property ¶
type Property struct {
Type string `json:"type"`
Description string `json:"description"`
Format string `json:"format,omitempty"`
Pattern string `json:"pattern,omitempty"`
Enum []any `json:"enum,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
MinLength *int `json:"min_length,omitempty"`
MaxLength *int `json:"max_length,omitempty"`
Items *Property `json:"items,omitempty"`
Properties map[string]*Property `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
Default any `json:"default,omitempty"`
Examples []any `json:"examples,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
Property represents a schema property.
type RegexValidator ¶
type RegexValidator struct {
// contains filtered or unexported fields
}
RegexValidator validates using regular expressions.
func NewRegexValidator ¶
func NewRegexValidator(schema *Schema) (*RegexValidator, error)
NewRegexValidator creates a new regex validator.
func (*RegexValidator) GetSchema ¶
func (rv *RegexValidator) GetSchema() *Schema
GetSchema implements Validator.
func (*RegexValidator) GetType ¶
func (rv *RegexValidator) GetType() string
GetType implements Validator.
func (*RegexValidator) Validate ¶
func (rv *RegexValidator) Validate(data any) error
Validate implements Validator.
type RegistryConfig ¶
type RegistryConfig struct {
EnableCache bool `json:"enable_cache" yaml:"enable_cache"`
CacheTTL time.Duration `json:"cache_ttl" yaml:"cache_ttl"`
AutoRegister bool `json:"auto_register" yaml:"auto_register"`
VersioningStrategy string `json:"versioning_strategy" yaml:"versioning_strategy"` // "strict", "compatible", "none"
ValidationLevel string `json:"validation_level" yaml:"validation_level"` // "strict", "lenient", "disabled"
AllowEvolution bool `json:"allow_evolution" yaml:"allow_evolution"`
MaxVersions int `json:"max_versions" yaml:"max_versions"`
}
RegistryConfig defines configuration for the schema registry.
func DefaultRegistryConfig ¶
func DefaultRegistryConfig() *RegistryConfig
DefaultRegistryConfig returns default configuration.
type Schema ¶
type Schema struct {
ID string `json:"id"`
Name string `json:"name"`
Version int `json:"version"`
Type string `json:"type"`
Title string `json:"title"`
Description string `json:"description"`
Properties map[string]*Property `json:"properties"`
Required []string `json:"required"`
Metadata map[string]any `json:"metadata"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
Schema represents an event schema.
type SchemaCache ¶
type SchemaCache interface {
// Get retrieves a schema from cache
Get(key string) (*Schema, bool)
// Set stores a schema in cache
Set(key string, schema *Schema, ttl time.Duration)
// Delete removes a schema from cache
Delete(key string)
// Clear clears all cached schemas
Clear()
// Stats returns cache statistics
Stats() map[string]any
}
SchemaCache defines interface for caching schemas.
type SchemaChange ¶
type SchemaChange struct {
Type string `json:"type"` // "add", "remove", "modify", "rename"
Path string `json:"path"` // JSON path to the changed property
OldValue any `json:"old_value,omitempty"`
NewValue any `json:"new_value,omitempty"`
Description string `json:"description,omitempty"`
}
SchemaChange represents a change in schema.
type SchemaEvolution ¶
type SchemaEvolution struct {
EventType string `json:"event_type"`
FromVersion int `json:"from_version"`
ToVersion int `json:"to_version"`
Changes []SchemaChange `json:"changes"`
Compatible bool `json:"compatible"`
Transformation *TransformationRule `json:"transformation,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
SchemaEvolution defines how schemas can evolve.
type SchemaRegistry ¶
type SchemaRegistry struct {
// contains filtered or unexported fields
}
SchemaRegistry manages event schemas for validation and evolution.
func NewSchemaRegistry ¶
func NewSchemaRegistry(store SchemaStore, cache SchemaCache, config *RegistryConfig, logger forge.Logger, metrics forge.Metrics) *SchemaRegistry
NewSchemaRegistry creates a new schema registry.
func (*SchemaRegistry) DeleteSchema ¶
DeleteSchema deletes a schema.
func (*SchemaRegistry) GetLatestSchema ¶
func (sr *SchemaRegistry) GetLatestSchema(eventType string) (*Schema, error)
GetLatestSchema retrieves the latest version of a schema.
func (*SchemaRegistry) GetSchema ¶
func (sr *SchemaRegistry) GetSchema(eventType string, version int) (*Schema, error)
GetSchema retrieves a schema by event type and version.
func (*SchemaRegistry) GetSchemaByID ¶
func (sr *SchemaRegistry) GetSchemaByID(schemaID string) (*Schema, error)
GetSchemaByID retrieves a schema by ID.
func (*SchemaRegistry) GetSchemaVersions ¶
func (sr *SchemaRegistry) GetSchemaVersions(eventType string) ([]*Schema, error)
GetSchemaVersions retrieves all versions of a schema.
func (*SchemaRegistry) GetStats ¶
func (sr *SchemaRegistry) GetStats() map[string]any
GetStats returns registry statistics.
func (*SchemaRegistry) ListEventTypes ¶
func (sr *SchemaRegistry) ListEventTypes() []string
ListEventTypes lists all registered event types.
func (*SchemaRegistry) RegisterSchema ¶
func (sr *SchemaRegistry) RegisterSchema(ctx context.Context, schema *Schema) error
RegisterSchema registers a new schema in the registry.
func (*SchemaRegistry) UpdateSchema ¶
func (sr *SchemaRegistry) UpdateSchema(ctx context.Context, schema *Schema) error
UpdateSchema updates an existing schema.
type SchemaStore ¶
type SchemaStore interface {
// SaveSchema saves a schema to persistent storage
SaveSchema(ctx context.Context, schema *Schema) error
// GetSchema retrieves a schema by type and version
GetSchema(ctx context.Context, eventType string, version int) (*Schema, error)
// GetSchemaByID retrieves a schema by ID
GetSchemaByID(ctx context.Context, schemaID string) (*Schema, error)
// GetLatestSchema retrieves the latest version of a schema
GetLatestSchema(ctx context.Context, eventType string) (*Schema, error)
// GetSchemaVersions retrieves all versions of a schema
GetSchemaVersions(ctx context.Context, eventType string) ([]*Schema, error)
// DeleteSchema deletes a schema
DeleteSchema(ctx context.Context, schemaID string) error
// ListEventTypes lists all registered event types
ListEventTypes(ctx context.Context) ([]string, error)
// Close closes the schema store
Close(ctx context.Context) error
}
SchemaStore defines interface for persisting schemas.
type StructValidator ¶
type StructValidator struct {
// contains filtered or unexported fields
}
StructValidator validates against Go struct definitions.
func NewStructValidator ¶
func NewStructValidator(schema *Schema) (*StructValidator, error)
NewStructValidator creates a new struct validator.
func (*StructValidator) GetSchema ¶
func (sv *StructValidator) GetSchema() *Schema
GetSchema implements Validator.
func (*StructValidator) GetType ¶
func (sv *StructValidator) GetType() string
GetType implements Validator.
func (*StructValidator) Validate ¶
func (sv *StructValidator) Validate(data any) error
Validate implements Validator.
type TransformationRule ¶
type TransformationRule struct {
Rule string `json:"rule"` // "copy", "rename", "transform", "default"
SourcePath string `json:"source_path,omitempty"`
TargetPath string `json:"target_path,omitempty"`
Transform string `json:"transform,omitempty"` // transformation expression
DefaultValue any `json:"default_value,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
TransformationRule defines how to transform data between schema versions.
type ValidationConfig ¶
type ValidationConfig struct {
StrictMode bool `json:"strict_mode" yaml:"strict_mode"`
RequiredFields []string `json:"required_fields" yaml:"required_fields"`
AllowExtraFields bool `json:"allow_extra_fields" yaml:"allow_extra_fields"`
ValidateMetadata bool `json:"validate_metadata" yaml:"validate_metadata"`
MaxDepth int `json:"max_depth" yaml:"max_depth"`
MaxSize int `json:"max_size" yaml:"max_size"`
}
ValidationConfig defines configuration for event validation.
func DefaultValidationConfig ¶
func DefaultValidationConfig() *ValidationConfig
DefaultValidationConfig returns default validation configuration.
type ValidationError ¶
type ValidationError struct {
Field string `json:"field"`
Value any `json:"value"`
Expected string `json:"expected"`
Message string `json:"message"`
Code string `json:"code"`
}
ValidationError represents a validation error.
func (*ValidationError) Error ¶
func (ve *ValidationError) Error() string
Error implements error interface.
type ValidationResult ¶
type ValidationResult struct {
Valid bool `json:"valid"`
Errors []*ValidationError `json:"errors"`
Schema *Schema `json:"schema"`
EventID string `json:"event_id"`
}
ValidationResult contains validation results.