A named, parameterised check that a Rule can refer to by id.

Each primitive declares which subject slots it needs (reads) and takes some args. Calling build(args) returns the actual check, a function that reads from a RuleScope and returns true or false. Primitives are registered once at bootstrap; rules reference them by id from then on.

Display fields (title, description, icon, a custom args editor) live in ConfigMetadata, passed alongside the primitive when registering it. Same pattern as WebComponentRegistry and CommandBus.

Example

A primitive that reads one slot. The args shape lives on build's parameter; TypeScript infers TArgs from there.

type OlderThanArgs = { days: number };

const olderThan = definePrimitive({
id: 'limetech.object-older-than',
reads: ['limeobject'],
build: ({ days }: OlderThanArgs) => (scope) => {
const obj = scope.get('limeobject');
if (!obj) return false;
return daysSince(obj.createdtime) > days;
},
});

Remarks

An id must contain a . (e.g. limetech.is-admin, pluginx.has-feature) so two unrelated authors can't accidentally claim the same one, and because the same id space is shared with saved rules, the prefix keeps those from colliding too.

There is no separate dependency-injection mechanism: the code that registers a primitive already has access to whatever it needs (translator, http, repositories, etc.) and the build callback closes over them.

If a slot from reads has no provider, get returns undefined and the predicate should return false. Primitive authors should also fail closed on unexpected args or downstream errors. The fail-closed behavior when a predicate does throw is part of compile's contract. See there for details.

See

Type Parameters

Hierarchy

  • RulePrimitive

Properties

Methods

Properties

id: string

Unique, namespaced identifier (e.g. limetech.is-admin).

reads: (keyof SubjectRegistry)[]

Subject slots the predicate will read at evaluation time. Used by validate to flag rules that reference slots a caller can't provide.

Methods

  • Bind args to a predicate. compile calls this once per ref leaf in the rule tree.

    Returns

    A function that reads from a RuleScope and returns true or false.

    Parameters

    • args: TArgs

      The args from the ref leaf.

    Returns ((scope: RuleScope) => boolean)

      • (scope: RuleScope): boolean
      • Bind args to a predicate. compile calls this once per ref leaf in the rule tree.

        Returns

        A function that reads from a RuleScope and returns true or false.

        Parameters

        Returns boolean