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

Model constraints for CADL #505

Open
1 of 3 tasks
mrkmarron opened this issue Sep 1, 2022 · 1 comment
Open
1 of 3 tasks

Model constraints for CADL #505

mrkmarron opened this issue Sep 1, 2022 · 1 comment

Comments

@mrkmarron
Copy link
Contributor

mrkmarron commented Sep 1, 2022

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.
@mrkmarron
Copy link
Contributor Author

Proof-of-concept cadl work here:
https://github.com/mrkmarron/cadl/tree/bsqemit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant