狒狒:具有自动演化和无标签二进制编解码器的建模数据
Baboon: Data Modeling with Automatic Evolutions and tagless binary codecs

原始链接: https://github.com/7mind/baboon

狒狒是一种数据建模语言(DML)和编译器,专注于创建健壮且可演化的数据模式。它采用声明式方法,为JSON和自定义二进制格式(UEBA)生成代码(目前为C#和Scala),并自动推导编解码器。 主要特性包括基于集合的继承、命名空间、集合和基本类型。编译器设计为多阶段DAG转换,以实现可维护性,并优先进行代码去重以减小二进制文件的大小。 虽然功能强大,但狒狒目前存在一些限制:名义继承基于特征(trait),泛型支持仅限于内置集合,并且不支持诸如注释和新类型等功能(但未来改进的可能性已记录在案)。 用户负责处理“外部类型”(非狒狒定义的类型)并确保正确的编解码器连接。该项目使用mudyla进行构建编排,并提供用于格式化、构建、测试和创建分发包的命令。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Baboon: 具有自动演化和无标签二进制编解码器的数据建模 (github.com/7mind) 7 分,pshirshov 1小时前 | 隐藏 | 过去 | 收藏 | 1 条评论 SubiculumCode 11 分钟前 [–] 我不明白这是什么。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

Build Status License Latest Release IntelliJ Plugin VSCode Extension Nix Nix Flake

Let the Baboon do the monkey job.

Baboon is a minimal Data Modeling Language and compiler that provides ergonomic, declarative schemas and enforces reliable schema evolution. The compiler runs as a fast immutable multi-phase DAG transform, and is easy to understand and maintain.

  • Set-based structural inheritance with +, -, and ^ operators
  • Automatic codec derivation for JSON and UEBA (Ultra-Efficient Binary Aggregate, a custom tagless binary format)
  • Evolution-aware codegen: derives migrations when possible, emits stubs when manual work is required
  • Structural and nominal inheritance (contracts)
  • Namespaces, includes, and imports
  • Collections (opt, lst, set, map) and timestamps/UID primitives
  • Codegen targets: C#, Scala, will be more.
  • Deduplicated C# output (reuse as much code as possible for lower binary footprint)

Detailed language walkthrough with copy-paste examples: docs/language-features.md.

  1. No templates
  2. Only Enums, DTOs and ADTs
  3. Nominal inheritance support is limited to trait model
  4. Generic/type constructor support is limited to builtin collections
  5. (*) This is a DML, not an IDL, service/interface definitions support is extremely limited at the moment
  6. (*) Comments are not preserved in the cogen output
  7. (*) No structural inheritance information is preserved in the transpiler output
  8. (*) Only integer constants may be associated with enum members
  9. (*) No newtypes/type aliases
  10. (*) No inheritance-based lenses/projections/conversions

Points marked with (*) will/may be improved in the future.

See build configuration in .mdl/defs/actions.md and test configuration in .mdl/defs/tests.md.

  1. All the types which are not transitively referenced by root types will be eliminated from the compiler output.
  2. Usages in structural inheritance are not considered references, so structural parents which are not directly referenced as fields and not marked as roots will be eliminated

Be careful about foreign types. It is your responsibility to wire codecs correctly.

For every foreign type:

  1. Create a custom codec
  2. Override the generated dummy codec with BaboonCodecs#Register
  3. Override the generated dummy codec using the setter on ${Foreign_Type_Name}_UEBACodec#Instance
  4. Override the generated dummy codec using the setter on ${Foreign_Type_Name}_JsonCodec#Instance

Make sure your foreign types are NOT primitive types or other generated types. It's a funny idea, but it will explode in runtime.

Foreign types may hold any position in generics but it's up to you to ensure correctness.

This project uses mudyla for build orchestration.

# Format code
direnv exec . mdl :fmt

# Build the compiler
direnv exec . mdl :build

# Run complete test suite
direnv exec . mdl :build :test

# Run full build pipeline (format, build, test)
direnv exec . mdl :full-build

# Run specific test suites
direnv exec . mdl :build :test-gen-regular-adt :test-cs-regular :test-scala-regular
direnv exec . mdl :build :test-gen-wrapped-adt :test-cs-wrapped :test-scala-wrapped
direnv exec . mdl :build :test-gen-manual :test-gen-compat-scala :test-gen-compat-cs :test-manual-cs :test-manual-scala

# Create distribution packages
direnv exec . mdl :build :mkdist

# Build with custom distribution paths
direnv exec . mdl --mkdist-source=./custom/path --mkdist-target=./output :build :mkdist

Setting up the environment

# Enter the nix development shell
nix develop

# Or use direnv for automatic shell activation
direnv allow
联系我们 contact @ memedata.com