statize

0.0.2 • Public • Published

Statize

statize sequelize models

Install

npm install

Build

npm run build

Run tests

npm run test

Usage

// initialize along with model definition
class Matter extends Model {
  async onMelt() {
    console.log('i am melting');
  }
}

Matter.init({
  name: DataTypes.STRING,
  state: DataTypes.STRING,
}, {sequelize, modelName: 'matter'})

Statize.model(Matter, {
  field: 'state',
  init: 'solid',
  transitions: [
    { name: 'melt',     from: 'solid',  to: 'liquid' },
    { name: 'freeze',   from: 'liquid', to: 'solid'  },
    { name: 'vaporize', from: 'liquid', to: 'gas'    },
    { name: 'condense', from: 'gas',    to: 'liquid' }
  ]
});

// use like so
const iron = await Matter.create({
  name: 'iron',
});

console.log(iron.state) // solid (default as configured)

// this saves the iron
await iron.melt();

console.log(iron.state) // liquid

// can also change other properties before state change
iron.name = 'iron vapour'

await iron.vapourize();

console.log(iron.state) // gas
console.log(iron.name) // iron vapour

Package Sidebar

Install

npm i statize

Weekly Downloads

0

Version

0.0.2

License

ISC

Unpacked Size

5.22 kB

Total Files

3

Last publish

Collaborators

  • nean