schema

package
v0.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package schema defines the database schema for the CMS plugin.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFieldTitleRequired = &ComponentSchemaError{Message: "field title is required"}
	ErrFieldNameRequired  = &ComponentSchemaError{Message: "field name is required"}
	ErrFieldTypeRequired  = &ComponentSchemaError{Message: "field type is required"}
	ErrDuplicateFieldName = &ComponentSchemaError{Message: "duplicate field name"}
)

Component schema specific errors

Functions

This section is empty.

Types

type Choice

type Choice struct {
	Value    string `json:"value"`
	Label    string `json:"label"`
	Icon     string `json:"icon,omitempty"`
	Color    string `json:"color,omitempty"`
	Disabled bool   `json:"disabled,omitempty"`
}

Choice represents a choice option for select fields

type ComponentSchema

type ComponentSchema struct {
	bun.BaseModel `bun:"table:cms_component_schemas,alias:cs"`

	ID            xid.ID          `bun:"id,pk,type:varchar(20)" json:"id"`
	AppID         xid.ID          `bun:"app_id,notnull,type:varchar(20)" json:"appId"`
	EnvironmentID xid.ID          `bun:"environment_id,notnull,type:varchar(20)" json:"environmentId"`
	Title         string          `bun:"title,notnull" json:"title"`
	Name          string          `bun:"name,notnull" json:"name"`
	Description   string          `bun:"description,nullzero" json:"description"`
	Icon          string          `bun:"icon,nullzero" json:"icon"`
	Fields        NestedFieldDefs `bun:"fields,type:jsonb,notnull" json:"fields"`
	CreatedBy     xid.ID          `bun:"created_by,type:varchar(20)" json:"createdBy"`
	UpdatedBy     xid.ID          `bun:"updated_by,type:varchar(20)" json:"updatedBy"`
	CreatedAt     time.Time       `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
	UpdatedAt     time.Time       `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`
	DeletedAt     *time.Time      `bun:"deleted_at,soft_delete,nullzero" json:"-"`

	// Relations
	App         *mainSchema.App         `bun:"rel:belongs-to,join:app_id=id" json:"app,omitempty"`
	Environment *mainSchema.Environment `bun:"rel:belongs-to,join:environment_id=id" json:"environment,omitempty"`
}

ComponentSchema represents a reusable schema definition for nested objects

func (*ComponentSchema) BeforeInsert

func (cs *ComponentSchema) BeforeInsert()

BeforeInsert sets default values before insert

func (*ComponentSchema) BeforeUpdate

func (cs *ComponentSchema) BeforeUpdate()

BeforeUpdate updates the UpdatedAt timestamp

func (*ComponentSchema) GetAllFieldNames

func (cs *ComponentSchema) GetAllFieldNames() []string

GetAllFieldNames returns all field names (including nested ones recursively)

func (*ComponentSchema) GetFieldByName

func (cs *ComponentSchema) GetFieldByName(name string) *NestedFieldDef

GetFieldByName returns a nested field by its name

func (*ComponentSchema) GetRequiredFields

func (cs *ComponentSchema) GetRequiredFields() []NestedFieldDef

GetRequiredFields returns all required nested fields

func (*ComponentSchema) HasNestedObjects

func (cs *ComponentSchema) HasNestedObjects() bool

HasNestedObjects returns true if any field is an object or array type

func (*ComponentSchema) TableName

func (cs *ComponentSchema) TableName() string

TableName returns the table name for ComponentSchema

func (*ComponentSchema) ValidateFields

func (cs *ComponentSchema) ValidateFields() error

ValidateFields validates all nested field definitions

type ComponentSchemaError

type ComponentSchemaError struct {
	Message string
}

ComponentSchemaError represents a component schema validation error

func (*ComponentSchemaError) Error

func (e *ComponentSchemaError) Error() string

type ContentEntry

type ContentEntry struct {
	bun.BaseModel `bun:"table:cms_content_entries,alias:ce"`

	ID            xid.ID     `bun:"id,pk,type:varchar(20)" json:"id"`
	ContentTypeID xid.ID     `bun:"content_type_id,notnull,type:varchar(20)" json:"contentTypeId"`
	AppID         xid.ID     `bun:"app_id,notnull,type:varchar(20)" json:"appId"`
	EnvironmentID xid.ID     `bun:"environment_id,notnull,type:varchar(20)" json:"environmentId"`
	Data          EntryData  `bun:"data,type:jsonb,notnull" json:"data"`
	Status        string     `bun:"status,notnull,default:'draft'" json:"status"`
	Version       int        `bun:"version,notnull,default:1" json:"version"`
	Locale        string     `bun:"locale,nullzero" json:"locale,omitempty"`
	PublishedAt   *time.Time `bun:"published_at,nullzero" json:"publishedAt"`
	ScheduledAt   *time.Time `bun:"scheduled_at,nullzero" json:"scheduledAt"`
	CreatedBy     xid.ID     `bun:"created_by,type:varchar(20)" json:"createdBy"`
	UpdatedBy     xid.ID     `bun:"updated_by,type:varchar(20)" json:"updatedBy"`
	CreatedAt     time.Time  `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
	UpdatedAt     time.Time  `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`
	DeletedAt     *time.Time `bun:"deleted_at,soft_delete,nullzero" json:"-"`

	// Relations
	App         *mainSchema.App         `bun:"rel:belongs-to,join:app_id=id" json:"app,omitempty"`
	Environment *mainSchema.Environment `bun:"rel:belongs-to,join:environment_id=id" json:"environment,omitempty"`
	ContentType *ContentType            `bun:"rel:belongs-to,join:content_type_id=id" json:"contentType,omitempty"`
	Revisions   []*ContentRevision      `bun:"rel:has-many,join:id=entry_id" json:"revisions,omitempty"`

	// Populated relations (not stored in DB, used for query population)
	PopulatedRelations map[string][]*ContentEntry `bun:"-" json:"populatedRelations,omitempty"`
}

ContentEntry represents a content entry in the database

func (*ContentEntry) Archive

func (ce *ContentEntry) Archive()

Archive archives the entry

func (*ContentEntry) BeforeInsert

func (ce *ContentEntry) BeforeInsert()

BeforeInsert sets default values before insert

func (*ContentEntry) BeforeUpdate

func (ce *ContentEntry) BeforeUpdate()

BeforeUpdate updates the UpdatedAt timestamp and increments version

func (*ContentEntry) CanArchive

func (ce *ContentEntry) CanArchive() bool

CanArchive returns true if the entry can be archived

func (*ContentEntry) CanPublish

func (ce *ContentEntry) CanPublish() bool

CanPublish returns true if the entry can be published

func (*ContentEntry) CanUnpublish

func (ce *ContentEntry) CanUnpublish() bool

CanUnpublish returns true if the entry can be unpublished

func (*ContentEntry) Clone

func (ce *ContentEntry) Clone() *ContentEntry

Clone creates a copy of the entry with a new ID

func (*ContentEntry) DeleteFieldValue

func (ce *ContentEntry) DeleteFieldValue(field string)

DeleteFieldValue removes a field value

func (*ContentEntry) GetDescription

func (ce *ContentEntry) GetDescription(descField string) string

GetDescription returns the description from entry data based on content type settings

func (*ContentEntry) GetFieldValue

func (ce *ContentEntry) GetFieldValue(field string) any

GetFieldValue returns a specific field value

func (*ContentEntry) GetTitle

func (ce *ContentEntry) GetTitle(titleField string) string

GetTitle returns the title from entry data based on content type settings

func (*ContentEntry) IsArchived

func (ce *ContentEntry) IsArchived() bool

IsArchived returns true if the entry is archived

func (*ContentEntry) IsDraft

func (ce *ContentEntry) IsDraft() bool

IsDraft returns true if the entry is a draft

func (*ContentEntry) IsPublished

func (ce *ContentEntry) IsPublished() bool

IsPublished returns true if the entry is published

func (*ContentEntry) IsScheduled

func (ce *ContentEntry) IsScheduled() bool

IsScheduled returns true if the entry is scheduled for publishing

func (*ContentEntry) Publish

func (ce *ContentEntry) Publish()

Publish publishes the entry

func (*ContentEntry) Schedule

func (ce *ContentEntry) Schedule(at time.Time)

Schedule schedules the entry for publishing

func (*ContentEntry) SetFieldValue

func (ce *ContentEntry) SetFieldValue(field string, value any)

SetFieldValue sets a specific field value

func (*ContentEntry) TableName

func (ce *ContentEntry) TableName() string

TableName returns the table name for ContentEntry

func (*ContentEntry) ToMap

func (ce *ContentEntry) ToMap() map[string]any

ToMap converts the entry to a map for API responses

func (*ContentEntry) Unpublish

func (ce *ContentEntry) Unpublish()

Unpublish unpublishes the entry (returns to draft)

type ContentField

type ContentField struct {
	bun.BaseModel `bun:"table:cms_content_fields,alias:cf"`

	ID            xid.ID       `bun:"id,pk,type:varchar(20)" json:"id"`
	ContentTypeID xid.ID       `bun:"content_type_id,notnull,type:varchar(20)" json:"contentTypeId"`
	Title         string       `bun:"title,notnull" json:"title"`
	Name          string       `bun:"name,notnull" json:"name"`
	Description   string       `bun:"description,nullzero" json:"description"`
	Type          string       `bun:"type,notnull" json:"type"`
	Required      bool         `bun:"required,notnull,default:false" json:"required"`
	Unique        bool         `bun:"unique,notnull,default:false" json:"unique"`
	Indexed       bool         `bun:"indexed,notnull,default:false" json:"indexed"`
	Localized     bool         `bun:"localized,notnull,default:false" json:"localized"`
	DefaultValue  string       `bun:"default_value,nullzero" json:"-"` // JSON-encoded default value
	Options       FieldOptions `bun:"options,type:jsonb,notnull" json:"options"`
	Order         int          `bun:"\"order\",notnull,default:0" json:"order"`
	Hidden        bool         `bun:"hidden,notnull,default:false" json:"hidden"`
	ReadOnly      bool         `bun:"read_only,notnull,default:false" json:"readOnly"`
	CreatedAt     time.Time    `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
	UpdatedAt     time.Time    `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`

	// Relations
	ContentType *ContentType `bun:"rel:belongs-to,join:content_type_id=id" json:"contentType,omitempty"`
}

ContentField represents a field definition within a content type

func (*ContentField) BeforeInsert

func (cf *ContentField) BeforeInsert()

BeforeInsert sets default values before insert

func (*ContentField) BeforeUpdate

func (cf *ContentField) BeforeUpdate()

BeforeUpdate updates the UpdatedAt timestamp

func (*ContentField) GetChoices

func (cf *ContentField) GetChoices() []Choice

GetChoices returns the choices for selectable fields

func (*ContentField) GetComponentRef

func (cf *ContentField) GetComponentRef() string

GetComponentRef returns the component schema reference slug

func (*ContentField) GetDefaultValue

func (cf *ContentField) GetDefaultValue() (any, error)

GetDefaultValue returns the parsed default value

func (*ContentField) GetDiscriminatorField

func (cf *ContentField) GetDiscriminatorField() string

GetDiscriminatorField returns the discriminator field name

func (*ContentField) GetHideCondition

func (cf *ContentField) GetHideCondition() *FieldCondition

GetHideCondition returns the hide condition

func (*ContentField) GetMaxItems

func (cf *ContentField) GetMaxItems() int

GetMaxItems returns the maximum array items constraint (-1 for no limit)

func (*ContentField) GetMinItems

func (cf *ContentField) GetMinItems() int

GetMinItems returns the minimum array items constraint

func (*ContentField) GetNestedFields

func (cf *ContentField) GetNestedFields() []NestedFieldDef

GetNestedFields returns the nested field definitions

func (*ContentField) GetOnDeleteAction

func (cf *ContentField) GetOnDeleteAction() string

GetOnDeleteAction returns the on-delete action for relation fields

func (*ContentField) GetRelatedType

func (cf *ContentField) GetRelatedType() string

GetRelatedType returns the related content type slug

func (*ContentField) GetRelationType

func (cf *ContentField) GetRelationType() string

GetRelationType returns the relation type for relation fields

func (*ContentField) GetSchemaForValue

func (cf *ContentField) GetSchemaForValue(value string) *OneOfSchemaOption

GetSchemaForValue returns the schema option for a discriminator value

func (*ContentField) GetSchemas

func (cf *ContentField) GetSchemas() map[string]OneOfSchemaOption

GetSchemas returns the oneOf schema options

func (*ContentField) GetShowCondition

func (cf *ContentField) GetShowCondition() *FieldCondition

GetShowCondition returns the show condition

func (*ContentField) HasComponentRef

func (cf *ContentField) HasComponentRef() bool

HasComponentRef returns true if the field references a component schema

func (*ContentField) HasConditionalVisibility

func (cf *ContentField) HasConditionalVisibility() bool

HasConditionalVisibility returns true if the field has any conditional visibility rules

func (*ContentField) HasDiscriminatorField

func (cf *ContentField) HasDiscriminatorField() bool

HasDiscriminatorField returns true if the field has a discriminator field configured

func (*ContentField) HasHideCondition

func (cf *ContentField) HasHideCondition() bool

HasHideCondition returns true if the field has a hide condition

func (*ContentField) HasLengthConstraint

func (cf *ContentField) HasLengthConstraint() bool

HasLengthConstraint returns true if the field has length constraints

func (*ContentField) HasNestedFields

func (cf *ContentField) HasNestedFields() bool

HasNestedFields returns true if the field has inline nested field definitions

func (*ContentField) HasNumericConstraint

func (cf *ContentField) HasNumericConstraint() bool

HasNumericConstraint returns true if the field has numeric constraints

func (*ContentField) HasPattern

func (cf *ContentField) HasPattern() bool

HasPattern returns true if the field has a validation pattern

func (*ContentField) HasShowCondition

func (cf *ContentField) HasShowCondition() bool

HasShowCondition returns true if the field has a show condition

func (*ContentField) IsArray

func (cf *ContentField) IsArray() bool

IsArray returns true if the field is an array type

func (*ContentField) IsCollapsible

func (cf *ContentField) IsCollapsible() bool

IsCollapsible returns true if the nested field should be collapsible in UI

func (*ContentField) IsDate

func (cf *ContentField) IsDate() bool

IsDate returns true if the field is date-related

func (*ContentField) IsDefaultExpanded

func (cf *ContentField) IsDefaultExpanded() bool

IsDefaultExpanded returns true if the nested field should be expanded by default

func (*ContentField) IsMultiValue

func (cf *ContentField) IsMultiValue() bool

IsMultiValue returns true if the field can have multiple values

func (*ContentField) IsNested

func (cf *ContentField) IsNested() bool

IsNested returns true if the field is an object, array, or oneOf type

func (*ContentField) IsNumeric

func (cf *ContentField) IsNumeric() bool

IsNumeric returns true if the field is numeric

func (*ContentField) IsObject

func (cf *ContentField) IsObject() bool

IsObject returns true if the field is an object type

func (*ContentField) IsOneOf

func (cf *ContentField) IsOneOf() bool

IsOneOf returns true if the field is a oneOf type

func (*ContentField) IsRelation

func (cf *ContentField) IsRelation() bool

IsRelation returns true if the field is a relation

func (*ContentField) IsSearchable

func (cf *ContentField) IsSearchable() bool

IsSearchable returns true if the field can be included in full-text search

func (*ContentField) IsSelectable

func (cf *ContentField) IsSelectable() bool

IsSelectable returns true if the field has selectable options

func (*ContentField) IsText

func (cf *ContentField) IsText() bool

IsText returns true if the field is a text-based field

func (*ContentField) SetDefaultValue

func (cf *ContentField) SetDefaultValue(value any) error

SetDefaultValue sets the default value as JSON

func (*ContentField) ShouldClearOnDiscriminatorChange

func (cf *ContentField) ShouldClearOnDiscriminatorChange() bool

ShouldClearOnDiscriminatorChange returns true if data should be cleared when discriminator changes

func (*ContentField) ShouldClearWhenHidden

func (cf *ContentField) ShouldClearWhenHidden() bool

ShouldClearWhenHidden returns true if data should be cleared when field is hidden

func (*ContentField) TableName

func (cf *ContentField) TableName() string

TableName returns the table name for ContentField

type ContentRelation

type ContentRelation struct {
	bun.BaseModel `bun:"table:cms_content_relations,alias:crel"`

	ID            xid.ID    `bun:"id,pk,type:varchar(20)" json:"id"`
	SourceEntryID xid.ID    `bun:"source_entry_id,notnull,type:varchar(20)" json:"sourceEntryId"`
	TargetEntryID xid.ID    `bun:"target_entry_id,notnull,type:varchar(20)" json:"targetEntryId"`
	FieldName     string    `bun:"field_name,notnull" json:"fieldName"`
	Order         int       `bun:"\"order\",notnull,default:0" json:"order"`
	Metadata      EntryData `bun:"metadata,type:jsonb,nullzero" json:"metadata,omitempty"`
	CreatedAt     time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`

	// Relations
	SourceEntry *ContentEntry `bun:"rel:belongs-to,join:source_entry_id=id" json:"sourceEntry,omitempty"`
	TargetEntry *ContentEntry `bun:"rel:belongs-to,join:target_entry_id=id" json:"targetEntry,omitempty"`
}

ContentRelation represents a many-to-many relation between content entries Used for storing bidirectional relations and many-to-many relationships

func NewOrderedRelation

func NewOrderedRelation(sourceID, targetID xid.ID, fieldName string, order int) *ContentRelation

NewOrderedRelation creates a new relation with ordering

func NewRelation

func NewRelation(sourceID, targetID xid.ID, fieldName string) *ContentRelation

NewRelation creates a new relation between two entries

func (*ContentRelation) BeforeInsert

func (cr *ContentRelation) BeforeInsert()

BeforeInsert sets default values before insert

func (*ContentRelation) TableName

func (cr *ContentRelation) TableName() string

TableName returns the table name for ContentRelation

type ContentRevision

type ContentRevision struct {
	bun.BaseModel `bun:"table:cms_content_revisions,alias:cr"`

	ID           xid.ID    `bun:"id,pk,type:varchar(20)" json:"id"`
	EntryID      xid.ID    `bun:"entry_id,notnull,type:varchar(20)" json:"entryId"`
	Version      int       `bun:"version,notnull" json:"version"`
	Data         EntryData `bun:"data,type:jsonb,notnull" json:"data"`
	Status       string    `bun:"status,notnull" json:"status"`
	ChangeReason string    `bun:"change_reason,nullzero" json:"changeReason"`
	ChangedBy    xid.ID    `bun:"changed_by,type:varchar(20)" json:"changedBy"`
	CreatedAt    time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`

	// Relations
	Entry *ContentEntry `bun:"rel:belongs-to,join:entry_id=id" json:"entry,omitempty"`
}

ContentRevision stores historical versions of content entries

func CreateRevisionFromEntry

func CreateRevisionFromEntry(entry *ContentEntry, changeReason string, changedBy xid.ID) *ContentRevision

CreateFromEntry creates a new revision from an entry

func (*ContentRevision) BeforeInsert

func (cr *ContentRevision) BeforeInsert()

BeforeInsert sets default values before insert

func (*ContentRevision) CompareData

func (cr *ContentRevision) CompareData(other *ContentRevision) map[string]FieldDiff

CompareData compares this revision's data with another and returns the differences

func (*ContentRevision) RestoreToEntry

func (cr *ContentRevision) RestoreToEntry(entry *ContentEntry)

RestoreToEntry restores this revision to the given entry

func (*ContentRevision) TableName

func (cr *ContentRevision) TableName() string

TableName returns the table name for ContentRevision

func (*ContentRevision) ToMap

func (cr *ContentRevision) ToMap() map[string]any

ToMap converts the revision to a map for API responses

type ContentType

type ContentType struct {
	bun.BaseModel `bun:"table:cms_content_types,alias:ct"`

	ID            xid.ID              `bun:"id,pk,type:varchar(20)" json:"id"`
	AppID         xid.ID              `bun:"app_id,notnull,type:varchar(20)" json:"appId"`
	EnvironmentID xid.ID              `bun:"environment_id,notnull,type:varchar(20)" json:"environmentId"`
	Title         string              `bun:"title,notnull" json:"title"`
	Name          string              `bun:"name,notnull" json:"name"`
	Description   string              `bun:"description,nullzero" json:"description"`
	Icon          string              `bun:"icon,nullzero" json:"icon"`
	Settings      ContentTypeSettings `bun:"settings,type:jsonb,notnull" json:"settings"`
	CreatedBy     xid.ID              `bun:"created_by,type:varchar(20)" json:"createdBy"`
	UpdatedBy     xid.ID              `bun:"updated_by,type:varchar(20)" json:"updatedBy"`
	CreatedAt     time.Time           `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
	UpdatedAt     time.Time           `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`
	DeletedAt     *time.Time          `bun:"deleted_at,soft_delete,nullzero" json:"-"`

	// Relations
	App         *mainSchema.App         `bun:"rel:belongs-to,join:app_id=id" json:"app,omitempty"`
	Environment *mainSchema.Environment `bun:"rel:belongs-to,join:environment_id=id" json:"environment,omitempty"`
	Fields      []*ContentField         `bun:"rel:has-many,join:id=content_type_id" json:"fields,omitempty"`
	Entries     []*ContentEntry         `bun:"rel:has-many,join:id=content_type_id" json:"entries,omitempty"`
}

ContentType represents a content type definition in the database

func (*ContentType) BeforeInsert

func (ct *ContentType) BeforeInsert()

BeforeInsert sets default values before insert

func (*ContentType) BeforeUpdate

func (ct *ContentType) BeforeUpdate()

BeforeUpdate updates the UpdatedAt timestamp

func (*ContentType) GetDescriptionField

func (ct *ContentType) GetDescriptionField() string

GetDescriptionField returns the field name to use as description

func (*ContentType) GetFieldByName

func (ct *ContentType) GetFieldByName(name string) *ContentField

GetFieldByName returns a field by its name

func (*ContentType) GetIndexedFields

func (ct *ContentType) GetIndexedFields() []*ContentField

GetIndexedFields returns all indexed fields

func (*ContentType) GetPreviewField added in v0.0.6

func (ct *ContentType) GetPreviewField() string

GetPreviewField returns the field name to use as preview

func (*ContentType) GetRelationFields

func (ct *ContentType) GetRelationFields() []*ContentField

GetRelationFields returns all relation fields

func (*ContentType) GetRequiredFields

func (ct *ContentType) GetRequiredFields() []*ContentField

GetRequiredFields returns all required fields

func (*ContentType) GetSearchableFields

func (ct *ContentType) GetSearchableFields() []*ContentField

GetSearchableFields returns all searchable fields

func (*ContentType) GetTitleField

func (ct *ContentType) GetTitleField() string

GetTitleField returns the field name to use as title

func (*ContentType) GetUniqueFields

func (ct *ContentType) GetUniqueFields() []*ContentField

GetUniqueFields returns all unique fields

func (*ContentType) HasDrafts

func (ct *ContentType) HasDrafts() bool

HasDrafts returns true if drafts are enabled

func (*ContentType) HasRevisions

func (ct *ContentType) HasRevisions() bool

HasRevisions returns true if revisions are enabled

func (*ContentType) HasScheduling

func (ct *ContentType) HasScheduling() bool

HasScheduling returns true if scheduling is enabled

func (*ContentType) TableName

func (ct *ContentType) TableName() string

TableName returns the table name for ContentType

type ContentTypeRelation

type ContentTypeRelation struct {
	bun.BaseModel `bun:"table:cms_content_type_relations,alias:ctr"`

	ID                  xid.ID    `bun:"id,pk,type:varchar(20)" json:"id"`
	SourceContentTypeID xid.ID    `bun:"source_content_type_id,notnull,type:varchar(20)" json:"sourceContentTypeId"`
	TargetContentTypeID xid.ID    `bun:"target_content_type_id,notnull,type:varchar(20)" json:"targetContentTypeId"`
	SourceFieldName     string    `bun:"source_field_name,notnull" json:"sourceFieldName"`
	TargetFieldName     string    `bun:"target_field_name,nullzero" json:"targetFieldName,omitempty"`
	RelationType        string    `bun:"relation_type,notnull" json:"relationType"`
	OnDelete            string    `bun:"on_delete,notnull,default:'setNull'" json:"onDelete"`
	CreatedAt           time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`

	// Relations
	SourceContentType *ContentType `bun:"rel:belongs-to,join:source_content_type_id=id" json:"sourceContentType,omitempty"`
	TargetContentType *ContentType `bun:"rel:belongs-to,join:target_content_type_id=id" json:"targetContentType,omitempty"`
}

ContentTypeRelation represents a relation definition between content types This is metadata about how two content types are related

func NewContentTypeRelation

func NewContentTypeRelation(
	sourceTypeID, targetTypeID xid.ID,
	sourceField, targetField string,
	relationType string,
	onDelete string,
) *ContentTypeRelation

NewContentTypeRelation creates a new content type relation definition

func (*ContentTypeRelation) BeforeInsert

func (ctr *ContentTypeRelation) BeforeInsert()

BeforeInsert sets default values before insert

func (*ContentTypeRelation) GetOnDeleteAction

func (ctr *ContentTypeRelation) GetOnDeleteAction() string

GetOnDeleteAction returns the on-delete action

func (*ContentTypeRelation) IsBidirectional

func (ctr *ContentTypeRelation) IsBidirectional() bool

IsBidirectional returns true if this relation has an inverse field

func (*ContentTypeRelation) IsManyToMany

func (ctr *ContentTypeRelation) IsManyToMany() bool

IsManyToMany returns true if this is a many-to-many relation

func (*ContentTypeRelation) IsManyToOne

func (ctr *ContentTypeRelation) IsManyToOne() bool

IsManyToOne returns true if this is a many-to-one relation

func (*ContentTypeRelation) IsOneToMany

func (ctr *ContentTypeRelation) IsOneToMany() bool

IsOneToMany returns true if this is a one-to-many relation

func (*ContentTypeRelation) IsOneToOne

func (ctr *ContentTypeRelation) IsOneToOne() bool

IsOneToOne returns true if this is a one-to-one relation

func (*ContentTypeRelation) RequiresJoinTable

func (ctr *ContentTypeRelation) RequiresJoinTable() bool

RequiresJoinTable returns true if this relation needs a join table

func (*ContentTypeRelation) TableName

func (ctr *ContentTypeRelation) TableName() string

TableName returns the table name for ContentTypeRelation

type ContentTypeSettings

type ContentTypeSettings struct {
	// Display settings
	TitleField       string `json:"titleField,omitempty"`
	DescriptionField string `json:"descriptionField,omitempty"`
	PreviewField     string `json:"previewField,omitempty"`

	// Features
	EnableRevisions  bool `json:"enableRevisions"`
	EnableDrafts     bool `json:"enableDrafts"`
	EnableSoftDelete bool `json:"enableSoftDelete"`
	EnableSearch     bool `json:"enableSearch"`
	EnableScheduling bool `json:"enableScheduling"`

	// Permissions
	DefaultPermissions []string `json:"defaultPermissions,omitempty"`

	// Limits
	MaxEntries int `json:"maxEntries,omitempty"`
}

ContentTypeSettings holds the configuration for a content type

func DefaultSettings

func DefaultSettings() ContentTypeSettings

DefaultSettings returns default content type settings

func (*ContentTypeSettings) Scan

func (s *ContentTypeSettings) Scan(value interface{}) error

Scan implements the sql.Scanner interface for database retrieval

func (ContentTypeSettings) Value

func (s ContentTypeSettings) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database storage

type DiffType

type DiffType string

DiffType represents the type of change in a field

const (
	DiffTypeAdded    DiffType = "added"
	DiffTypeRemoved  DiffType = "removed"
	DiffTypeModified DiffType = "modified"
)

type EntryData

type EntryData map[string]any

EntryData represents the dynamic data stored in a content entry

func (EntryData) Get

func (d EntryData) Get(key string) (any, bool)

Get returns a value from the entry data

func (EntryData) GetBool

func (d EntryData) GetBool(key string) bool

GetBool returns a boolean value from the entry data

func (EntryData) GetFloat

func (d EntryData) GetFloat(key string) float64

GetFloat returns a float value from the entry data

func (EntryData) GetInt

func (d EntryData) GetInt(key string) int

GetInt returns an integer value from the entry data

func (EntryData) GetString

func (d EntryData) GetString(key string) string

GetString returns a string value from the entry data

func (*EntryData) Scan

func (d *EntryData) Scan(value interface{}) error

Scan implements the sql.Scanner interface for database retrieval

func (EntryData) Value

func (d EntryData) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database storage

type FieldCondition

type FieldCondition struct {
	Field    string `json:"field"`           // Field name to watch
	Operator string `json:"operator"`        // eq, ne, in, notIn, exists, notExists
	Value    any    `json:"value,omitempty"` // Value(s) to compare
}

FieldCondition defines a condition for showing/hiding fields

type FieldDiff

type FieldDiff struct {
	Field    string   `json:"field"`
	OldValue any      `json:"oldValue,omitempty"`
	NewValue any      `json:"newValue,omitempty"`
	Type     DiffType `json:"type"`
}

FieldDiff represents a difference in a field between revisions

type FieldOptions

type FieldOptions struct {
	// Text fields
	MinLength int    `json:"minLength,omitempty"`
	MaxLength int    `json:"maxLength,omitempty"`
	Pattern   string `json:"pattern,omitempty"`

	// Number fields
	Min     *float64 `json:"min,omitempty"`
	Max     *float64 `json:"max,omitempty"`
	Step    *float64 `json:"step,omitempty"`
	Integer bool     `json:"integer,omitempty"`

	// Select fields
	Choices []Choice `json:"choices,omitempty"`

	// Relation fields
	RelatedType  string `json:"relatedType,omitempty"`
	RelationType string `json:"relationType,omitempty"`
	OnDelete     string `json:"onDelete,omitempty"`
	InverseField string `json:"inverseField,omitempty"`

	// Rich text fields
	AllowHTML bool `json:"allowHtml,omitempty"`
	MaxWords  int  `json:"maxWords,omitempty"`

	// Media fields
	AllowedMimeTypes []string `json:"allowedMimeTypes,omitempty"`
	MaxFileSize      int64    `json:"maxFileSize,omitempty"`

	// Slug fields
	SourceField string `json:"sourceField,omitempty"`

	// JSON fields
	Schema string `json:"schema,omitempty"`

	// Date fields
	MinDate    *time.Time `json:"minDate,omitempty"`
	MaxDate    *time.Time `json:"maxDate,omitempty"`
	DateFormat string     `json:"dateFormat,omitempty"`

	// Enumeration fields
	EnumValues []string `json:"enumValues,omitempty"`

	// Decimal fields
	Precision int `json:"precision,omitempty"`
	Scale     int `json:"scale,omitempty"`

	// Object/Array fields (nested structures)
	NestedFields    []NestedFieldDef `json:"nestedFields,omitempty"`    // Inline sub-field definitions
	ComponentRef    string           `json:"componentRef,omitempty"`    // Reference to ComponentSchema slug
	MinItems        *int             `json:"minItems,omitempty"`        // For array: minimum items
	MaxItems        *int             `json:"maxItems,omitempty"`        // For array: maximum items
	Collapsible     bool             `json:"collapsible,omitempty"`     // UI: collapsible in form
	DefaultExpanded bool             `json:"defaultExpanded,omitempty"` // UI: expanded by default

	// OneOf fields (discriminated union)
	DiscriminatorField         string                       `json:"discriminatorField,omitempty"`         // Field name to watch for schema selection
	Schemas                    map[string]OneOfSchemaOption `json:"schemas,omitempty"`                    // Value -> schema mapping
	ClearOnDiscriminatorChange bool                         `json:"clearOnDiscriminatorChange,omitempty"` // Clear data when discriminator changes

	// Conditional visibility
	ShowWhen        *FieldCondition `json:"showWhen,omitempty"`        // Show field when condition is met
	HideWhen        *FieldCondition `json:"hideWhen,omitempty"`        // Hide field when condition is met
	ClearWhenHidden bool            `json:"clearWhenHidden,omitempty"` // Clear value when hidden
}

FieldOptions holds type-specific options for a content field

func (*FieldOptions) Scan

func (o *FieldOptions) Scan(value interface{}) error

Scan implements the sql.Scanner interface for database retrieval

func (FieldOptions) Value

func (o FieldOptions) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database storage

type NestedFieldDef

type NestedFieldDef struct {
	Title       string        `json:"title"`
	Name        string        `json:"name"`
	Type        string        `json:"type"`
	Required    bool          `json:"required,omitempty"`
	Description string        `json:"description,omitempty"`
	Options     *FieldOptions `json:"options,omitempty"` // Recursive for multi-level nesting
}

NestedFieldDef defines a field within a nested object or component schema

type NestedFieldDefs

type NestedFieldDefs []NestedFieldDef

NestedFieldDefs is a slice of NestedFieldDef for database storage

func (*NestedFieldDefs) Scan

func (n *NestedFieldDefs) Scan(value interface{}) error

Scan implements the sql.Scanner interface for database retrieval

func (NestedFieldDefs) Value

func (n NestedFieldDefs) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database storage

type OneOfSchemaOption

type OneOfSchemaOption struct {
	ComponentRef string           `json:"componentRef,omitempty"` // Reference to ComponentSchema slug
	NestedFields []NestedFieldDef `json:"nestedFields,omitempty"` // Or inline field definitions
	Label        string           `json:"label,omitempty"`        // Display label for this option
}

OneOfSchemaOption defines a schema option for oneOf fields

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL