فهرست منبع

chore: rename property.type vars

- renamed schema-type to property-type as its not
  a type of schema and schema is an ambiguous context
  as it also applies to a class
- renamed builtin to built-in to be more correct
Gabriel Horner 2 سال پیش
والد
کامیت
0ffce18d15

+ 0 - 2
deps/db/.carve/ignore

@@ -10,5 +10,3 @@ logseq.db.frontend.rules/extract-rules
 logseq.db.frontend.property.type/type-or-closed-value?
 ;; Internal API
 logseq.db.frontend.rules/rules
-;; API
-logseq.db.frontend.property.type/property-types-with-cardinality

+ 4 - 4
deps/db/src/logseq/db/frontend/malli_schema.cljs

@@ -65,7 +65,7 @@
                                          [:block/schema :type]))}]
    (map (fn [[prop-type value-schema]]
           ^:property-value [prop-type (if (vector? value-schema) (last value-schema) value-schema)])
-        db-property-type/builtin-schema-types)))
+        db-property-type/built-in-validation-schemas)))
 
 (def block-properties
   "Validates a slightly modified version of :block/properties. Properties are
@@ -142,8 +142,8 @@
       (vec
        (concat
         [:map
-         [:type (apply vector :enum (into db-property-type/internal-builtin-schema-types
-                                          db-property-type/user-builtin-schema-types))]]
+         [:type (apply vector :enum (into db-property-type/internal-built-in-property-types
+                                          db-property-type/user-built-in-property-types))]]
         property-common-schema-attrs
         property-type-schema-attrs))]]
     page-attrs
@@ -163,7 +163,7 @@
          property-common-schema-attrs
          (remove #(not (db-property-type/property-type-allows-schema-attribute? prop-type (first %)))
                  property-type-schema-attrs)))])
-    db-property-type/user-builtin-schema-types)))
+    db-property-type/user-built-in-property-types)))
 
 (def user-property
   (vec

+ 15 - 15
deps/db/src/logseq/db/frontend/property/type.cljs

@@ -9,25 +9,25 @@
 ;; These vars enumerate all known property types and their associated behaviors
 ;; except for validation which is in its own section
 
-(def internal-builtin-schema-types
-  "Valid schema :type only to be used by built-in-properties"
+(def internal-built-in-property-types
+  "Valid property types only for use by internal built-in-properties"
   #{:keyword :map :coll :any})
 
-(def user-builtin-schema-types
-  "Valid schema :type for users in order they appear in the UI"
+(def user-built-in-property-types
+  "Valid property types for users in order they appear in the UI"
   [:default :number :date :checkbox :url :page :template])
 
-(def closed-values-schema-types
+(def closed-value-property-types
   "Valid schema :type for closed values"
   #{:default :number :date :url :page})
 
-(assert (set/subset? closed-values-schema-types (set user-builtin-schema-types))
+(assert (set/subset? closed-value-property-types (set user-built-in-property-types))
         "All closed value types are valid property types")
 
 (def ^:private user-built-in-allowed-schema-attributes
   "Map of types to their set of allowed :schema attributes"
   (merge-with into
-              (zipmap closed-values-schema-types (repeat #{:values :position}))
+              (zipmap closed-value-property-types (repeat #{:values :position}))
               {:number #{:cardinality}
                :date #{:cardinality}
                :url #{:cardinality}
@@ -35,7 +35,7 @@
                :template #{:classes}
                :checkbox #{}}))
 
-(assert (= (set user-builtin-schema-types) (set (keys user-built-in-allowed-schema-attributes)))
+(assert (= (set user-built-in-property-types) (set (keys user-built-in-allowed-schema-attributes)))
         "Each user built in type should have an allowed schema attribute")
 
 ;; Property value validation
@@ -90,8 +90,8 @@
       (existing-closed-value-valid? db property type-validate-fn value)
       (type-validate-fn value))))
 
-(def builtin-schema-types
-  "Map of types to malli fns that validate a property value for that type"
+(def built-in-validation-schemas
+  "Map of types to malli validation schemas that validate a property value for that type"
   {:default  [:fn
               {:error/message "should be a text"}
               ;; uuid check needed for property block values
@@ -120,15 +120,15 @@
    :coll     coll?
    :any      some?})
 
+(assert (= (set (keys built-in-validation-schemas))
+           (into internal-built-in-property-types
+                 user-built-in-property-types))
+        "Built-in property types must be equal")
+
 (def property-types-with-db
   "Property types whose validation fn requires a datascript db"
   #{:date :page :template})
 
-(assert (= (set (keys builtin-schema-types))
-           (into internal-builtin-schema-types
-                 user-builtin-schema-types))
-        "Built-in schema types must be equal")
-
 ;; Helper fns
 ;; ==========
 (defn property-type-allows-schema-attribute?

+ 3 - 3
src/main/frontend/components/property.cljs

@@ -137,7 +137,7 @@
         class? (contains? (:block/type block) "class")
         property-type (get-in property [:block/schema :type])
         save-property-fn (fn [] (components-pu/update-property! property @*property-name @*property-schema))
-        enable-closed-values? (contains? db-property-type/closed-values-schema-types (or property-type :default))]
+        enable-closed-values? (contains? db-property-type/closed-value-property-types (or property-type :default))]
     [:div.property-configure.flex.flex-1.flex-col
      {:on-mouse-down #(state/set-state! :editor/mouse-down-from-property-configure? true)
       :on-mouse-up #(state/set-state! :editor/mouse-down-from-property-configure? nil)}
@@ -168,9 +168,9 @@
 
       [:div.grid.grid-cols-4.gap-1.items-center.leading-8
        [:label.col-span-1 "Schema type:"]
-       (let [schema-types (->> (concat db-property-type/user-builtin-schema-types
+       (let [schema-types (->> (concat db-property-type/user-built-in-property-types
                                        (when built-in-property?
-                                         db-property-type/internal-builtin-schema-types))
+                                         db-property-type/internal-built-in-property-types))
                                (map (fn [type]
                                       {:label (property-type-label type)
                                        :disabled disabled?

+ 8 - 8
src/main/frontend/handler/db_based/property.cljs

@@ -20,15 +20,15 @@
 ;; schema -> type, cardinality, object's class
 ;;           min, max -> string length, number range, cardinality size limit
 
-(defn builtin-schema-types
-  "A frontend version of builtin-schema-types that adds the current database to
+(defn built-in-validation-schemas
+  "A frontend version of built-in-validation-schemas that adds the current database to
    schema fns"
   [property & {:keys [new-closed-value?]
                :or {new-closed-value? false}}]
   (into {}
         (map (fn [[property-type property-val-schema]]
                (cond
-                 (db-property-type/closed-values-schema-types property-type)
+                 (db-property-type/closed-value-property-types property-type)
                  (let [[_ schema-opts schema-fn] property-val-schema
                        schema-fn' (if (db-property-type/property-types-with-db property-type) #(schema-fn (db/get-db) %) schema-fn)]
                    [property-type [:fn
@@ -39,7 +39,7 @@
                    [property-type [:fn schema-opts #(schema-fn (db/get-db) %)]])
                  :else
                  [property-type property-val-schema]))
-             db-property-type/builtin-schema-types)))
+             db-property-type/built-in-validation-schemas)))
 
 (defn- fail-parse-long
   [v-str]
@@ -122,7 +122,7 @@
     (when (and multiple-values? (seq values))
       (let [infer-schema (when-not type (infer-schema-from-input-string (first values)))
             property-type (or type infer-schema :default)
-            schema (get (builtin-schema-types property) property-type)
+            schema (get (built-in-validation-schemas property) property-type)
             properties (:block/properties block)
             values' (try
                       (set (map #(convert-property-input-string property-type %) values))
@@ -199,7 +199,7 @@
         (when (some? v)
           (let [infer-schema (when-not type (infer-schema-from-input-string v))
                 property-type (or type infer-schema :default)
-                schema (get (builtin-schema-types property) property-type)
+                schema (get (built-in-validation-schemas property) property-type)
                 properties (:block/properties block)
                 value (get properties property-uuid)
                 v* (try
@@ -645,7 +645,7 @@
   [property {:keys [id value icon description]}]
   (assert (or (nil? id) (uuid? id)))
   (let [property-type (get-in property [:block/schema :type] :default)]
-    (when (contains? db-property-type/closed-values-schema-types property-type)
+    (when (contains? db-property-type/closed-value-property-types property-type)
       (let [value (if (string? value) (string/trim value) value)
             property-schema (:block/schema property)
             closed-values (:values property-schema)
@@ -659,7 +659,7 @@
             block (when id (db/entity [:block/uuid id]))
             value-block (when (uuid? value) (db/entity [:block/uuid value]))
             validate-message (validate-property-value
-                              (get (builtin-schema-types property {:new-closed-value? true}) property-type)
+                              (get (built-in-validation-schemas property {:new-closed-value? true}) property-type)
                               resolved-value)]
         (cond
           (nil? resolved-value)