API Docs for:
Show:

BaseModel Class

Base model class of DDD pattern.

Methods

$include

(
  • [options]
)
Promise(BaseModel)

include all relational models and returns new model

Parameters:

  • [options] Object optional
    • [async=true] Boolean optional

      get async values

    • [props] Array(String) optional

      include only given props

Returns:

Promise(BaseModel):

new model

$set

() BaseModel

set value to prop and create a new model

Returns:

BaseModel:

this

$unset

(
  • prop
)
BaseModel

unset property and create a new model

Parameters:

  • prop String

    property name

Returns:

BaseModel:

this

clone

() BaseModel public

create clone

Returns:

copyWith

() BaseModel

shallow copy the model with props

Returns:

deprecated

(
  • methodName
  • message
)
Error protected

Show indication message of deprecated method

Parameters:

  • methodName String
  • message String

Returns:

Error:

diff

(
  • plainObj
)
Array(String) public

Get difference props

Parameters:

  • plainObj Any

Returns:

Array(String):

diff

(
  • plainObj
  • [options]
)
Array(String) public

Get diff props

Parameters:

  • plainObj Any
  • [options] Object optional
    • [ignores] Array(String) optional

      prop names to skip checking diff

Returns:

Array(String):

enum

() Object public

Returns:

Object:

enum

() Object(key: String => Number) public

Returns:

Object(key: String => Number):

equals

(
  • model
)
Boolean

check equality

Parameters:

Returns:

Boolean:

error

(
  • reason
  • [message]
)
Error

create instance of DomainError

Parameters:

  • reason String

    reason of the error

  • [message] String optional

Returns:

Error:

getDiff

(
  • plainObj
  • [options]
)
Object public

Get diff prop values

Parameters:

  • plainObj Any
  • [options] Object optional
    • [ignores] Array(String) optional

      prop names to skip checking diff

Returns:

Object:

getFacade

() Facade deprecated

Inherited from Base: /home/ubuntu/base-domain/src/lib/base.coffee:81

Deprecated: just use this.facade

Get facade

Returns:

getModelProps

() ModelProps private

Returns:

getModule

() BaseModule

Get module which this class belongs to

Returns:

getParent

() Function

get parent class

Returns:

Function:

include

(
  • [options]
)
Promise(BaseModel)

include all relational models if not set

Parameters:

  • [options] Object optional
    • [async=true] Boolean optional

      get async values

    • [props] Array(String) optional

      include only given props

Returns:

Promise(BaseModel):

self

included

() Boolean

Check if all subentities are included.

Returns:

Boolean:

inherit

(
  • anotherModel
)
BaseModel

inherit value of anotherModel

Parameters:

Returns:

BaseModel:

this

plainClone

() Object public

clone the model as a plain object

Returns:

Object:

setEnum

(
  • prop
  • value
)
private

set enum value

Parameters:

  • prop String
  • value String | Number

setRoot

() protected

toPlainObject

() Object

create plain object without relational entities descendants of Entity are removed, but not descendants of BaseModel descendants of Entity in descendants of BaseModel are removed ( = recursive)

Returns:

Object:

plainObject

unset

(
  • prop
)
BaseModel

unset property

Parameters:

  • prop String

    property name

Returns:

BaseModel:

this

withParentProps

() Object protected static

extend @properties of Parent class

Returns:

Object:

Example:

class Parent extends BaseModel

Properties

isImmutable

Boolean static

Flag of the model's immutablity

properties

Object protected static

key-value pair representing property's name - type of the model

firstName    : @TYPES.STRING
lastName     : @TYPES.STRING
age          : @TYPES.NUMBER
registeredAt : @TYPES.DATE
team         : @TYPES.MODEL 'team'
hobbies      : @TYPES.MODEL 'hobby-list'
info         : @TYPES.ANY

see type-info.coffee for full options.

TYPES

Object protected final static

key-value pair representing typeName - type

use for definition of @properties for each extender