Documentation ¶
Overview ¶
Package filters contains helper functions to be used by the storage implementations for filtering out elements at load time.
Index ¶
- Constants
- Variables
- func CacheKey(f *Filters) vocab.IRI
- func Counted(fns ...Check) int
- func CursorFromItem(it vocab.Item, filters ...Check) (vocab.Item, vocab.Item, vocab.Item)
- func FilterIt(it vocab.Item, f Filterable) (vocab.Item, error)
- func FirstPage() pagValues
- func GetLimit(f ...Check) int
- func GetWhereClauses(f ...Check) ([]string, []any)
- func IRIf(f Filters, iri string) string
- func IsItemIRI(f vocab.LinkOrIRI) bool
- func LoadCollectionFilters(f *Filters, auth vocab.Actor) error
- func LoadItemFilters(f *Filters, auth vocab.Actor) error
- func MaxCount(fns ...Check) int
- func NextPage(it vocab.Item) pagValues
- func PaginateCollection(it vocab.Item, filters ...Check) vocab.Item
- func PaginatorValues(q url.Values) pagValues
- func PrevPage(it vocab.Item) pagValues
- func SearchIndex(i *index.Index, ff ...Check) ([]vocab.IRI, error)
- func ToValues(ff ...Check) url.Values
- func ValidActivityCollection(typ vocab.CollectionPath) bool
- func ValidCollection(typ vocab.CollectionPath) bool
- func ValidCollectionCount(col vocab.ItemCollection, f Filterable) bool
- func ValidObjectCollection(typ vocab.CollectionPath) bool
- func VocabularyTypesFilter(types ...string) vocab.ActivityVocabularyTypes
- type Check
- func Actor(fns ...Check) Check
- func After(fns ...Check) Check
- func All(fns ...Check) Check
- func Any(fns ...Check) Check
- func AttributedToLike(frag string) Check
- func Authorized(iri vocab.IRI) Check
- func Before(fn ...Check) Check
- func ContentIs(cont string) Check
- func ContentLike(cont string) Check
- func ContextLike(frag string) Check
- func HasType(ty ...vocab.ActivityVocabularyType) Check
- func IDLike(frag string) Check
- func IRILike(frag string) Check
- func InReplyToLike(frag string) Check
- func MaxCountCheck(fns ...Check) Check
- func NameIs(name string) Check
- func NameLike(name string) Check
- func Not(fn Check) Check
- func Object(fns ...Check) Check
- func Recipients(iri vocab.IRI) Check
- func SameAttributedTo(iri vocab.IRI) Check
- func SameContext(iri vocab.IRI) Check
- func SameID(i vocab.IRI) Check
- func SameIRI(iri vocab.IRI) Check
- func SameInReplyTo(iri vocab.IRI) Check
- func SameURL(iri vocab.IRI) Check
- func SummaryIs(sum string) Check
- func SummaryLike(sum string) Check
- func Tag(fns ...Check) Check
- func Target(fns ...Check) Check
- func URLLike(frag string) Check
- func WithMaxCount(max int) Check
- type Checks
- func ActivityChecks(fns ...Check) Checks
- func ActorChecks(fns ...Check) Checks
- func AfterChecks(fns ...Check) Checks
- func AuthorizedChecks(fns ...Check) Checks
- func BeforeChecks(fns ...Check) Checks
- func CursorChecks(fns ...Check) Checks
- func FilterChecks(fns ...Check) Checks
- func FromIRI(i vocab.IRI) (Checks, error)
- func FromURL(u url.URL) Checks
- func FromValues(q url.Values) Checks
- func IntransitiveActivityChecks(fns ...Check) Checks
- func ItemChecks(fns ...Check) Checks
- func ObjectChecks(fns ...Check) Checks
- func RecipientsChecks(fns ...Check) Checks
- func TagChecks(fns ...Check) Checks
- func TargetChecks(fns ...Check) Checks
- func TypeChecks(fns ...Check) Checks
- type CollectionFilterer
- type CompStr
- type CompStrs
- type FilterFn
- type Filterable
- type FilterableActivity
- type FilterableCollection
- type FilterableItems
- type FilterableObject
- type Filtersdeprecated
- func (f Filters) Actors() vocab.IRIs
- func (f Filters) After() Hash
- func (f Filters) AttributedTo() CompStrs
- func (f Filters) Audience() CompStrs
- func (f Filters) Before() Hash
- func (f Filters) Content() CompStrs
- func (f Filters) Context() CompStrs
- func (f Filters) Count() int
- func (f Filters) FilterCollection(col vocab.ItemCollection) (vocab.ItemCollection, int)
- func (f Filters) Generator() CompStrs
- func (f *Filters) GetLink() vocab.IRI
- func (f Filters) IRIs() CompStrs
- func (f Filters) InReplyTo() CompStrs
- func (f *Filters) IsItemIRI() bool
- func (f *Filters) ItemsMatch(col ...vocab.Item) bool
- func (f Filters) MediaTypes() []vocab.MimeType
- func (f Filters) Names() CompStrs
- func (f Filters) Objects() vocab.IRIs
- func (f Filters) Page() int
- func (f Filters) Tags() *Filters
- func (f Filters) Targets() vocab.IRIs
- func (f Filters) Types() CompStrs
- func (f Filters) URLs() CompStrs
- type Hash
- type ItemMatcher
- type KeysetPaginator
- type OffsetPaginator
Examples ¶
Constants ¶
const ( // ActorsType is a constant that represents the URL path for the local actors collection. // It is used as the parent for all To IDs ActorsType = vocab.CollectionPath("actors") // ActivitiesType is a constant that represents the URL path for the local activities collection // It is used as the parent for all Activity IDs ActivitiesType = vocab.CollectionPath("activities") // ObjectsType is a constant that represents the URL path for the local objects collection // It is used as the parent for all non To, non Activity Object IDs ObjectsType = vocab.CollectionPath("objects") // BlockedType is an internally used collection, to store a list of actors the actor has blocked BlockedType = vocab.CollectionPath("blocked") // IgnoredType is an internally used collection, to store a list of actors the actor has ignored IgnoredType = vocab.CollectionPath("ignored") )
const ( ByID = index.ByID ByType = index.ByType ByName = index.ByName ByPreferredUsername = index.ByPreferredUsername BySummary = index.BySummary ByContent = index.ByContent ByActor = index.ByActor ByObject = index.ByObject ByRecipients = index.ByRecipients ByAttributedTo = index.ByAttributedTo ByInReplyTo = index.ByInReplyTo )
const MaxItems int = 100
Variables ¶
var ( HiddenCollections = vocab.CollectionPaths{ BlockedType, IgnoredType, } FedBOXCollections = vocab.CollectionPaths{ ActivitiesType, ActorsType, ObjectsType, BlockedType, IgnoredType, } )
TODO(marius): here we need a better separation between the collections which are exposed in the HTTP API
(activities,actors,objects) and the ones that are internal (blocked,ignored)
var AbsentHash = []Hash{Hash(absentValue)}
var AbsentIRI = CompStr{Str: absentValue, Operator: "="}
var AbsentIRIs = CompStrs{AbsentIRI}
var ContentEmpty = contentCheck("", naturalLanguageEmpty)
ContentEmpty checks an vocab.Object's Content, *and*, in the case of an vocab.Actor also the PreferredUsername to be empty. If *all* of the values are empty, the function returns true.
Please note that the logic of this check is different from ContentIs and ContentLike.
var ErrNotFound = func(s string) error { return errors.Errorf("%s not found", s) }
var NameEmpty = nameCheck("", naturalLanguageEmpty)
NameEmpty checks an vocab.Object's Name, *and*, in the case of an vocab.Actor also its PreferredUsername to be empty. If *all* of the values are empty, the function returns true.
Please note that the logic of this check is different from NameIs and NameLike.
var NilAttributedTo = attributedToNil{}
var NilContext = contextNil{}
var NilID = idNil{}
NilID checks if the vocab.Object's ID property matches any of the two magic values that denote an empty value: vocab.NilID = "-", or vocab.EmptyID = ""
var NilIRI = iriNil{}
NilIRI checks if the activitypub.Item's IRI that matches any of the two magic values that denote an empty value: activitypub.NilID = "-", or activitypub.EmptyID = ""
var NilInReplyTo = inReplyToNil{}
var NotNilID = Not(NilID)
NotNilID checks if the vocab.Object's ID property is not nil
var NotNilIRI = Not(iriNil{})
NotNilIRI checks if the activitypub.Object's URL property matches any of the two magic values that denote an empty value: activitypub.NilID = "-", or activitypub.EmptyID = ""
var SummaryEmpty = summaryCheck("", naturalLanguageEmpty)
SummaryEmpty checks an vocab.Object's Summary, *and*, in the case of an vocab.Actor also the PreferredUsername to be empty. If *all* of the values are empty, the function returns true.
Please note that the logic of this check is different from SummaryIs and SummaryLike.
Functions ¶
func CacheKey ¶
CacheKey generates a unique vocab.IRI hash based on its authenticated user and other parameters
func CursorFromItem ¶
func FirstPage ¶
func FirstPage() pagValues
FirstPage returns the default url.Values for getting to the first page of a collection.
func GetWhereClauses ¶
func LoadCollectionFilters ¶
LoadCollectionFilters uses specific logic for adding elements to the filters when loading collections from the database.
func LoadItemFilters ¶
LoadItemFilters uses specific logic for adding elements to the filters when loading single items from the database.
func PaginateCollection ¶
PaginateCollection is a function that populates the received collection
func PaginatorValues ¶
func SearchIndex ¶
SearchIndex does a fast index search for the received filters.
Example ¶
activities := []vocab.LinkOrIRI{ // NOTE(marius): if the object for the Create activity is not indexed independently, like we have here, // it will not be findable in the index, and the composite search by activity type: Create, // and object ID:https://federated.local/objects/1 will fail. // In a previous version of this example this object was embedded in the activity directly, // but we decided that the logic to add embedded objects to the index, would be too complicated, // so this is the compromise. &vocab.Object{ ID: "https://federated.local/objects/1", Type: vocab.PageType, Name: vocab.NaturalLanguageValues{{Ref: "-", Value: vocab.Content("Link to example.com")}}, URL: vocab.IRI("https://example.com"), }, &vocab.Activity{ ID: "https://federated.local/1", Type: vocab.CreateType, To: vocab.ItemCollection{vocab.IRI("https://federated.local/~jdoe")}, Actor: vocab.IRI("https://federated.local/~jdoe"), Object: vocab.IRI("https://federated.local/objects/1"), }, &vocab.Activity{ ID: "https://federated.local/2", Type: vocab.LikeType, To: vocab.ItemCollection{vocab.IRI("https://federated.local/~jdoe")}, Actor: vocab.IRI("https://federated.local/~jdoe"), Object: vocab.IRI("https://federated.local/objects/1"), }, &vocab.Activity{ ID: "https://federated.local/3", Type: vocab.DislikeType, To: vocab.ItemCollection{vocab.IRI("https://federated.local/~jdoe")}, Actor: vocab.IRI("https://federated.local/~jdoe"), Object: vocab.IRI("https://federated.local/objects/1"), }, &vocab.Activity{ ID: "https://federated.local/4", Type: vocab.FlagType, To: vocab.ItemCollection{vocab.IRI("https://federated.local/~jdoe")}, Actor: vocab.IRI("https://federated.local/~jdoe"), Object: vocab.IRI("https://federated.local/objects/1"), }, } in := index.Full() // Add the activities to the index in.Add(activities...) findCreate := Checks{ HasType(vocab.CreateType), Object(SameID("https://federated.local/objects/1")), } iris, err := SearchIndex(in, findCreate...) fmt.Printf("Find Create:\n") fmt.Printf("Error: %v\n", err) fmt.Printf("IRIs: %#v\n", iris) findBlock := Checks{ HasType(vocab.FlagType), AttributedToLike("https://federated.local/~jdoe"), } iris, err = SearchIndex(in, findBlock...) fmt.Printf("Find Flag:\n") fmt.Printf("Error: %v\n", err) fmt.Printf("IRIs: %#v\n", iris)
Output: Find Create: Error: <nil> IRIs: []activitypub.IRI{https://federated.local/1} Find Flag: Error: <nil> IRIs: []activitypub.IRI{https://federated.local/4}
func ValidActivityCollection ¶
func ValidActivityCollection(typ vocab.CollectionPath) bool
ValidActivityCollection shows if the current ActivityPub end-point type is a valid collection for handling Activities
func ValidCollection ¶
func ValidCollection(typ vocab.CollectionPath) bool
ValidCollection shows if the current ActivityPub end-point type is a valid collection
func ValidCollectionCount ¶
func ValidCollectionCount(col vocab.ItemCollection, f Filterable) bool
func ValidObjectCollection ¶
func ValidObjectCollection(typ vocab.CollectionPath) bool
ValidObjectCollection shows if the current ActivityPub end-point type is a valid collection for handling Objects
func VocabularyTypesFilter ¶
func VocabularyTypesFilter(types ...string) vocab.ActivityVocabularyTypes
VocabularyTypesFilter converts the received list of strings to a list of ActivityVocabularyTypes that can be used with the HasType filter function. The individual strings are not validated against the known vocabulary types.
Types ¶
type Check ¶
Check represents an interface for a filter that can be applied on a vocab.Item and it returns true if it matches and false if it does not.
func After ¶
After checks the activitypub.Item against a specified "fn" filter function. This should be used when iterating over a collection, and it resolves to true after fn returns true and to false check.
Due to relying on the static check function return value the After is not reentrant.
func All ¶
All aggregates a list of individual Check functions into a single Check which resolves true if all individual members resolve as true, and false otherwise. It is equivalent to a sequence of AND operators.
func Any ¶
Any aggregates a list of individual Check functions into a single Check which resolves to false if all the individual members resolve as false, and true if any of them resolves as true. It is equivalent to a sequence of OR operators.
func AttributedToLike ¶
AttributedToLike creates a filter that checks the vocab.IRI against the attributedTo property of the item it gets applied on using a similarity match.
func Authorized ¶
Authorized creates a filter that checks the vocab.IRI against the recipients list of the item it gets applied on. The ActivityStreams Public Namespace IRI gets special treatment, because servers use it to signify that the audience of an object is public.
func Before ¶
Before checks the activitypub.Item against a specified "fn" filter function. This should be used when iterating over a collection, and it resolves to true check the fn has returned true and to false after.
Due to relying on the static check function return value the function is not reentrant.
func ContentIs ¶
ContentIs checks an vocab.Object's Content against the "cont" value. If any of the Language Ref map values match the value, the function returns true.
func ContentLike ¶
ContentLike checks an vocab.Object's Content property against the "cont" value. If any of the Language Ref map values contains the value as a substring, the function returns true.
func ContextLike ¶
func HasType ¶
func HasType(ty ...vocab.ActivityVocabularyType) Check
HasType checks an activitypub.Object's Type property against a series of values. If any of the ty values matches, the function returns true.
func InReplyToLike ¶
func MaxCountCheck ¶
func NameIs ¶
NameIs checks an vocab.Object's Name, or, in the case of an vocab.Actor also the PreferredUsername against the "name" value. If any of the Language Ref map values match the value, the function returns true.
func NameLike ¶
NameLike checks an vocab.Object's Name, or, in the case of an vocab.Actor // also the PreferredUsername against the "name" value. If any of the Language Ref map values contains the value as a substring, the function returns true.
func Recipients ¶
Recipients creates a filter that checks the vocab.IRI against the recipients list of the item it gets applied on.
func SameAttributedTo ¶
SameAttributedTo creates a filter that checks the vocab.IRI against the attributedTo property of the item it gets applied on.
func SameContext ¶
func SameID ¶
SameID checks a vocab.Object's ID property against the received iri.
func SameInReplyTo ¶
SameInReplyTo checks an activitypub.Object's InReplyTo
func SummaryIs ¶
SummaryIs checks an vocab.Object's Summary against the "sum" value. If any of the Language Ref map values match the value, the function returns true.
func SummaryLike ¶
SummaryLike checks an vocab.Object's Summary property against the "sum" value. If any of the Language Ref map values contains the value as a substring, the function returns true.
func WithMaxCount ¶
WithMaxCount is used to limit a collection's items count to the 'max' value. It can be used from slicing from the first element of the collection to max. Due to relying on the static max value the function is not reentrant.
type Checks ¶
type Checks []Check
Checks aggregates a list of Check functions to be tested on a vocab.Item.
func ActivityChecks ¶
func ActorChecks ¶
func AfterChecks ¶
func AuthorizedChecks ¶
func BeforeChecks ¶
func CursorChecks ¶
func FilterChecks ¶
func FromValues ¶
func ItemChecks ¶
func ObjectChecks ¶
func RecipientsChecks ¶
func TargetChecks ¶
func TypeChecks ¶
func (Checks) IndexMatch ¶
type CollectionFilterer ¶
type CollectionFilterer interface {
FilterCollection(col vocab.ItemCollection) (vocab.ItemCollection, int)
}
type CompStr ¶
type CompStr = qstring.ComparativeString
func StringDifferent ¶
func StringEquals ¶
func StringLike ¶
type Filterable ¶
func FiltersOnActivityActor ¶
func FiltersOnActivityActor(f Filterable) (bool, Filterable)
func FiltersOnActivityObject ¶
func FiltersOnActivityObject(f Filterable) (bool, Filterable)
func FiltersOnActivityTarget ¶
func FiltersOnActivityTarget(f Filterable) (bool, Filterable)
type FilterableActivity ¶
type FilterableActivity interface { FilterableObject Actors() vocab.IRIs Objects() vocab.IRIs Targets() vocab.IRIs }
FilterableActivity can filter activities
type FilterableCollection ¶
type FilterableCollection interface { FilterableObject TotalItemsGt() uint TotalItemsLt() uint TotalItemsEq() uint TotalItemsGtE() uint TotalItemsLtE() uint Contains() vocab.IRIs }
FilterableCollection can filter collections
type FilterableItems ¶
type FilterableItems interface { Filterable Types() vocab.ActivityVocabularyTypes IRIs() vocab.IRIs }
type FilterableObject ¶
type FilterableObject interface { FilterableItems AttributedTo() vocab.IRIs InReplyTo() vocab.IRIs MediaTypes() []vocab.MimeType Names() []string Content() []string //PublishedBefore() time.Time //PublishedAfter() time.Time URLs() vocab.IRIs // Audience returns the list of IRIs to check against full Audience targeting for the object // It should include all relevant fields: To, CC, BTo, BCC, and Audience // --- // An element of the Audience is used to get its Inbox end-point and then disseminate the current Activity // to it. Audience() vocab.IRIs // Context returns the list of IRIs to check against an Object's Context property. Context() vocab.IRIs // Generator returns the list of IRIs to check against an Object's Generator property. Generator() vocab.IRIs }
FilterableObject can filter objects
type Filters
deprecated
type Filters struct { BaseURL vocab.IRI `qstring:"-"` Name CompStrs `qstring:"name,omitempty"` Cont CompStrs `qstring:"content,omitempty"` Authenticated *vocab.Actor `qstring:"-"` To *vocab.Actor `qstring:"-"` Author *vocab.Actor `qstring:"-"` Parent *vocab.Actor `qstring:"-"` IRI vocab.IRI `qstring:"-"` Collection vocab.CollectionPath `qstring:"-"` URL CompStrs `qstring:"url,omitempty"` MedTypes []vocab.MimeType `qstring:"mediaType,omitempty"` Aud CompStrs `qstring:"recipients,omitempty"` Gen CompStrs `qstring:"generator,omitempty"` Key []Hash `qstring:"-"` ItemKey CompStrs `qstring:"iri,omitempty"` Type CompStrs `qstring:"type,omitempty"` AttrTo CompStrs `qstring:"attributedTo,omitempty"` InReplTo CompStrs `qstring:"inReplyTo,omitempty"` OP CompStrs `qstring:"context,omitempty"` FollowedBy []Hash `qstring:"followedBy,omitempty"` // todo(marius): not really used OlderThan time.Time `qstring:"olderThan,omitempty"` NewerThan time.Time `qstring:"newerThan,omitempty"` Prev Hash `qstring:"before,omitempty"` Next Hash `qstring:"after,omitempty"` Object *Filters `qstring:"object,omitempty"` Actor *Filters `qstring:"actor,omitempty"` Target *Filters `qstring:"target,omitempty"` Tag *Filters `qstring:"tag,omitempty"` CurPage int `qstring:"page,omitempty"` MaxItems int `qstring:"maxItems,omitempty"` Req *http.Request `qstring:"-"` }
Filters
Deprecated: This is functionality cribbed from the original FedBOX filtering mechanism which we want to move away from in favour of using []Check TODO(marius) we can make some small changes so it's not necessary to export this struct
func FiltersNew ¶
func FromRequest ¶
FromRequest loads the filters we use for generating storage queries from the HTTP request
func (Filters) AttributedTo ¶
func (Filters) Audience ¶
Audience returns a filter for audience members. This is important for filtering out objects that don't have a public audience.
func (Filters) FilterCollection ¶
func (f Filters) FilterCollection(col vocab.ItemCollection) (vocab.ItemCollection, int)
func (Filters) MediaTypes ¶
type ItemMatcher ¶
type KeysetPaginator ¶
KeysetPaginator