Function: matchRulesAgainstTables()
function matchRulesAgainstTables<TContext, TDomainConfig>(context: TContext, options: {
conditionsTable: Record<string, Condition>;
customConditions?: CustomConditionDef<unknown, TContext>[];
domain: string;
domainConfigSchema: ZodType<TDomainConfig>;
organizationId: string;
rulesTable: Record<string, Rule>;
scopeMapping: Record<string, string>;
}): Promise<MatchResult<TDomainConfig>>;Defined in: shared/rules/engine.ts:385
Pure rules-engine kernel. Match active rules against the given context
using caller-supplied rulesTable and conditionsTable.
- Loads active, current rules from
rulesTablefor the domain/org - Filters by scope matching
- Evaluates each rule's
condition_logictree, dispatching built-in conditions viats-patternand custom conditions viacustomConditions - Parses each matched rule's
domain_configthroughdomainConfigSchema, typing the result asTDomainConfig
Most consumers should use the higher-level matchRules() from
@the-kaizen-labs/taproot/rules/server, which loads tables from
Postgres and delegates here. This kernel is exposed for tests, static
authoring tools, and any caller that wants to manage rule data itself.
Custom conditions take precedence over built-ins — a conditionType
matching a built-in replaces it entirely.
Time semantics: each time-aware condition handler manages its own
evaluation date (defaulting to DateTime.now()). The engine does not
thread a clock — tests pin time via vi.setSystemTime(...), and
production replays anchor to context fields via per-condition config
(e.g. RelativeDateCheckConfig.evaluation_date_field).
Type Parameters
| Type Parameter |
|---|
TContext |
TDomainConfig |
Parameters
| Parameter | Type |
|---|---|
context | TContext |
options | { conditionsTable: Record<string, Condition>; customConditions?: CustomConditionDef<unknown, TContext>[]; domain: string; domainConfigSchema: ZodType<TDomainConfig>; organizationId: string; rulesTable: Record<string, Rule>; scopeMapping: Record<string, string>; } |
options.conditionsTable | Record<string, Condition> |
options.customConditions? | CustomConditionDef<unknown, TContext>[] |
options.domain | string |
options.domainConfigSchema | ZodType<TDomainConfig> |
options.organizationId | string |
options.rulesTable | Record<string, Rule> |
options.scopeMapping | Record<string, string> |
Returns
Promise<MatchResult<TDomainConfig>>