Skip to content
Domain Driven Design Schema for JavaScript
JavaScript TypeScript
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.yarn Switch to yarn v2 Jul 26, 2019
packages Switch to yarn v2 Jul 26, 2019
tssdk Switch to yarn v2 Jul 26, 2019
.gitignore Ignore .npmrc Jun 7, 2018
.huskyrc Enable yarn v2 support in Husky Jul 26, 2019
.pnp.js Switch to yarn v2 Jul 26, 2019
.travis.yml Add first test to domain-knex Nov 9, 2017
.yarnrc.yml Switch to yarn v2 Jul 26, 2019
LICENSE Initial commit Nov 1, 2017
README.md Update root README.md Feb 8, 2018
babel.config.js Switch to yarn v2 Jul 26, 2019
jest.config.js Switch to yarn v2 Jul 26, 2019
lerna.json v0.0.19 Feb 8, 2018
package.json Enable yarn v2 support in Husky Jul 26, 2019
tsconfig.json Switch to yarn v2 Jul 26, 2019
tslint.json Fix source code Jun 4, 2019
yarn.lock Switch to yarn v2 Jul 26, 2019

README.md

Domain Schema

Twitter Follow

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:

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

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):

This project follows the all-contributors specification. Contributions of any kind welcome!

License

Copyright © 2017 SysGears INC. This source code is licensed under the MIT license.

You can’t perform that action at this time.