depreciator

versioning for object function arguments

Depreciator versioning support for data argument

Sometimes a it is nice to know which version of data a function is passed. Especially in NoSQL land it can be used to ensure some kind of schema, and handle changes transparently.

Todo this Depreciator assumes that the data contains a numeric version under the key __version

{ __version: 1, something: 'else', can: 'be here' }

This version is checked against the ensured, and actions can be take for it. No version present assumes a 0.

For depreciator to hook the functions it need to be required and enabled for a given module

var depreciator = require('depreciator')
 
var myThing = {
  myFuncfunction(thingparamstuff) {
    doGreatThings(thing, param, stuff)
  },
  funcfunction(thingstuff) {
    doAwesomeStuff(thing, stuff)
  }
}
 
module.exports = depreciator.enable(myThing)

Now versions can be ensured on the functions, it will check the first argument to the function for it's __version field.

ensure version for just this function

depreciator.ensure(2, 'myFunc')

ensure version globally for every function in the module it is enabled for.

depreciator.ensure(1)

ensure version for just this function and call fallback if versions don't match

version.ensure(3, 'func', function(thingversionexpectedVersion) {
  console.log("you are old")
})

install a global fallback function to be called on version missmatch

version.ensure(1, function(thingversionexpected) {
  console.log("OLD!!!")
})

register hook for when versions are not satisfied hooks are run before the function is called

version.registerMismatchHook(function(thingversionexpected) {
  console.log("OLD!!!")
})

MIT