(ns emptyhead.principle.crud "Implements CRUD operations on principles. Since principles are ideas, 'missing' operations here are implemented in [[emptyhead.idea.crud]]." (:require [emptyhead.idea.protocol :as prtc] [emptyhead.idea.crud :as idea] [emptyhead.idea.property :as prop] [emptyhead.contract.eval :as contract] [emptyhead.util.magic :as magic])) (defn make-principle "Helper function to make principle object. You may want `register-principle!` instead." [operator & {:keys [data ext-contract ext-stages transient] :or {data {} ext-contract {} ext-stages [[:principle operator]] transient true}}] (hash-map :operator operator :data data :ext-contract ext-contract :ext-stages ext-stages :return {} :transient (not (false? transient)))) (defn register-principle! "Create a principle and register it in the state. Returns a reference to the created principle." [operator & {:keys [data ext-contract ext-stages transient] :as args}] (idea/have-idea! :prefix (str "principle_" (name operator) "_") :properties [magic/principle-ns] :data (make-principle operator args))) (defn contract "Get the extension contract of a `principle`. Returns the contract." [principle] (prtc/val-fn :ext-contract principle)) (defn stages "Get the extension stages of a `principle`. Returns the list of stages." [principle] (prtc/val-fn :ext-stages principle)) (defn operator "Get the operator id of a `principle`. Returns the operator keyword." [principle] (prtc/val-fn :operator principle))