Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contract declaration #48

Open
minenwerfer opened this issue Nov 25, 2024 · 0 comments
Open

Add contract declaration #48

minenwerfer opened this issue Nov 25, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@minenwerfer
Copy link
Contributor

minenwerfer commented Nov 25, 2024

Contracts are DTOs plus access control directives: https://github.com/aeria-org/aeria/blob/9c98734bc5d89831d9fce8980abc4a9fa870601f/packages/types/src/contract.ts#L20

Simplest form:

contract Test {
  roles {
    root
    customer
  }
  query {
    properties {
      name str
    }
  }
}

Outputs:

export const test = defineContract({
  roles: [
    'root',
    'customer',
  ],
  query: {
    type: 'object',
    properties: {
      name: {
        type: 'string',
      },
    },
  },
})

With unions:

contract Test {
  roles {
    root
    customer
  }
  // inspired by TypeScript union syntax
  query
    | {
      properties {
        type const @value("by_name")
        name str
      }
    }
    | {
      properties {
        val const @value("by_age")
        age int
      }
    }
}

Outputs:

export const test = defineContract({
  roles: [
    'root',
    'customer',
  ],
  query: [
    {
      type: 'object',
      properties: {
        type: { const: 'by_name', },
        name: { type: 'string', },
      },
    },
    {
      type: 'object',
      properties: {
        type: { const: 'by_age', },
        age: { type: 'integer', },
      },
    },
  ],
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant