https://github.com/uber5/u5-domain
https://github.com/uber5/u5-domain
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/uber5/u5-domain
- Owner: Uber5
- Created: 2016-07-05T20:49:36.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-15T15:52:33.000Z (almost 10 years ago)
- Last Synced: 2025-01-06T19:19:38.618Z (over 1 year ago)
- Language: JavaScript
- Size: 31.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# What?
The idea is to describe a domain (classes, their properties and relationships)
for a business application, so that other artefacts can be deduced from it.
This is probably not going to be a generic tool, but may be useful in our
context / on our stack.
The aspects we try to cover here:
- persistence
- API
- validation
# Example
Say, we need orders and order items in our domain model. We may describe the
domain model as follows:
```
const orderType = new DomainType({
name: 'Order',
fields: {
id: DomainID,
orderedByName: { type: DomainString, required: true },
orderedByEmail: {
type: DomainString,
validate: v => /\S+@\S+\.\S+/.test(v) // TODO: don't validate email addresses like this in real life
}
tipInCents: DomainInt
},
belongsTo: {
shop: 'Shop'
}
})
// TODO: complete the example
const domainSchema = new DomainSchema([ orderType, shopType ])
import * as graphql from 'graphql'
const graphQLOrderType = domain.toGraphQLSchema(graphql, domainSchema)
```