Move the old statsdb.template.user-mixins.* idea into a cleaner entity-level model.
The entity should declare what capabilities it has. Those capabilities should drive generation of:
The entity declaration remains PG-first. The generation system should emit actual output code rather than hide the logic inside a large macro expansion chain.
In statstrade-core, the statsdb.template.user-mixins.* namespaces already act as
a capability system around a base table.
Examples:
accessstarredjoin-requestjoin-inviteThose templates generate recurring patterns like:
TopicAccess, TopicStarred, TopicJoinRequesttopic-assert-is-ownertopic-add-member, topic-remove-star:db/syncSo the old system should be treated as an important reference for what addon generation needs to produce.
Replace the old template-registry mental model with an entity-addon model.
Conceptually:
(defentity.pg Topic
{:addons [:track/default
:record/default
:ownership
:access/member
:starred
:join-request
:join-invite]}
[...fields...])
The entity stays the source of truth. Addons describe repeated behavior families.
There should be two kinds of generated output.
Generated for most entities by default.
Typical examples:
createcreate-rawmodifyremove or archivegetlistThese functions are part of the normal CRUD surface of the table.
Generated only when the entity declares that addon.
Typical examples:
These functions are not universal. They are capability-driven.
The initial addon catalog should be derived from the proven patterns in
statsdb.template.user-mixins.*.
:track/defaultPurpose:
Typical generated output:
:record/defaultPurpose:
Typical generated output:
:ownershipPurpose:
Typical generated output:
assert-is-ownercreateremovetransfer-ownership:access/memberPurpose:
Typical generated output:
assert-is-memberassert-is-adminassert-is-managementadd-memberremove-memberset-member-accessleave-as-member:starredPurpose:
Typical generated output:
add-starremove-star:join-requestPurpose:
Typical generated output:
assert-can-send-join-requestsend-join-requestaccept-join-requestreject-join-requestcancel-join-requestlist-join-requests-*:join-invitePurpose:
Typical generated output:
assert-can-send-join-invitesend-join-inviteaccept-join-invitereject-join-invitecancel-join-invitelist-join-invites-*:public-togglePurpose:
Typical generated output:
set-public-as-memberThe old statsdb.template.user-mixins.* modules map cleanly to addons:
user-mixins.access -> :ownership, :access/member, :public-toggleuser-mixins.starred -> :starreduser-mixins.join-request -> :join-requestuser-mixins.join-invite -> :join-inviteSo the new system should not discard the old logic. It should reorganize it around entity-declared capabilities.
The macro should stay thin.
defentity.pg should do two things:
Actual helper generation should happen in explicit codegen steps that emit normal source files.
For example:
This model is better than the old template registry because:
This document is about entity capabilities first, not final sync generation.
However, addons are the right place to later attach sync expectations.
Examples:
:starred can imply sync over the starred companion table:access/member can imply sync over the access table and base table:join-request can imply sync over request state transitionsThat means addon generation and inferred :db/sync generation should fit together
naturally later.
Conceptual authoring:
(defentity.pg Organisation
{:addons [:track/default
:record/default
:ownership
:access/member
:join-request
:join-invite]}
[:name {:type :citext :required true}
:title {:type :text}])
Conceptual generated outputs:
OrganisationAccessOrganisationJoinRequestOrganisationJoinInviteorganisation-createorganisation-modifyorganisation-removeorganisation-assert-is-ownerorganisation-assert-is-memberorganisation-add-memberorganisation-remove-memberorganisation-send-join-requestorganisation-accept-join-inviteThe system should answer this question clearly:
Given one entity declaration, what standard functions and addon functions should exist for it?
That should be derivable from the entity spec without consulting a separate template registry by hand.
Turn the old user-mixins family into a formal addon spec table.
For each addon:
That would make the capability model concrete enough to drive real generation.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |