From 528131513b0535ac04e459e3e4bb83c9ef5399f8 Mon Sep 17 00:00:00 2001 From: Milton Reder Date: Thu, 11 Jan 2024 11:11:21 -0500 Subject: [PATCH] SQL-211 make identityPaths fuzzier (#356) * SQL-211 make identityPaths fuzzier * SQL-211 please linter --- src/main/lrsql/util/reaction.clj | 26 +++++++++++++++----------- src/test/lrsql/util/reaction_test.clj | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/lrsql/util/reaction.clj b/src/main/lrsql/util/reaction.clj index 27ff64cab..e0c6713be 100644 --- a/src/main/lrsql/util/reaction.clj +++ b/src/main/lrsql/util/reaction.clj @@ -41,19 +41,23 @@ (defn statement-identity "Given a vector of identity paths and a statement, return a map of paths to - values. Return nil if any are missing or a collection is found." + values. Return nil if no specified paths or a collection is found." [identity-paths statement] - (reduce - (fn [m path] - (if-some [found-val (get-in statement - path)] - (if (coll? found-val) - (reduced nil) - (assoc m path found-val)) - (reduced nil))) - {} - identity-paths)) + (if (empty? identity-paths) + {} ;; empty explicitly covers all statements + (let [found-paths (reduce + (fn [m path] + (if-some [found-val (get-in statement + path)] + (if (coll? found-val) + (reduced nil) + (assoc m path found-val)) + m)) + {} + identity-paths)] + (when (seq found-paths) + found-paths)))) (s/fdef add-reaction-metadata :args (s/cat :statement ::xs/statement diff --git a/src/test/lrsql/util/reaction_test.clj b/src/test/lrsql/util/reaction_test.clj index a9820effa..278574235 100644 --- a/src/test/lrsql/util/reaction_test.clj +++ b/src/test/lrsql/util/reaction_test.clj @@ -39,6 +39,13 @@ [["actor" "mbox"]] {["actor" "mbox"] "mailto:bob@example.com"} + [["actor" "mbox"] + ["actor" "mbox_sha1sum"] + ["actor" "openid"] + ["actor" "account" "homePage"] + ["actor" "account" "name"]] + {["actor" "mbox"] "mailto:bob@example.com"} + [["actor" "mbox"] ["context" "registration"]] {["actor" "mbox"] "mailto:bob@example.com" @@ -46,7 +53,13 @@ [["actor" "openid"] ["context" "registration"]] - nil)) + {["context" "registration"] "6fbd600f-d17c-4c74-801a-2ec2e53231f7"} + + [["actor" "openid"]] + nil + + [] + {})) (deftest add-reaction-metadata-test (let [reaction-id (u/generate-squuid)