Explainable and budget-limited JSON business rules for MoonBit
{
"id": "adult-check",
"description": "成年人准入",
"condition": {
">=": [{ "var": "user.age" }, 18]
}
}{
"user": { "age": 20 }
}PASS adult-check [>=]
├─ VALUE var(user.age)
│ └─ result = 20
├─ VALUE literal
│ └─ result = 18
└─ result = truecurl -fsSL https://cli.moonbitlang.com/install/unix.sh | bashmoon check --deny-warn
moon test
moon build --target nativemoon run --target native cmd/main check examples/coupon.rule.jsonmoon run --target native cmd/main eval examples/coupon.rule.json --data examples/coupon.data.json| 预算 | 默认上限 |
|---|---|
| 规则深度 | 64 |
| 规则节点 | 4096 |
| 执行步骤 | 10000 |
| Trace 节点 | 4096 |
| 文本预览字符 | 256 |
moon fmt --check
moon check --deny-warn
moon test --target native
moon test --target wasm-gc
moon build --target native
moon build --target wasm-gcpub(all) struct Diagnostic {
code : String
severity : DiagnosticSeverity
rule_path : String
message : String
suggestion : String
} derive(Eq, Debug)pub(all) struct EvaluationReport {
decision : Decision
trace : TraceNode
stats : ExecutionStats
} derive(Eq, Debug)pub(all) struct TraceNode {
rule_path : String
operator : String
status : TraceStatus
resolved_inputs : Array[ResolvedInput]
result : Json?
message : String
children : Array[TraceNode]
} derive(Eq, Debug)fn evaluate(rule : RuleDocument, data : Json, budget : Budget, trace_mode? : TraceMode) -> EvaluationReportfn evaluate_condition(condition : Expr, data : Json, budget : Budget, trace_mode? : TraceMode) -> EvaluationReportfn evaluate_json(rule_source : String, data_source : String, budget? : Budget, trace_mode? : TraceMode) -> Result[EvaluationReport, String]Install
Download zipExplainable and budget-limited JSON business rules for MoonBit