core

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package core provides core types and utilities for the CMS plugin.

Index

Constants

View Source
const (
	// ErrCodeContentTypeNotFound is the error code for content type not found.
	ErrCodeContentTypeNotFound    = "CMS_CONTENT_TYPE_NOT_FOUND"
	ErrCodeContentTypeExists      = "CMS_CONTENT_TYPE_EXISTS"
	ErrCodeContentTypeHasEntries  = "CMS_CONTENT_TYPE_HAS_ENTRIES"
	ErrCodeInvalidContentTypeSlug = "CMS_INVALID_CONTENT_TYPE_SLUG"

	// ErrCodeFieldNotFound is the error code for field not found.
	ErrCodeFieldNotFound    = "CMS_FIELD_NOT_FOUND"
	ErrCodeFieldExists      = "CMS_FIELD_EXISTS"
	ErrCodeInvalidFieldSlug = "CMS_INVALID_FIELD_SLUG"
	ErrCodeInvalidFieldType = "CMS_INVALID_FIELD_TYPE"
	ErrCodeFieldRequired    = "CMS_FIELD_REQUIRED"

	// ErrCodeComponentSchemaNotFound is the error code for component schema not found.
	ErrCodeComponentSchemaNotFound    = "CMS_COMPONENT_SCHEMA_NOT_FOUND"
	ErrCodeComponentSchemaExists      = "CMS_COMPONENT_SCHEMA_EXISTS"
	ErrCodeComponentSchemaInUse       = "CMS_COMPONENT_SCHEMA_IN_USE"
	ErrCodeInvalidComponentSchemaSlug = "CMS_INVALID_COMPONENT_SCHEMA_SLUG"
	ErrCodeCircularComponentRef       = "CMS_CIRCULAR_COMPONENT_REF"

	// ErrCodeEntryNotFound is the error code for entry not found.
	ErrCodeEntryNotFound         = "CMS_ENTRY_NOT_FOUND"
	ErrCodeEntryValidationFailed = "CMS_ENTRY_VALIDATION_FAILED"
	ErrCodeEntryAlreadyPublished = "CMS_ENTRY_ALREADY_PUBLISHED"
	ErrCodeEntryNotPublished     = "CMS_ENTRY_NOT_PUBLISHED"
	ErrCodeEntryLimitReached     = "CMS_ENTRY_LIMIT_REACHED"
	ErrCodeUniqueConstraint      = "CMS_UNIQUE_CONSTRAINT_VIOLATION"

	// ErrCodeRevisionNotFound is the error code for revision not found.
	ErrCodeRevisionNotFound = "CMS_REVISION_NOT_FOUND"
	ErrCodeRollbackFailed   = "CMS_ROLLBACK_FAILED"

	// ErrCodeRelationNotFound is the error code for relation not found.
	ErrCodeRelationNotFound   = "CMS_RELATION_NOT_FOUND"
	ErrCodeInvalidRelation    = "CMS_INVALID_RELATION"
	ErrCodeCircularRelation   = "CMS_CIRCULAR_RELATION"
	ErrCodeRelationConstraint = "CMS_RELATION_CONSTRAINT_VIOLATION"

	// ErrCodeInvalidQuery is the error code for invalid query.
	ErrCodeInvalidQuery    = "CMS_INVALID_QUERY"
	ErrCodeInvalidFilter   = "CMS_INVALID_FILTER"
	ErrCodeInvalidSort     = "CMS_INVALID_SORT"
	ErrCodeInvalidOperator = "CMS_INVALID_OPERATOR"

	// ErrCodeAccessDenied is the error code for access denied.
	ErrCodeAccessDenied      = "CMS_ACCESS_DENIED"
	ErrCodeInvalidRequest    = "CMS_INVALID_REQUEST"
	ErrCodeAppContextMissing = "CMS_APP_CONTEXT_MISSING"
	ErrCodeEnvContextMissing = "CMS_ENV_CONTEXT_MISSING"
)

Error codes for the CMS plugin.

Variables

This section is empty.

Functions

func ErrAccessDenied

func ErrAccessDenied(reason string) error

ErrAccessDenied returns a forbidden error when access is denied.

func ErrAppContextMissing

func ErrAppContextMissing() error

ErrAppContextMissing returns a bad request error when app context is missing.

func ErrCircularComponentRef

func ErrCircularComponentRef(path string) error

ErrCircularComponentRef returns an error when a circular component reference is detected.

func ErrCircularRelation

func ErrCircularRelation(path string) error

ErrCircularRelation returns an error when a circular relation is detected.

func ErrComponentSchemaExists

func ErrComponentSchemaExists(slug string) error

ErrComponentSchemaExists returns a conflict error when a component schema already exists.

func ErrComponentSchemaInUse

func ErrComponentSchemaInUse(slug string, usageCount int) error

ErrComponentSchemaInUse returns an error when trying to delete a component schema that is in use.

func ErrComponentSchemaNotFound

func ErrComponentSchemaNotFound(identifier string) error

ErrComponentSchemaNotFound returns a not found error for a component schema.

func ErrContentTypeExists

func ErrContentTypeExists(slug string) error

ErrContentTypeExists returns a conflict error when a content type already exists.

func ErrContentTypeHasEntries

func ErrContentTypeHasEntries(slug string, entryCount int) error

ErrContentTypeHasEntries returns an error when trying to delete a content type with entries.

func ErrContentTypeNotFound

func ErrContentTypeNotFound(identifier string) error

ErrContentTypeNotFound returns a not found error for a content type.

func ErrDatabaseError

func ErrDatabaseError(message string, cause error) error

ErrDatabaseError returns an internal server error for database issues.

func ErrEntryAlreadyPublished

func ErrEntryAlreadyPublished() error

ErrEntryAlreadyPublished returns a conflict error when entry is already published.

func ErrEntryLimitReached

func ErrEntryLimitReached(contentType string, limit int) error

ErrEntryLimitReached returns an error when entry limit is reached for a content type.

func ErrEntryNotFound

func ErrEntryNotFound(identifier string) error

ErrEntryNotFound returns a not found error for a content entry.

func ErrEntryNotPublished

func ErrEntryNotPublished() error

ErrEntryNotPublished returns a bad request error when entry is not published.

func ErrEntryValidationFailed

func ErrEntryValidationFailed(errors map[string]string) error

ErrEntryValidationFailed returns a bad request error when entry validation fails.

func ErrEntryValidationFailedSingle

func ErrEntryValidationFailedSingle(field, reason string) error

ErrEntryValidationFailedSingle returns a bad request error for a single validation failure.

func ErrEnvContextMissing

func ErrEnvContextMissing() error

ErrEnvContextMissing returns a bad request error when environment context is missing.

func ErrFieldExists

func ErrFieldExists(slug string) error

ErrFieldExists returns a conflict error when a field already exists.

func ErrFieldNotFound

func ErrFieldNotFound(identifier string) error

ErrFieldNotFound returns a not found error for a content field.

func ErrFieldRequired

func ErrFieldRequired(fieldName string) error

ErrFieldRequired returns a bad request error when a required field is missing.

func ErrInternalError

func ErrInternalError(message string, cause error) error

ErrInternalError is an alias for InternalError for consistency.

func ErrInvalidComponentSchemaSlug

func ErrInvalidComponentSchemaSlug(slug, reason string) error

ErrInvalidComponentSchemaSlug returns a bad request error for invalid component schema slug format.

func ErrInvalidContentTypeSlug

func ErrInvalidContentTypeSlug(slug, reason string) error

ErrInvalidContentTypeSlug returns a bad request error for invalid slug format.

func ErrInvalidFieldSlug

func ErrInvalidFieldSlug(slug, reason string) error

ErrInvalidFieldSlug returns a bad request error for invalid field name.

func ErrInvalidFieldType

func ErrInvalidFieldType(fieldType string) error

ErrInvalidFieldType returns a bad request error for invalid field type.

func ErrInvalidFilter

func ErrInvalidFilter(filter, reason string) error

ErrInvalidFilter returns an error for invalid filter expression.

func ErrInvalidOperator

func ErrInvalidOperator(operator string) error

ErrInvalidOperator returns an error for invalid query operator.

func ErrInvalidQuery

func ErrInvalidQuery(reason string) error

ErrInvalidQuery returns an error for invalid query syntax.

func ErrInvalidRelation

func ErrInvalidRelation(reason string) error

ErrInvalidRelation returns an error for invalid relation configuration.

func ErrInvalidRequest

func ErrInvalidRequest(reason string) error

ErrInvalidRequest returns a bad request error for generic invalid requests.

func ErrInvalidSort

func ErrInvalidSort(sort, reason string) error

ErrInvalidSort returns an error for invalid sort expression.

func ErrRelationConstraint

func ErrRelationConstraint(reason string) error

ErrRelationConstraint returns an error when a relation constraint is violated.

func ErrRelationNotFound

func ErrRelationNotFound(identifier string) error

ErrRelationNotFound returns a not found error for a relation.

func ErrRevisionNotFound

func ErrRevisionNotFound(entryID string, version int) error

ErrRevisionNotFound returns a not found error for a revision.

func ErrRevisionsNotEnabled

func ErrRevisionsNotEnabled() error

ErrRevisionsNotEnabled returns an error when revisions are not enabled.

func ErrRollbackFailed

func ErrRollbackFailed(reason string, cause error) error

ErrRollbackFailed returns an error when rollback fails.

func ErrTypeRelationNotFound

func ErrTypeRelationNotFound(identifier string) error

ErrTypeRelationNotFound returns a not found error for a type relation.

func ErrUniqueConstraint

func ErrUniqueConstraint(field, value string) error

ErrUniqueConstraint returns an error when a unique constraint is violated.

func GetFieldTypesByCategory

func GetFieldTypesByCategory() map[string][]FieldTypeInfo

GetFieldTypesByCategory returns field types grouped by category.

func InternalError

func InternalError(message string, cause error) error

InternalError returns an internal server error with the given message.

Types

type CMSStatsDTO

type CMSStatsDTO struct {
	TotalContentTypes int            `json:"totalContentTypes"`
	TotalEntries      int            `json:"totalEntries"`
	TotalRevisions    int            `json:"totalRevisions"`
	EntriesByStatus   map[string]int `json:"entriesByStatus"`
	EntriesByType     map[string]int `json:"entriesByType"`
	RecentlyUpdated   int            `json:"recentlyUpdated"`
	ScheduledEntries  int            `json:"scheduledEntries"`
}

CMSStatsDTO contains overall CMS statistics.

type ChoiceDTO

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

ChoiceDTO represents a choice option for select fields.

type ComponentSchemaDTO

type ComponentSchemaDTO struct {
	ID            string              `json:"id"`
	AppID         string              `json:"appId"`
	EnvironmentID string              `json:"environmentId"`
	Title         string              `json:"title"`
	Name          string              `json:"name"`
	Description   string              `json:"description,omitempty"`
	Icon          string              `json:"icon,omitempty"`
	Fields        []NestedFieldDefDTO `json:"fields"`
	UsageCount    int                 `json:"usageCount,omitempty"`
	CreatedBy     string              `json:"createdBy,omitempty"`
	UpdatedBy     string              `json:"updatedBy,omitempty"`
	CreatedAt     time.Time           `json:"createdAt"`
	UpdatedAt     time.Time           `json:"updatedAt"`
}

ComponentSchemaDTO is the API response for a component schema.

type ComponentSchemaSummaryDTO

type ComponentSchemaSummaryDTO struct {
	ID          string    `json:"id"`
	Title       string    `json:"title"`
	Name        string    `json:"name"`
	Description string    `json:"description,omitempty"`
	Icon        string    `json:"icon,omitempty"`
	FieldCount  int       `json:"fieldCount"`
	UsageCount  int       `json:"usageCount"`
	CreatedAt   time.Time `json:"createdAt"`
	UpdatedAt   time.Time `json:"updatedAt"`
}

ComponentSchemaSummaryDTO is a lightweight component schema for lists.

type ContentEntryDTO

type ContentEntryDTO struct {
	ID            string                 `json:"id"`
	ContentTypeID string                 `json:"contentTypeId"`
	ContentType   *ContentTypeSummaryDTO `json:"contentType,omitempty"`
	AppID         string                 `json:"appId"`
	EnvironmentID string                 `json:"environmentId"`
	Data          map[string]any         `json:"data"`
	Status        string                 `json:"status"`
	Version       int                    `json:"version"`
	PublishedAt   *time.Time             `json:"publishedAt,omitempty"`
	ScheduledAt   *time.Time             `json:"scheduledAt,omitempty"`
	CreatedBy     string                 `json:"createdBy,omitempty"`
	UpdatedBy     string                 `json:"updatedBy,omitempty"`
	CreatedAt     time.Time              `json:"createdAt"`
	UpdatedAt     time.Time              `json:"updatedAt"`
	// Relations maps field names to related entry IDs
	Relations map[string][]string `json:"relations,omitempty"`
}

ContentEntryDTO is the API response for a content entry.

type ContentEntrySummaryDTO

type ContentEntrySummaryDTO struct {
	ID          string     `json:"id"`
	Title       string     `json:"title,omitempty"`
	Description string     `json:"description,omitempty"`
	Status      string     `json:"status"`
	Version     int        `json:"version"`
	PublishedAt *time.Time `json:"publishedAt,omitempty"`
	CreatedAt   time.Time  `json:"createdAt"`
	UpdatedAt   time.Time  `json:"updatedAt"`
}

ContentEntrySummaryDTO is a lightweight entry for lists.

type ContentFieldDTO

type ContentFieldDTO struct {
	ID            string          `json:"id"`
	ContentTypeID string          `json:"contentTypeId"`
	Title         string          `json:"title"`
	Name          string          `json:"name"`
	Description   string          `json:"description,omitempty"`
	Type          string          `json:"type"`
	Required      bool            `json:"required"`
	Unique        bool            `json:"unique"`
	Indexed       bool            `json:"indexed"`
	Localized     bool            `json:"localized"`
	DefaultValue  any             `json:"defaultValue,omitempty"`
	Options       FieldOptionsDTO `json:"options,omitempty"`
	Order         int             `json:"order"`
	Hidden        bool            `json:"hidden"`
	ReadOnly      bool            `json:"readOnly"`
	CreatedAt     time.Time       `json:"createdAt"`
	UpdatedAt     time.Time       `json:"updatedAt"`
}

ContentFieldDTO is the API response for a content field.

type ContentRevisionDTO

type ContentRevisionDTO struct {
	ID           string         `json:"id"`
	EntryID      string         `json:"entryId"`
	Version      int            `json:"version"`
	Data         map[string]any `json:"data"`
	Status       string         `json:"status"`
	ChangeReason string         `json:"changeReason,omitempty"`
	ChangedBy    string         `json:"changedBy,omitempty"`
	CreatedAt    time.Time      `json:"createdAt"`
}

ContentRevisionDTO is the API response for a content revision.

type ContentTypeDTO

type ContentTypeDTO struct {
	ID            string                 `json:"id"`
	AppID         string                 `json:"appId"`
	EnvironmentID string                 `json:"environmentId"`
	Title         string                 `json:"title"`
	Name          string                 `json:"name"`
	Description   string                 `json:"description,omitempty"`
	Icon          string                 `json:"icon,omitempty"`
	Settings      ContentTypeSettingsDTO `json:"settings"`
	Fields        []*ContentFieldDTO     `json:"fields,omitempty"`
	EntryCount    int                    `json:"entryCount,omitempty"`
	CreatedBy     string                 `json:"createdBy,omitempty"`
	UpdatedBy     string                 `json:"updatedBy,omitempty"`
	CreatedAt     time.Time              `json:"createdAt"`
	UpdatedAt     time.Time              `json:"updatedAt"`
}

ContentTypeDTO is the API response for a content type.

type ContentTypeSettingsDTO

type ContentTypeSettingsDTO 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"`
}

ContentTypeSettingsDTO represents content type settings.

type ContentTypeStatsDTO

type ContentTypeStatsDTO struct {
	ContentTypeID    string         `json:"contentTypeId"`
	TotalEntries     int            `json:"totalEntries"`
	DraftEntries     int            `json:"draftEntries"`
	PublishedEntries int            `json:"publishedEntries"`
	ArchivedEntries  int            `json:"archivedEntries"`
	EntriesByStatus  map[string]int `json:"entriesByStatus"`
	LastEntryAt      *time.Time     `json:"lastEntryAt,omitempty"`
}

ContentTypeStatsDTO contains statistics for a specific content type.

type ContentTypeSummaryDTO

type ContentTypeSummaryDTO struct {
	ID          string    `json:"id"`
	Title       string    `json:"title"`
	Name        string    `json:"name"`
	Description string    `json:"description,omitempty"`
	Icon        string    `json:"icon,omitempty"`
	EntryCount  int       `json:"entryCount"`
	FieldCount  int       `json:"fieldCount"`
	CreatedAt   time.Time `json:"createdAt"`
	UpdatedAt   time.Time `json:"updatedAt"`
}

ContentTypeSummaryDTO is a lightweight content type for lists.

type CreateComponentSchemaRequest

type CreateComponentSchemaRequest struct {
	Title       string              `json:"title"                 validate:"required,min=1,max=100"`
	Name        string              `json:"name"                  validate:"required"`
	Description string              `json:"description,omitempty"`
	Icon        string              `json:"icon,omitempty"`
	Fields      []NestedFieldDefDTO `json:"fields,omitempty"`
}

CreateComponentSchemaRequest is the request to create a component schema.

type CreateContentTypeRequest

type CreateContentTypeRequest struct {
	Title       string                  `json:"title"                 validate:"required,min=1,max=100"`
	Name        string                  `json:"name"                  validate:"required"`
	Description string                  `json:"description,omitempty"`
	Icon        string                  `json:"icon,omitempty"`
	Settings    *ContentTypeSettingsDTO `json:"settings,omitempty"`
}

CreateContentTypeRequest is the request to create a content type.

type CreateEntryRequest

type CreateEntryRequest struct {
	Data        map[string]any `json:"data"                  validate:"required"`
	Status      string         `json:"status,omitempty"`
	ScheduledAt *time.Time     `json:"scheduledAt,omitempty"`
}

CreateEntryRequest is the request to create a content entry.

type CreateFieldRequest

type CreateFieldRequest struct {
	Title        string           `json:"title"                  validate:"required,min=1,max=100"`
	Name         string           `json:"name"                   validate:"required"`
	Description  string           `json:"description,omitempty"`
	Type         string           `json:"type"                   validate:"required"`
	Required     bool             `json:"required"`
	Unique       bool             `json:"unique"`
	Indexed      bool             `json:"indexed"`
	Localized    bool             `json:"localized"`
	DefaultValue any              `json:"defaultValue,omitempty"`
	Options      *FieldOptionsDTO `json:"options,omitempty"`
	Order        int              `json:"order"`
	Hidden       bool             `json:"hidden"`
	ReadOnly     bool             `json:"readOnly"`
}

CreateFieldRequest is the request to create a content field.

type CreateTypeRelationRequest

type CreateTypeRelationRequest struct {
	SourceContentTypeID xid.ID `json:"sourceContentTypeId"`
	TargetContentTypeID xid.ID `json:"targetContentTypeId"`
	SourceFieldName     string `json:"sourceFieldName"`
	TargetFieldName     string `json:"targetFieldName,omitempty"`
	RelationType        string `json:"relationType"`
	OnDelete            string `json:"onDelete,omitempty"`
}

CreateTypeRelationRequest is the request to create a type relation.

type DiffType

type DiffType string

DiffType represents the type of difference.

const (
	// DiffTypeAdded indicates a field was added.
	DiffTypeAdded DiffType = "added"
	// DiffTypeRemoved indicates a field was removed.
	DiffTypeRemoved DiffType = "removed"
	// DiffTypeModified indicates a field was modified.
	DiffTypeModified DiffType = "modified"
)

type EntryStatus

type EntryStatus string

EntryStatus defines the status of a content entry.

const (
	// EntryStatusDraft indicates the entry is a draft.
	EntryStatusDraft EntryStatus = "draft"
	// EntryStatusPublished indicates the entry is published.
	EntryStatusPublished EntryStatus = "published"
	// EntryStatusArchived indicates the entry is archived.
	EntryStatusArchived EntryStatus = "archived"
	// EntryStatusScheduled indicates the entry is scheduled for publishing.
	EntryStatusScheduled EntryStatus = "scheduled"
)

func ParseEntryStatus

func ParseEntryStatus(s string) (EntryStatus, bool)

ParseEntryStatus parses a string into an EntryStatus.

func (EntryStatus) IsValid

func (s EntryStatus) IsValid() bool

IsValid checks if the status is valid.

func (EntryStatus) String

func (s EntryStatus) String() string

String returns the string representation of the status.

type FieldConditionDTO

type FieldConditionDTO 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
}

FieldConditionDTO defines a condition for showing/hiding fields.

type FieldDifference

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

FieldDifference represents a difference in a specific field.

type FieldOptionsDTO

type FieldOptionsDTO 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 []ChoiceDTO `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"`

	// Object/Array fields (nested structures)
	NestedFields    []NestedFieldDefDTO `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]OneOfSchemaOptionDTO `json:"schemas,omitempty"`                    // Value -> schema mapping
	ClearOnDiscriminatorChange bool                            `json:"clearOnDiscriminatorChange,omitempty"` // Clear data when discriminator changes

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

FieldOptionsDTO contains type-specific field options.

type FieldOrderItem

type FieldOrderItem struct {
	FieldID string `json:"fieldId" validate:"required"`
	Order   int    `json:"order"`
}

FieldOrderItem represents a field and its new order.

type FieldType

type FieldType string

FieldType defines the type of data a field holds.

const (
	// FieldTypeText is a short text field (varchar).
	FieldTypeText FieldType = "text"
	// FieldTypeRichText is a long formatted text field.
	FieldTypeRichText FieldType = "richText"
	// FieldTypeNumber is a numeric field (integer or float).
	FieldTypeNumber FieldType = "number"
	// FieldTypeBoolean is a true/false field.
	FieldTypeBoolean FieldType = "boolean"
	// FieldTypeDate is a date-only field.
	FieldTypeDate FieldType = "date"
	// FieldTypeDateTime is a date and time field.
	FieldTypeDateTime FieldType = "datetime"
	// FieldTypeTime is a time-only field.
	FieldTypeTime FieldType = "time"
	// FieldTypeEmail is an email field with validation.
	FieldTypeEmail FieldType = "email"
	// FieldTypeURL is a URL field with validation.
	FieldTypeURL FieldType = "url"
	// FieldTypeJSON is an arbitrary JSON object/array field.
	FieldTypeJSON FieldType = "json"
	// FieldTypeSelect is a single select from options.
	FieldTypeSelect FieldType = "select"
	// FieldTypeMultiSelect is a multi-select from options.
	FieldTypeMultiSelect FieldType = "multiSelect"
	// FieldTypeRelation is a reference to another content type.
	FieldTypeRelation FieldType = "relation"
	// FieldTypeMedia is a file/image reference.
	FieldTypeMedia FieldType = "media"
	// FieldTypeSlug is a URL-friendly slug (auto-generated).
	FieldTypeSlug FieldType = "slug"
	// FieldTypeUUID is a UUID field.
	FieldTypeUUID FieldType = "uuid"
	// FieldTypeColor is a color picker field.
	FieldTypeColor FieldType = "color"
	// FieldTypePassword is a password field (hashed).
	FieldTypePassword FieldType = "password"
	// FieldTypePhone is a phone number field.
	FieldTypePhone FieldType = "phone"
	// FieldTypeTextarea is a multiline text field.
	FieldTypeTextarea FieldType = "textarea"
	// FieldTypeMarkdown is a markdown text field.
	FieldTypeMarkdown FieldType = "markdown"
	// FieldTypeEnumeration is an enumeration field.
	FieldTypeEnumeration FieldType = "enumeration"
	// FieldTypeInteger is an integer-only number field.
	FieldTypeInteger FieldType = "integer"
	// FieldTypeFloat is a float/decimal number field.
	FieldTypeFloat FieldType = "float"
	// FieldTypeBigInteger is a big integer field.
	FieldTypeBigInteger FieldType = "bigInteger"
	// FieldTypeDecimal is a decimal field with precision.
	FieldTypeDecimal FieldType = "decimal"
	// FieldTypeObject is a nested object with sub-fields.
	FieldTypeObject FieldType = "object"
	// FieldTypeArray is an array of objects with sub-fields.
	FieldTypeArray FieldType = "array"
	// FieldTypeOneOf is a discriminated union - schema determined by another field's value.
	FieldTypeOneOf FieldType = "oneOf"
)

func ParseFieldType

func ParseFieldType(s string) (FieldType, bool)

ParseFieldType parses a string into a FieldType.

func (FieldType) IsArray

func (t FieldType) IsArray() bool

IsArray returns true if the field type is an array.

func (FieldType) IsDate

func (t FieldType) IsDate() bool

IsDate returns true if the field type is date-related.

func (FieldType) IsNested

func (t FieldType) IsNested() bool

IsNested returns true if the field type supports nested sub-fields.

func (FieldType) IsNumeric

func (t FieldType) IsNumeric() bool

IsNumeric returns true if the field type is numeric.

func (FieldType) IsObject

func (t FieldType) IsObject() bool

IsObject returns true if the field type is an object.

func (FieldType) IsOneOf

func (t FieldType) IsOneOf() bool

IsOneOf returns true if the field type is a discriminated union.

func (FieldType) IsSelectable

func (t FieldType) IsSelectable() bool

IsSelectable returns true if the field type has selectable options.

func (FieldType) IsText

func (t FieldType) IsText() bool

IsText returns true if the field type is text-based.

func (FieldType) IsValid

func (t FieldType) IsValid() bool

IsValid checks if the field type is valid.

func (FieldType) RequiresOptions

func (t FieldType) RequiresOptions() bool

RequiresOptions returns true if the field type requires options configuration.

func (FieldType) String

func (t FieldType) String() string

String returns the string representation of the field type.

func (FieldType) SupportsIndex

func (t FieldType) SupportsIndex() bool

SupportsIndex returns true if the field type supports indexing.

func (FieldType) SupportsSearch

func (t FieldType) SupportsSearch() bool

SupportsSearch returns true if the field type supports full-text search.

func (FieldType) SupportsUnique

func (t FieldType) SupportsUnique() bool

SupportsUnique returns true if the field type supports unique constraint.

type FieldTypeInfo

type FieldTypeInfo struct {
	Type            FieldType `json:"type"`
	Name            string    `json:"name"`
	Description     string    `json:"description"`
	Category        string    `json:"category"`
	Icon            string    `json:"icon"`
	SupportsUnique  bool      `json:"supportsUnique"`
	SupportsIndex   bool      `json:"supportsIndex"`
	SupportsSearch  bool      `json:"supportsSearch"`
	RequiresOptions bool      `json:"requiresOptions"`
}

FieldTypeInfo provides metadata about a field type.

func GetAllFieldTypes

func GetAllFieldTypes() []FieldTypeInfo

GetAllFieldTypes returns information about all available field types.

func GetFieldTypeInfo

func GetFieldTypeInfo(t FieldType) *FieldTypeInfo

GetFieldTypeInfo returns information about a specific field type.

type FieldValidator

type FieldValidator struct {
	FieldName string
	FieldType FieldType
	Required  bool
	Unique    bool
	Options   *FieldOptionsDTO
}

FieldValidator validates a field value against its type and options.

func NewFieldValidator

func NewFieldValidator(name string, fieldType FieldType, required, unique bool, options *FieldOptionsDTO) *FieldValidator

NewFieldValidator creates a new field validator.

func (*FieldValidator) Validate

func (v *FieldValidator) Validate(value any) *ValidationResult

Validate validates a value against the field's type and options.

type ListComponentSchemasQuery

type ListComponentSchemasQuery struct {
	Search    string `json:"search,omitempty"`
	SortBy    string `json:"sortBy,omitempty"`
	SortOrder string `json:"sortOrder,omitempty"`
	Page      int    `json:"page,omitempty"`
	PageSize  int    `json:"pageSize,omitempty"`
}

ListComponentSchemasQuery defines query parameters for listing component schemas.

type ListComponentSchemasResponse

type ListComponentSchemasResponse struct {
	Components []*ComponentSchemaSummaryDTO `json:"components"`
	Page       int                          `json:"page"`
	PageSize   int                          `json:"pageSize"`
	TotalItems int                          `json:"totalItems"`
	TotalPages int                          `json:"totalPages"`
}

ListComponentSchemasResponse is the response for listing component schemas.

type ListContentTypesQuery

type ListContentTypesQuery struct {
	Search    string `json:"search,omitempty"`
	SortBy    string `json:"sortBy,omitempty"`
	SortOrder string `json:"sortOrder,omitempty"`
	Page      int    `json:"page,omitempty"`
	PageSize  int    `json:"pageSize,omitempty"`
}

ListContentTypesQuery defines query parameters for listing content types.

type ListContentTypesResponse

type ListContentTypesResponse struct {
	ContentTypes []*ContentTypeSummaryDTO `json:"contentTypes"`
	Page         int                      `json:"page"`
	PageSize     int                      `json:"pageSize"`
	TotalItems   int                      `json:"totalItems"`
	TotalPages   int                      `json:"totalPages"`
}

ListContentTypesResponse is the response for listing content types.

type ListEntriesQuery

type ListEntriesQuery struct {
	Status    string         `json:"status,omitempty"`
	Search    string         `json:"search,omitempty"`
	Filters   map[string]any `json:"filters,omitempty"`
	SortBy    string         `json:"sortBy,omitempty"`
	SortOrder string         `json:"sortOrder,omitempty"`
	Page      int            `json:"page,omitempty"`
	PageSize  int            `json:"pageSize,omitempty"`
	Select    []string       `json:"select,omitempty"`
	Populate  []string       `json:"populate,omitempty"`
}

ListEntriesQuery defines query parameters for listing entries.

type ListEntriesResponse

type ListEntriesResponse struct {
	Entries    []*ContentEntryDTO `json:"entries"`
	Page       int                `json:"page"`
	PageSize   int                `json:"pageSize"`
	TotalItems int                `json:"totalItems"`
	TotalPages int                `json:"totalPages"`
}

ListEntriesResponse is the response for listing entries.

type ListRevisionsQuery

type ListRevisionsQuery struct {
	Page     int `json:"page,omitempty"`
	PageSize int `json:"pageSize,omitempty"`
}

ListRevisionsQuery defines query parameters for listing revisions.

type ListRevisionsResponse

type ListRevisionsResponse struct {
	Revisions  []*ContentRevisionDTO `json:"revisions"`
	Page       int                   `json:"page"`
	PageSize   int                   `json:"pageSize"`
	TotalItems int                   `json:"totalItems"`
	TotalPages int                   `json:"totalPages"`
}

ListRevisionsResponse is the response for listing revisions.

type NestedFieldDefDTO

type NestedFieldDefDTO struct {
	Title       string           `json:"title"`
	Name        string           `json:"name"`
	Type        string           `json:"type"`
	Required    bool             `json:"required,omitempty"`
	Description string           `json:"description,omitempty"`
	Options     *FieldOptionsDTO `json:"options,omitempty"`
}

NestedFieldDefDTO represents a field definition within a nested object or component schema.

type OnDeleteAction

type OnDeleteAction string

OnDeleteAction defines what happens when a related entry is deleted.

const (
	// OnDeleteCascade deletes the related entries.
	OnDeleteCascade OnDeleteAction = "cascade"
	// OnDeleteSetNull sets the relation to null.
	OnDeleteSetNull OnDeleteAction = "setNull"
	// OnDeleteRestrict prevents deletion if related entries exist.
	OnDeleteRestrict OnDeleteAction = "restrict"
	// OnDeleteNoAction takes no action.
	OnDeleteNoAction OnDeleteAction = "noAction"
)

func (OnDeleteAction) IsValid

func (a OnDeleteAction) IsValid() bool

IsValid checks if the on-delete action is valid.

type OneOfSchemaOptionDTO

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

OneOfSchemaOptionDTO defines a schema option for oneOf fields.

type PaginatedResponse

type PaginatedResponse[T any] struct {
	Items      []T `json:"items"`
	Total      int `json:"total"`
	Page       int `json:"page"`
	PageSize   int `json:"pageSize"`
	TotalPages int `json:"totalPages"`
}

PaginatedResponse is a generic paginated response wrapper.

type PublishEntryRequest

type PublishEntryRequest struct {
	ScheduledAt *time.Time `json:"scheduledAt,omitempty"`
}

PublishEntryRequest is the request to publish an entry.

type RelatedEntryDTO

type RelatedEntryDTO struct {
	ID    string                  `json:"id"`
	Order int                     `json:"order"`
	Entry *ContentEntrySummaryDTO `json:"entry,omitempty"`
}

RelatedEntryDTO represents a related entry.

type RelationType

type RelationType string

RelationType defines the type of relation between content types.

const (
	// RelationTypeOneToOne represents a one-to-one relation.
	RelationTypeOneToOne RelationType = "oneToOne"
	// RelationTypeOneToMany represents a one-to-many relation.
	RelationTypeOneToMany RelationType = "oneToMany"
	// RelationTypeManyToOne represents a many-to-one relation.
	RelationTypeManyToOne RelationType = "manyToOne"
	// RelationTypeManyToMany represents a many-to-many relation.
	RelationTypeManyToMany RelationType = "manyToMany"
)

func (RelationType) IsValid

func (r RelationType) IsValid() bool

IsValid checks if the relation type is valid.

func (RelationType) String

func (r RelationType) String() string

String returns the string representation.

type ReorderFieldsRequest

type ReorderFieldsRequest struct {
	FieldOrders []FieldOrderItem `json:"fieldOrders" validate:"required,min=1"`
}

ReorderFieldsRequest is the request to reorder fields.

type ReorderRelationsRequest

type ReorderRelationsRequest struct {
	OrderedTargetIDs []xid.ID `json:"orderedTargetIds"`
}

ReorderRelationsRequest is the request to reorder relations.

type RevisionCompareDTO

type RevisionCompareDTO struct {
	From        *RevisionDTO      `json:"from"`
	To          *RevisionDTO      `json:"to"`
	Differences []FieldDifference `json:"differences"`
}

RevisionCompareDTO contains revision comparison results.

type RevisionDTO

type RevisionDTO struct {
	ID        string         `json:"id"`
	EntryID   string         `json:"entryId"`
	Version   int            `json:"version"`
	Data      map[string]any `json:"data"`
	ChangedBy string         `json:"changedBy,omitempty"`
	Reason    string         `json:"reason,omitempty"`
	CreatedAt time.Time      `json:"createdAt"`
}

RevisionDTO represents a content revision.

type RollbackEntryRequest

type RollbackEntryRequest struct {
	TargetVersion int    `json:"targetVersion"    validate:"required,min=1"`
	Reason        string `json:"reason,omitempty"`
}

RollbackEntryRequest is the request to rollback an entry.

type SetRelationRequest

type SetRelationRequest struct {
	TargetID xid.ID `json:"targetId"`
}

SetRelationRequest is the request to set a relation.

type SetRelationsRequest

type SetRelationsRequest struct {
	TargetIDs []xid.ID `json:"targetIds"`
}

SetRelationsRequest is the request to set multiple relations.

type TypeRelationDTO

type TypeRelationDTO struct {
	ID                     string    `json:"id"`
	SourceContentTypeID    string    `json:"sourceContentTypeId"`
	TargetContentTypeID    string    `json:"targetContentTypeId"`
	SourceContentTypeTitle string    `json:"sourceContentTypeTitle,omitempty"`
	SourceContentTypeName  string    `json:"sourceContentTypeName,omitempty"`
	TargetContentTypeTitle string    `json:"targetContentTypeTitle,omitempty"`
	TargetContentTypeName  string    `json:"targetContentTypeName,omitempty"`
	SourceFieldName        string    `json:"sourceFieldName"`
	TargetFieldName        string    `json:"targetFieldName,omitempty"`
	RelationType           string    `json:"relationType"`
	OnDelete               string    `json:"onDelete"`
	CreatedAt              time.Time `json:"createdAt"`
}

TypeRelationDTO represents a type relation definition.

type UpdateComponentSchemaRequest

type UpdateComponentSchemaRequest struct {
	Title       string              `json:"title,omitempty"`
	Description string              `json:"description,omitempty"`
	Icon        string              `json:"icon,omitempty"`
	Fields      []NestedFieldDefDTO `json:"fields,omitempty"`
}

UpdateComponentSchemaRequest is the request to update a component schema.

type UpdateContentTypeRequest

type UpdateContentTypeRequest struct {
	Title       string                  `json:"title,omitempty"`
	Description string                  `json:"description,omitempty"`
	Icon        string                  `json:"icon,omitempty"`
	Settings    *ContentTypeSettingsDTO `json:"settings,omitempty"`
}

UpdateContentTypeRequest is the request to update a content type.

type UpdateEntryRequest

type UpdateEntryRequest struct {
	Data         map[string]any `json:"data,omitempty"`
	Status       string         `json:"status,omitempty"`
	ScheduledAt  *time.Time     `json:"scheduledAt,omitempty"`
	ChangeReason string         `json:"changeReason,omitempty"`
}

UpdateEntryRequest is the request to update a content entry.

type UpdateFieldRequest

type UpdateFieldRequest struct {
	Title        string           `json:"title,omitempty"`
	Description  string           `json:"description,omitempty"`
	Required     *bool            `json:"required,omitempty"`
	Unique       *bool            `json:"unique,omitempty"`
	Indexed      *bool            `json:"indexed,omitempty"`
	Localized    *bool            `json:"localized,omitempty"`
	DefaultValue any              `json:"defaultValue,omitempty"`
	Options      *FieldOptionsDTO `json:"options,omitempty"`
	Order        *int             `json:"order,omitempty"`
	Hidden       *bool            `json:"hidden,omitempty"`
	ReadOnly     *bool            `json:"readOnly,omitempty"`
}

UpdateFieldRequest is the request to update a content field.

type UpdateTypeRelationRequest

type UpdateTypeRelationRequest struct {
	TargetFieldName *string `json:"targetFieldName,omitempty"`
	OnDelete        *string `json:"onDelete,omitempty"`
}

UpdateTypeRelationRequest is the request to update a type relation.

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
	Code    string `json:"code,omitempty"`
}

ValidationError represents a validation error for a field.

type ValidationResult

type ValidationResult struct {
	Valid  bool              `json:"valid"`
	Errors []ValidationError `json:"errors,omitempty"`
}

ValidationResult holds the result of validation.

func ValidateArrayData

func ValidateArrayData(items []map[string]any, fields []NestedFieldDefDTO, minItems, maxItems *int) *ValidationResult

ValidateArrayData validates an array of data against nested field definitions.

func ValidateNestedData

func ValidateNestedData(data map[string]any, fields []NestedFieldDefDTO) *ValidationResult

ValidateNestedData validates data against nested field definitions (exported for use by services).

func ValidateOneOfWithDiscriminator

func ValidateOneOfWithDiscriminator(data map[string]any, discriminatorValue string, options *FieldOptionsDTO) *ValidationResult

ValidateOneOfWithDiscriminator validates oneOf data with a specific discriminator value.

Jump to

Keyboard shortcuts

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