entity.core

Define domain types

defentity

macro

(defentity ent-name fields primary & more)
Define a record type with fields, keys and any additional information

defenum

macro

(defenum name symsvals default)
Define an enum type, mapping keywords to values, for example

  (defenum :foo/Active {:y 1
                        :n 0} :y)

defines the enum :foo/Active with two keyword symbols and
corresponding values, and whose default is :y

defscalar

macro

(defscalar name val)
Define a scalar type, for example:

  (defscalar :foo/Money 0.00M

defines the type :foo/Money as a big decimal with 2 decimal
places of accuracy.

delete-instance

(delete-instance instance)
Delete the given entity instance from its persistent storage.

entity-instance?

(entity-instance? arg entity)
Returns true if the argument is an instance of the given entity. The
entity can be a keyword (a literal referral to the domain type) or
an instance (from which the type will be determined).
If arg is not an instance of entity, returns false.

enum-sym

macro

(enum-sym enum val)
Return the symbol for a given domain enum type and value

enum-val

macro

(enum-val enum sym)
Return the value for the given domain enum type and symbol

enum-val-fn

(enum-val-fn enum sym)
Return the value for the given domain enum type and symbol

find-entity

(find-entity entity)
Find the type from the given keyword ref

find-value

(find-value scalar)(find-value entity field)
Find a value from the types catalog. Two args means type:field.
Single arg means scalar. If type:field does not resolve then field is
considered a key name, returning the key proto if found.

get-alias

(get-alias instance)
Return a keyword that can be used to associate the
instance in a map. This will be either its unqualified
name or any alias that was specified when defined.

get-create-fn

(get-create-fn instance)
Return the function that can be called to correctly initialise this
and anything other required in the domain.

get-destroy-fn

(get-destroy-fn instance)
Return the function that can be called to destroy this
and anything else required in the domain.

get-key-info

(get-key-info entity key-name)

get-mutate-fn

(get-mutate-fn instance)
Return the function that can be called to verify what changes are
allowed and perform any consequential actions in the domain.

get-primary-key

(get-primary-key instance)
Return the instance's primary key from its meta data.
If not found, throws, if identifiable as the primary key
itself then returns the argument

key-val?

(key-val? arg)
Returns true if the argument appears to be a value returned
by make-key

make-key

(make-key key-val entity key-name)
Make a key value. Returns a map comprising only the map keys
for the given domain key name. Any missing fields are
nil (or explicit default value); additional
fields are ignored.

new-instance

(new-instance entity)(new-instance entity ent-val)
Make an instance of the specified type, setting any fields
when an initial value is given. Any missing fields remain their
default values; additional fields are ignored.

null-io

I/O that does nothing

primary-key-to-meta

(primary-key-to-meta instance)
Augment the instance meta data with the primary key.
This can only be done when the primary key is established,
but it is trusted this is so

read-entity

(read-entity key-val)(read-entity entity-name key-val)(read-entity key-val entity-name key-name)
Read the given entity, applying the key value

write-instance

(write-instance instance)
Write the given entity instance to its persistent storage