@qarar/sdk Reference
The @qarar/sdk package is the main entry point to the Qarar platform. It re-exports all essential functions, compilers, builders, and types with zero external runtime dependencies.
pnpm add @qarar/sdkExported Functions
| Function | Signature | Description |
|---|---|---|
rule(nameOrId?) | (nameOrId?: string) => RuleBuilder | Starts building a dynamic rule AST using fluent chainable methods. |
field(path) | (path: string) => ValueNode | Creates a dynamic field reference node for dynamic two-sided comparisons. |
switchRule(nameOrId?) | <T>(nameOrId?: string) => DecisionTableBuilder<T> | Starts building a multi-branch decision table matrix. |
checkRule(rule, data, opts?) | (rule: Rule, data: unknown) => CheckRuleResult | All-in-one validator, evaluator, and human-readable explanation generator. |
compileRule(rule) | (rule: Rule) => (data: unknown) => boolean | Compiles a rule into an optimized closure executing at ~6.2M ops/sec. |
evaluate(rule, data) | (rule: Rule, data: unknown) => EvaluationResult | Evaluates a rule against data and returns the raw TraceEntry[] tree. |
evaluateDecisionTable(table, data) | <T>(table: DecisionTable<T>, data: unknown) => DecisionTableResult<T> | Evaluates an input payload against a decision table matrix. |
compileToSQL(rule, opts?) | (rule: Rule, opts?: SqlCompileOptions) => SqlCompileResult | Compiles a rule AST into a SQL WHERE clause at ~1.69M compiles/sec. |
compileToMongo(rule) | (rule: Rule) => MongoCompileResult | Compiles a rule AST into a MongoDB query filter at ~4.22M compiles/sec. |
explainFailures(trace) | (trace: TraceEntry[]) => string[] | Formats failed condition trace entries into human-readable strings. |
validateRule(json) | (input: unknown) => Rule | Validates an untrusted JSON object against the strict Qarar rule schema (throws on invalid input). |
safeValidateRule(json) | (input: unknown) => ValidationResult<Rule> | Safely validates an untrusted JSON object without throwing ({ success, data / error }). |
createQarar(schema) | <T>(schema: SchemaLike<T>) => QararSchemaInstance<T> | Binds rule execution to a domain schema validator for runtime payload validation. |
Core TypeScript Types
// Top-Level Rule Containerexport interface Rule { id: string; name: string; description?: string; version: string; root: RuleNode;}
// Decision Table Containerexport interface DecisionTable<T = unknown> { id: string; name: string; version: string; mode: "first" | "all"; defaultOutput: T; branches: Array<{ id: string; name: string; condition: RuleNode; output: T; }>;}
// Result of checkRule()export interface CheckRuleResult { result: boolean; valid: boolean; reasons: string[]; trace: TraceEntry[]; errors?: string[];}
// Single Condition Execution Traceexport interface TraceEntry { path?: string; operator?: string; expected?: unknown; actual?: unknown; passed: boolean; message?: string; nodeType: string;}