JSPM

  • Created
  • Published
  • Downloads 1091
  • Score
    100M100P100Q91740F
  • License MIT

simple module to help build Domain-Driven Design

Package Exports

  • base-domain
  • base-domain/ify

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (base-domain) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

base-domain

simple module to help build Domain-Driven Design"

latest API documentation Page

concept

installation

$ npm install -g base-domain

usage

generate base file

MODEL_NAME='foo-bar'
DIR_NAME='.'
$ base-domain $MODEL_NAME $DIR_NAME
  • ./foo-bar.coffee
  • ./foo-bar-factory.coffee
  • ./foo-bar-repository.coffee

are generated.

  • foo-bar.coffee defines and exports class FooBar extends Entity
  • foo-bar-factory.coffee defines and exports class FooBarFactory extends BaseFactory
  • foo-bar-repository.coffee defines and exports class FooBarRepository extends BaseRepository

model definition

# {domain-dir}/hospital.coffee
class Hospital extends require('base-domain').Entity

    # property types
    @properties:
        name         : @TYPES.STRING
        address      : @TYPES.STRING
        beds         : @TYPES.NUMBER
        registeredAt : @TYPES.DATE
        isValidated  : @TYPES.BOOLEAN
        doctors      : @TYPES.MODEL_LIST 'doctor'

module.exports = Hospital

factory definition

# {domain-dir}/hospital-factory.coffee
class HospitalFactory extends require('base-domain').BaseFactory

    @modelName: 'hospital'

module.exports = HospitalFactory

repository definition

# {domain-dir}/hospital-repository.coffee
class HospitalRepository extends require('base-domain').BaseRepository

    @modelName: 'hospital'

module.exports = HospitalRepository

use them by facade

domain = require('base-domain').createInstance
    dirname: '/path/to/domain-dir'


Hospital = domain.getModel('hospital')
hospitalFactory = domain.createFactory('hospital')
hospitalRepository = domain.createRepository('hospital')

hosp = hospitalFactory.createFromObject(name: 'Suzuki Clinic')


hospitalRepository.find(where: name: 'CureApp Hp.').then (hospitals)->
    console.log hospitals

use in browser with browserify

browserify is a tool for packing a js project into one file for web browsers

to enable base-domain's requiring system in browsers, use 'base-domain/ify' transformer.

browserify -t [ base-domain/ify --dirname /path/to/domain/dir ] <entry-file>

API documentations