5.2.0 • Published 8 years ago

base-domain v5.2.0

Weekly downloads
41
License
MIT
Repository
github
Last release
8 years ago

Circle CI

Stories in Progress(https://badge.waffle.io/CureApp/base-domain.png?label=In%20Progress&title=In Progress)

base-domain

framework for Domain-Driven Design in JavaScript (or CoffeeScript, recommended.)

latest API documentation Page

installation

$ npm install -g base-domain

concept

base-domain helps easier practice of Domain-Driven Design.

  1. list models in the domain of your concern (by your own way)
  2. define models with base-domain
  3. define their factories with base-domain
  4. define their repositories with base-domain
  5. define services with base-domain if needed

essential classes and relations

  • Base
  • Facade
  • BaseModel
  • BaseFactory
  • BaseRepository
  • BaseService
  • Entity
  • AggregateRoot
  • ValueObject
  • BaseList
  • BaseDict

class relations

Base

API Doc

  • Base is an origin of all classes
  • Base has Facade
  • Base does not have any other properties or methods

Facade

API Doc

  • Facade is the gate of all classes
  • Facade knows all classes
  • Facade is module-exported in base-domain: require('base-domain') returns Facade class

BaseModel

API Doc

  • BaseModel is a base class of model
  • essential methods for model are defined
  • BaseModel is a child of Base

BaseFactory

API Doc

  • BaseFactory is a base class of factory
  • BaseFactory creates specific BaseModel instance
  • BaseFactory is a child of Base

BaseRepository

API Doc

  • BaseRepository is a base class of repository
  • BaseRepository connects to database, filesystem or other external data resources (settings needed).
  • BaseRepository saves specific BaseModel to data resources
  • BaseRepository read BaseModels from data resources
  • BaseRepository has BaseFactory (to generate BaseModel from data resources)

ValueObject

API Doc

  • ValueObject is child of BaseModel
  • instance of ValueObject does not have id
  • ValueObject.isEntity is false
  • that's all of ValueObject

Entity

API Doc

  • Entity is child of BaseModel
  • instance of Entity has id
  • Entity.isEntity is true

AggregateRoot

API Doc

  • AggregateRoot is child of Entity
  • AggregateRoot implements RootInterface, thus it can create other models, factories and repositories.

BaseList

API Doc

  • BaseList is child of ValueObject
  • BaseList has many BaseModels as items
  • BaseList#items is array of specific BaseModel

BaseDict

API Doc

  • BaseDict is child of ValueObject
  • BaseDict has many BaseModels as items
  • BaseDict#items is dictionary of key => specific BaseModel
  • BaseDict.key is function to get key from item

usage

model definition

model is classified into "Entity" and "ValueObject"

Entity is model with id, ValueObject is model without id.

# {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 'doctor-list'
        flags        : @TYPES.MODEL 'flag-dict'
        state        : @TYPES.ENUM ['PREPARED', 'RUNNING', 'CLOSED']

module.exports = Hospital

properties definition

@TYPES.XXX is an object and also a function.

    @properties:
        aaa: @TYPES.STRING
        bbb: @TYPES.NUMBER 3
        ccc: @TYPES.MODEL 'foo-bar'
markproperty typemeaningarg1arg2
x@TYPES.ANYprop accepts any typedefault value
x@TYPES.STRINGprop is stringdefault value
x@TYPES.NUMBERprop is numberdefault value
x@TYPES.DATEprop is datedefault value
x@TYPES.BOOLEANprop is booleandefault value
x@TYPES.ARRAYprop is arraydefault value
x@TYPES.OBJECTprop is objectdefault value
x@TYPES.BUFFERprop is bufferdefault value
x@TYPES.GEOPOINTprop is geopointdefault value
o@TYPES.CREATED_ATdate set when first saveddefault value
o@TYPES.UPDATED_ATdate set each time saveddefault value
o@TYPES.MODELprop is BaseModelmodel nameid prop name (if model is Entity)
o@TYPES.ENUMprop is index of the alternativesalternativesdefault value

Types with marked "x" just provide the name of the type. base-domain does not validate the prop's type.

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.query(where: name: 'CureApp Hp.').then (hospitals)->
    console.log hospitals

list definition

# {domain-dir}/hospital-list.coffee
class HospitalList extends require('base-domain').BaseList

    @itemModelName: 'hospital'

module.exports = HospitalList

dict definition

# {domain-dir}/hospital-dict.coffee
class HospitalDict extends require('base-domain').BaseDict

    @itemModelName: 'hospital'
    @key: (item) -> item.id

module.exports = HospitalDict
5.2.0

8 years ago

5.1.9

8 years ago

5.1.8

8 years ago

5.1.7

8 years ago

5.1.6

9 years ago

5.1.5

9 years ago

5.1.4

9 years ago

5.1.3

9 years ago

5.1.2

9 years ago

5.1.1

9 years ago

5.1.0

9 years ago

5.0.5

9 years ago

4.7.7

9 years ago

5.0.4

9 years ago

5.0.3

9 years ago

4.7.6

9 years ago

5.0.2

9 years ago

5.0.1

9 years ago

5.0.0

9 years ago

4.7.5

9 years ago

4.7.4

9 years ago

4.7.3

9 years ago

4.7.2

9 years ago

4.7.1

9 years ago

4.7.0

9 years ago

4.6.1

9 years ago

4.6.0

9 years ago

4.5.4

9 years ago

4.5.3

9 years ago

4.5.2

9 years ago

4.5.1

9 years ago

4.5.0

9 years ago

4.4.2

9 years ago

4.4.1

9 years ago

4.4.0

9 years ago

4.3.7

9 years ago

4.3.6

9 years ago

4.3.5

9 years ago

4.3.4

9 years ago

4.3.3

9 years ago

4.3.2

9 years ago

4.3.1

9 years ago

4.3.0

9 years ago

4.2.1

9 years ago

4.2.0

9 years ago

4.1.3

9 years ago

4.1.2

9 years ago

4.1.1

9 years ago

4.1.0

9 years ago

4.0.0

9 years ago

3.8.0

9 years ago

3.7.0

10 years ago

3.6.5

10 years ago

3.6.4

10 years ago

3.6.3

10 years ago

3.6.2

10 years ago

3.6.1

10 years ago

3.6.0

10 years ago

3.5.0

10 years ago

3.4.3

10 years ago

3.4.2

10 years ago

3.4.1

10 years ago

3.4.0

10 years ago

3.3.2

10 years ago

3.3.1

10 years ago

3.3.0

10 years ago

3.2.0

10 years ago

3.1.4

10 years ago

3.1.3

10 years ago

3.1.2

10 years ago

3.1.1

10 years ago

3.1.0

10 years ago

3.0.4

10 years ago

3.0.3

10 years ago

3.0.2

10 years ago

3.0.1

10 years ago

3.0.0

10 years ago

2.2.0

10 years ago

2.1.4

10 years ago

2.1.3

10 years ago

2.1.2

10 years ago

2.1.1

10 years ago

2.1.0

10 years ago

1.9.6

10 years ago

1.9.5

10 years ago

1.9.4

10 years ago

1.9.3

10 years ago

1.10.0

10 years ago

1.9.2

10 years ago

1.9.1

10 years ago

1.9.0

10 years ago

1.8.7

10 years ago

1.8.6

10 years ago

1.8.5

10 years ago

1.8.4

10 years ago

1.8.3

10 years ago

1.8.2

10 years ago

1.8.1

10 years ago

1.8.0

10 years ago

1.7.3

10 years ago

1.7.2

10 years ago

1.7.1

10 years ago

1.7.0

10 years ago

1.6.0

10 years ago

1.5.4

10 years ago

1.5.3

10 years ago

1.5.2

10 years ago

1.5.1

10 years ago

1.5.0

10 years ago

1.4.2

10 years ago

1.4.1

10 years ago

1.4.0

10 years ago

1.3.0

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.7

10 years ago

1.1.6

10 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.7.4

10 years ago

0.7.3

10 years ago

0.7.2

10 years ago

0.7.1

10 years ago

0.6.3

10 years ago

0.6.2

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.4

10 years ago

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.9

10 years ago

0.3.8

10 years ago

0.3.7

10 years ago

0.3.5

10 years ago

0.3.4

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.1.14

10 years ago

0.1.13

10 years ago

0.1.12

10 years ago