-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
smart_map.cljc
753 lines (614 loc) · 21.9 KB
/
smart_map.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
(ns com.wsscode.pathom3.interface.smart-map
"Smart map is a Pathom interface that provides a map-like data structure, but this
structure will realize the values as the user requests then. Values realized are
cached, meaning that subsequent lookups are fast."
(:require
[clojure.core.protocols :as d]
[clojure.spec.alpha :as s]
[com.fulcrologic.guardrails.core :refer [<- => >def >defn >fdef ? |]]
[com.wsscode.misc.coll :as coll]
[com.wsscode.misc.refs :as refs]
[com.wsscode.pathom3.connect.indexes :as pci]
[com.wsscode.pathom3.connect.runner :as pcr]
[com.wsscode.pathom3.connect.runner.stats :as pcrs]
[com.wsscode.pathom3.entity-tree :as p.ent]
[com.wsscode.pathom3.interface.eql :as p.eql]
[edn-query-language.core :as eql]
#?@(:bb []
:clj [[potemkin.collections :refer [def-map-type]]])))
(declare smart-map smart-map? sm-env datafy-smart-map)
(>def ::error-mode
#{::error-mode-silent
::error-mode-loud})
(>def ::keys-mode
"How "
#{::keys-mode-cached
::keys-mode-reachable})
(>def ::wrap-nested?
"Flag to decide if values read from a Smart Map should also be wrapped on a Smart Map.
True by default."
boolean?)
(>def ::smart-map? boolean?)
(>defn with-error-mode
"This configures what happens when some error occur during the Pathom process to
provide more data to the Smart Map.
Available modes:
::error-mode-silent (default): Return `nil` as the value, don't throw errors.
::error-mode-loud: Throw the errors on read."
[env error-mode]
[map? ::error-mode => map?]
(assoc env ::error-mode error-mode))
(>defn with-keys-mode
"Configure how the Smart Map should respond to `keys`.
Available modes:
::keys-mode-cached (default): in this mode, keys will return only the keys that are
currently cached in the Smart Map. This is the safest mode, given it will only
read things from memory.
::keys-mode-reachable: in this mode, keys will list all possible keys that Pathom can
reach given the current indexes and available data. Be careful with this mode, on large
graphs there is a risk that a scan operation (like printing it) may trigger a large amount of resolver
processing."
[env key-mode]
[map? ::keys-mode => map?]
(assoc env ::keys-mode key-mode))
(>defn with-wrap-nested?
"Configure smart map to enable or disable the automatic wrapping of nested structures."
[env wrap?]
[map? ::wrap-nested? => map?]
(assoc env ::wrap-nested? wrap?))
(defn wrap-smart-map
"If x is a composite data structure, return the data wrapped by smart maps."
[{::keys [wrap-nested?]
:or {wrap-nested? true}
:as env} x]
(cond
(not wrap-nested?)
x
(coll/native-map? x)
(smart-map env x)
(sequential? x)
(if (vector? x)
(mapv #(wrap-smart-map env %) x)
(map #(wrap-smart-map env %) x))
(set? x)
(into #{} (map #(wrap-smart-map env %)) x)
:else
x))
(defn smart-run-stats
"Wrap runner run stats with smart definitions to traverse the runner data."
[run-stats]
(smart-map
(pcrs/run-stats-env run-stats)
run-stats))
(defn sm-env-get
"Get a property from a smart map.
First it checks if the property is available in the cache-tree, if not it triggers
the connect engine to lookup for the property. After the lookup is triggered the
cache-tree will be updated in place, note this has a mutable effect in this data,
but this change is consistent.
Repeated lookups will use the cache-tree and should be as fast as reading from a
regular Clojure map."
([env k] (sm-env-get env k nil))
([{::p.ent/keys [entity-tree*] :as env} k default-value]
(let [ent-tree @entity-tree*]
(if-let [x (find ent-tree k)]
(wrap-smart-map env (val x))
(let [ast {:type :root
:children [{:type :prop, :dispatch-key k, :key k}]}
stats (-> (pcr/run-graph! env ast entity-tree*) meta ::pcr/run-stats)]
(when-let [error (and (refs/kw-identical? (get env ::error-mode) ::error-mode-loud)
(-> (p.eql/process (pcrs/run-stats-env stats)
{:com.wsscode.pathom3.attribute/attribute k}
[::pcrs/attribute-error])
::pcrs/attribute-error
::pcr/node-error))]
(throw error))
(wrap-smart-map env (get @entity-tree* k default-value)))))))
(defn sm-env-assoc
"Creates a new smart map by adding k v to the initial context.
When you read information in the smart map, that information is cached into an internal
atom, and any dependencies that were required to get to the requested data is also
included in this atom.
When you assoc into a smart map, it will discard all the data loaded by Pathom itself
and will be like you have assoced in the original map and created a new smart object."
[env k v]
(smart-map env
(-> (::source-context env)
(assoc k v))))
(defn sm-env-dissoc
"Creates a new smart map by adding k v to the initial context.
When you read information in the smart map, that information is cached into an internal
atom, and any dependencies that were required to get to the requested data is also
included in this atom.
When you assoc into a smart map, it will discard all the data loaded by Pathom itself
and will be like you have assoced in the original map and created a new smart object."
[env k]
(smart-map env
(-> (::source-context env)
(dissoc k))))
(defn sm-env-keys
"Retrieve the keys in the smart map cache-tree."
[{::keys [keys-mode] :as env}]
(case keys-mode
::keys-mode-reachable
(pci/reachable-attributes env (p.ent/entity env))
(keys (p.ent/entity env))))
(defn sm-env-contains?
"Check if a property is present in the cache-tree."
[env k]
(let [ks (into #{} (sm-env-keys env))]
(contains? ks k)))
(defn sm-env-meta
"Returns meta data of smart map, which is the same as the meta data from context
map used to create the smart map."
[env]
(meta (p.ent/entity env)))
(defn sm-env-with-meta
"Return a new smart-map with the given meta."
[env meta]
(smart-map env (with-meta (p.ent/entity env) meta)))
(defn sm-env-find
"Check if attribute can be found in the smart map."
[env k]
(if (or (sm-env-contains? env k)
(pci/attribute-reachable? env (p.ent/entity env) k))
(coll/make-map-entry k (sm-env-get env k))))
(defn sm-env-empty
"Return a new smart map with the same environment and an empty map context."
[env]
(smart-map env (with-meta {} (sm-env-meta env))))
(defn sm-env-to-string [env]
(str "#SmartMap " (p.ent/entity env)))
(defn associative-conj [m entry]
#?(:cljs
(if (vector? entry)
(-assoc m (-nth entry 0) (-nth entry 1))
(loop [ret m
es (seq entry)]
(if (nil? es)
ret
(let [e (first es)]
(if (vector? e)
(recur (-assoc ret (-nth e 0) (-nth e 1))
(next es))
(throw (js/Error. "conj on a map takes map entries or seqables of map entries")))))))
:default
(if (vector? entry)
(assoc m (nth entry 0) (nth entry 1))
(loop [ret m
es (seq entry)]
(if (nil? es)
ret
(let [e (first es)]
(if (vector? e)
(recur (assoc ret (nth e 0) (nth e 1))
(next es))
(throw (ex-info "conj on a map takes map entries or seqables of map entries" {})))))))))
; region type definition
#?(:bb
(defn ->LazyMapEntry
[key_ val_]
(reify
clojure.lang.Associative
(containsKey [this k]
(boolean (#{0 1} k)))
(entryAt [this k]
(cond
(= k 0) (clojure.lang.MapEntry. 0 key_)
(= k 1) (->LazyMapEntry 1 val_)
:else nil))
(assoc [this k v]
(cond
(= k 0) (->LazyMapEntry v val_)
(= k 1) (->LazyMapEntry key_ v)
(= k 2) (vector k (force val_) v)
:else (throw (IndexOutOfBoundsException.))))
clojure.lang.IFn
(invoke [this k]
(.valAt this k))
clojure.lang.ILookup
(valAt [this k]
(cond
(= k 0) key_
(= k 1) (force val_)
:else nil))
(valAt [this k not-found]
(cond
(= k 0) key_
(= k 1) (force val_)
:else not-found))
clojure.lang.IMapEntry
(key [this] key_)
(val [this] (force val_))
clojure.lang.Indexed
(nth [this i]
(cond
(= i 0) key_
(= i 1) (force val_)
(integer? i) (throw (IndexOutOfBoundsException.))
:else (throw (IllegalArgumentException. "Key must be integer")))
(.valAt this i))
(nth [this i not-found]
(try
(.nth this i)
(catch Exception _ not-found)))
clojure.lang.IPersistentCollection
(count [this] 2)
(empty [this] false)
(equiv [this o]
(.equiv
[key_ (force val_)]
o))
clojure.lang.IPersistentStack
(peek [this] (force val_))
(pop [this] [key_])
clojure.lang.IPersistentVector
(assocN [this i v]
(.assocN [key_ (force val_)] i v))
(cons [this o]
(.cons [key_ (force val_)] o))
clojure.lang.Reversible
(rseq [this] (lazy-seq (list (force val_) key_)))
clojure.lang.ISeq
(seq [this]
(seq [key_ (force val_)]))
clojure.lang.Sequential
java.lang.Comparable
(compareTo [this o]
(.compareTo
^java.lang.Comparable
(vector key_ (force val_))
o))
java.lang.Iterable
(iterator [this]
(.iterator
^java.lang.Iterable
(.seq this)))
java.lang.Object
(toString [this]
(str [key_ val_]))
java.util.Map$Entry
(getKey [this] key_)
(getValue [this] (force val_))))
:cljs
#_{:clj-kondo/ignore [:private-call]}
(deftype SmartMapEntry [env key]
Object
(indexOf [coll x]
(-indexOf coll x 0))
(indexOf [coll x start]
(-indexOf coll x start))
(lastIndexOf [coll x]
(-lastIndexOf coll x (count coll)))
(lastIndexOf [coll x start]
(-lastIndexOf coll x start))
IMapEntry
(-key [_node] key)
(-val [_node] (sm-env-get env key))
IEquiv
(-equiv [coll other] (equiv-sequential coll other))
IMeta
(-meta [_node] nil)
IWithMeta
(-with-meta [node meta]
(with-meta [key (-val node)] meta))
IStack
(-peek [node] (-val node))
(-pop [_node] [key])
ICollection
(-conj [node o] [key (-val node) o])
IEmptyableCollection
(-empty [_node] nil)
ISequential
ISeqable
(-seq [node] (IndexedSeq. #js [key (-val node)] 0 nil))
IReversible
(-rseq [node] (IndexedSeq. #js [(-val node) key] 0 nil))
ICounted
(-count [_node] 2)
IIndexed
(-nth [node n]
(cond (== n 0) key
(== n 1) (-val node)
:else (throw (js/Error. "Index out of bounds"))))
(-nth [node n not-found]
(cond (== n 0) key
(== n 1) (-val node)
:else not-found))
ILookup
(-lookup [node k] (-nth node k nil))
(-lookup [node k not-found] (-nth node k not-found))
IAssociative
(-assoc [node k v]
(assoc [key (-val node)] k v))
(-contains-key? [_node k]
(or (== k 0) (== k 1)))
IFind
(-find [node k]
(case k
0 (coll/make-map-entry 0 key)
1 (coll/make-map-entry 1 (-val node))
nil))
IVector
(-assoc-n [node n v]
(-assoc-n [key (-val node)] n v))
IReduce
(-reduce [node f]
(ci-reduce node f))
(-reduce [node f start]
(ci-reduce node f start))
IFn
(-invoke [node k]
(-nth node k))
(-invoke [node k not-found]
(-nth node k not-found))))
#?(:bb (defprotocol ISmartMap (-smart-map-env [this])))
#?(:bb (defn sm-env-lazy-map-entry [env k]
(->LazyMapEntry k (delay (sm-env-get env k)))))
#?(:bb
(defn ->SmartMap [env]
(reify
clojure.lang.ILookup
(valAt [this k] (sm-env-get env k))
(valAt [this k default-value] (sm-env-get env k default-value))
clojure.lang.Associative
(containsKey [this k] (sm-env-contains? env k))
(entryAt [this k] (sm-env-find env k))
(assoc [this k v] (sm-env-assoc env k v))
clojure.lang.IPersistentCollection
(equiv [this other]
(= (p.ent/entity env)
(cond-> other
(smart-map? other)
(-> sm-env p.ent/entity))))
(cons [this entry] (associative-conj this entry))
(empty [this] (sm-env-empty env))
clojure.lang.Counted
(count [this] (count (p.ent/entity env)))
clojure.lang.Seqable
(seq [this]
(some->> (sm-env-keys env)
(map #(sm-env-lazy-map-entry env %))))
clojure.lang.IFn
(invoke [this k] (sm-env-get env k))
clojure.lang.IPersistentMap
(without [this k] (sm-env-dissoc env k))
clojure.lang.IReduce
(reduce [coll f]
(clojure.core/reduce
(fn [acc k]
(f acc (sm-env-lazy-map-entry env k)))
(sm-env-keys env)))
clojure.lang.IReduceInit
(reduce [coll f val]
(clojure.core/reduce
(fn [acc k]
(f acc (sm-env-lazy-map-entry env k)))
val
(sm-env-keys env)))
clojure.lang.IKVReduce
(kvreduce [_ f init]
(clojure.core/reduce
(fn [acc k]
(f acc k (sm-env-get env k)))
init
(sm-env-keys env)))
java.lang.Iterable
(iterator [this]
(coll/iterator
(eduction
(map #(sm-env-lazy-map-entry env %))
(sm-env-keys env))))
java.lang.Object
(toString [this] (sm-env-to-string env))
d/Datafiable
(datafy [sm] (datafy-smart-map sm))
ISmartMap
(-smart-map-env [_] env)))
:cljs
#_{:clj-kondo/ignore [:private-call]}
(deftype SmartMap [env]
Object
(toString [_] (sm-env-to-string env))
(equiv [_ other] (-equiv (p.ent/entity env) other))
;; ES6
(keys [_] (es6-iterator (sm-env-keys env)))
(entries [_] (es6-entries-iterator (seq (p.ent/entity env))))
(values [_] (es6-iterator (vals (p.ent/entity env))))
(has [_ k] (sm-env-contains? env k))
(get [_ k not-found] (-lookup (p.ent/entity env) k not-found))
(forEach [_ f] (doseq [[k v] (p.ent/entity env)] (f v k)))
ICloneable
(-clone [_] (smart-map env (p.ent/entity env)))
IWithMeta
(-with-meta [_ new-meta] (sm-env-with-meta env new-meta))
IMeta
(-meta [_] (sm-env-meta env))
ICollection
(-conj [coll entry]
(associative-conj coll entry))
IEmptyableCollection
(-empty [_] (sm-env-empty env))
IEquiv
(-equiv [_ other] (-equiv (p.ent/entity env) other))
IHash
(-hash [_] (hash (p.ent/entity env)))
ISeqable
(-seq [_]
(some->> (seq (sm-env-keys env))
(map #(->SmartMapEntry env %))))
ICounted
(-count [_] (count (p.ent/entity env)))
ILookup
(-lookup [_ k] (sm-env-get env k nil))
(-lookup [_ k not-found] (sm-env-get env k not-found))
IAssociative
(-assoc [_ k v] (sm-env-assoc env k v))
(-contains-key? [_ k] (sm-env-contains? env k))
IFind
(-find [_ k] (sm-env-find env k))
IMap
(-dissoc [_ k] (sm-env-dissoc env k))
IKVReduce
(-kv-reduce [_ f init]
(reduce-kv (fn [cur k v] (f cur k (wrap-smart-map env v))) init (p.ent/entity env)))
IIterable
(-iterator [_this]
(transformer-iterator (map #(->SmartMapEntry env %))
(-iterator (vec (sm-env-keys env))) false))
IReduce
(-reduce [coll f] (iter-reduce coll f))
(-reduce [coll f start] (iter-reduce coll f start))
IFn
(-invoke [_ k] (sm-env-get env k))
(-invoke [_ k not-found] (sm-env-get env k not-found))
IPrintWithWriter
(-pr-writer [_ writer opts]
(-pr-writer (p.ent/entity env) writer opts)))
:clj
(def-map-type SmartMap [env]
(get [_ k default-value] (sm-env-get env k default-value))
(assoc [_ k v] (sm-env-assoc env k v))
(dissoc [_ k] (sm-env-dissoc env k))
(keys [_] (sm-env-keys env))
(meta [_] (sm-env-meta env))
(empty [_] (sm-env-empty env))
(with-meta [_ new-meta] (sm-env-with-meta env new-meta))
(entryAt [_ k] (sm-env-find env k))
(toString [_] (sm-env-to-string env))))
(defn smart-map? [x]
#?(:bb
(satisfies? ISmartMap x)
:default
(instance? SmartMap x)))
(>def ::smart-map smart-map?)
(defn datafy-smart-map
"Returns a map with all reachable keys from the smart map. The cached keys get their
value in this map, unresolved keys return with the special value `::pcr/unknown-value`.
This is helpful to use with REPL tools that support the Clojure Datafiable/Navitable
protocols. On navigation Pathom try to load the attribute you navigate to."
[sm]
(let [env (sm-env sm)
ent (p.ent/entity env)]
(-> (into (empty ent)
(map (fn [attr]
(if-let [x (find ent attr)]
x
(coll/make-map-entry attr :com.wsscode.pathom3.connect.operation/unknown-value))))
(pci/reachable-attributes env ent))
(vary-meta assoc
`d/nav
(fn [_ k v]
(if (refs/kw-identical? v :com.wsscode.pathom3.connect.operation/unknown-value)
(get sm k)
v))))))
#?(:bb
nil
:default
(extend-type SmartMap
d/Datafiable
(datafy [sm] (datafy-smart-map sm))))
; endregion
(>defn sm-env
"Extract the env map from the smart map."
[;^SmartMap
smart-map]
[::smart-map => map?]
#?(:bb
(-smart-map-env smart-map)
:default
(.-env smart-map)))
(>defn sm-update-env
"Update smart map environment"
[;^SmartMap
sm f & args]
[::smart-map fn? (s/* any?) => ::smart-map]
(let [env (apply f (sm-env sm) args)]
(smart-map env (::source-context env))))
(>defn sm-get-with-stats
"Return the graph run analysis, use for debugging. You can find the get value return
in the ::psm/value key.
Note that if the value is cached, there will be a blank stats."
([;^SmartMap
sm k]
[::smart-map any? => any?]
(let [{::p.ent/keys [entity-tree*] :as env} (sm-env sm)
ast {:type :root
:children [{:type :prop, :dispatch-key k, :key k}]}
run-stats (-> (pcr/run-graph! env ast entity-tree*)
meta ::pcr/run-stats)]
(assoc run-stats ::value (wrap-smart-map env (get @entity-tree* k))))))
(>defn sm-replace-context
"Replace the context data for the smart map with new-context, keeping the
same environment. This returns a new smart map."
[;^SmartMap
sm new-context]
[::smart-map map? => ::smart-map]
(smart-map (sm-env sm) new-context))
(defn sm-entity
"Return the source cached entity for the smart map"
[sm]
(-> sm sm-env p.ent/entity))
(>defn sm-assoc!
"Assoc on the smart map in place, this function mutates the current cache and return
the same instance of smart map.
You should use this only in cases where the optimization is required, try starting
with the immutable versions first, given this has side effects and so more error phone."
[;^SmartMap
smart-map k v]
[::smart-map any? any? => ::smart-map]
(p.ent/swap-entity! (sm-env smart-map) assoc k v)
smart-map)
(>defn sm-dissoc!
"Dissoc on the smart map in place, this function mutates the current cache and return
the same instance of smart map.
You should use this only in cases where the optimization is required, try starting
with the immutable versions first, given this has side effects and so more error phone."
[;^SmartMap
smart-map k]
[::smart-map any? => ::smart-map]
(p.ent/swap-entity! (sm-env smart-map) dissoc k)
smart-map)
(>defn sm-touch-ast!
[;^SmartMap
smart-map ast]
[::smart-map :edn-query-language.ast/node
=> ::smart-map]
(let [env (sm-env smart-map)]
(pcr/run-graph! env ast (::p.ent/entity-tree* env))
smart-map))
(>defn sm-touch!
"Will pre-fetch data in a smart map, given the EQL request. Use this to optimize the
load of data ahead of time, instead of pulling one by one lazily."
[;^SmartMap
smart-map eql]
[::smart-map ::eql/query
=> ::smart-map]
(sm-touch-ast! smart-map (eql/query->ast eql)))
(>defn ;^SmartMap
smart-map
"Create a new smart map.
Smart maps are a special data structure that realizes properties using Pathom resolvers.
They work like maps and can be used interchangeable with it.
To create a smart map you need send an environment with the indexes and a context
map with the initial context data:
(smart-map (pci/register [resolver1 resolver2]) {:some \"context\"})
When the value of a property of the smart map is a map, that map will also be cast
into a smart map, including maps inside collections."
([env]
[(s/keys :opt [::pci/index-oir]) => ::smart-map]
(smart-map env {}))
([{::keys [persistent-cache?]
:or {persistent-cache? true}
:as env} context]
[(s/keys :opt [::pci/index-oir])
map? => ::smart-map]
(->SmartMap
(-> env
(assoc ::smart-map? true)
(coll/merge-defaults
(cond-> {:com.wsscode.pathom3.connect.planner/plan-cache* (atom {})}
persistent-cache?
(assoc ::pcr/resolver-cache* (atom {}))))
(p.ent/with-entity context)
(assoc ::source-context context)))))