Lime Web Components API Documentation - v6.24.0
    Preparing search index...

    Interface RulePrimitive<TArgs, TReads>Alpha

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

    Each primitive declares which context keys it reads (reads) and takes some args. Calling build(args) returns the actual check, a function that reads from a ContextScope 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.

    A primitive that reads one context key. The args shape lives on build's parameter; TypeScript infers TArgs from there, and TReads from the reads tuple.

    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;
    },
    });

    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 context key from reads has no provider, ContextScope.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.

    reads is a readonly tuple, so the predicate's scope.get parameter is restricted to keys declared here. The trade-off is that callers should not mutate the array after construction; the registry implementation already treats it as read-only.

    interface RulePrimitive<
        TArgs extends JsonValue = JsonValue,
        TReads extends keyof ContextMap = keyof ContextMap,
    > {
        id: string;
        reads: readonly TReads[];
        build(args: TArgs): (scope: ContextScope<TReads>) => boolean;
    }

    Type Parameters

    Index

    Properties

    Methods

    Properties

    id: string

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

    reads: readonly TReads[]

    Context keys the predicate will read at evaluation time. Used by validate to flag rules that reference keys a caller can't provide, and by the type system to narrow ContextScope.get to just those keys.

    Methods