Add base class AS-OBJECT in the hierarchy

This way, LINK (which as per ActivityVocabulary
spec doesn’t inherent OBJECT) can still be
generalized.
This commit is contained in:
Jaidyn Ann 2024-06-23 12:17:40 -05:00
parent 2501e3e0de
commit 3f3370c194

View File

@ -143,17 +143,20 @@ again and again, by YASON:ENCODE-SLOTS."
;;; Core types ;;; Core types
;;; ———————————————————————————————————————— ;;; ————————————————————————————————————————
(defclass as-object ()
((@context :initform "https://www.w3.org/ns/activitystreams")
(type :accessor object-type)))
;; https://www.w3.org/ns/activitystreams#Object ;; https://www.w3.org/ns/activitystreams#Object
(defclass-w-accessors object () (defclass-w-accessors object (as-object)
( (
attachment attributed-to audience bcc bto cc content context attachment attributed-to audience bcc bto cc content context
duration end-time generator icon id image in-reply-to location duration end-time generator icon id image in-reply-to location
media-type name preview published replies start-time summary media-type name preview published replies start-time summary
tag to type updated url tag to updated url))
(@context :initform "https://www.w3.org/ns/activitystreams")))
;; https://www.w3.org/ns/activitystreams#Link ;; https://www.w3.org/ns/activitystreams#Link
(defclass-w-accessors link () (defclass-w-accessors link (as-object)
(height href hreflang media-type name preview rel width)) (height href hreflang media-type name preview rel width))
;; https://www.w3.org/ns/activitystreams#Activity ;; https://www.w3.org/ns/activitystreams#Activity
@ -169,14 +172,17 @@ again and again, by YASON:ENCODE-SLOTS."
(current first items last total-items)) (current first items last total-items))
;; https://www.w3.org/ns/activitystreams#OrderedCollection ;; https://www.w3.org/ns/activitystreams#OrderedCollection
(defclass ordered-collection (collection) ()) ;; Funnily enough, “orderedItems” is actually a ghost! Its only *implied*. :-P
;; https://jam.xwx.moe/notice/AjE1LkpLoBvWmDUmK8
(defclass-w-accessors ordered-collection (collection)
(ordered-items))
;; https://www.w3.org/ns/activitystreams#CollectionPage ;; https://www.w3.org/ns/activitystreams#CollectionPage
(defclass-w-accessors collection-page (collection) (defclass-w-accessors collection-page (collection)
(next part-of prev)) (next part-of prev))
;; https://www.w3.org/ns/activitystreams#OrderedCollectionPage ;; https://www.w3.org/ns/activitystreams#OrderedCollectionPage
(defclass-w-accessors ordered-collection-page (collection-page) (defclass-w-accessors ordered-collection-page (collection-page ordered-collection)
(start-index)) (start-index))
@ -279,11 +285,11 @@ into one. Otherwise, parse it into an associative list."
;;; JSON serialization ;;; JSON serialization
;;; ———————————————————————————————————————— ;;; ————————————————————————————————————————
;; Note-worthy: See the above-defined DEFINE-YASON-ENCODE-SLOTS. ;; Note-worthy: See the above-defined DEFINE-YASON-ENCODE-SLOTS.
(defmethod yason:encode ((obj object) &optional (stream *standard-output*)) (defmethod yason:encode ((obj as-object) &optional (stream *standard-output*))
(yason:with-output (stream) (yason:with-output (stream)
(yason:encode-object obj))) (yason:encode-object obj)))
(defmethod yason:encode-object ((obj object)) (defmethod yason:encode-object ((obj as-object))
(typecase *@context* (typecase *@context*
(null ; If this is the top-level (non-nested) object, establish a @context. (null ; If this is the top-level (non-nested) object, establish a @context.
(let ((*@context* 'top-level)) (let ((*@context* 'top-level))
@ -404,5 +410,6 @@ COLLECTION-AGAIN would return:
(closer-mop:finalize-inheritance class) (closer-mop:finalize-inheritance class)
(eval `(define-yason-encode-slots ,class))) (eval `(define-yason-encode-slots ,class)))
(mapcar #'find-class (mapcar #'find-class
'(object link activity collection collection-page '(as-object object link activity collection collection-page
ordered-collection-page place profile relationship tombstone))) ordered-collection ordered-collection-page place profile
relationship tombstone)))