moonverity

    MoonBit-native data contract and quality gate toolkit for CSV and JSONL datasets.

    moonbit
    data-contract
    csv
    jsonl
    quality-gate
    Download zip
    Author
    Version
    0.1.2
    License
    Apache-2.0
    Last updated
    3 months ago
    Downloads
    62

    #MoonVerity

    MoonVerity is a MoonBit-native data contract and data quality gate toolkit for CSV and JSONL datasets. It combines executable field schemas, explicit quality rules, profile metrics, contract diffs, and CI-friendly command exits.

    #Example API

    ///|
    import {
    "Wchwch777/moonverity",
    }

    ///|
    let contract = @moonverity.parse_contract_json(contract_text)

    ///|
    let rows = @moonverity.parse_csv_text(csv_text)

    ///|
    let report = @moonverity.validate_rows_with_schema(contract, rows)

    ///|
    let summary = @moonverity.summarize_report(report)

    validate_rows remains available for callers that only want explicit rules. validate_rows_with_schema additionally checks required/nullable fields, Int/Bool/Date values, bounds, allowed values, and declared patterns.

    #Commands

    moon fmt && git diff --exit-code moon check --deny-warn --target all moon build --deny-warn --target all moon test --deny-warn --target wasm-gc python scripts/verify_benchmark.py moon run cmd/main validate examples/retail-orders/contract.json examples/retail-orders/orders-valid.csv moon run cmd/main profile examples/retail-orders/orders-valid.csv --json moon run cmd/main diff-contract examples/retail-orders/contract.json examples/retail-orders/contract_v1_1.json --json moon run cmd/main check-contract examples/retail-orders/contract.json

    The invalid fixture intentionally exits with status 1:

    moon run cmd/main validate examples/retail-orders/contract.json examples/retail-orders/orders-invalid.csv

    #Packages

    • core/: contract model, schema validation, quality rules, profiles, analysis, normalization, and contract diff
    • adapters/: CSV/JSONL parsing, row normalization, projection, and serialization
    • cli/: pure command behavior and text/JSON renderers
    • cmd/main/: process entry point and truthful exit codes
    • examples/retail-orders/: valid and invalid fixtures
    • docs/: architecture, competition requirements, runbook, and acceptance material
    • scripts/: repository compliance, CLI exit, acceptance, and proposal helpers

    The project also includes field-reference diagnostics, a deterministic quality score, a benchmark-suite API, row-shape inspection, and a 24-row reproducible retail-order fixture with an invalid variant.

    #Open-source delivery

    • Apache-2.0 license
    • Three-platform CI with full-history checkout and explicit MoonBit build
    • Generated public interfaces checked by moon info and git diff --exit-code
    • Mooncakes metadata declared in moon.mod; publish with moon publish --dry-run before the authorized release command

    BenchmarkCase

    One reproducible validation case for a benchmark or acceptance fixture.

    BenchmarkCaseResult

    The observed result of one benchmark case.

    BenchmarkSuite

    Aggregated benchmark results. passed means every expectation matched.

    ColumnProfile

    ContractIssue

    ContractReferences

    The field references used by a contract's rules.

    ContractStats

    DatasetProfile

    DatasetShape

    Structural facts about a normalized row collection.

    QualityScore

    A diagnostic quality score derived from profile completeness and validation rows. The score is a dashboard signal, not a replacement for the contract gate.

    ValidationOutcome

    ValidationReport

    ValidationSummary

    analyze_contract_references

    Analyze rule-to-field dependencies before executing a contract.

    contract_field_names

    fn contract_field_names(contract :
    Contract
    ) -> Array[String]

    contract_rule_names

    fn contract_rule_names(contract :
    Contract
    ) -> Array[String]

    contract_stats

    Return stable complexity indicators for documentation and review tooling.

    field_spec

    fn field_spec(name : String, kind? :
    FieldType
    , required? : Bool, nullable? : Bool, allowed_values? : Array[String], min_int? : Int, max_int? : Int, pattern? : String, description? : String) ->
    FieldSpec

    has_field

    fn has_field(contract :
    Contract
    , name : String) -> Bool

    inspect_contract

    Inspect a contract before running it so configuration errors are explicit.

    inspect_shape

    fn inspect_shape(rows : Array[Map[String, String]]) ->
    DatasetShape

    Inspect row shape without interpreting field values.

    normalize_contract

    Normalize user-authored contract metadata without changing its intent.

    normalize_rows

    fn normalize_rows(rows : Array[Map[String, String]]) -> Array[Map[String, String]]

    Trim keys and values so records from different input sources share one normalization policy before validation or serialization.

    parse_contract_json

    fn parse_contract_json(source : String) ->
    Contract

    parse_csv_text

    fn parse_csv_text(source : String) -> Array[Map[String, String]]

    parse_jsonl_text

    fn parse_jsonl_text(source : String) -> Array[Map[String, String]]

    profile_rows

    fn profile_rows(rows : Array[Map[String, String]]) ->
    DatasetProfile

    project_rows

    fn project_rows(rows : Array[Map[String, String]], columns : Array[String]) -> Array[Map[String, String]]

    Project records to a stable set of columns, filling missing cells with "".

    quality_score

    Calculate a deterministic score for dashboards and benchmark reports.

    read_csv_file

    fn read_csv_file(path : String) -> Array[Map[String, String]]

    read_jsonl_file

    fn read_jsonl_file(path : String) -> Array[Map[String, String]]

    render_csv

    fn render_csv(rows : Array[Map[String, String]], columns : Array[String]) -> String

    Serialize rows as RFC 4180-compatible single-line CSV records.

    render_jsonl

    fn render_jsonl(rows : Array[Map[String, String]]) -> String

    Serialize rows as JSONL with every cell represented as a JSON string.

    row_of

    fn row_of(entries : Array[(String, String)]) -> Map[String, String]

    rule_field_references

    fn rule_field_references(rule :
    Rule
    ) -> Array[String]

    Return the fields a rule reads, preserving the rule's declaration order.

    rule_summaries

    Return one compact summary item for each validation rule.

    run_benchmark_suite

    Run a deterministic suite without wall-clock timing or platform noise.

    run_contract_check_json

    fn run_contract_check_json(contract_text : String) ->
    ValidationOutcome

    run_contract_check_text

    fn run_contract_check_text(contract_text : String) ->
    ValidationOutcome

    run_diff_contract_json

    fn run_diff_contract_json(before_text : String, after_text : String) -> String

    run_diff_contract_text

    fn run_diff_contract_text(before_text : String, after_text : String) -> String

    run_profile_json

    fn run_profile_json(data_text : String, data_format : String) -> String

    run_profile_text

    fn run_profile_text(data_text : String, data_format : String) -> String

    run_validate_json

    fn run_validate_json(contract_text : String, data_text : String, data_format : String) -> String

    run_validate_text

    fn run_validate_text(contract_text : String, data_text : String, data_format : String) -> String

    summarize_report

    Summarize a report for dashboards and CI annotations.

    validate_json

    fn validate_json(contract_text : String, data_text : String, data_format : String) ->
    ValidationOutcome

    validate_rows_with_schema

    Validate field declarations in addition to the explicit contract rules.

    This opt-in entry point keeps validate_rows compatible with the original rule-only API while making the field metadata executable for applications that want a complete data-contract gate.

    validate_text

    fn validate_text(contract_text : String, data_text : String, data_format : String) ->
    ValidationOutcome

    Source Files