From 6abd045273e0b8baf65150bedbf2592f42d468d2 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 7 Aug 2025 12:36:14 +0200 Subject: [PATCH] :bug: Add missing generator for token-set file change operation (#7080) * :bug: Add missing generator for token-set file change operation * :bug: Use ::sm/any instead of :any for on get-file-data-for-thumbnail rpc method Mainly because :any will use a very generic generator that can generate instances of Character that are not directly serializable to JSON --- backend/src/app/rpc/commands/files_thumbnails.clj | 2 +- common/src/app/common/files/changes.cljc | 9 ++++++++- common/src/app/common/types/tokens_lib.cljc | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/backend/src/app/rpc/commands/files_thumbnails.clj b/backend/src/app/rpc/commands/files_thumbnails.clj index 9d64ec504d..c74f023b9d 100644 --- a/backend/src/app/rpc/commands/files_thumbnails.clj +++ b/backend/src/app/rpc/commands/files_thumbnails.clj @@ -185,7 +185,7 @@ [:map {:title "PartialFile"} [:id ::sm/uuid] [:revn {:min 0} ::sm/int] - [:page :any]]) + [:page [:map-of :keyword ::sm/any]]]) (sv/defmethod ::get-file-data-for-thumbnail "Retrieves the data for generate the thumbnail of the file. Used diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index d9965ce556..8915402b06 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -418,7 +418,14 @@ [:type [:= :set-token-set]] [:set-name :string] [:group? :boolean] - [:token-set [:maybe [:fn ctob/token-set?]]]]] + + ;; FIXME: we should not pass private types as part of changes + ;; protocol, the changes protocol should reflect a + ;; method/protocol for perform surgical operations on file data, + ;; this has nothing todo with internal types of a file data + ;; structure. + [:token-set {:gen/gen (sg/generator ctob/schema:token-set)} + [:maybe [:fn ctob/token-set?]]]]] [:set-token [:map {:title "SetTokenChange"} diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index a802679a2c..498801f2d8 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -186,6 +186,10 @@ :modified-at modified-at :tokens tokens})]) + #?@(:clj + [json/JSONWriter + (-write [this writter options] (json/-write (deref this) writter options))]) + #?@(:cljs [cljs.core/IEncodeJS (-clj->js [_] (js-obj "id" (clj->js id) "name" (clj->js name) @@ -292,7 +296,9 @@ (declare make-token-set) (def schema:token-set - (sm/required-keys schema:token-set-attrs)) + [:schema {:gen/gen (->> (sg/generator schema:token-set-attrs) + (sg/fmap #(make-token-set %)))} + (sm/required-keys schema:token-set-attrs)]) (sm/register! ::token-set schema:token-set) ;; need to register for the recursive schema of token-sets