Documentation
¶
Index ¶
- Constants
- Variables
- func ComponentReferences(tx *gorm.DB, name string) ([]string, error)
- func CountUsers() (int64, error)
- func CreateComponent(cmp *models.Component) error
- func CreateItems(collection models.Collection, inputs []ItemInput) ([]*models.Item, error)
- func CreateSingleItem(st *models.Singleton, itemData map[string]any) (*models.SingleItem, error)
- func CreateUser(user *models.User) error
- func DeleteAgent(agentID uint) error
- func DeleteCollection(collectionID uint) error
- func DeleteComponent(name string) error
- func DeleteItem(id uint) error
- func DeleteMedia(ctx context.Context, id uint) error
- func DeleteRole(id uint) error
- func DeleteSingleItem(SingletonName string) error
- func DeleteSingleton(SingletonID uint) error
- func DeleteUser(id uint) error
- func FetchNestedRelations(collection models.Collection, data models.JSONMap, level uint) (models.JSONMap, error)
- func FindAgentsByEventTrigger(collectionName string, eventType string) ([]models.Agent, error)
- func GetAgentByID(id uint) (*models.Agent, error)
- func GetAgentByName(name string) (*models.Agent, error)
- func GetAllAgents(filters map[string]any, rangeValues []int) ([]models.Agent, int, error)
- func GetAllCollections(filters map[string]any, sortValues []string, rangeValues []int) ([]models.Collection, int, error)
- func GetAllComponents() ([]models.Component, error)
- func GetAllRoles() ([]models.UserRole, error)
- func GetAllSingletons() ([]models.Singleton, error)
- func GetAllUsers() ([]models.User, error)
- func GetCollectionByID(id uint) (*models.Collection, error)
- func GetCollectionByName(name string) (*models.Collection, error)
- func GetCollectionSchema(id int) (map[string]any, error)
- func GetComponentByName(name string) (*models.Component, error)
- func GetConversationHistory(agentID uint) ([]llm.Message, error)
- func GetItemByID(collectionID uint, itemID uint) (*models.Item, error)
- func GetItems(collectionID uint, page, pageSize int) ([]models.Item, int, error)
- func GetItemsByOffset(ct models.Collection, offset, limit int, status string) ([]models.Item, int, error)
- func GetMedia(id uint) (*models.Media, error)
- func GetRoleByID(id uint) (*models.UserRole, error)
- func GetRoleByName(name string) (*models.UserRole, error)
- func GetSingleItemByType(SingletonName string) (*models.SingleItem, error)
- func GetSingletonByName(name string) (*models.Singleton, error)
- func GetUserByID(id uint) (*models.User, error)
- func GetUserByUsername(username string) (*models.User, error)
- func GetVisibleItem(ct models.Collection, itemID uint, publishedOnly bool) (*models.Item, error)
- func InitAsynqClient(client *asynq.Client)
- func InitMediaStore(s media.Store)
- func InvalidateComponentCache()
- func IsReferencedByOtherCollections(collectionName string, tx *gorm.DB) ([]models.Attribute, error)
- func ListMedia(q MediaQuery) ([]models.Media, int, error)
- func MediaStore() media.Store
- func MediaURL(ctx context.Context, m models.Media) string
- func PopulateMedia(ctx context.Context, attrs []models.Attribute, data models.JSONMap) models.JSONMap
- func PopulateRelations(collection models.Collection, data models.JSONMap, level uint, ...) (models.JSONMap, error)
- func QueryItems(ct models.Collection, q ItemQuery) ([]models.Item, int, error)
- func ResolveMediaValue(ctx context.Context, v any, multiple bool) any
- func SaveAgent(agent *models.Agent) error
- func SaveCollection(ct *models.Collection) error
- func SaveConversationHistory(agentID uint, messages []llm.Message) error
- func SaveItem(collection models.Collection, itemData models.JSONMap) (*models.Item, error)
- func SaveItems(collection models.Collection, batch []models.JSONMap) ([]*models.Item, error)
- func SaveMedia(ctx context.Context, in UploadFile, policy UploadPolicy) (*models.Media, error)
- func SaveOrUpdateSingleton(st *models.Singleton) error
- func SaveRole(role *models.UserRole) error
- func SetItemPublished(collection models.Collection, itemID uint, publish bool) (*models.Item, error)
- func UpdateAgent(id uint, updated *models.Agent) error
- func UpdateCollection(id uint, updated *models.Collection) error
- func UpdateComponent(name string, updated *models.Component) error
- func UpdateItem(itemID uint, data models.JSONMap) error
- func UpdateItemContent(collection models.Collection, itemID uint, data models.JSONMap, publish *bool) (*models.Item, error)
- func UpdateMedia(id uint, info MediaInfo) (*models.Media, error)
- func UpdateRole(id uint, updates map[string]interface{}) error
- func UpdateSingleItem(SingletonName string, newData map[string]any) (*models.SingleItem, error)
- func UpdateUser(id uint, updates map[string]interface{}) error
- type DBToolCall
- type DuplicateEntryError
- type GeneralDatabaseError
- type ItemFilter
- type ItemInput
- type ItemQuery
- type ItemSort
- type ItemValidationError
- type MediaError
- type MediaInfo
- type MediaQuery
- type QueryFieldError
- type UploadFile
- type UploadPolicy
Constants ¶
const ( OpEq = "$eq" OpNe = "$ne" OpLt = "$lt" OpLte = "$lte" OpGt = "$gt" OpGte = "$gte" OpContains = "$contains" )
Filter operators supported on item lists.
Variables ¶
var ErrComponentInUse = errors.New("component is in use")
ErrComponentInUse is returned when deleting or renaming a component that attributes still reference.
var ErrDraftAndPublishDisabled = errors.New("this collection does not use draft and publish")
ErrDraftAndPublishDisabled is returned when publishing an item of a collection that does not use draft and publish.
var ErrItemNotFound = errors.New("item not found")
ErrItemNotFound is returned when an item does not exist in a collection.
var ErrMediaNotFound = errors.New("media not found")
ErrMediaNotFound is returned for unknown media IDs.
var ErrNoMediaStore = errors.New("media uploads are not configured")
ErrNoMediaStore is returned when no store is configured.
Functions ¶
func ComponentReferences ¶ added in v0.4.0
ComponentReferences lists the attributes (as "collection.attribute", "singleton.attribute" or "component.attribute") that use the component.
func CountUsers ¶
CountUsers returns the total number of (non-deleted) users.
func CreateComponent ¶
CreateComponent stores a new Component definition in the DB, including its attributes.
func CreateItems ¶ added in v0.4.0
CreateItems validates and creates several items atomically: either all are stored or none. Nested relations created during validation are part of the same transaction, and the stored data is the processed (validated) data. Events are published only after a successful commit.
func CreateSingleItem ¶
CreateSingleItem creates a new SingleItem for a given Singleton. Returns an error if an item already exists for that Singleton (one-to-one).
func CreateUser ¶
func DeleteAgent ¶
DeleteAgent deletes an agent from the database by its ID.
func DeleteCollection ¶
DeleteCollection deletes a collection and all associated data by its ID.
func DeleteComponent ¶
DeleteComponent removes a component definition by name. It refuses to delete a component that attributes still use.
func DeleteItem ¶
func DeleteMedia ¶ added in v0.4.0
DeleteMedia removes a media file and its content. Items that referenced it then show null, like a deleted related item. The record goes first, so a failure to delete the content leaves an orphan object (logged), never a record pointing at nothing.
func DeleteSingleItem ¶
DeleteSingleItem removes the SingleItem for a given single type name (if it exists).
func DeleteSingleton ¶
DeleteSingleton permanently deletes a single type by its ID (including attributes). Note: Strapi typically doesn't expose DELETE for single types, but you can implement it if needed.
func FetchNestedRelations ¶
func FetchNestedRelations(collection models.Collection, data models.JSONMap, level uint) (models.JSONMap, error)
FetchNestedRelations replaces relation IDs in data with the related items, down to level levels, including drafts. See PopulateRelations.
func FindAgentsByEventTrigger ¶
FindAgentsByEventTrigger queries for agents subscribed to a specific collection event. TOFIX This version uses a query for JSONB that is compatible with PostgreSQL.
func GetAgentByID ¶
GetAgentByID retrieves an agent by its ID.
func GetAgentByName ¶
GetAgentByName retrieves an agent by its name.
func GetAllAgents ¶
GetAllAgents retrieves agents with optional filtering and pagination.
func GetAllCollections ¶
func GetAllComponents ¶
GetAllComponents returns every component definition with its attributes, ordered by name.
func GetAllRoles ¶
GetAllRoles retrieves all roles from the database.
func GetAllSingletons ¶
GetAllSingletons returns every singleton definition with its attributes, ordered by name.
func GetAllUsers ¶
GetAllUsers retrieves all users from the database.
func GetCollectionByID ¶
func GetCollectionByID(id uint) (*models.Collection, error)
GetCollectionByID retrieves a collection by its ID.
func GetCollectionByName ¶
func GetCollectionByName(name string) (*models.Collection, error)
GetCollectionByName retrieves a collection by its name.
func GetCollectionSchema ¶
GetCollectionSchema retrieves the schema definition of a collection by name.
func GetComponentByName ¶
GetComponentByName retrieves a component definition by its name.
func GetConversationHistory ¶
GetConversationHistory retrieves the messages for an agent.
func GetItemByID ¶
GetItemByID fetches an item by its ID and collection ID.
func GetItemsByOffset ¶
func GetItemsByOffset(ct models.Collection, offset, limit int, status string) ([]models.Item, int, error)
GetItemsByOffset lists items using offset/limit pagination (as GraphQL does). status filters draft-and-publish collections: "" (all), models.StatusPublished or models.StatusDraft.
func GetRoleByID ¶
GetRoleByID retrieves a role by its ID.
func GetRoleByName ¶
GetRoleByName retrieves a role by its name.
func GetSingleItemByType ¶
func GetSingleItemByType(SingletonName string) (*models.SingleItem, error)
GetSingleItemByType retrieves the SingleItem for a given single type name.
func GetSingletonByName ¶
GetSingletonByName retrieves a single type by its name (including associated attributes).
func GetUserByID ¶
GetUserByID retrieves a user by their ID.
func GetUserByUsername ¶
GetUserByUsername retrieves a user by their username.
func GetVisibleItem ¶ added in v0.4.0
GetVisibleItem fetches an item of the collection. With publishedOnly, a draft of a draft-and-publish collection is reported as not found.
func InitAsynqClient ¶
func InitMediaStore ¶ added in v0.4.0
InitMediaStore sets the store used for uploads and media URLs.
func InvalidateComponentCache ¶ added in v0.4.0
func InvalidateComponentCache()
InvalidateComponentCache drops cached component definitions.
func ListMedia ¶ added in v0.4.0
func ListMedia(q MediaQuery) ([]models.Media, int, error)
ListMedia lists media files, newest first.
func MediaStore ¶ added in v0.4.0
MediaStore returns the configured store (nil when uploads are disabled).
func PopulateMedia ¶ added in v0.4.0
func PopulateMedia(ctx context.Context, attrs []models.Attribute, data models.JSONMap) models.JSONMap
PopulateMedia replaces media IDs in an item's data (including inside components) with media objects.
func PopulateRelations ¶ added in v0.4.0
func PopulateRelations(collection models.Collection, data models.JSONMap, level uint, publishedOnly bool) (models.JSONMap, error)
PopulateRelations replaces relation IDs in data with the related items (in the API's flat item shape), down to level levels. With publishedOnly, drafts of draft-and-publish target collections are left out, as are related items that no longer exist.
func QueryItems ¶
QueryItems lists the items of a collection with optional filters and sort. Every field is validated against the collection schema; attribute names and values are always bound as SQL parameters.
func ResolveMediaValue ¶ added in v0.4.0
ResolveMediaValue converts one stored media value (an ID, a list of IDs, or URL strings) to API objects; GraphQL uses it.
func SaveAgent ¶
SaveAgent persists an Agent to the database, handling both new and soft-deleted records.
func SaveCollection ¶
func SaveCollection(ct *models.Collection) error
SaveCollection persists a Collection to the database, handling both new and soft-deleted records.
func SaveConversationHistory ¶
SaveConversationHistory replaces the old history with the new one for an agent.
func SaveItem ¶
SaveItem validates and creates a single item, then publishes an 'item:created' event once the transaction has committed.
func SaveItems ¶
SaveItems validates and creates several items atomically, as drafts in draft-and-publish collections. See CreateItems.
func SaveMedia ¶ added in v0.4.0
func SaveMedia(ctx context.Context, in UploadFile, policy UploadPolicy) (*models.Media, error)
SaveMedia checks a file against the policy, stores its content and records it. The type is detected from the content, not from the client.
func SaveOrUpdateSingleton ¶
SaveOrUpdateSingleton either creates a new single type or updates/restores a previously soft-deleted record with the same name.
This mimics the "single type" behavior in Strapi (one record per name).
func SetItemPublished ¶ added in v0.4.0
func SetItemPublished(collection models.Collection, itemID uint, publish bool) (*models.Item, error)
SetItemPublished publishes or unpublishes an item of a draft-and-publish collection. Publishing an already published item keeps its publishedAt.
func UpdateAgent ¶
UpdateAgent updates an existing Agent in the database by its ID.
func UpdateCollection ¶
func UpdateCollection(id uint, updated *models.Collection) error
UpdateCollectionByID updates an existing Collection in the database by its ID.
func UpdateComponent ¶
UpdateComponent updates an existing component definition by name.
func UpdateItemContent ¶ added in v0.4.0
func UpdateItemContent(collection models.Collection, itemID uint, data models.JSONMap, publish *bool) (*models.Item, error)
UpdateItemContent validates data (the item's complete new data) and saves it. publish changes the publication state of a draft-and-publish item (nil leaves it unchanged). It returns ErrItemNotFound when the item is not in the collection, an *ItemValidationError for invalid data, and publishes item:updated (plus item:published / item:unpublished on a state change).
func UpdateMedia ¶ added in v0.4.0
UpdateMedia changes a media file's name, alternative text or caption.
func UpdateRole ¶
UpdateRole updates an existing role by ID.
func UpdateSingleItem ¶
UpdateSingleItem updates the SingleItem for a given single type with new data. Returns the updated SingleItem or an error if not found or validation fails.
func UpdateUser ¶
UpdateUser updates the details of an existing user by ID.
Types ¶
type DBToolCall ¶
type DBToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
FunctionName string `json:"function_name"`
Arguments string `json:"arguments"`
}
DBToolCall represents a simplified tool call for database storage
type DuplicateEntryError ¶
type DuplicateEntryError struct {
Field string
}
Custom error types
func (*DuplicateEntryError) Error ¶
func (e *DuplicateEntryError) Error() string
type GeneralDatabaseError ¶
type GeneralDatabaseError struct {
Message string
}
func (*GeneralDatabaseError) Error ¶
func (e *GeneralDatabaseError) Error() string
type ItemFilter ¶
ItemFilter is one condition on an item attribute (or a built-in column).
type ItemInput ¶ added in v0.4.0
type ItemInput struct {
Data models.JSONMap
// Publish creates the item as published. It is ignored unless the
// collection uses draft and publish (other items are always visible).
Publish bool
}
ItemInput is one item to create.
type ItemQuery ¶
type ItemQuery struct {
Page int
PageSize int
Filters []ItemFilter
Sort []ItemSort
// Status filters draft-and-publish collections: "" (all items),
// models.StatusPublished or models.StatusDraft. Ignored otherwise.
Status string
}
ItemQuery describes a filtered, sorted, paginated item listing.
type ItemValidationError ¶
ItemValidationError wraps a validation failure for an item, as opposed to a database error, so callers can answer 400 instead of 500.
func (*ItemValidationError) Error ¶
func (e *ItemValidationError) Error() string
func (*ItemValidationError) Unwrap ¶
func (e *ItemValidationError) Unwrap() error
type MediaError ¶ added in v0.4.0
MediaError is an upload refused for a reason the client can fix.
func (*MediaError) Error ¶ added in v0.4.0
func (e *MediaError) Error() string
type MediaQuery ¶ added in v0.4.0
type MediaQuery struct {
Page, PageSize int
MimePrefix string // e.g. "image/" or "application/pdf"
Search string // substring of the file name
}
MediaQuery filters the media library.
type QueryFieldError ¶
type QueryFieldError struct{ Msg string }
QueryFieldError reports a filter or sort the collection cannot satisfy.
func (*QueryFieldError) Error ¶
func (e *QueryFieldError) Error() string
type UploadFile ¶ added in v0.4.0
type UploadFile struct {
Name string // client file name
Size int64 // bytes
Content io.ReadSeeker // positioned at the start
Alt string
Caption string
User string
}
UploadFile describes one file to upload.
type UploadPolicy ¶ added in v0.4.0
type UploadPolicy struct {
MaxSize int64 // bytes; 0 means no limit
AllowedTypes []string // MIME patterns; empty means media.DefaultAllowedTypes
}
UploadPolicy limits what can be uploaded.