Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Model constraints for CADL #505

@mrkmarron

Description

@mrkmarron

Issue #961 in the CADL repository discusses the utility of Bosque style data constraints. It would be great to have support from the Bosque side to allow these constraints to be specified in Bosque as well as in the CADL expression language. E.g. allow:

function accountValidator(balance: Int, kind: AccountKind, owners: List<AccountOwner>): Bool {
    if (owners.empty()) {
        return false;
    }
    elif (owners.size() == 1n) {
        return kind === AccountKind::single;
    }
    else { 
        if (!owners.unique(pred(a, b) => a.name !== b.name)) {
            return false;
        }

        return kind === AccountKind::joint;
    }
}
...
ensure ${accountValidator}[./validators/account.bsq]

for more complex validation logic in addition to:

ensure if (kind == "joint") { owners.length > 1 }

from #961.

Key wins here would be:

  1. CADL specs can use the full expressive power of Bosque and trivially handle the no side-effect requirement.
  2. We get the CADL -- structured input fuzzing/solving, semantic version checking, and auto-mock generation -- features for free!

This is a longer term project and requires collaboration with CADL:

  • Emitter from CADL types to Bosque types. Most should be simple but there are probably some tricky bits around "open types" and splatting.
  • Convention or configuration for running validation logic. Do we provide a AOT binary or maybe the first step is Morphir integration?
  • Workflow integration for fuzzing, version checking, version diffing, and mock-generation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions