Everything compiles, tests pass.

This commit is contained in:
Simon Brooke 2022-12-24 22:09:08 +00:00
parent 629f73ab4d
commit a60187eb2a
5 changed files with 86 additions and 24 deletions

View file

@ -23,6 +23,9 @@
:no-context "Section 3 of the ActivityPub specification states Implementers SHOULD include the ActivityPub context in their object definitions`."
:no-id-persistent "Persistent objects MUST have unique global identifiers."
:no-id-transient "The ActivityPub specification allows objects without `id` fields only if they are intentionally transient; even so it is preferred that the object should have an explicit null id."
:null-id-persistent "Persistent objects MUST have non-null identifiers."
:no-inbox "Actor objects MUST have an `inbox` property, whose value MUST be a reference to an ordered collection."
:no-outbox "Actor objects MUST have an `outbox` property, whose value MUST be a reference to an ordered collection."
:no-type "The ActivityPub specification states that the `type` field is optional, but it is hard to process objects with no known type."
:not-actor-type "The `type` value of the object was not a recognised actor type."
:null-id-persistent "Persistent objects MUST have non-null identifiers."
:not-an-object "ActivityStreams object must be JSON objects."})

View file

@ -207,9 +207,8 @@
(defmacro nil-if-empty
"if `x` is an empty collection, return `nil`; else return `x`."
[x]
`(if (coll? ~x)
(nil-if-empty ~x)
~x))
`(if (and (coll? ~x) (empty? ~x)) nil
~x))
(defn has-type-or-fault
"If object `x` has a `:type` value which is `acceptable`, return `nil`;
@ -271,7 +270,9 @@
(uri-or-fault u severity if-missing-token if-missing-token))
([u severity if-missing-token if-invalid-token]
(try
(uri? (URI. u))
(if (uri? (URI. u))
nil
(make-fault-object severity if-invalid-token))
(catch URISyntaxException _
(make-fault-object severity if-invalid-token))
(catch NullPointerException _
@ -306,10 +307,10 @@
"Person"
"Service"})
(defmacro actor-type?
(defn actor-type?
"Return `true` if the `x` is a recognised actor type, else `false`."
[^String x]
`(if (actor-types ~x) true false))
(if (actor-types x) true false))
(defn has-actor-type?
"Return `true` if the object `x` has a type which is an actor type, else
@ -344,11 +345,11 @@
"Offer" "Question" "Reject" "Read" "Remove" "TentativeAccept"
"TentativeReject" "Travel" "Undo" "Update" "View"})
(defmacro verb-type?
(defn verb-type?
"`true` if `x`, a string, represents a recognised ActivityStreams activity
type."
[^String x]
`(if (verb-types ~x) true false))
(if (verb-types x) true false))
(defn has-activity-type?
"Return `true` if the object `x` has a type which is an activity type, else
@ -474,8 +475,8 @@
:object
(fn [v]
(object-reference-or-faults v #{"Invite" "Person"}
:must
:bad-accept-target))))
:must
:bad-accept-target))))
(def ^:const activity-required-properties
"Properties activities should have, keyed by activity type. Values are maps

View file

@ -15,7 +15,9 @@
(:require [dog-and-duck.quack.picky :refer [*reject-severity* activity-faults
actor-faults filter-severity link-faults
object-faults persistent-object-faults]]))
object-faults persistent-object-faults]])
(:import [java.net URI URISyntaxException]))
;;; Copyright (C) Simon Brooke, 2022
@ -81,13 +83,16 @@
*must be* to an actor object, but before, may only be to a URI pointing to
one."
[x]
(and
(cond (string? x) (uri? (URI. x))
:else (actor? x))
true))
(try
(and
(cond (string? x) (uri? (URI. x))
:else (actor? x))
true)
(catch URISyntaxException _ false)
(catch NullPointerException _ false)))
(defn activity?
"`true` iff `x` quacks like an activity, else false."
"`true` iff `x` quacks like an activity, else false."
([x] (activity? x *reject-severity*))
([x severity]
(empty? (filter-severity (activity-faults x) severity))))