(alias-resolver from to)Create a resolver that will convert attribute from to a attribute to with
the same value. This only creates the alias in one direction.
Create a resolver that will convert attribute `from` to a attribute `to` with the same value. This only creates the alias in one direction.
(attr-alias-resolver-name from to)(attr-alias-resolver-name from to suffix)(attribute-table-resolver table-name attr-key output)Similar to static-table-resolver, but instead of a static map, this will pull the table from another attribute in the system. Given in this case the values can be dynamic, this helper requires a pre-defined output, so the attributes on this output get delegated to the created resolver.
(def registry
[(pbir/static-table-resolver `song-names :song/id
{1 {:song/name "Marchinha Psicotica de Dr. Soup"}
2 {:song/name "There's Enough"}})
(pbir/constantly-resolver ::song-analysis
{1 {:song/duration 280 :song/tempo 98}
2 {:song/duration 150 :song/tempo 130}})
(pbir/attribute-table-resolver ::song-analysis :song/id
[:song/duration :song/tempo])])
(let [sm (psm/smart-map (pci/register registry)
{:song/id 2})]
(select-keys sm [:song/id :song/name :song/duration]))
; => #:song{:id 2, :name "There's Enough", :duration 150}
Similar to static-table-resolver, but instead of a static map, this will pull the
table from another attribute in the system. Given in this case the values can be dynamic,
this helper requires a pre-defined output, so the attributes on this output get
delegated to the created resolver.
(def registry
[(pbir/static-table-resolver `song-names :song/id
{1 {:song/name "Marchinha Psicotica de Dr. Soup"}
2 {:song/name "There's Enough"}})
(pbir/constantly-resolver ::song-analysis
{1 {:song/duration 280 :song/tempo 98}
2 {:song/duration 150 :song/tempo 130}})
(pbir/attribute-table-resolver ::song-analysis :song/id
[:song/duration :song/tempo])])
(let [sm (psm/smart-map (pci/register registry)
{:song/id 2})]
(select-keys sm [:song/id :song/name :song/duration]))
; => #:song{:id 2, :name "There's Enough", :duration 150}
(constantly-fn-resolver attribute value-fn)Create a simple resolver that always calls value-fn and return its value. Note that cache is disabled by default in this resolver.
Create a simple resolver that always calls value-fn and return its value. Note that cache is disabled by default in this resolver.
(constantly-resolver attribute value)Create a simple resolver that always return value for attribute.
Create a simple resolver that always return `value` for `attribute`.
(edn-file-resolver file-path)Creates a resolver to provide data loaded from a file.
This is a macro and the file will be read at compilation time, this way it can work on both Clojure and Clojurescript, without a need for async processing.
It's also possible to provide static tables data (as with attribute-table-resolver) from the data itself, you can do this by setting the meta data :pathom3/entity-table meta data in your EDN data. For example:
{:my.system/generic-db
^{:com.wsscode.pathom3/entity-table :my.system/user-id}
{4 {:my.system.user/name "Anne"}
2 {:my.system.user/name "Fred"}}}
Doing this, the resolvers for the attribute table will be provided automatically.
Full example:
; my-config.edn
{:my.system/port
1234
:my.system/initial-path
"/tmp/system"
:my.system/generic-db
^{:com.wsscode.pathom3/entity-table :my.system/user-id}
{4 {:my.system.user/name "Anne"}
2 {:my.system.user/name "Fred"}}}
; app
(def registry [(edn-file-resolver "my-config.edn")])
(let [sm (psm/smart-map (pci/register registry) {:my.system/user-id 4})]
(select-keys sm [:my.system/port :my.system.user/name])
; => {:my.system/port 1234, :my.system.user/name "Anne"}
Note that the tables need to be a value of a top level attribute of the config, if its deeper inside it won't work.
Creates a resolver to provide data loaded from a file.
This is a macro and the file will be read at compilation time, this way it
can work on both Clojure and Clojurescript, without a need for async processing.
It's also possible to provide static tables data (as with attribute-table-resolver)
from the data itself, you can do this by setting the meta data :pathom3/entity-table
meta data in your EDN data. For example:
{:my.system/generic-db
^{:com.wsscode.pathom3/entity-table :my.system/user-id}
{4 {:my.system.user/name "Anne"}
2 {:my.system.user/name "Fred"}}}
Doing this, the resolvers for the attribute table will be provided automatically.
Full example:
; my-config.edn
{:my.system/port
1234
:my.system/initial-path
"/tmp/system"
:my.system/generic-db
^{:com.wsscode.pathom3/entity-table :my.system/user-id}
{4 {:my.system.user/name "Anne"}
2 {:my.system.user/name "Fred"}}}
; app
(def registry [(edn-file-resolver "my-config.edn")])
(let [sm (psm/smart-map (pci/register registry) {:my.system/user-id 4})]
(select-keys sm [:my.system/port :my.system.user/name])
; => {:my.system/port 1234, :my.system.user/name "Anne"}
Note that the tables need to be a value of a top level attribute of the config, if
its deeper inside it won't work.(env-table-resolver table-name attr-key output)Similar to attribute-table-resolver, but pulls table from env instead of other resolver.
(def registry [(pbir/static-table-resolver `song-names :song/id {1 {:song/name "Marchinha Psicotica de Dr. Soup"} 2 {:song/name "There's Enough"}})
(pbir/env-table-resolver ::song-analysis :song/id [:song/duration :song/tempo])])
(def table {::song-analysis {1 {:song/duration 280 :song/tempo 98} 2 {:song/duration 150 :song/tempo 130}}})
; merge table into env (let [sm (psm/smart-map (merge (pci/register registry) table) {:song/id 2})] (select-keys sm [:song/id :song/name :song/duration])) ; => #:song{:id 2, :name "There's Enough", :duration 150}
Similar to attribute-table-resolver, but pulls table from env instead of other resolver.
(def registry
[(pbir/static-table-resolver `song-names :song/id
{1 {:song/name "Marchinha Psicotica de Dr. Soup"}
2 {:song/name "There's Enough"}})
(pbir/env-table-resolver ::song-analysis :song/id
[:song/duration :song/tempo])])
(def table
{::song-analysis
{1 {:song/duration 280 :song/tempo 98}
2 {:song/duration 150 :song/tempo 130}}})
; merge table into env
(let [sm (psm/smart-map (merge (pci/register registry) table)
{:song/id 2})]
(select-keys sm [:song/id :song/name :song/duration]))
; => #:song{:id 2, :name "There's Enough", :duration 150}
(equivalence-resolver attribute-a attribute-b)Make two attributes equivalent. It's like alias-resolver, but returns a vector containing the alias in both directions.
Make two attributes equivalent. It's like alias-resolver, but returns a vector containing the alias in both directions.
(global-data-resolver data)Expose data as a resolver, note this data will be available everywhere in the system.
Works the same as edn-file-resolver, but uses the data directly instead of reading from a file. This also applies for the attribute tables inside the data.
Expose data as a resolver, note this data will be available everywhere in the system. Works the same as edn-file-resolver, but uses the data directly instead of reading from a file. This also applies for the attribute tables inside the data.
(single-attr-resolver source target f)Apply fn f to input source and spits the result with the name target.
f receives a single argument, which is the attribute value from source.
Apply fn `f` to input `source` and spits the result with the name `target`. `f` receives a single argument, which is the attribute value from `source`.
(single-attr-with-env-resolver source target f)Similar single-attr-resolver, but f receives two arguments, env and the input.
Similar single-attr-resolver, but `f` receives two arguments, `env` and the input.
(static-attribute-map-resolver input output mapping)This is like the static-table-resolver, but provides a single attribute on each map entry.
(def registry
[(pbir/static-attribute-map-resolver :song/id :song/name
{1 "Marchinha Psicotica de Dr. Soup"
2 "There's Enough"})
(pbir/static-table-resolver `song-analysis :song/id
{1 {:song/duration 280 :song/tempo 98}
2 {:song/duration 150 :song/tempo 130}})])
(let [sm (psm/smart-map (pci/register registry)
{:song/id 1})]
(select-keys sm [:song/id :song/name :song/duration]))
; => #:song{:id 1, :name "Marchinha Psicotica de Dr. Soup", :duration 280}
This is like the static-table-resolver, but provides a single attribute on each
map entry.
(def registry
[(pbir/static-attribute-map-resolver :song/id :song/name
{1 "Marchinha Psicotica de Dr. Soup"
2 "There's Enough"})
(pbir/static-table-resolver `song-analysis :song/id
{1 {:song/duration 280 :song/tempo 98}
2 {:song/duration 150 :song/tempo 130}})])
(let [sm (psm/smart-map (pci/register registry)
{:song/id 1})]
(select-keys sm [:song/id :song/name :song/duration]))
; => #:song{:id 1, :name "Marchinha Psicotica de Dr. Soup", :duration 280}
(static-table-resolver attribute table)(static-table-resolver resolver-name attribute table)Exposes data for entities, indexes by attr-key. This is a simple way to extend/provide data for entities using simple Clojure maps. Example:
(def registry
[(pbir/static-table-resolver :song/id
{1 {:song/name "Marchinha Psicotica de Dr. Soup"}
2 {:song/name "There's Enough"}})
; you can provide a name for the resolver, if so, prefer fully qualified symbols
(pbir/static-table-resolver `song-analysis :song/id
{1 {:song/duration 280 :song/tempo 98}
2 {:song/duration 150 :song/tempo 130}})])
(let [sm (psm/smart-map (pci/register registry)
{:song/id 1})]
(select-keys sm [:song/id :song/name :song/duration]))
; => #:song{:id 1, :name "Marchinha Psicotica de Dr. Soup", :duration 280}
In this example, we create two different tables that provides data about songs, the
entities are related by the keys on the table, the attr-key says what's the attribute
name to be used to related the data, in this case we use :song/id on both, so they
get connected by it.
Exposes data for entities, indexes by attr-key. This is a simple way to extend/provide
data for entities using simple Clojure maps. Example:
(def registry
[(pbir/static-table-resolver :song/id
{1 {:song/name "Marchinha Psicotica de Dr. Soup"}
2 {:song/name "There's Enough"}})
; you can provide a name for the resolver, if so, prefer fully qualified symbols
(pbir/static-table-resolver `song-analysis :song/id
{1 {:song/duration 280 :song/tempo 98}
2 {:song/duration 150 :song/tempo 130}})])
(let [sm (psm/smart-map (pci/register registry)
{:song/id 1})]
(select-keys sm [:song/id :song/name :song/duration]))
; => #:song{:id 1, :name "Marchinha Psicotica de Dr. Soup", :duration 280}
In this example, we create two different tables that provides data about songs, the
entities are related by the keys on the table, the `attr-key` says what's the attribute
name to be used to related the data, in this case we use `:song/id` on both, so they
get connected by it.
(table-output table)For a given static table, compute the accumulated output query of the entity values.
For a given static table, compute the accumulated output query of the entity values.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |