Socket
Book a DemoInstallSign in
Socket

ilorm-plugin-depreciation

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ilorm-plugin-depreciation

Plugin to handle depreciation of field with ilorm

0.1.1
latest
npmnpm
Version published
Maintainers
1
Created
Source

ilorm-plugin-depreciation

Depreciation

Sometimes you schema evolve, and you want to soft change your data from the old schema to the new one.

Fonctionnalities

Call event handler when you try to write or read an depreciated field

const schema = schema.new({
  firstName: schema.String().required(),
  first_name: schema.String().depreciated({
    onRead: () => throw new Error('Use depreciated field'),
    onWrite: () => throw new Error('Use depreciated field'),
  }),
});

### Migrate old field to the new one :

const schema = schema.new({
  firstName: schema.String().required(),
  first_name: schema.String().depreciated({
    newField: 'firstName'
  }),
});


// After ;
user.first_name = 'guillaume';

// user.firstName will have guillaume as value

Declare old field based on the new one :

const schema = schema.new({
  firstName: schema.String().required(),
  first_name: schema.String().depreciated({
    newField: 'firstName'
  }),
});

// After ;
user.firstName = 'guillaume';

// user.first_name will have guillaume as value

Change how to store the data

const schema = schema.new({
  firstName: schema.String().required(),
  lastName: schema.String().required(),
  name: schema.String().depreciated({
    onWrite: (instance, value) => {
      const [firstName, lastName] = value.split(' ');
      
      instance.firstName = firstName;
      instance.lastName = lastName;
    },
  }),
});

// After :
user.name = 'Guillaume Daix';

// user.firstName = 'Guillaume' && user.lastName = 'Daix'

API

Add in every schema field a depreciated command with these parameters.

  • {String} newField : bind the the old field with the new one.
  • {Function(instance, oldFieldValue)} onWrite: The function will be called everytime the field is write.
  • {Function(instance, oldFieldValue)} onRead: The function will be called everytime the field is read.

Keywords

plugin

FAQs

Package last updated on 05 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.