https://github.com/sysgears/domain-schema
Domain Driven Design Schema for JavaScript
https://github.com/sysgears/domain-schema
domain-driven-design javascript schema typescript
Last synced: about 1 year ago
JSON representation
Domain Driven Design Schema for JavaScript
- Host: GitHub
- URL: https://github.com/sysgears/domain-schema
- Owner: sysgears
- License: mit
- Created: 2017-11-01T16:13:18.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-26T16:49:25.000Z (almost 7 years ago)
- Last Synced: 2025-04-07T01:04:02.554Z (about 1 year ago)
- Topics: domain-driven-design, javascript, schema, typescript
- Language: JavaScript
- Size: 34.9 MB
- Stars: 22
- Watchers: 17
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Domain Schema
[](https://twitter.com/sysgears)
Domain Schema is a set of packages that let you design your application using Domain Driven Design Principles.
You create your schemas with any fields your application needs.
Then use them as a single source of truth in the application to generate database schemas, forms, GraphQL types, etc.
Domain Schema set of packages try to help you with this task, not stay on your way, by imposing minimal limitations on the shape
of your domain schemas, not the fields and the meaning you can use.
Example Domain Schema using ES6 syntax:
```js
class AuthCertificate extends Schema {
__ = { name: 'AuthCertificate' };
serial = {
type: String,
unique: true
};
}
class AuthFacebook extends Schema {
__ = { name: 'AuthFacebook' };
fbId = {
type: String,
unique: true
};
displayName = {
type: String,
optional: true
};
}
class UserProfile extends Schema {
__ = { name: 'UserProfile' };
firstName = {
type: String,
optional: true
};
lastName = {
type: String,
optional: true
};
fullName = {
type: String,
optional: true,
transient: true
};
notes = [String];
}
class UserAuth extends Schema {
__ = { name: 'UserAuth', transient: true };
certificate = {
type: AuthCertificate,
optional: true
};
facebook = {
type: AuthFacebook,
optional: true
};
}
export const User = new DomainSchema(
class User extends Schema {
__ = { name: 'User' };
id = DomainSchema.Integer;
username = {
type: String,
unique: true
};
email = {
type: String,
unique: true
};
password = {
type: String,
private: true
};
role = {
type: String,
default: 'user'
};
isActive = {
type: Boolean,
default: false,
optional: true
};
auth = {
type: [UserAuth],
optional: true
};
profile = {
type: [UserProfile],
optional: true
};
}
);
```
Example cyclic Domain Schema definition
```js
class Product extends Schema {
__ = { name: 'Product' };
id = DomainSchema.Integer;
name = String;
category = Category;
}
class Category extends Schema {
__ = { name: 'Category' };
public id = DomainSchema.Integer;
name = String;
products = [Product];
}
const ProductSchema = new DomainSchema(Product);
```
Such cyclic dependencies must be contained in one file.
## Contributors
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
## License
Copyright © 2017 [SysGears INC]. This source code is licensed under the [MIT] license.
[MIT]: LICENSE
[SysGears INC]: http://sysgears.com