From aabc895dd9e132201859bf653b25d3156a7e3858 Mon Sep 17 00:00:00 2001 From: joaopluigi Date: Thu, 14 Nov 2024 15:33:56 -0300 Subject: [PATCH 1/4] remove promesa as default engine --- src/nodely/engine/applicative.clj | 47 ++++++++++++------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/src/nodely/engine/applicative.clj b/src/nodely/engine/applicative.clj index 2fb3caa..dbf6726 100644 --- a/src/nodely/engine/applicative.clj +++ b/src/nodely/engine/applicative.clj @@ -5,7 +5,6 @@ [clojure.pprint :as pp] [nodely.data :as data] [nodely.engine.applicative.core :as app] - [nodely.engine.applicative.promesa :as promesa] [nodely.engine.applicative.protocols :as protocols] [nodely.engine.core :as core] [nodely.engine.lazy-env :as lazy-env])) @@ -75,37 +74,27 @@ (validator node-ret node))) (defn eval-key - ([env k] - (eval-key env k {})) - ([env k opts] - (let [opts (merge {::context promesa/context} opts) - lazy-env (lazy-env/lazy-env env eval-in-context opts)] - (::data/value (protocols/-extract (get lazy-env k)))))) + [env k opts] + (let [lazy-env (lazy-env/lazy-env env eval-in-context opts)] + (::data/value (protocols/-extract (get lazy-env k))))) (defn eval-key-contextual - ([env k] - (eval-key env k {})) - ([env k opts] - (let [opts (merge {::context promesa/context} opts) - lazy-env (lazy-env/lazy-env env eval-in-context opts)] - (app/fmap ::data/value (get lazy-env k))))) + [env k opts] + (let [lazy-env (lazy-env/lazy-env env eval-in-context opts)] + (app/fmap ::data/value (get lazy-env k)))) (defn eval-key-channel - ([env k] - (eval-key-channel env k {})) - ([env k opts] - (let [contextual-v (eval-key-contextual env k opts) - chan (async/promise-chan)] - (app/fmap (partial async/put! chan) contextual-v) - chan))) + [env k opts] + (let [contextual-v (eval-key-contextual env k opts) + chan (async/promise-chan)] + (app/fmap (partial async/put! chan) contextual-v) + chan)) (defn eval - ([env k] - (eval env k {::context promesa/context})) - ([env k opts] - (let [lazy-env (lazy-env/lazy-env env eval-in-context opts)] - (protocols/-extract (get lazy-env k)) ;; ensures k is resolved - (merge env - (reduce (fn [acc [k v]] (assoc acc k (protocols/-extract v))) - {} - (lazy-env/scheduled-nodes lazy-env)))))) + [env k opts] + (let [lazy-env (lazy-env/lazy-env env eval-in-context opts)] + (protocols/-extract (get lazy-env k)) ;; ensures k is resolved + (merge env + (reduce (fn [acc [k v]] (assoc acc k (protocols/-extract v))) + {} + (lazy-env/scheduled-nodes lazy-env))))) From 234abfdb0fa05c826e915ca25b516e1a2bf279a9 Mon Sep 17 00:00:00 2001 From: joaopluigi Date: Thu, 14 Nov 2024 15:34:47 -0300 Subject: [PATCH 2/4] make tests that were not passing an engine to applicative/env to now pass this argument --- test/nodely/engine/applicative_test.clj | 31 ++++++++++++++----------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/test/nodely/engine/applicative_test.clj b/test/nodely/engine/applicative_test.clj index 9848e32..296925b 100644 --- a/test/nodely/engine/applicative_test.clj +++ b/test/nodely/engine/applicative_test.clj @@ -124,13 +124,13 @@ (deftest eval-key-test (testing "eval promise" - (is (match? 3 (applicative/eval-key test-env :c)))) + (is (match? 3 (applicative/eval-key test-env :c {::applicative/context promesa/context})))) (testing "async works" - (let [[time-ns result] (criterium/time-body (applicative/eval-key test-env+delay :d))] + (let [[time-ns result] (criterium/time-body (applicative/eval-key test-env+delay :d {::applicative/context promesa/context}))] (is (match? {:a 3 :b 6 :c 9} result)) (is (match? (matchers/within-delta 100000000 1000000000) time-ns)))) (testing "tricky example" - (is (match? 4 (applicative/eval-key tricky-example :z))))) + (is (match? 4 (applicative/eval-key tricky-example :z {::applicative/context promesa/context}))))) (deftest eval-key-test-core-async (testing "eval promise" @@ -150,7 +150,7 @@ (is (match? {:a {::data/value 2} :b {::data/value 1} :c {::data/value 3}} - (applicative/eval test-env :c)))) + (applicative/eval test-env :c {::applicative/context promesa/context})))) (testing "tricky example" (is (match? {:x (data/value 1) :y (data/value 2) @@ -160,29 +160,29 @@ :w (data/value 4) :z {::data/type :leaf ::data/inputs #{:w}}} - (applicative/eval tricky-example :w))))) + (applicative/eval tricky-example :w {::applicative/context promesa/context}))))) (deftest eval-env-with-sequence (testing "async response is equal to sync response" (is (match? (-> (core/resolve :b env-with-sequence) (get :b) ::data/value) - (applicative/eval-key env-with-sequence :b)))) + (applicative/eval-key env-with-sequence :b {::applicative/context promesa/context})))) (testing "sync=async for sequence with nil values" (is (match? (-> (core/resolve :b env+sequence-with-nil-values) (get :b) ::data/value) - (applicative/eval-key env+sequence-with-nil-values :b)))) + (applicative/eval-key env+sequence-with-nil-values :b {::applicative/context promesa/context})))) (testing "sync=async for sequence returning nil values" (is (match? (-> (core/resolve :b env+sequence-returning-nil-values) (get :b) ::data/value) - (applicative/eval-key env+sequence-returning-nil-values :b)))) + (applicative/eval-key env+sequence-returning-nil-values :b {::applicative/context promesa/context})))) (testing "async version takes a third of the time of sync version (runtime diff is 2 sec, within a tolerance of 3ms" (let [[nanosec-sync _] (criterium/time-body (core/resolve :c env-with-sequence+delay-sync)) - [nanosec-async _] (criterium/time-body (applicative/eval-key env-with-sequence+delay :c))] + [nanosec-async _] (criterium/time-body (applicative/eval-key env-with-sequence+delay :c {::applicative/context promesa/context}))] (is (match? (matchers/within-delta 8000000 2000000000) (- nanosec-sync nanosec-async))))) (testing "Actually computes the correct answers" - (is (match? [2 3 4] (applicative/eval-key env-with-sequence+delay :c)))) + (is (match? [2 3 4] (applicative/eval-key env-with-sequence+delay :c {::applicative/context promesa/context})))) (testing "resolve closure sequence" (is (= [2 4 6] - (applicative/eval-key env-with-closure-sequence :y))))) + (applicative/eval-key env-with-closure-sequence :y {::applicative/context promesa/context}))))) (deftest schema-test (let [env-with-schema {:a (>value 2) @@ -192,7 +192,8 @@ :b (>value 1) :c (yielding-schema (>leaf (+ ?a ?b)) s/Bool)}] (testing "it should not fail" - (is (match? 3 (applicative/eval-key env-with-schema :c {::applicative/fvalidate schema/fvalidate})))) + (is (match? 3 (applicative/eval-key env-with-schema :c {::applicative/context promesa/context + ::applicative/fvalidate schema/fvalidate})))) (testing "returns ex-info when schema is selected as fvalidate, and schema fn validation is enabled" (is (thrown-match? clojure.lang.ExceptionInfo {:type :schema.core/error @@ -200,9 +201,11 @@ :value 3} (ex-data (s/with-fn-validation - (applicative/eval-key env-with-failing-schema :c {::applicative/fvalidate schema/fvalidate})))))) + (applicative/eval-key env-with-failing-schema :c {::applicative/context promesa/context + ::applicative/fvalidate schema/fvalidate})))))) (testing "doesn't validate when validation is disabled" - (is (match? 3 (applicative/eval-key env-with-failing-schema :c {::applicative/fvalidate schema/fvalidate})))))) + (is (match? 3 (applicative/eval-key env-with-failing-schema :c {::applicative/context promesa/context + ::applicative/fvalidate schema/fvalidate})))))) (deftest synchronous-applicative-test (let [simple-env {:a (>value 2) From 393f5eb2b64722448c2659e5e886bb20c60bc469 Mon Sep 17 00:00:00 2001 From: joaopluigi Date: Thu, 14 Nov 2024 15:34:55 -0300 Subject: [PATCH 3/4] bump project version --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index c2c78f7..46d7758 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject dev.nu/nodely "2.0.1" +(defproject dev.nu/nodely "2.0.2" :description "Decoupling data fetching from data dependency declaration" :url "https://github.com/nubank/nodely" :license {:name "MIT"} From ebc2fa6c4ad7e4c52bfd4abeb7d945dc368a3965 Mon Sep 17 00:00:00 2001 From: joaopluigi Date: Thu, 14 Nov 2024 15:45:42 -0300 Subject: [PATCH 4/4] update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d33302..381cd83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 2.0.2 / 2024-11-14 +- Remove the default engine behavior in internal applicative eval functions + ## 2.0.1 / 2024-11-07 - Allow implicit args for nodely syntax macros (e.g. >leaf) to include namespaces in the implicit arg symbols.