Portable JSONLogic evaluation, scoped analysis, batch execution and native QueryX integration
Dependencies
moon update
npm ci
npm run build:browser
npm run serve:browserJSONLogic 规则 + JSON 数据
→ MoonBit JSONLogic 求值库
→ 业务结果、日志或结构化错误存量 JSONLogic 筛选规则 + 服务端字段与类型约束
→ 导入与语义检查
→ QueryX Expr
→ 复用 foxql 生成参数化 SQL
→ 数据库返回匹配记录moon update
npm ci --prefix tools/queryx-fixtures
node tools/queryx-fixtures/generate.mjs --check
python3 tools/check_queryx.py| 部分 | 用途 |
|---|---|
| src/ | JSONLogic 求值库;供应用安装与调用 |
| src/queryx/ | native JSONLogic 筛选规则导入与记录校验 |
| src/analysis/、src/batch/ | 作用域/依赖分析与带预算的规则集执行 |
| src/cli/ | native JSON 批量请求 CLI |
| src/interop/、sdk/ | 编译导出、JS/Wasm GC 加载器及 TypeScript 声明 |
| examples/browser/ | 真实 Form.io 表单与浏览器演示 |
| src/examples/queryx/ | 调用实际 QueryX/foxql 的 native 接入程序 |
| compat/、tools/、tests/ | 与原版 JavaScript 对照的回归验证;不进入应用运行路径 |
| docs/queryx-integration.md | 查询接入约定、复现方法和扩展范围 |
| 工具 | 已有能力 | 本项目的补充方向 |
|---|---|---|
| QueryX | 自定义 JSON 筛选格式、表达式求值、字段解析和 foxql 桥接 | 将标准 JSONLogic 的受约束筛选子集导入其现有 Expr |
| foxql | SQL 查询构建 | 复用其 SQL 输出,提供 JSONLogic 导入与语义拒绝报告 |
| mbel、moon_cel 等表达式库 | 使用其他表达式或规则标准,具备相似的规则求值用途 | 直接接受 JSONLogic 规则对象,按其 truthiness、类型转换、短路和集合作用域执行,并给出固定版本语义对照 |
| json-logic-js | 在 JavaScript 中执行 JSONLogic | 已实现 MoonBit 求值与固定版本对照,并作为查询接入的独立参考 |
{"and": [
{">=": [{"var": "age"}, 18]},
{"==": [{"var": "country"}, "CN"]}
]}git clone https://github.com/kaigeliang/moonbit-jsonlogic.git
cd moonbit-jsonlogic
moon update
moon run src/examples/form --target native
moon run src/examples/order --target js
moon run src/examples/filter --target wasm-gc{"show_company":true,"missing_required":["company"]}
{"subtotal":110,"discount_percent":10}
["Ming"]moon add kaigeliang/jsonlogic@0.2.1import { "kaigeliang/jsonlogic@0.2.1" }members = [".", "../moonbit-jsonlogic"]import { "kaigeliang/jsonlogic" @logic }fn main raise {
let rule : Json = { ">=": [{ "var": "age" }, 18] }
let result = @logic.apply(rule, { "age": 22 })
assert_eq(result, true)
}| 类别 | 操作 |
|---|---|
| 数据 | var、missing、missing_some |
| 条件 | if、?:、and、or、!、!! |
| 比较 | ==、!=、===、!==、>、>=、<、<= |
| 数值 | +、-、*、/、%、min、max |
| 字符串与集合 | cat、substr、in、merge、map、filter、reduce、all、some、none |
| 调试 | log(捕获到返回值) |
moon test --target native
python3 tools/check_compat.pysrc/ JSONLogic 运行库与单元测试
src/queryx/ native 筛选规则接入适配器与单元测试
src/analysis/ 全分支静态分析、作用域与字段依赖
src/batch/、src/cli/ 带预算的规则集 API 与 native CLI
src/interop/、sdk/ JS/Wasm GC JSON ABI、加载器与类型声明
examples/browser/ Form.io 实际表单演示
src/examples/ 基础求值示例与 native 查询接入程序
compat/ 跨实现、跨后端的验证程序
tests/ 边界输入 fixtures
tools/ 原版执行器、fixture 生成器、兼容性检查
third_party/ 固定版本的原版 JS、官方测试与许可证
docs/ 基础 API、兼容性说明与查询接入约定npm ci
npm run check:types
npm run build:sdk
npm run check:sdk
npm run check:formio
npm run bundle:sdk
npm run check:bundle
npm run build:browser
npx --no-install playwright install chromium
npm run check:browser
python3 -m unittest discover -s tests -p 'test_*.py' -vpub(all) suberror LogicError {
InvalidRule(String, String)
LimitExceeded(String)
NonFiniteNumber(String)
InvalidInput(String)
}fn evaluate(rule : Json, data : Json, max_steps? : Int, max_depth? : Int) -> Evaluation raise LogicErrorInstall
Download zipPortable JSONLogic evaluation, scoped analysis, batch execution and native QueryX integration
Dependencies