std/entity
模块 zio.entity — Entity model (identity + metadata) · 7 个符号
defentity / make-entity / entity-id work in native and browser sessions. Default ids are unique only within this loaded library context. A host may explicitly supply a cryptographic identity generator.
概览
defentity
(defmacro defentity [name fields] …)
defentity — 定义名为 entity-
每个字段生成以对应关键字为 :initarg 的构造参数;在原生与 浏览器会话中均可用。
entity--counter
(def entity--counter …)
No implicit host dependency: browser pure use retains local identity.
entity--counter — 默认实体 id 的进程内计数器。
entity--identity-source
(def entity--identity-source …)
entity--identity-source — 可选的身份生成器 (fn [] id)。
非 nil 时 make-entity 改用它生成 id;nil 表示退回 entity--counter 计数。
entity-set-identity-source!
(defn entity-set-identity-source! [source] …)
entity-set-identity-source! — 安装 make-entity 使用的身份生成器。
source 必须可调用(fn?),否则抛出 invalid-input。
entity-use-host-identity!
(defn entity-use-host-identity! …)
entity-use-host-identity! — 将身份源设为宿主加密随机 id。
即 (host/sha256 (host/random-bytes 32));需要宿主提供 host/sha256 与 host/random-bytes 绑定。
make-entity
(defn make-entity [type-sym & kvs] …)
make-entity — 以 kvs 构造 entity-
返回 {:entity/type ... :entity/id ... :entity/instance ...}。
id 来自身份源 entity--identity-source;缺省为 entity-
entity-id
(defn entity-id [entity] …)
entity-id — 返回实体映射的 :entity/id;非映射输入返回 nil。