{"_id":"@codebit-programando-solucoes/sequelize-paper-trail","name":"@codebit-programando-solucoes/sequelize-paper-trail","dist-tags":{"latest":"3.0.1"},"versions":{"3.0.1":{"name":"@codebit-programando-solucoes/sequelize-paper-trail","version":"3.0.1","description":"Track changes to your Sequelize models data. Perfect for auditing or versioning.","author":{"name":"Niels van Galen Last","email":"nvangalenlast@gmail.com","url":"https://nielsgl.com"},"license":"MIT","homepage":"https://github.com/Codebit-Programando-Solucoes/sequelize-paper-trail#readme","repository":{"type":"git","url":"git+https://github.com/Codebit-Programando-Solucoes/sequelize-paper-trail.git"},"bugs":{"url":"https://github.com/Codebit-Programando-Solucoes/sequelize-paper-trail/issues"},"keywords":["sequelize","sequelize-plugin","audit","paper trail","audit trail","trail","revision","revisions","versioning","nodejs"],"main":"dist/index.js","engines":{"node":">=5.0.0","npm":">=3.3"},"scripts":{"prepare":"npm run build","build":"babel lib/ --out-dir dist/","lint":"eslint --ext .js lib test","lint:fix":"npm run lint -- --fix","release":"release-it","test":"jest"},"devDependencies":{"@babel/cli":"^7.5.5","@babel/core":"^7.5.5","@babel/node":"^7.5.5","@babel/preset-env":"^7.5.5","babel-eslint":"^10.0.2","babel-jest":"^24.8.0","babel-plugin-add-module-exports":"^1.0.2","babel-plugin-transform-flow-strip-types":"^6.22.0","babel-register":"^6.26.0","eslint":"^6.1.0","eslint-config-airbnb":"^18.0.0","eslint-config-prettier":"^6.0.0","eslint-plugin-babel":"^5.3.0","eslint-plugin-flowtype":"^4.2.0","eslint-plugin-import":"^2.18.2","eslint-plugin-jest":"^22.15.1","eslint-plugin-jsx-a11y":"^6.2.3","eslint-plugin-prettier":"^3.1.0","eslint-plugin-react":"^7.14.3","eslint-plugin-react-hooks":"^1.7.0","jest":"^24.8.0","prettier":"^1.18.2","pretty-error":"^2.1.1","release-it":"^12.3.5","sequelize":"^5.14.0","sqlite3":"^4.0.9"},"dependencies":{"continuation-local-storage":"^3.2.1","deep-diff":"^1.0.2","diff":"^4.0.1","lodash":"^4.17.15"},"babel":{"presets":[["@babel/preset-env",{"targets":{"node":"current"}}]]},"_id":"@codebit-programando-solucoes/sequelize-paper-trail@3.0.1","gitHead":"ac06b1fffe5f019a87f9ef33b1d76d04cf1b20ee","_nodeVersion":"20.18.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-YaN5VhsHPXLUoKamqxj5RO3Giyz2+jAbqIuQikCqrGauAQYLBULOQSsxBoTKbLbf5EJfDsgdk9QW93V+4crjBg==","shasum":"2fb2721815d3fa91a73144f93cf2f8321cf19c43","tarball":"https://registry.npmjs.org/@codebit-programando-solucoes/sequelize-paper-trail/-/sequelize-paper-trail-3.0.1.tgz","fileCount":22,"unpackedSize":72509,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGB2ynSYFaj17FkiRYKR2KD67zYdjyP+Qe2FrkjRgu79AiAZqWH3MzyVyHDQJaUf4kq9U7UcEMcHZaxE51Gf4Bb6cw=="}]},"_npmUser":{"name":"ksfreitas","email":"ksfreitas@gmail.com"},"directories":{},"maintainers":[{"name":"bibliotecas-codebit","email":"bibliotecas@codebit.com.br"},{"name":"ksfreitas","email":"ksfreitas@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sequelize-paper-trail_3.0.1_1733865657120_0.994406962246688"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-10T21:20:56.948Z","3.0.1":"2024-12-10T21:20:57.407Z","modified":"2024-12-10T21:20:57.728Z"},"maintainers":[{"name":"bibliotecas-codebit","email":"bibliotecas@codebit.com.br"},{"name":"ksfreitas","email":"ksfreitas@gmail.com"}],"description":"Track changes to your Sequelize models data. Perfect for auditing or versioning.","homepage":"https://github.com/Codebit-Programando-Solucoes/sequelize-paper-trail#readme","keywords":["sequelize","sequelize-plugin","audit","paper trail","audit trail","trail","revision","revisions","versioning","nodejs"],"repository":{"type":"git","url":"git+https://github.com/Codebit-Programando-Solucoes/sequelize-paper-trail.git"},"author":{"name":"Niels van Galen Last","email":"nvangalenlast@gmail.com","url":"https://nielsgl.com"},"bugs":{"url":"https://github.com/Codebit-Programando-Solucoes/sequelize-paper-trail/issues"},"license":"MIT","readme":"# Sequelize Paper Trail\n\n---\n\n> **Help wanted:** _Please try out `sequelize-paper-trail@3.0.0-rc.6` and give a 👍/👎 [here](https://github.com/nielsgl/sequelize-paper-trail/pull/74) if it works as expected._\n\n---\n\n> Track changes to your models, for auditing or versioning. See how a model looked at any stage in its lifecycle, revert it to any version, or restore it after it has been destroyed. Record the user who created the version.\n\n<!-- [![NPM](https://nodei.co/npm/sequelize-paper-trail.png?downloads=true)](https://nodei.co/npm/sequelize-paper-trail/) -->\n\n[![node-version](https://img.shields.io/node/v/sequelize-paper-trail.svg)](https://www.npmjs.org/package/sequelize-paper-trail)\n[![npm-version](https://img.shields.io/npm/v/sequelize-paper-trail.svg)](https://www.npmjs.org/package/sequelize-paper-trail)\n[![David](https://img.shields.io/david/nielsgl/sequelize-paper-trail.svg?maxAge=3600)]()\n[![David](https://img.shields.io/david/dev/nielsgl/sequelize-paper-trail.svg?maxAge=3600)]()\n\n[![GitHub release](https://img.shields.io/github/release/nielsgl/sequelize-paper-trail.svg)](https://www.npmjs.org/package/sequelize-paper-trail)\n[![GitHub tag](https://img.shields.io/github/tag/nielsgl/sequelize-paper-trail.svg)](https://www.npmjs.org/package/sequelize-paper-trail)\n[![GitHub commits](https://img.shields.io/github/commits-since/nielsgl/sequelize-paper-trail/1.2.0.svg)]()\n[![npm-downloads](https://img.shields.io/npm/dt/sequelize-paper-trail.svg)](https://www.npmjs.org/package/sequelize-paper-trail)\n\n[![license](https://img.shields.io/github/license/nielsgl/sequelize-paper-trail.svg)](https://github.com/nielsgl/sequelize-paper-trail/blob/master/LICENSE)\n\n<!-- START doctoc generated TOC please keep comment here to allow auto update -->\n<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->\n\n## Table of Contents\n\n-   [Sequelize Paper Trail](#sequelize-paper-trail) - [Table of Contents](#table-of-contents) - [Installation](#installation) - [Usage](#usage) - [Example](#example) - [User Tracking](#user-tracking) - [Options](#options) - [Default options](#default-options) - [Options documentation](#options-documentation) - [Limitations](#limitations) - [Testing](#testing) - [Support](#support) - [Contributing](#contributing) - [Author](#author) - [Thanks](#thanks) - [Links](#links)\n\n<!-- END doctoc generated TOC please keep comment here to allow auto update -->\n\n## Installation\n\n```bash\nnpm install --save sequelize-paper-trail\n# or with yarn:\n# yarn add sequelize-paper-trail\n```\n\n_Note: the current test suite is very limited in coverage._\n\n## Usage\n\nSequelize Paper Trail assumes that you already set up your Sequelize connection, for example, like this:\n\n```javascript\nconst Sequelize = require('sequelize');\nconst sequelize = new Sequelize('database', 'username', 'password');\n```\n\nthen adding Sequelize Paper Trail is as easy as:\n\n```javascript\nconst PaperTrail = require('sequelize-paper-trail').init(sequelize, options);\nPaperTrail.defineModels();\n```\n\nwhich loads the Paper Trail library, and the `defineModels()` method sets up a `Revisions` and `RevisionHistory` table.\n\n_Note: If you pass `userModel` option to `init` in order to enable user tracking, `userModel` should be setup before `defineModels()` is called._\n\nThen for each model that you want to keep a paper trail you simply add:\n\n```javascript\nModel.hasPaperTrail();\n```\n\n`hasPaperTrail` returns the `hasMany` association to the `revisionModel` so you can keep track of the association for reference later.\n\n### Example\n\n```javascript\nconst Sequelize = require('sequelize');\nconst sequelize = new Sequelize('database', 'username', 'password');\n\nconst PaperTrail = require('sequelize-paper-trail').init(\n\tsequelize,\n\toptions || {},\n);\nPaperTrail.defineModels();\n\nconst User = sequelize.define('User', {\n\tusername: Sequelize.STRING,\n\tbirthday: Sequelize.DATE,\n});\n\nUser.Revisions = User.hasPaperTrail();\n```\n\n## User Tracking\n\nThere are 2 steps to enable user tracking, ie, recording the user who created a particular revision.\n\n1. Enable user tracking by passing `userModel` option to `init`, with the name of the model which stores users in your application as the value.\n\n```javascript\nconst options = {\n\t/* ... */\n\tuserModel: 'user',\n};\n```\n\n2. Pass the id of the user who is responsible for the database operation to `sequelize-paper-trail` either by sequelize options or by using [continuation-local-storage](https://www.npmjs.com/package/continuation-local-storage).\n\n```javascript\nModel.update({\n  /* ... */\n}, {\n  userId: user.id\n}).then(() {\n  /* ... */\n});\n```\n\nOR\n\n```javascript\nconst createNamespace = require('continuation-local-storage').createNamespace;\nconst session = createNamespace('my session');\n\nsession.set('userId', user.id);\n\nModel.update({\n  /* ... */\n}).then(() {\n  /* ... */\n});\n\n```\n\nTo enable continuation-local-storage set `continuationNamespace` in initialization options.\nAdditionally, you may also have to call `.run()` or `.bind()` on your cls namespace, as described in the [docs](https://www.npmjs.com/package/continuation-local-storage).\n\n## Disable logging for a single call\n\nTo not log a specific change to a revisioned object, just pass a `noPaperTrail` with a truthy (true, 1, ' ') value.\n\n```javascript\nconst instance = await Model.findOne();\ninstance.update({ noPaperTrail: true }).then(() {\n  /* ... */\n});\n```\n\n## Options\n\nPaper Trail supports various options that can be passed into the initialization. The following are the default options:\n\n### Default options\n\n```javascript\n// Default options\nconst options = {\n\texclude: [\n\t\t'id',\n\t\t'createdAt',\n\t\t'updatedAt',\n\t\t'deletedAt',\n\t\t'created_at',\n\t\t'updated_at',\n\t\t'deleted_at',\n\t],\n\trevisionAttribute: 'revision',\n\trevisionModel: 'Revision',\n\trevisionChangeModel: 'RevisionChange',\n\tenableRevisionChangeModel: false,\n\tUUID: false,\n\tunderscored: false,\n\tunderscoredAttributes: false,\n\tdefaultAttributes: {\n\t\tdocumentId: 'documentId',\n\t\trevisionId: 'revisionId',\n\t},\n\tenableCompression: false,\n\tenableMigration: false,\n\tenableStrictDiff: true,\n\tenablePreviousDocument: false,\n\tcontinuationKey: 'userId',\n\tbelongsToUserOptions: undefined,\n\tmetaDataFields: undefined,\n\tmetaDataContinuationKey: 'metaData',\n\tdocumentFieldType: 'postgres',\n};\n```\n\n### Options documentation\n\n| Option                      | Type    | Default Value                                                                                                        | Description                                                                                                                                                                                                           |\n| --------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| [debug]                     | Boolean | false                                                                                                                | Enables logging to the console.                                                                                                                                                                                       |\n| [exclude]                   | Array   | ['id', 'createdAt', 'updatedAt', 'deletedAt', 'created_at', 'updated_at', 'deleted_at', [options.revisionAttribute]] | Array of global attributes to exclude from the paper trail.                                                                                                                                                           |\n| [revisionAttribute]         | String  | 'revision'                                                                                                           | Name of the attribute in the table that corresponds to the current revision.                                                                                                                                          |\n| [revisionModel]             | String  | 'Revision'                                                                                                           | Name of the model that keeps the revision models.                                                                                                                                                                     |\n| [tableName]                 | String  | undefined                                                                                                            | Name of the table that keeps the revision models. Passed to Sequelize. Necessary in Sequelize 5+ when underscored is true and the table is camelCase or PascalCase.                                                   |\n| [revisionChangeModel]       | String  | 'RevisionChange'                                                                                                     | Name of the model that tracks all the attributes that have changed during each create and update call.                                                                                                                |\n| [enableRevisionChangeModel] | Boolean | false                                                                                                                | Disable the revision change model to save space.                                                                                                                                                                      |\n| [UUID]                      | Boolean | false                                                                                                                | The [revisionModel] has id attribute of type UUID for postgresql.                                                                                                                                                     |\n| [underscored]               | Boolean | false                                                                                                                | The [revisionModel] and [revisionChangeModel] have 'createdAt' and 'updatedAt' attributes, by default, setting this option to true changes it to 'created_at' and 'updated_at'.                                       |\n| [underscoredAttributes]     | Boolean | false                                                                                                                | The [revisionModel] has a [defaultAttribute] 'documentId', and the [revisionChangeModel] has a [defaultAttribute] 'revisionId, by default, setting this option to true changes it to 'document_id' and 'revision_id'. |\n| [defaultAttributes]         | Object  | { documentId: 'documentId', revisionId: 'revisionId' }                                                               |                                                                                                                                                                                                                       |\n| [userModel]                 | String  |                                                                                                                      | Name of the model that stores users in your.                                                                                                                                                                          |\n| [enableCompression]         | Boolean | false                                                                                                                | Compresses the revision attribute in the [revisionModel] to only the diff instead of all model attributes.                                                                                                            |\n| [enableMigration]           | Boolean | false                                                                                                                | Automatically adds the [revisionAttribute] via a migration to the models that have paper trails enabled.                                                                                                              |\n| [enableStrictDiff]          | Boolean | true                                                                                                                 | Reports integers and strings as different, e.g. `3.14` !== `'3.14'`                                                                                                                                                   |\n| [enablePreviousDocument]    | Boolean | false                                                                                                                | Create the column 'previousDocument' to save the values before the update values.                                                                                                                                     |\n| [continuationNamespace]     | String  |                                                                                                                      | Name of the name space used with the continuation-local-storage module.                                                                                                                                               |\n| [continuationKey]           | String  | 'userId'                                                                                                             | The continuation-local-storage key that contains the user id.                                                                                                                                                         |\n| [belongsToUserOptions]      | Object  | undefined                                                                                                            | The options used for belongsTo between userModel and Revision model                                                                                                                                                   |\n| [metaDataFields]            | Object  | undefined                                                                                                            | The keys that will be provided in the meta data object. { key: isRequired (boolean)} format. Can be used to privovide additional fields - other associations, dates, etc to the Revision model                        |\n| [metaDataContinuationKey]   | String  | 'metaData'                                                                                                           | The continuation-local-storage key that contains the meta data object, from where the metaDataFields are extracted.                                                                                                   |\n| [documentFieldType]         | String  | ['legacy', 'postgres', 'mysql']                                                                                      | Changes the type of field 'document' what will be created. 'legacy' produces a `TEXT`, 'postgres' a `JSONB` and 'mysql' a `JSON` field.                                                                               |\n\n## Limitations\n\n-   This project does not support models with composite primary keys. You can work around using a unique index with multiple fields.\n\n## Testing\n\nThe tests are designed to run on SQLite3 in-memory tables, built from Sequelize migration files. If you want to actually generate a database file, change the storage option to a filename and run the tests.\n\n```bash\nnpm test\n# or with yarn:\n# yarn test\n```\n\n## Support\n\nPlease use:\n\n-   GitHub's [issue tracker](https://github.com/nielsgl/sequelize-paper-trail/issues)\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n## Author\n\n© [Niels van Galen Last](https://nielsgl.com) – [@nielsgl](https://twitter.com/nielsgl) – nvangalenlast@gmail.com\nDistributed under the MIT license. See `LICENSE` for more information.\n[https://github.com/nielsgl/sequelize-paper-trail](https://github.com/nielsgl/)\n\n## Thanks\n\nThis project was inspired by:\n\n-   [Sequelize-Revisions](https://github.com/bkniffler/sequelize-revisions)\n-   [Paper Trail](https://github.com/airblade/paper_trail)\n\nContributors:\n[https://github.com/nielsgl/sequelize-paper-trail/graphs/contributors](https://github.com/nielsgl/sequelize-paper-trail/graphs/contributors)\n\n## Links\n\n-   [Example application](https://github.com/nielsgl/sequelize-paper-trail-example)\n","readmeFilename":"README.md"}