Access host defined functions

This commit is contained in:
janherich 2018-09-04 08:32:07 +02:00
parent 95e44c9eee
commit d4b625cc8e
No known key found for this signature in database
GPG Key ID: C23B473AFBE94D13
3 changed files with 25 additions and 1 deletions

View File

@ -22,7 +22,8 @@
::forbidden-write-path
::query-not-exposed
::invalid-event-handler
::event-not-exposed})
::event-not-exposed
::function-not-exposed})
(spec/def ::value any?)

View File

@ -60,6 +60,9 @@
(defmethod resolve-property :query [def hook {:keys [capacities]} _]
(resolve-capacities-value :queries ::errors/query-not-exposed capacities def hook))
(defmethod resolve-property :function [def hook {:keys [capacities]} _]
(resolve-capacities-value :functions ::errors/function-not-exposed capacities def hook))
(defn- resolve-property-value [f {:keys [name optional?]} hook]
(if-let [o (get hook name)]
(if (f o)

View File

@ -94,6 +94,26 @@
{:query :get-in}
{:capacities {:queries #{:get-in}}}
{}))))
(testing "Function"
(is (= {:errors [{:pluto.reader.errors/type ::errors/invalid-property-name
:pluto.reader.errors/value :function}]}
(hooks/resolve-property {:type :function :name :function}
{}
{:capacities {}}
{})))
(is (= {:errors [{:pluto.reader.errors/type ::errors/function-not-exposed
:pluto.reader.errors/value '+}]}
(hooks/resolve-property {:type :function :name :function}
{:function '+}
{:capacities {:functions #{}}}
{})))
(is (= {:data +}
(hooks/resolve-property {:type :function :name :function}
{:function '+}
{:capacities {:functions {'+ +}}}
{}))))
(testing "Set"
(is (= {:data :one} (hooks/resolve-property {:name :keyword :type {:one-of #{:one :two :three}}} {:keyword :one} {} {})))
(is (= {:errors [{::errors/type ::errors/invalid-property-value