Documentation
¶
Overview ¶
Package transformations provides utility functions for converting ActivityPub objects and actors to Mastodon API compatible models and data structures.
Index ¶
- Variables
- func ActivityPubActivityToStorage(activity *activitypub.Activity) (*storagemodels.Activity, error)
- func ActivityPubActorToMastodon(actor *activitypub.Actor, baseURL string) (*models.Account, error)
- func ActivityPubActorToStorage(actor *activitypub.Actor) (*storagemodels.Actor, error)
- func ActivityPubObjectToMastodon(obj *activitypub.Note, actor *activitypub.Actor, baseURL string) (*models.Status, error)
- func ActivityPubObjectToStorage(obj *activitypub.Note) (*storagemodels.Object, error)
- func ActorToAccountBase(actor *activitypub.Actor, baseURL string) models.Account
- func ActorToAccountWithContext(ctx context.Context, actor *activitypub.Actor) (models.Account, error)
- func ActorToAccountWithCounts(actor *activitypub.Actor, baseURL string, ...) models.Account
- func ExtractUsernameFromActorID(actorID string) string
- func GenerateNumericIDFromURL(url string) string
- func GenerateNumericIDFromUsername(username string) string
- func NewActivityToStorageTransformer() common.Transformer[*activitypub.Activity, *storagemodels.Activity]
- func NewActorBatchToMastodonTransformer() common.BatchTransformer[*activitypub.Actor, *models.Account]
- func NewActorToMastodonTransformer() common.Transformer[*activitypub.Actor, *models.Account]
- func NewActorToStorageTransformer() common.Transformer[*activitypub.Actor, *storagemodels.Actor]
- func NewObjectBatchToMastodonTransformer() common.BatchTransformer[*activitypub.Note, *models.Status]
- func NewObjectToMastodonTransformer() common.Transformer[*activitypub.Note, *models.Status]
- func NewObjectToStorageTransformer() common.Transformer[*activitypub.Note, *storagemodels.Object]
- func NewStorageToActivityTransformer() common.Transformer[*storagemodels.Activity, *activitypub.Activity]
- func NewStorageToActorTransformer() common.Transformer[*storagemodels.Actor, *activitypub.Actor]
- func NewStorageToObjectTransformer() common.Transformer[*storagemodels.Object, *activitypub.Note]
- func NotesToStatusAny(note any, baseURL string) models.Status
- func ObjectToStatusAny(obj any, actor *activitypub.Actor, baseURL string) models.Status
- func ObjectToStatusBase(obj map[string]interface{}, actor *activitypub.Actor, baseURL string) models.Status
- func ObjectToStatusWithContext(ctx context.Context, obj map[string]interface{}) (models.Status, error)
- func ObjectToStatusWithContextAndCounts(_ context.Context, obj any, actor *activitypub.Actor, ...) models.Status
- func StorageActivityToActivityPub(activity *storagemodels.Activity) (*activitypub.Activity, error)
- func StorageActorToActivityPub(actor *storagemodels.Actor) (*activitypub.Actor, error)
- func StorageArticleToActivityPub(article *storagemodels.Article) (*activitypub.Article, error)
- func StorageObjectToActivityPub(obj *storagemodels.Object) (*activitypub.Note, error)
- func TransformErrorResponse(err error) map[string]interface{}
- func TransformIDList(ids []string, prefix string) []string
- func TransformPaginationInfo(info PaginationInfo) map[string]interface{}
- func TransformTimestamp(timestamp time.Time, format string) string
- type APIResponseTransformer
- type ActivityPubTransformer
- type BaseTransformer
- type GraphQLTransformer
- type PaginationInfo
- type StatusResponseTransformer
- type StorageModelTransformer
- type Transformer
Constants ¶
This section is empty.
Variables ¶
var ActivityPubRegistry *common.TransformationRegistry
ActivityPubRegistry is the global transformation registry for ActivityPub transformations
Functions ¶
func ActivityPubActivityToStorage ¶
func ActivityPubActivityToStorage(activity *activitypub.Activity) (*storagemodels.Activity, error)
ActivityPubActivityToStorage converts an ActivityPub Activity to a storage Activity model
func ActivityPubActorToMastodon ¶
ActivityPubActorToMastodon converts an ActivityPub Actor to a Mastodon Account
func ActivityPubActorToStorage ¶
func ActivityPubActorToStorage(actor *activitypub.Actor) (*storagemodels.Actor, error)
ActivityPubActorToStorage converts an ActivityPub Actor to a storage Actor model
func ActivityPubObjectToMastodon ¶
func ActivityPubObjectToMastodon(obj *activitypub.Note, actor *activitypub.Actor, baseURL string) (*models.Status, error)
ActivityPubObjectToMastodon converts an ActivityPub Note to a Mastodon Status
func ActivityPubObjectToStorage ¶
func ActivityPubObjectToStorage(obj *activitypub.Note) (*storagemodels.Object, error)
ActivityPubObjectToStorage converts an ActivityPub Note to a storage Object model
func ActorToAccountBase ¶
func ActorToAccountBase(actor *activitypub.Actor, baseURL string) models.Account
ActorToAccountBase provides base actor to account conversion
func ActorToAccountWithContext ¶
func ActorToAccountWithContext(ctx context.Context, actor *activitypub.Actor) (models.Account, error)
ActorToAccountWithContext provides context-aware actor to account conversion
func ActorToAccountWithCounts ¶
func ActorToAccountWithCounts(actor *activitypub.Actor, baseURL string, followersCount, followingCount, statusesCount int) models.Account
ActorToAccountWithCounts provides actor to account conversion with count values
func ExtractUsernameFromActorID ¶
ExtractUsernameFromActorID extracts username from an actor ID URL
func GenerateNumericIDFromURL ¶
GenerateNumericIDFromURL generates a stable numeric ID from URL
func GenerateNumericIDFromUsername ¶
GenerateNumericIDFromUsername generates a stable numeric ID from username
func NewActivityToStorageTransformer ¶
func NewActivityToStorageTransformer() common.Transformer[*activitypub.Activity, *storagemodels.Activity]
NewActivityToStorageTransformer creates a new Activity to Storage transformer
func NewActorBatchToMastodonTransformer ¶
func NewActorBatchToMastodonTransformer() common.BatchTransformer[*activitypub.Actor, *models.Account]
NewActorBatchToMastodonTransformer creates a batch transformer for actors to Mastodon accounts
func NewActorToMastodonTransformer ¶
func NewActorToMastodonTransformer() common.Transformer[*activitypub.Actor, *models.Account]
NewActorToMastodonTransformer creates a new Actor to Mastodon transformer
func NewActorToStorageTransformer ¶
func NewActorToStorageTransformer() common.Transformer[*activitypub.Actor, *storagemodels.Actor]
NewActorToStorageTransformer creates a new Actor to Storage transformer
func NewObjectBatchToMastodonTransformer ¶
func NewObjectBatchToMastodonTransformer() common.BatchTransformer[*activitypub.Note, *models.Status]
NewObjectBatchToMastodonTransformer creates a batch transformer for objects to Mastodon statuses
func NewObjectToMastodonTransformer ¶
func NewObjectToMastodonTransformer() common.Transformer[*activitypub.Note, *models.Status]
NewObjectToMastodonTransformer creates a new Object to Mastodon transformer
func NewObjectToStorageTransformer ¶
func NewObjectToStorageTransformer() common.Transformer[*activitypub.Note, *storagemodels.Object]
NewObjectToStorageTransformer creates a new Object to Storage transformer
func NewStorageToActivityTransformer ¶
func NewStorageToActivityTransformer() common.Transformer[*storagemodels.Activity, *activitypub.Activity]
NewStorageToActivityTransformer creates a new Storage to Activity transformer
func NewStorageToActorTransformer ¶
func NewStorageToActorTransformer() common.Transformer[*storagemodels.Actor, *activitypub.Actor]
NewStorageToActorTransformer creates a new Storage to Actor transformer
func NewStorageToObjectTransformer ¶
func NewStorageToObjectTransformer() common.Transformer[*storagemodels.Object, *activitypub.Note]
NewStorageToObjectTransformer creates a new Storage to Object transformer
func NotesToStatusAny ¶
NotesToStatusAny provides flexible note-to-status conversion for any note type
func ObjectToStatusAny ¶
ObjectToStatusAny provides flexible object to status conversion for any object type
func ObjectToStatusBase ¶
func ObjectToStatusBase(obj map[string]interface{}, actor *activitypub.Actor, baseURL string) models.Status
ObjectToStatusBase provides base object to status conversion
func ObjectToStatusWithContext ¶
func ObjectToStatusWithContext(ctx context.Context, obj map[string]interface{}) (models.Status, error)
ObjectToStatusWithContext provides context-aware object to status conversion
func ObjectToStatusWithContextAndCounts ¶
func ObjectToStatusWithContextAndCounts(_ context.Context, obj any, actor *activitypub.Actor, likeCount, reblogCount int, favorited, reblogged, bookmarked bool, baseURL string) models.Status
ObjectToStatusWithContextAndCounts provides full context-aware object to status conversion with counts and user state
func StorageActivityToActivityPub ¶
func StorageActivityToActivityPub(activity *storagemodels.Activity) (*activitypub.Activity, error)
StorageActivityToActivityPub converts a storage Activity to an ActivityPub Activity
func StorageActorToActivityPub ¶
func StorageActorToActivityPub(actor *storagemodels.Actor) (*activitypub.Actor, error)
StorageActorToActivityPub converts a storage Actor to an ActivityPub Actor
func StorageArticleToActivityPub ¶
func StorageArticleToActivityPub(article *storagemodels.Article) (*activitypub.Article, error)
StorageArticleToActivityPub converts a storage Article to an ActivityPub Article
func StorageObjectToActivityPub ¶
func StorageObjectToActivityPub(obj *storagemodels.Object) (*activitypub.Note, error)
StorageObjectToActivityPub converts a storage Object to an ActivityPub Note
func TransformErrorResponse ¶
TransformErrorResponse converts an error to a standardized response format
func TransformIDList ¶
TransformIDList adds a prefix to a list of IDs
func TransformPaginationInfo ¶
func TransformPaginationInfo(info PaginationInfo) map[string]interface{}
TransformPaginationInfo converts pagination info to map format
Types ¶
type APIResponseTransformer ¶
type APIResponseTransformer[T any] struct { *BaseTransformer[T, models.Account] // contains filtered or unexported fields }
APIResponseTransformer handles Mastodon API response transformations
func NewAPIResponseTransformer ¶
func NewAPIResponseTransformer[T any](baseURL string, transformFunc func(context.Context, T) (models.Account, error)) *APIResponseTransformer[T]
NewAPIResponseTransformer creates a new API response transformer
type ActivityPubTransformer ¶
type ActivityPubTransformer[T any] struct { *BaseTransformer[T, *activitypub.Actor] }
ActivityPubTransformer handles ActivityPub protocol transformations
func NewActivityPubTransformer ¶
func NewActivityPubTransformer[T any](transformFunc func(context.Context, T) (*activitypub.Actor, error)) *ActivityPubTransformer[T]
NewActivityPubTransformer creates a new ActivityPub transformer
type BaseTransformer ¶
type BaseTransformer[TSource, TTarget any] struct { TransformFunc func(context.Context, TSource) (TTarget, error) }
BaseTransformer provides common transformation functionality
func (*BaseTransformer[TSource, TTarget]) Transform ¶
func (bt *BaseTransformer[TSource, TTarget]) Transform(ctx context.Context, source TSource) (TTarget, error)
Transform performs a single transformation
func (*BaseTransformer[TSource, TTarget]) TransformList ¶
func (bt *BaseTransformer[TSource, TTarget]) TransformList(ctx context.Context, sources []TSource) ([]TTarget, error)
TransformList transforms a slice of source items
type GraphQLTransformer ¶
type GraphQLTransformer[T any] struct { *BaseTransformer[T, map[string]interface{}] }
GraphQLTransformer handles GraphQL schema transformations
func NewGraphQLTransformer ¶
func NewGraphQLTransformer[T any](transformFunc func(context.Context, T) (map[string]interface{}, error)) *GraphQLTransformer[T]
NewGraphQLTransformer creates a new GraphQL transformer
type PaginationInfo ¶
type PaginationInfo struct {
MaxID string `json:"max_id,omitempty"`
MinID string `json:"min_id,omitempty"`
SinceID string `json:"since_id,omitempty"`
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
}
PaginationInfo represents pagination metadata
type StatusResponseTransformer ¶
type StatusResponseTransformer[T any] struct { *BaseTransformer[T, models.Status] // contains filtered or unexported fields }
StatusResponseTransformer handles Mastodon Status API response transformations
func NewStatusResponseTransformer ¶
func NewStatusResponseTransformer[T any](baseURL string, transformFunc func(context.Context, T) (models.Status, error)) *StatusResponseTransformer[T]
NewStatusResponseTransformer creates a new Status response transformer
type StorageModelTransformer ¶
type StorageModelTransformer[TSource, TTarget any] struct { *BaseTransformer[TSource, TTarget] }
StorageModelTransformer handles storage model transformations
func NewStorageModelTransformer ¶
func NewStorageModelTransformer[TSource, TTarget any](transformFunc func(context.Context, TSource) (TTarget, error)) *StorageModelTransformer[TSource, TTarget]
NewStorageModelTransformer creates a new storage model transformer