Should make reloading AND aot work again

This commit is contained in:
2024-02-08 15:20:58 -08:00
parent 5b32518562
commit a5e6b0549d
20 changed files with 280 additions and 351 deletions

View File

@@ -18,38 +18,38 @@
(defn kebab [x]
(if (qualified-keyword? x)
(keyword (snake->kebab (namespace x)) (snake->kebab (name x)) )
(keyword (snake->kebab (namespace x)) (snake->kebab (name x)))
(keyword (snake->kebab (name x)))))
(defn kebab->snake [s]
(str/replace (str/replace s #"-" "_") #"\?$" "" ))
(str/replace (str/replace s #"-" "_") #"\?$" ""))
(defn snake [x]
(keyword (kebab->snake (name x))))
(defn ->graphql [m]
(walk/postwalk
(fn [node]
(cond
(fn [node]
(cond
(keyword? node)
(snake node)
(keyword? node)
(snake node)
:else
node))
m))
:else
node))
m))
(defn <-graphql [m]
(walk/postwalk
(fn [node]
(cond
(fn [node]
(cond
(keyword? node)
(kebab node)
(keyword? node)
(kebab node)
:else
node))
m))
:else
node))
m))
(defn is-admin? [id]
(= "admin" (:user/role id)))
@@ -141,7 +141,7 @@
not-empty
(str "*"))
query (as-> exacts e
(filter #(not (str/blank? %)) e)
(filter #(not (str/blank? %)) e)
(mapv #(str "+" %) e)
(conj e partial)
(str/join " " e))]
@@ -150,44 +150,43 @@
(defn trace-query [key f]
(fn trace [a b c]
(mu/with-context (merge
(:log-context a {})
{:query key
:mutation (boolean (= "mutation"
(namespace key)))
:user (:id a)})
(:log-context a {})
{:query key
:mutation (boolean (= "mutation"
(namespace key)))
:user (:id a)})
(mu/trace (keyword "graphql" (name key))
[]
(f a b c)))))
[]
(f a b c)))))
(defn attach-tracing-resolvers [schema m]
(attach-resolvers schema
(reduce
(fn [resolvers [resolver-key resolver-fn]]
(assoc resolvers
resolver-key (trace-query resolver-key resolver-fn))
)
{}
m)))
(fn [resolvers [resolver-key resolver-fn]]
(assoc resolvers
resolver-key (trace-query resolver-key resolver-fn)))
{}
m)))
(defn extract-client-ids [user-clients & possible-clients]
(let [coerce-client-ids (fn coerce-client-ids [x]
(cond (and (map? x)
(:db/id x))
[(:db/id x)]
(cond (and (map? x)
(:db/id x))
[(:db/id x)]
(nat-int? x)
[x]
(nat-int? x)
[x]
(and (vector? x)
(= :client/code (first x)))
[(entid (dc/db conn) x)]
(and (vector? x)
(= :client/code (first x)))
[(entid (dc/db conn) x)]
(sequential? x)
(mapcat coerce-client-ids x)
(sequential? x)
(mapcat coerce-client-ids x)
:else
[]))
:else
[]))
user-client-ids (set (mapcat coerce-client-ids user-clients))
extra-client-ids (set (mapcat coerce-client-ids possible-clients))]
(if (seq extra-client-ids)

View File

@@ -1,5 +1,4 @@
(ns auto-ap.jobs.bulk-journal-import
(:gen-class)
(:require
[amazonica.aws.s3 :as s3]
[auto-ap.graphql.ledger :refer [import-ledger]]

View File

@@ -1,5 +1,4 @@
(ns auto-ap.jobs.close-auto-invoices
(:gen-class)
(:require
[auto-ap.datomic :refer [conn]]
[auto-ap.jobs.core :refer [execute]]

View File

@@ -1,5 +1,4 @@
(ns auto-ap.jobs.current-balance-cache
(:gen-class)
(:require
[auto-ap.graphql.clients :as clients]
[auto-ap.jobs.core :refer [execute]]))

View File

@@ -1,5 +1,4 @@
(ns auto-ap.jobs.ezcater-upsert
(:gen-class)
(:require
[auto-ap.jobs.core :refer [execute]]
[auto-ap.ezcater.core :as ezcater]))

View File

@@ -1,5 +1,4 @@
(ns auto-ap.jobs.intuit
(:gen-class)
(:require
[auto-ap.import.intuit :as intuit]
[auto-ap.jobs.core :refer [execute]]))

View File

@@ -1,5 +1,4 @@
(ns auto-ap.jobs.ledger-reconcile
(:gen-class)
(:require
[auto-ap.jobs.core :refer [execute]]
[auto-ap.ledger :as ledger]))

View File

@@ -1,5 +1,4 @@
(ns auto-ap.jobs.load-historical-sales
(:gen-class)
(:require
[auto-ap.datomic :refer [conn]]
[auto-ap.jobs.core :refer [execute]]

View File

@@ -1,5 +1,4 @@
(ns auto-ap.jobs.plaid
(:gen-class)
(:require
[auto-ap.import.plaid :as plaid]
[auto-ap.jobs.core :refer [execute]]))

View File

@@ -1,5 +1,4 @@
(ns auto-ap.jobs.register-invoice-import
(:gen-class)
(:require
[amazonica.aws.s3 :as s3]
[auto-ap.datomic :refer [audit-transact conn pull-attr]]

View File

@@ -1,5 +1,4 @@
(ns auto-ap.jobs.square
(:gen-class)
(:require
[auto-ap.jobs.core :refer [execute]]
[auto-ap.square.core3 :as square3]))

View File

@@ -1,5 +1,4 @@
(ns auto-ap.jobs.vendor-usages
(:gen-class)
(:require
[auto-ap.datomic :refer [conn]]
[auto-ap.jobs.core :refer [execute]]

View File

@@ -1,5 +1,4 @@
(ns auto-ap.jobs.yodlee2
(:gen-class)
(:require
[auto-ap.import.yodlee2 :as yodlee2]
[auto-ap.jobs.core :refer [execute]]

View File

@@ -1,107 +0,0 @@
(ns auto-ap.main
(:gen-class)
(:require
[auto-ap.handler :refer [app]]
[auto-ap.server :as server]
[auto-ap.jobs.restore-from-backup :as job-restore-from-backup]
[auto-ap.jobs.bulk-journal-import :as job-bulk-journal-import]
[auto-ap.jobs.close-auto-invoices :as job-close-auto-invoices]
[auto-ap.jobs.current-balance-cache :as job-current-balance-cache]
[auto-ap.jobs.ezcater-upsert :as job-ezcater-upsert]
[auto-ap.jobs.import-uploaded-invoices :as job-import-uploaded-invoices]
[auto-ap.jobs.intuit :as job-intuit]
[auto-ap.jobs.ntg :as job-ntg]
#_[auto-ap.backup :as backup]
[auto-ap.jobs.ledger-reconcile :as job-reconcile-ledger]
[auto-ap.jobs.load-historical-sales :as job-load-historical-sales]
[auto-ap.jobs.plaid :as job-plaid]
[auto-ap.jobs.register-invoice-import :as job-register-invoice-import]
[auto-ap.jobs.square :as job-square]
[auto-ap.jobs.sysco :as job-sysco]
[auto-ap.jobs.vendor-usages :as job-vendor-usages]
[auto-ap.jobs.yodlee2 :as job-yodlee2]
[auto-ap.logging :as alog]
[com.unbounce.dogstatsd.core :as statsd]
[config.core :refer [env]]
[mount.core :as mount]
[nrepl.server :refer [start-server]]
[ring.adapter.jetty :refer [run-jetty]]
[yang.scheduler :as scheduler]
[auto-ap.jobs.insight-outcome-recommendation :as insight-outcome-recommendation])
(:import
(org.eclipse.jetty.server.handler StatisticsHandler)
(org.eclipse.jetty.server.handler.gzip GzipHandler)))
(defn add-shutdown-hook! [^Runnable f]
(.addShutdownHook (Runtime/getRuntime)
(Thread. f)))
(defn shutdown-mount []
(mount/stop))
(defn -main [& _]
(let [job (System/getenv "INTEGREAT_JOB")]
(println "JOB is" job)
(cond (= job "square-import-job")
(job-square/-main)
(= job "reconcile-ledger")
(job-reconcile-ledger/-main)
(= job "current-balance-cache")
(job-current-balance-cache/-main)
(= job "yodlee2")
(job-yodlee2/-main)
(= job "yodlee2-accounts")
(job-yodlee2/accounts-only)
(= job "plaid")
(job-plaid/-main)
(= job "intuit")
(job-intuit/-main)
(= job "vendor-usages")
(job-vendor-usages/-main)
(= job "import-uploaded-invoices")
(job-import-uploaded-invoices/-main)
(= job "sysco")
(job-sysco/-main)
(= job "close-auto-invoices")
(job-close-auto-invoices/-main)
(= job "ezcater-upsert")
(job-ezcater-upsert/-main)
(= job "register-invoice-import")
(job-register-invoice-import/-main)
(= job "load-historical-sales")
(job-load-historical-sales/-main)
(= job "bulk-journal-import")
(job-bulk-journal-import/-main)
(= job "restore-from-backup")
(job-restore-from-backup/-main)
(= job "insight-outcome-recommendation")
(insight-outcome-recommendation/-main)
;; (= job "export-backup")
;; (backup/-main)
(= job "ntg")
(job-ntg/-main)
:else
(do
(add-shutdown-hook! shutdown-mount)
(start-server :port 9000 :bind "0.0.0.0" #_#_:handler (cider-nrepl-handler))
(mount/start)
#_(alter-var-root #'nrepl.middleware.print/*print-fn* (constantly clojure.pprint/pprint))))))

View File

@@ -31,6 +31,9 @@
(org.eclipse.jetty.server.handler StatisticsHandler)
(org.eclipse.jetty.server.handler.gzip GzipHandler)))
(println "LOADING SERVER")
(defn add-shutdown-hook! [^Runnable f]
(.addShutdownHook (Runtime/getRuntime)
(Thread. f)))

View File

@@ -27,22 +27,22 @@
query (format "_text_:(%s) AND %s" (cleanse-query query) client-part)]
(mu/log ::searching :search-query query)
(for [{:keys [account_id name] :as g} (solr/query solr/impl "accounts"
{"query" query
"fields" "id, name, client_id, numeric_code, applicability, account_id"})]
{"query" query
"fields" "id, name, client_id, numeric_code, applicability, account_id"})]
{:account_id (first account_id)
:name (first name)})))
:name (first name)})))
(defn account-search [{{:keys [q client-id allowance vendor-id] :as qp} :query-params id :identity}]
(when client-id
(assert-can-see-client id client-id))
(assert-can-see-client id client-id))
(let [num (some-> (re-find #"([0-9]+)" q)
second
(not-empty )
(not-empty)
Integer/parseInt)
valid-allowances (cond-> #{:allowance/allowed
:allowance/warn}
(is-admin? id) (conj :allowance/admin-only))
@@ -55,23 +55,23 @@
vendor-account (when vendor-id
(-> (dc/q '[:find ?da
:in $ ?v
:where [?v :vendor/default-account ?da]]
(dc/db conn)
vendor-id)
:in $ ?v
:where [?v :vendor/default-account ?da]]
(dc/db conn)
vendor-id)
ffirst))
xform (comp
(filter (fn [[_ a]]
(or
(valid-allowances (-> a allowance :db/ident))
(= (:db/id a) vendor-account))))
(map (fn [[n a]]
{:label (str (:account/numeric-code a) " - " n)
:value (:db/id a)
:location (:account/location a)
:warning (when (= :allowance/warn (-> a allowance :db/ident))
"This account is not typically used for this purpose.")})))]
{:body (take 10 (if q
(filter (fn [[_ a]]
(or
(valid-allowances (-> a allowance :db/ident))
(= (:db/id a) vendor-account))))
(map (fn [[n a]]
{:label (str (:account/numeric-code a) " - " n)
:value (:db/id a)
:location (:account/location a)
:warning (when (= :allowance/warn (-> a allowance :db/ident))
"This account is not typically used for this purpose.")})))]
{:body (take 10 (if q
(if num
(->> (dc/q '[:find ?n (pull ?i pattern)
:in $ ?numeric-code ?allowance pattern
@@ -87,18 +87,18 @@
(sequence xform))
(->> (search- id q client-id)
(sequence
(comp (map (fn [i] [(:name i) (dc/pull (dc/db conn) search-pattern (:account_id i))]))
xform))))
(comp (map (fn [i] [(:name i) (dc/pull (dc/db conn) search-pattern (:account_id i))]))
xform))))
[]))}))
(def account-search (wrap-json-response (wrap-schema-enforce account-search
:query-schema [:map
[:q :string]
[:client-id {:optional true
:default nil}
[:maybe entity-id]]
[:vendor-id {:optional true}
[:maybe entity-id]]
[:allowance {:optional true}
[:maybe (ref->enum-schema "allowance")]]])))
:query-schema [:map
[:q :string]
[:client-id {:optional true
:default nil}
[:maybe entity-id]]
[:vendor-id {:optional true}
[:maybe entity-id]]
[:allowance {:optional true}
[:maybe (ref->enum-schema "allowance")]]])))

View File

@@ -40,6 +40,7 @@
[manifold.deferred :as de])
(:import [java.util UUID]))
;; TODO make more reusable malli schemas, use unions if it would be helpful
;; TODO copy save logic from graphql version
;; TODO cash drawer shift
@@ -1416,8 +1417,7 @@
(first step-key)))))
(form-schema [_] form-schema-2)
(submit [_ {:keys [multi-form-state request-method identity] :as request}]
(let [
snapshot (mc/decode
(let [snapshot (mc/decode
form-schema-2
(:snapshot multi-form-state)
mt/strip-extra-keys-transformer)