dog-and-duck.quack.picky.utils
Utility functions supporting the picky validator
any-or-faults
(any-or-faults options severity-if-none token)Return nil if validating one of these options returns nil; otherwise return a list comprising a fault report object with this severity-if-none and this token followed by all the fault reports from validating each option.
There are several places - but especially in validating collections - where there are several different valid configurations, but few or no properties are always required.
coll-object-reference-or-fault
(coll-object-reference-or-fault value expected-type severity token)As object-reference-or-fault, except value argument may also be a list of objects and/or object references.
concat-non-empty
(concat-non-empty & lists)Quick function to replace the pattern (nil-if-empty (remove nil? (concat …))) which I’m using a lot!
cond-make-fault-object
macro
(cond-make-fault-object v severity token)If v is false or nil, return a fault object with this severity and token, else return nil.
context?
(context? x)Returns true iff x quacks like an ActivityStreams context, else false.
A context is either 1. the URI (actually an IRI) activitystreams-context-uri, or 2. a collection comprising that URI and a map.
filter-severity
(filter-severity reports severity)Return a list of reports taken from these reports where the severity of the report is greater than this or equal to this severity.
has-activity-type?
(has-activity-type? x)Return true if the object x has a type which is an activity type, else false.
has-actor-type?
(has-actor-type? x)Return true if the object x has a type which is an actor type, else false.
has-context?
macro
(has-context? x)True if x is an ActivityStreams object with a valid context, else false.
has-type-or-fault
(has-type-or-fault x acceptable severity token)If object x has a :type value which is acceptable, return nil; else return a fault object with this severity and token.
acceptable may be passed as either nil, a string, or a set of strings. If acceptable is nil, no type specific tests will be performed.
has-type?
(has-type? x type)Return true if object x has type type, else false.
The values of type fields of ActivityStreams objects may be lists; they are considered to have a type if the type token is a member of the list.
link-or-uri?
macro
(link-or-uri? x)Very basic check that x is either a link object or a URI.
make-fault-object
(make-fault-object severity fault)Return a fault object with these severity, fault and narrative values.
An ActivityPub object MUST have a globally unique ID. Whether this is meaningful depends on whether we persist fault report objects and serve them, which at present I have no plans to do.
object-faults
(object-faults x)(object-faults x expected-type)Return a list of faults found in object x, or nil if none are.
If expected-type is also passed, verify that x has expected-type. expected-type may be passed as a string or as a set of strings. Detailed verification of the particular features of types is not done here.
object-reference-or-faults
(object-reference-or-faults value expected-type severity token)If this value is either
- an object of
expected-type; - a URI referencing an object of
expected-type; or - a link object referencing an object of
expected-type
and no faults are returned from validating the linked object, then return nil; else return a sequence comprising a fault object with this severity and token, prepended to the faults returned.
As with has-type-or-fault (q.v.), expected-type may be passed as a string, as a set of strings, or nil (indicating the type of the referenced object should not be checked).
NOTE THAT if *reify-refs* is false, referenced objects will not actually be checked.
string-or-fault
(string-or-fault value severity token)(string-or-fault value severity token pattern)If this value is not a string, return a fault object with this severity and token, else nil. If pattern is also passed, it is expected to be a Regex, and the fault object will be returned unless value matches the pattern.
truthy?
(truthy? x)Return true if x is truthy, else false. There must be some more idiomatic way to do this?
verb-type?
(verb-type? x)true if x, a string, represents a recognised ActivityStreams activity type.