Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns cljdoc.pathom3
(:require [com.wsscode.pathom.core :as p]
[com.wsscode.pathom.connect :as pc]
[clojure.core.async :as async]
[clojure.set]
[cljdoc.util.repositories :as repos]
[cljdoc.util.pom :as pom]
[cljdoc.config :as config]
[cljdoc.storage.sqlite-impl :as cljdoc-sqlite]))
;; {::pc/sym `some-resolver ; this is important! we need to name each resolver, prefer qualified symbols
;; ::pc/input #{:customer/id}
;; ::pc/output [:customer/id :customer/name :customer/email]
;; ::pc/resolve (fn [env input] ...)}
(def +db+ (config/db (config/config)))
(def namespaces-resolver
{::pc/sym `namespaces-resolver
::pc/input #{:cljdoc.artifact/sql-id}
::pc/output [:cljdoc.artifact/namespaces]
::pc/resolve (fn [env input]
{:cljdoc.artifact/namespaces []})})
(def artifact-id-resolver
{::pc/sym `artifact-id-resolver
::pc/input #{:cljdoc/artifact}
::pc/output [:cljdoc.artifact/sql-id]
::pc/resolve (fn [env {:keys [group name version] :as in}]
(println "in reader:" in)
(try (#'cljdoc-sqlite/get-version-id +db+ group name version)
(catch Throwable e
(.printStacktrace e)))
(println in (#'cljdoc-sqlite/get-version-id +db+ group name version))
{:cljdoc.artifact/sql-id (#'cljdoc-sqlite/get-version-id +db+ group name version)})})
(defmulti resolver-fn pc/resolver-dispatch)
(def indexes (atom {}))
(def defresolver (pc/resolver-factory resolver-fn indexes))
(def reg-config {::pc/defresolver defresolver})
; register the resolver we created previously
(pc/register reg-config [namespaces-resolver artifact-id-resolver])
;; Create a parser that uses the resolvers:
(def parser (p/parallel-parser {::p/env (fn [env]
(merge
{::p/reader [p/map-reader
pc/parallel-reader
pc/open-ident-reader
p/env-placeholder-reader]
::p/placeholder-prefixes #{">"}
::pc/resolver-dispatch resolver-fn
::pc/indexes @indexes}
env))
#_{::p/reader [p/map-reader
pc/parallel-reader
pc/open-ident-reader
p/env-placeholder-reader]
::p/placeholder-prefixes #{">"}
::pc/resolver-dispatch resolver-fn
::pc/indexes-fn #(deref indexes)}}))
(comment
(def a {:group "compojure" :name "compojure" :version "1.6.1"})
(let [{:keys [group name version]} a]
(println (#'cljdoc-sqlite/get-version-id +db+ group name version))
{:cljdoc.artifact/sql-id (#'cljdoc-sqlite/get-version-id +db+ group name version)})
(async/<!!
(parser {} [{[:cljdoc/artifact {:group "compojure" :name "compojure" :version "1.6.1"}]
[:cljdoc.artifact/sql-id]}]))
(def artifact #:artifact{:group "org.martinklepsch" :name "derivatives" :version "0.3.0"})
(cljdoc-parser {::p/entity artifact
:db (config/db (config/config))}
'[:artifact/pom-url
:artifact/sql-id
{:artifact/dependencies [* :artifact/sql-id]}])
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.