{"_id":"@biggillystyle/sequelize-history","_rev":"3-d52ea9d06bb66948b2ca23e606dcafc3","name":"@biggillystyle/sequelize-history","dist-tags":{"latest":"1.3.4"},"versions":{"1.3.2":{"name":"@biggillystyle/sequelize-history","description":"Creates a revision history for instances of a given Sequelize model.","author":{"name":"tyler peterson","email":"tylerjpeterson@gmail.com"},"version":"1.3.2","main":"index.js","scripts":{"coverage":"nyc npm run test","report":"istanbul report --root coverage lcov && open coverage/lcov-report/index.html","lint":"xo ./index.js || true && xo ./test/spec/test.js || true","docs":"jsdoc index.js -p -c .jsdoc.json -d docs/","test":"node test/spec/test.js | tap-spec"},"dependencies":{"lodash":"^4.17.4"},"devDependencies":{"nyc":"^14.1.1","jsdoc":"^3.5.4","sequelize":"^4.23.4","sqlite3":"^4.0.9","tap-spec":"^5.0.0","tape":"^4.10.2","xo":"^0.18.2"},"bugs":{"url":"https://github.com/tylerjpeterson/sequelize-history/issues"},"repository":{"type":"git","url":"git+https://github.com/tylerjpeterson/sequelize-history.git"},"homepage":"https://github.com/tylerjpeterson/sequelize-history","contributors":[{}],"xo":{"globals":["assert","beforeEach","describe","expect","it","module","require"]},"keywords":[],"engines":{"node":">=8.9.1"},"license":"MIT","directories":{"test":"test"},"gitHead":"3095b3d5b16972c2d6d9fc83b9c740f85b0af2db","_id":"@biggillystyle/sequelize-history@1.3.2","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-C5pFWTtunzllWddFBm/s8WrgQNwWsnA7HzhnsQ01uo0v2V7zVAPFXBRa6uO+ktExT1Qq+234sanuKl6/+8GFxA==","shasum":"c05b582a45991446010ef5b51d01a3d5ee0df62c","tarball":"https://registry.npmjs.org/@biggillystyle/sequelize-history/-/sequelize-history-1.3.2.tgz","fileCount":7,"unpackedSize":31615,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdBjRUCRA9TVsSAnZWagAA2q0QAIqCpHtEFAHEM0CHJPCG\neqHF1W77OnJti8Dx6feazBhM/jQFhcWg+198NOB3hLsaNMELkbYsavPB9Fsj\n+UlVExZJdyKKqTg7PgaddeuamlE3pYVxQr+l/1htA1QHG7NunI+X6i2ZYNvF\n57vE9w6Hn6vXGhvf4C87tpXktXL+emIhOMYXt+3JVSXIAZzaRHWUJYWL3sgK\nt0tYbCkrNRGvKJ3xR+OwERHXVCNUoyhDclB3UInK6UBCLDvH6owRyX8JPK7y\n/4d5+rdFs2LDs+/qNsrEd6bwIayUInfPOvQCNhKT8ZB6lscD/8YBjZ6WYs9G\nzMAQXUbwMkf1Hg+S8w78WaH32NhAs4xMokA8G/QUvb5Ba5fPCD5qe3CF1bHU\ntC8SzfjSmghXVwAFVDCDYLYkH6iqRC4IwK+4OWP6VgsBZpEw4cGSQG2BUgb6\nhNaKIqMI2vm3hwSE4tRWV+y8KA4VOkj2xahzABmAwRdgo1FGw9K5EWHisf5e\nY6yn13zXpDk021cl1LTkpXraSB1owb6rS1n4HjMmwUsbZul44OI6tUozVkOa\n8RMIDBaRCpg8dswKkGTwHdTTUOmgt5ZqKXdfKhuToJg26WBpoSTsFVR/VJvN\nxB3KEouZXsaOaOYgAR8jcTOhAPSIl0uWQkt9AOEMRW5R3IPi8shROelhp6BP\nJBTb\r\n=WNKR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDwuYIw6Vz6vbtfpWIMchj9XxrfHdQx3En3BNVnD5G5IwIhAOzy1lzLY60OvGbcmv+3F1I1OBdhhTUdjO+w1kYomPBP"}]},"maintainers":[{"name":"biggillystyle","email":"andy.pickler@gmail.com"}],"_npmUser":{"name":"biggillystyle","email":"andy.pickler@gmail.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sequelize-history_1.3.2_1560687699801_0.06542813852506324"},"_hasShrinkwrap":false},"1.3.3":{"name":"@biggillystyle/sequelize-history","description":"Creates a revision history for instances of a given Sequelize model.","author":{"name":"Andy Pickler","email":"andy.pickler@gmail.com"},"version":"1.3.3","main":"index.js","scripts":{"coverage":"nyc npm run test","report":"istanbul report --root coverage lcov && open coverage/lcov-report/index.html","lint":"xo ./index.js || true && xo ./test/spec/test.js || true","docs":"jsdoc index.js -p -c .jsdoc.json -d docs/","test":"node test/spec/test.js | tap-spec"},"dependencies":{"lodash":"^4.17.4"},"devDependencies":{"nyc":"^14.1.1","jsdoc":"^3.5.4","sequelize":"^4.23.4","sqlite3":"^4.0.9","tap-spec":"^5.0.0","tape":"^4.10.2","xo":"^0.18.2"},"bugs":{"url":"https://github.com/BigGillyStyle/sequelize-history/issues"},"repository":{"type":"git","url":"git+https://github.com/BigGillyStyle/sequelize-history.git"},"homepage":"https://github.com/BigGillyStyle/sequelize-history","contributors":[{}],"xo":{"globals":["assert","beforeEach","describe","expect","it","module","require"]},"keywords":[],"engines":{"node":">=8.9.1"},"license":"MIT","directories":{"test":"test"},"gitHead":"70c4bf67bf4d977f81bf9502ce667ef0c7d06341","_id":"@biggillystyle/sequelize-history@1.3.3","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-ZzowlW98rIWolA1M4k/dDeQOaJXO9T7bFxqQcWP4oKOJxkiossLLhkQJTzw0pFeFRgp7i0LodRMob5+UIo4fDg==","shasum":"def3b4bc9b29d59f1c2b4319796da59480ba4088","tarball":"https://registry.npmjs.org/@biggillystyle/sequelize-history/-/sequelize-history-1.3.3.tgz","fileCount":7,"unpackedSize":31604,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdDh85CRA9TVsSAnZWagAAlDEP/2cBh+Wq4+VO3CHsElet\n6vYCN7iuzIABpoBEprw+Zdbg19CML4COejVy+WUOpbFei+Sj0i/YmPVPxaAa\nmFXY4yyjj3OpNsWCiByqhECGLCFlZXZLoo52d6+VMuo7eZLL5/fWRMeQbmqb\n8xt9z+NKBIGHwuaqOFE4P7Iz/tV3KFeAa7A7Pmtgfve5rRVGHgGBLmoWUywY\n3St86PXyKBYEyjmABeZuAfklqjq4fNa7ur6xGU8ORNgudo2Hk60OrFVgPz0U\nCvSjoSr6lCB2QRT1xMdnTAwKFtWVvIqaAKXrSR1YaG8SW28nZM8AKyhmH92E\nzTyhk8EJhAmUyzDAwsxRwrAGgNN79tKOB/nCxtS8JujS6/w1MonQicRNa9Ng\n70YM62+JS+DZTCzyQdS4IBfjhUKQdhkUwTw8XozGsW4jjSIFOiJOjzUsK4NR\nY85pzekpeVr1CSwLAtwluPUzoToaz6SvOuMEi0hIGbSUIOxXAKHEchvU1nqZ\ndY0K+R6extai6zGl07v3S6wSSDpf2XJNrni5d61huudzmWQriFPQDKbFcNdk\nurDh56KnHiENjwbxsYtdPqas+HAC6RPBjS0RrZWwzeKSNJQbuvOJjBwZuI9y\nsrdKmd8nWW6fDGxoZCzuTscAqzNpI4aqkXhnJOAVm86QsEabAg4kFStAmKDK\n98kp\r\n=q51X\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFj3OV/zZXrJcvMqKUNa4WlmMV/xYDUlxIvyq06bS9oIAiBUYiOooUHvCm1Xa4Mq+ojIkvnUHyoniP3fQa/XgNbLDA=="}]},"maintainers":[{"name":"biggillystyle","email":"andy.pickler@gmail.com"}],"_npmUser":{"name":"biggillystyle","email":"andy.pickler@gmail.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sequelize-history_1.3.3_1561206584269_0.2677721389357173"},"_hasShrinkwrap":false},"1.3.4":{"name":"@biggillystyle/sequelize-history","description":"Creates a revision history for instances of a given Sequelize model.","author":{"name":"Andy Pickler","email":"andy.pickler@gmail.com"},"version":"1.3.4","main":"index.js","scripts":{"coverage":"nyc npm run test","report":"istanbul report --root coverage lcov && open coverage/lcov-report/index.html","lint":"xo ./index.js || true && xo ./test/spec/test.js || true","docs":"jsdoc index.js -p -c .jsdoc.json -d docs/","test":"node test/spec/test.js | tap-spec","snyk-protect":"snyk protect","prepare":"npm run snyk-protect"},"dependencies":{"lodash":"^4.17.15","snyk":"^1.217.3"},"devDependencies":{"jsdoc":"^3.6.3","nyc":"^14.1.1","sequelize":"^4.44.3","sqlite3":"^4.1.0","tap-spec":"^5.0.0","tape":"^4.11.0","xo":"^0.24.0"},"bugs":{"url":"https://github.com/BigGillyStyle/sequelize-history/issues"},"repository":{"type":"git","url":"git+https://github.com/BigGillyStyle/sequelize-history.git"},"homepage":"https://github.com/BigGillyStyle/sequelize-history","contributors":[{}],"xo":{"globals":["assert","beforeEach","describe","expect","it","module","require"]},"keywords":[],"engines":{"node":">=8.9.1"},"license":"MIT","directories":{"test":"test"},"snyk":true,"gitHead":"7cc10eaefa8728ca10d9398a809d01cfc9cef183","_id":"@biggillystyle/sequelize-history@1.3.4","_nodeVersion":"10.16.3","_npmVersion":"6.11.2","dist":{"integrity":"sha512-1VtcY0bOzrxVvRDvnBeHYvme3hoBHmxjXqPWXFIA8NrsxyCud43hxEo+TvHSdKVY31RsSrr1t2QBvl+3vDdxxg==","shasum":"4f435779c8931cb2c163fd65c617d336c9decb3e","tarball":"https://registry.npmjs.org/@biggillystyle/sequelize-history/-/sequelize-history-1.3.4.tgz","fileCount":8,"unpackedSize":32975,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdYJAaCRA9TVsSAnZWagAAxgwP/0rQ/becBeKHQIo6LnmB\nhssSx/Mtq2QXlJLvCQo7wDmbZhj0nqrLEKwOWBddnj1Jj54zHFL5YNYY6tQF\niDIDbUlZIe82B3x+cRLYR9fSvCn/WjHZmcb961qfLjmMQtwrvptU2fMDLsiX\n8muGTCjFIDNirIgoMcMvQh+OOCaPVDbj3i4OqY3pRUf8qzuoNLKvg3lFaM/s\npnjjHZkHzptwYJZG9PP/e1jTpbgN06pTAMQWK2zhqgl2lJyKG6z+rKBb5bm8\n2GCShl54HY/29ZeAektTXsDu5o4+lOQRe/k9KDCkj0CIkGaBczdAU77GN2oz\nKZnSp+vPrOslrE8WlU+d2kVHc0ffPOY3ycGhfKENEegHFRGdncSDI9zyfJnT\nOstH+fId7Xn8dUcehDkq9b3VY2pTybaYwHirVZVnuW+E19z2cwXIJhyTbX4Q\nI921AonawZkdd+8/MuQSLTTNNWUCSyOh5Ow7BMNZp9aJ/NsBqQXHvPpHRP7M\n3tzEqpObLElPFjxyATZToL8DgKxvZ79MzOecgWnPyxneyP097TUBX8d/BvAM\nSRdqKFY3BWx0jyo7GSGu2xcGBJDr+LDCAEBVgXNHnvbSSADiY11sd3Ql/j4R\nCevE8Za/gXIXvdB/3hoOdPBTX0xjldnt2rro2fqIFFRZqRTo1Hm1H8UjiypV\nTZMk\r\n=maz/\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC17Ql+T4UB/66FD2u6379uFxa/uJd+OAHSb6FA/fccjAIhAP72XsLu+Dr9eUuH0f4vY2y9ucOkOdeLDRhT1I9lWpmj"}]},"maintainers":[{"name":"biggillystyle","email":"andy.pickler@gmail.com"}],"_npmUser":{"name":"biggillystyle","email":"andy.pickler@gmail.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sequelize-history_1.3.4_1566609433268_0.5002204814827995"},"_hasShrinkwrap":false}},"time":{"created":"2019-06-16T12:21:39.767Z","1.3.2":"2019-06-16T12:21:39.924Z","modified":"2022-04-04T18:46:16.977Z","1.3.3":"2019-06-22T12:29:44.423Z","1.3.4":"2019-08-24T01:17:13.426Z"},"maintainers":[{"name":"biggillystyle","email":"andy.pickler@gmail.com"}],"description":"Creates a revision history for instances of a given Sequelize model.","homepage":"https://github.com/BigGillyStyle/sequelize-history","keywords":[],"repository":{"type":"git","url":"git+https://github.com/BigGillyStyle/sequelize-history.git"},"contributors":[{}],"author":{"name":"Andy Pickler","email":"andy.pickler@gmail.com"},"bugs":{"url":"https://github.com/BigGillyStyle/sequelize-history/issues"},"license":"MIT","readme":"[![CircleCI](https://circleci.com/gh/BigGillyStyle/sequelize-history.svg?style=svg)](https://circleci.com/gh/BigGillyStyle/sequelize-history)    \n[![Known Vulnerabilities](https://snyk.io//test/github/BigGillyStyle/sequelize-history/badge.svg?targetFile=package.json)](https://snyk.io//test/github/BigGillyStyle/sequelize-history?targetFile=package.json)\n\n# sequelize-history\n> Creates a revision history for instances of a given Sequelize model.\n\nThis module will setup automatic revision tracking for any [Sequelize](https://github.com/sequelize/sequelize) model.\nThis is effectively a re-write of [`sequelize-temporal`](https://github.com/bonaval/sequelize-temporal), which deserves any and all due credit.\nMore specifically...\n\n- re-written in ES6-_ish_ code\n- addition of a couple of factory methods to make instantiation simpler (this is especially true if you're going to track revisions on all of your models)\n- optionally tracks revision author\n- a few new instantiation options\n- up-to-date dependencies\n- tests re-written in `tape`\n- linted against `xo`\n- less lodash magic\n\n## Installation\nInstall via npm:\n\n```sh\n$ npm i sequelize-history --save\n```\n\n## Usage\nCreate your Sequelize instance and models per usual.\n\n```js\nconst Sequelize = require('sequelize');\nconst sequelizeHistory = require('sequelize-history');\n\n// Create a sequelize instance\nconst sequelize = new Sequelize('', '', '', {\n  dialect: 'sqlite',\n  operatorsAliases: false,\n  storage: path.join(__dirname, 'test.sqlite')\n});\n\n// Create the model class to be tracked\nconst Model = sequelize.define('Model', {name: Sequelize.TEXT});\n```\n\nBy default, the module exports a factory method to avoid having to deal with the constructor.\nAll options are passed transparently as they would be to the constructor if called directly.\nTo begin tracking a model's revisions:\n\n```js\n// If you want a reference to the tracking model...\nconst ModelHistory = sequelizeHistory(Model, sequelize);\n\n// Otherwise...\nsequelizeHistory(Model, sequelize);\n\n// You're done.\n// A record of all changes to instances of\n// `Model` will be recorded in the modelHistory table via the\n// `ModelHistory` collection.\n```\n\nIf you need to access the constructor for some reason, it is exported as `SequelizeHistory`.\n\n```js\n// Require the constructor instead of the factory\nconst sequelizeHistory = require('sequelize-history').SequelizeHistory;\n\n// Create an instance\nconst history = new SequelizeHistory(Model, sequelize);\n\n// If you want a reference to the tracking model...\nconst modelHistory = history.modelHistory;\n```\n\nFinally, if you want to track all of your models, an `all` method is exported.\nJust pass it your sequelize instance and you're done.\n\n```js\nconst trackAll = require('sequelize-history').all;\n\ntrackAll(sequelize);\n```\n\n## Tracking revision author\nIf you pass an `authorFieldName` option, the tracking model gets a field of the same name added to its table.\nIt also results in your original model getting a new `setRevisionAuthor` static method.\n\nUse this method by passing in any appropriate value before updating your original model instances, and the passed value will be written to the `authorFieldName` column of the tracking table.\nThe value is reset immediately after the next update is written to the history model.\n\n_This functionality is available to both single instance updates and static bulk updates._\n\n```js\nconst Sequelize = require('sequelize');\nconst sequelizeHistory = require('sequelize-history');\n\n// Create a sequelize instance\nconst sequelize = new Sequelize('', '', '', {\n  dialect: 'sqlite',\n  operatorsAliases: false,\n  storage: path.join(__dirname, 'test.sqlite')\n});\n\n// Create the model class to be tracked\nconst Model = sequelize.define('Model', {name: Sequelize.TEXT});\n\n// Create some instances of the model\nModel\n  .create({name: 'test-1'})\n  .then(() => Model.create({name: 'test-2'}))\n  .then(() => {\n    // Now we update our instances\n    // First, set the revision author\n    Model.setRevisingAuthor(100);\n    // Then update the instances\n    // Both bulk updates and instance updates are supported\n    return Model.update({name: 'same'}, {where: {}});\n  })\n  // Get all of our recent revisions\n  .then(() => sequelize.models.ModelHistory.findAll({where: {name: 'same'}}))\n  .then(revisions => {\n    revisions.forEach(revision => {\n      // Should output 100 for each returned row\n      console.log(revision.authorId);\n    });\n  })\n  .catch(err => console.error.bind(console));\n```\n\nThere are more examples in the tests.\n\n\n# Options\nThe constructor and factory methods accept the following instantiation object properties:\n- **authorFieldName** `string|null` - string to indicate a field name to store author of the revisions, or null to disable\n- **modelSuffix** `string` - string to append to tracked model's name when creating name of tracking model\n- **excludedAttributes** `array` - collection of model attributes to be excluded when creating history model from the target model\n- **excludedAttributeProperties** `array` - collection of attribute properties to ignore when duplicating the target model's attributes\n\n**NOTE** - if `authorFieldName` is set, `hasMany` and `belongsTo` relationships will be created between the history model and the target model.\nThis is to ensure that constraints are not enforced in creating the associations.\n\n### Defaults\n\n```js\nSequelizeHistory.DEFAULTS = {\n    // String to indicate a field name to use to store the\n    // author of the revisions to the model, or null if you\n    // don't want to track revision authors\n    authorFieldName: null,\n    // String to append to tracked model's name in creating\n    // name of model's history model\n    modelSuffix: 'History',\n    // Array of attributes to be ignored and excluded when\n    // recording a change to the target model\n    excludedAttributes: [],\n    // Array of attribute properties to ignore when duplicating\n    // the target model's attributes - this is mostly to prevent\n    // the use of constraints that may be in place on the target\n    excludedAttributeProperties: [\n        'Model',\n        'unique',\n        'primaryKey',\n        'references',\n        'onUpdate',\n        'onDelete',\n        'autoIncrement',\n        'set',\n        'get',\n        '_modelAttribute'\n    ]\n};\n```\n\n# Tests and coverage\nWritten with tape and Istanbul respectively.\n\nTo run the tests:\n```\n$ npm test\n```\n\nTo generate a coverage report:\n```\n$ npm run coverage\n```\n\nTo build JSDoc docs from in-line documentation:\n```\n$ npm run docs && open docs/index.html\n```\n","readmeFilename":"README.md"}