dog-and-duck.quack.picky.utils
Utility functions supporting the picky validator
activity-type?
(activity-type? x)
true
if x
, a string, represents a recognised ActivityStreams activity type.
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.
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
(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 acceptable)
Return true
if object x
has a type in acceptable
, else false
.
The values of :type
fields of ActivityStreams objects may be lists; they are considered to have a type if a member of the list is in acceptable
.
acceptable
may be passed as a string, in which case there is only one acceptable value, or as a set of strings, in which case any member of the set is acceptable.
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-or-uri?
(object-or-uri? x)
(object-or-uri? x type)
Very basic check that x
is either an object or a URI.
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?
xsd-non-negative-integer?
(xsd-non-negative-integer? x)
Return true
if value
matches the pattern for an xsd:nonNegativeInteger, else false