npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

base-domain

v5.2.0

Published

simple module to help build Domain-Driven Design

Downloads

2,140

Readme

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'

mark | property type | meaning | arg1 | arg2 -----|-------------------|------------------------------|-----------------|----------------------------------- x | @TYPES.ANY | prop accepts any type | default value | x | @TYPES.STRING | prop is string | default value | x | @TYPES.NUMBER | prop is number | default value | x | @TYPES.DATE | prop is date | default value | x | @TYPES.BOOLEAN | prop is boolean | default value | x | @TYPES.ARRAY | prop is array | default value | x | @TYPES.OBJECT | prop is object | default value | x | @TYPES.BUFFER | prop is buffer | default value | x | @TYPES.GEOPOINT | prop is geopoint | default value | o | @TYPES.CREATED_AT | date set when first saved | default value | o | @TYPES.UPDATED_AT | date set each time saved | default value | o | @TYPES.MODEL | prop is BaseModel | model name | id prop name (if model is Entity) o | @TYPES.ENUM | prop is index of the alternatives | alternatives | default 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