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

    Interface RuleRegistryAlpha

    The central place primitives and rules come together.

    This package only describes the contract; the actual behavior is supplied by an implementation, reached through the platform service ruleRegistry.

    What the API does, by area:

    • Primitives. register adds a RulePrimitive; listPrimitives lists them.
    • Rule lifecycle. compile turns a Rule into a callable predicate. validate runs the same checks without throwing or producing a predicate.
    • Building a scope (convenience). scope delegates to ContextRegistry.scope so rule code does not have to thread two services. New consumers that don't compile rules should go to the context registry directly.

    Context resolution (DOM-walked providers, session-wide fallbacks, scope construction) lives on ContextRegistry. Primitives read from a ContextScope without needing to know which service built it.

    Saved rules are loaded by the host client from its own config layer at boot and live in the same id namespace as primitives. They are not registered through this interface. The registry resolves references during compile and validate but exposes no public API for managing them.

    Compiling and evaluating a rule from a web component

    const registry = platform.get(PlatformServiceName.RuleRegistry);
    const compiled = registry.compile(this.descriptor.rules.visibility);
    const visible = compiled(registry.scope({ host: this.host }));

    Test-fixture scope

    const scope = registry.scope({
    with: { user: testUser, limeobject: testObject },
    });
    const passes = registry.compile(rule)(scope);
    interface RuleRegistry {
        attachMetadata(id: string, metadata: ConfigMetadata): void;
        compile(rule: Rule): CompiledRule;
        listMetadata?(): PrimitiveMetadata[];
        listPrimitives(): RulePrimitive<JsonValue, keyof ContextMap>[];
        register(primitive: RulePrimitive, metadata?: ConfigMetadata): void;
        scope(options?: ContextScopeOptions): ContextScope;
        validate(
            rule: Rule,
            available?: (keyof ContextMap)[],
        ): RuleValidationResult;
    }
    Index

    Methods

    • Alpha

      Attach or replace the display metadata for an already-registered primitive. Use this when the runtime side of a primitive (the factory + matching engine) is registered by the platform, and the UI binding (a configComponent to author its args) is contributed by a UI layer that loads later.

      Replaces any prior metadata for id wholesale; merge externally if partial updates are needed.

      Parameters

      • id: string

        The primitive id whose metadata to set.

      • metadata: ConfigMetadata

        The display metadata to attach.

      Returns void

      If no primitive with id has been registered. Throwing (rather than silently retaining orphan metadata) surfaces typos and ordering bugs at boot.

    • Alpha

      Turn a Rule into a callable predicate.

      Every ref is resolved against the registered primitives and saved rules. Saved rules are expanded in place and cycles are detected. Args at each leaf are not validated by the contract; primitives are responsible for handling their own args (see RulePrimitive). An implementation may surface args-mismatch issues if it has a way to introspect a primitive's args, but the contract does not require it.

      The returned predicate is a snapshot: it reflects whatever was registered when compile ran, so anything compiled against an older set of saved rules is stale once those rules change. If results are cached, recompile when saved rules change. Re-running compile on a structurally-equal rule may or may not return the same CompiledRule instance, so don't rely on identity equality.

      Thrown errors inside a predicate are caught and treated as false for that node, the same outcome as a missing context key. Callers do not need to wrap evaluations in try/catch. This fail-closed behavior applies only to errors raised at evaluation time. Errors raised by RulePrimitive.build while compiling propagate out of compile, so a primitive that cannot handle its args should return a constant-false predicate from build rather than throwing.

      Parameters

      • rule: Rule

        The rule to compile.

      Returns CompiledRule

      A predicate over ContextScope.

      If the rule has an unknown-ref or cycle issue, or if a RulePrimitive.build call throws. Implementations that validate args may also throw args-mismatch. args-on-saved-rule does not throw, the args are dropped and RuleRegistry.validate reports it as a diagnostic. Use RuleRegistry.validate for the non-throwing variant.

    • Alpha

      List the display metadata supplied at registration.

      Optional, an implementation that doesn't track metadata can leave this method off. When present, returns one entry per registered primitive.

      Returns PrimitiveMetadata[]

      Metadata for each registered primitive.

    • Alpha

      Register a RulePrimitive.

      The id must be namespaced (contain a .) and must not be in use already, neither by another primitive nor by a saved rule.

      metadata is optional and carries the display side of things: title, description, icon, tags, and a configComponent for editing the primitive's args. None of it is used at evaluation time; it shows up later via listMetadata.

      Parameters

      Returns void

      If the id is unnamespaced, already taken by another primitive, or already in use by a saved rule.

    • Alpha

      Same checks as compile, but returns structured diagnostics instead of throwing, and no predicate is produced.

      available is a hint from the caller, not something the registry can verify: the registry doesn't know which context keys will be supplied at evaluation time, only the caller building the scope does. Pass it when known; otherwise the runtime fallback (missing keys produce false) catches the gap.

      Parameters

      • rule: Rule

        The rule to validate.

      • Optionalavailable: (keyof ContextMap)[]

        Optional list of context keys the caller knows will be available where the rule runs. Used to surface missing-slot issues at save time.

      Returns RuleValidationResult

      ok: true when the rule passes every check; otherwise ok: false with a list of issues.