Package Exports
- base-domain
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"
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.MODELS '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