-
Notifications
You must be signed in to change notification settings - Fork 87
/
schema.cljs
37 lines (33 loc) · 1.28 KB
/
schema.cljs
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
(ns schema
"Enforce schema constraints on page types"
(:require [clojure.test :refer [deftest is]]
[logseq.graph-validator.state :as state]
[logseq.db.rules :as rules]
[datascript.core :as d]))
(defn- get-property-names-for-type [type']
(->> (d/q '[:find (pull ?b [:block/properties])
:in $ ?type %
:where (page-property ?b :type ?type)]
@state/db-conn
type'
(vals rules/query-dsl-rules))
(map (comp :block/properties first))
(mapcat keys)
set
;; Remove built ins
((fn [x] (apply disj x [:id :title :alias :tags :type])))))
(defn- get-properties-for-type [type']
(->> (d/q '[:find (pull ?b [:block/properties])
:in $ ?type %
:where (page-property ?b :type ?type)]
@state/db-conn
type'
(vals rules/query-dsl-rules))
(map (comp :block/properties first))))
(deftest feature-schema
(is (= #{:platforms :description :initial-version}
(get-property-names-for-type "Feature"))
"Features should only have theses properties")
(let [props (get-properties-for-type "Feature")]
(is (empty? (remove :platforms props))
"All features should have a :platforms property")))