{"_id":"sequelize-strict-attributes","_rev":"16-a560c0185f072344014a1da198f97e1a","name":"sequelize-strict-attributes","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"sequelize-strict-attributes","version":"1.0.0","description":"Plugin that configures Sequelize to throw when accessing attributes omitted from a select.","author":{"name":"Alec Perkins","email":"mail@alecperkins.me"},"license":"MIT","bugs":{"url":"https://github.com/alecperkins/sequelize-strict-attributes/issues"},"repository":{"type":"git","url":"git+https://github.com/alecperkins/sequelize-strict-attributes.git"},"homepage":"https://alecperkins.net/sequelize-strict-attributes","keywords":["sequelize","orm","attributes","plugin","safety"],"type":"commonjs","main":"./index.cjs","types":"./index.d.ts","exports":{".":{"types":"./index.d.ts","import":"./index.mjs","require":"./index.cjs"},"./package.json":"./package.json"},"peerDependencies":{"sequelize":"^6"},"gitHead":"957c656d6a77835873ce38c8c723b4084da8485e","_id":"sequelize-strict-attributes@1.0.0","_nodeVersion":"18.11.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-2jbtaw67ygEzA2ohvK0TYOnLS92NKEVeW4HKayPW5fyFEI+Pftz7A5+OFu194kn8WNd/02xGqRmw5cn4lN2PWw==","shasum":"3056a7fee43226583ee77ba9b5c876bb266f6d02","tarball":"https://registry.npmjs.org/sequelize-strict-attributes/-/sequelize-strict-attributes-1.0.0.tgz","fileCount":6,"unpackedSize":11457,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIChKUJ/fsi+5hOgMPbu2EXY2LQSjOPOlNIfyu8hFx9atAiEA2Sg4wz4u6SfBw1hTlGVchA9hYxuiriFVY0yzH2eKSO4="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkHQiSACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqEpw/+MGVeU5HCDbROYWS1JbtSE7U1PldUs3I/FtJONr2hHDIRZQ7l\r\nR6YIKdRpIC54ZSJaR/LuH/+wdzsUsoJUPaJhZ693F+zxFKIe0R1RRwCHJDV7\r\n8KnWqJFWlfZjnEdJOgZZergJSkILdDgJ5d0ad3xShriDGqQxW/uo80nunruy\r\nVSp39ww8OBe6m0hI/8ewupzX9bj6VQOnSi7AxYbWcbzrvatgE+FiQ104jWoo\r\nTuu/ANqFvgOOYdZxVPpMHnUXY1sTUNrb8uTpHL3QyQvNd+mGHZjb7K9rkgob\r\nkbypQnRH3ot3ABJ1moBpMufYV7zvsmxzOiBCJTrmSXTYe4QJ4GN5ZXZh8SWg\r\ndXOE78HoSYMNozS9IapW+KMbpU1ozk4CsqZzvSAeKREC1vKRICRDVw6j3wiI\r\nt8GiCRaFJtWbSV6XVjAYMey+psg3bhV6ECa9QlKpkwLiid3rSjaE6CfshlV+\r\n+jc0WqcE/FWh86JdAJyBIiYqmMt0Gw20R45Q+Zg1zdSlOcqFfpUs/Rguqq8x\r\nJ1eNMjont3HrIA0EdFq7bj6zkffLTdU9Kb/dbCB9wKZXlyJIXGx96yNAl81a\r\n8+0h6627+D7Uogie6n8JRO/RzriguaT9v0PpL/IwUGka/EeZ/lHm2XTewEtU\r\nXE68dGq7azyKvJXaU1TIaEV8IkCFfApGJ5g=\r\n=/TP2\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alecperkins","email":"mail@alecperkins.me"},"directories":{},"maintainers":[{"name":"alecperkins","email":"mail@alecperkins.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sequelize-strict-attributes_1.0.0_1679624338518_0.3104442932187157"},"_hasShrinkwrap":false},"1.0.1":{"name":"sequelize-strict-attributes","version":"1.0.1","description":"Plugin that configures Sequelize to throw when accessing attributes omitted from a select.","author":{"name":"Alec Perkins","email":"mail@alecperkins.me"},"license":"MIT","bugs":{"url":"https://github.com/alecperkins/sequelize-strict-attributes/issues"},"repository":{"type":"git","url":"git+https://github.com/alecperkins/sequelize-strict-attributes.git"},"homepage":"https://alecperkins.net/sequelize-strict-attributes","keywords":["sequelize","orm","attributes","plugin","safety"],"type":"commonjs","main":"./index.cjs","types":"./index.d.ts","exports":{".":{"types":"./index.d.ts","import":"./index.mjs","require":"./index.cjs"},"./package.json":"./package.json"},"peerDependencies":{"sequelize":"^6"},"gitHead":"ed0fc015dd3343d0ef3774b8839cdbcd66bf7e02","_id":"sequelize-strict-attributes@1.0.1","_nodeVersion":"18.11.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-MAkBclK88BW1KPPcTrf0THQhOnen9oozrxz/4vyYNPvirGarWZENLfgz7nYyXSWeMvS0c1eLb1cVzsrw2AI1Dw==","shasum":"51a937ee5092410048eaf1a26e25644f39faf78b","tarball":"https://registry.npmjs.org/sequelize-strict-attributes/-/sequelize-strict-attributes-1.0.1.tgz","fileCount":6,"unpackedSize":11918,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGIbBrFsZ4Xv10DzRMduw0DS9h8bnVmH+ensohduWjyVAiAlpXFyhrcy/IvDFCtEPziCIwIT6wx8ys5Fm4AhkP/GSw=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkHafZACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmogSw/9HTnRXDCWsaNyHUzdl4baQt2Z8vy0tFVmB/DCy74an99cfS08\r\nplRlatjd4RL8dU3l8JASNMxfzuAsua/WozJi5n2UDYmjiEejxK0eWmLfLKg7\r\nohHGFKgHpsVuq5+8hHEDRmsOGANgBAg81xWQMNeuCNPOldxKGDFI8or5Fwbi\r\nhgfvIXghDT76/4RUfRVPDMI0opd52tWeHsJbR8BwpMkjfL+f4zAqdQietqkX\r\nb1EY6BQOuuovrzUxID8m7HNhI4rk06DjCtB12xzyirhADc73bvGajSnsoDTu\r\nFbpy842Wlbk9msok6fkwchg/im6OkMcDHcxq9CemW1bOHEg8vdabYzCL+gIA\r\nhmLOSf3rrfJv+Eq9KULKyhRa7wn2MkV9uOhrobtNdaHu2IxFdqrnLyH0kGnf\r\nMahsT41Wjjf/xG9Zvh09RFJTHgC5Q4T9c2L1JaPQTf3Y8bQxgt5uiyHMlf5O\r\nj5mriQe02xktr8LXZ+na6MFzXyjBXr2BVLw68rOqAfJ/2nEMDAZrsq8dBqyb\r\nOKh8iUl997MLIIsymfLEJ9YVhm7/InDvxFrt6WqkbfLSCUmGpzGwOAL7cKa5\r\nHqR4eX6x4G5rKLuy2cgM+99BJBes+h5KCnhp//NpMJvjBtyPWYpkCH5kZdec\r\nBc1iUn5HFbPpIcy/lMAogVo+UwC1Zzr16TM=\r\n=IEjs\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alecperkins","email":"mail@alecperkins.me"},"directories":{},"maintainers":[{"name":"alecperkins","email":"mail@alecperkins.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sequelize-strict-attributes_1.0.1_1679665113577_0.9732974927079443"},"_hasShrinkwrap":false},"1.0.2":{"name":"sequelize-strict-attributes","version":"1.0.2","description":"Plugin that configures Sequelize to throw when accessing attributes omitted from a select.","author":{"name":"Alec Perkins","email":"mail@alecperkins.me"},"license":"MIT","bugs":{"url":"https://github.com/alecperkins/sequelize-strict-attributes/issues"},"repository":{"type":"git","url":"git+https://github.com/alecperkins/sequelize-strict-attributes.git"},"homepage":"https://alecperkins.net/sequelize-strict-attributes","keywords":["sequelize","orm","attributes","plugin","safety"],"type":"commonjs","main":"./index.cjs","types":"./index.d.ts","exports":{".":{"types":"./index.d.ts","import":"./index.mjs","require":"./index.cjs"},"./package.json":"./package.json"},"peerDependencies":{"sequelize":"^6"},"gitHead":"f79bcb1d8df8a7c50f6b62f2d5c94868539edb62","_id":"sequelize-strict-attributes@1.0.2","_nodeVersion":"18.11.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-FAzGrB4BAQzLD0xkGvAhWQf0Y8IRSn8ydaG6j8D8eMxT2z8iKIMzDdxtm9YFhHrTkLd+ILRktQLhEmGm921QvA==","shasum":"d51c5322551abe59e95249011fdb335c513ade53","tarball":"https://registry.npmjs.org/sequelize-strict-attributes/-/sequelize-strict-attributes-1.0.2.tgz","fileCount":6,"unpackedSize":11964,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCBOfytHp4XMp/cfYJ46pTseruFkD30OIMnAtTF7EwgrAIgFfz6UdZibBt5DYB82N11ARiq16VcWAwHleRqGD9jLb4="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkHa+hACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqZYQ/+NQ2NO966AMmZjzwRrk6goDc8c7NDRUTC0btm3fKuDS53HzYA\r\nOJq7rs8vzfM14a7ea4KtxH00Ie5W720ZoYye6Fhoa+iiEMSJdQfPX2nQeZ4A\r\nNxoDVvE+93Na5Tx2wJBQEr8i1WvqqFJQx3DE5ooRHpjhcMPjnyY6WB8VHopH\r\nHD1nVVYYNCRnihRTrkCfEBUIR7d3+2cBjxRzc/IBZKhAuaeC493ulOZT69z0\r\nhJp6i1+eGcuTPcn7WOXNv3gYHX4BQvVcxXjm1bOt8M5PedonVvbKt1nkLLhe\r\na86BVv2QKFbK5bsbhBr3oESo/AVL1UMOwh8D4bHEYak4br11C6j/iN5PYInH\r\nnU4WmNOUUMjA7+fYAdOXJKhJKyGE/CVvv9vA3FlGGpBIsrESLJdaTnAfTmPy\r\n+8MSTSqXIAdslEeHG03pW2lh1DdlOytt2XycBW8dVHJ5sVVISdVrrcuDErUk\r\nO8jhoZrbEwplguGzuO7MaJd0kHv17P6tCvKUjMrrowfcQOeI0ul+5KJM2PtD\r\nQD67QRpUvnJEOnEBULxuINJypZTKDvvk1eOPavswSqEAzAujcy+P7TkM8tCc\r\nyBqB1pf97U43PALsq6+uOIWG0iWn6PtJtYlv+Q+Pp9s+cdEr0e855+czmJJu\r\nJNbeNpdwag7n9Qwr2PoAmDoavxQxV28JFUg=\r\n=xbih\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alecperkins","email":"mail@alecperkins.me"},"directories":{},"maintainers":[{"name":"alecperkins","email":"mail@alecperkins.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sequelize-strict-attributes_1.0.2_1679667105374_0.6677928980494603"},"_hasShrinkwrap":false}},"time":{"created":"2023-03-22T21:22:14.211Z","0.0.1":"2023-03-22T21:22:14.431Z","modified":"2023-03-24T14:11:45.822Z","0.0.2":"2023-03-22T22:00:42.036Z","0.0.3":"2023-03-23T00:10:06.247Z","0.0.4":"2023-03-23T13:02:33.863Z","0.0.5":"2023-03-23T13:17:20.883Z","0.0.6":"2023-03-23T16:31:49.494Z","0.0.7":"2023-03-23T16:54:24.687Z","1.0.0":"2023-03-24T02:18:58.676Z","1.0.1":"2023-03-24T13:38:33.725Z","1.0.2":"2023-03-24T14:11:45.715Z"},"maintainers":[{"name":"alecperkins","email":"mail@alecperkins.me"}],"author":{"name":"Alec Perkins","email":"mail@alecperkins.me"},"license":"MIT","readme":"\n# sequelize-strict-attributes\n\n[![npm package](https://img.shields.io/npm/v/sequelize-strict-attributes)](https://www.npmjs.com/package/sequelize-strict-attributes) [![typescript](https://img.shields.io/npm/types/sequelize-strict-attributes)](https://github.com/alecperkins/sequelize-strict-attributes) [![MIT license](https://img.shields.io/npm/l/sequelize-strict-attributes)](https://github.com/alecperkins/sequelize-strict-attributes/blob/main/LICENSE) [![test status](https://github.com/alecperkins/sequelize-strict-attributes/actions/workflows/test.yml/badge.svg)](https://github.com/alecperkins/sequelize-strict-attributes/actions/workflows/test.yml)\n\n`sequelize-strict-attributes` is a plugin for [Sequelize](https://sequelize.org) that adds stricter treatment of attribute access after [specifying attributes](https://sequelize.org/docs/v6/core-concepts/model-querying-basics/#specifying-attributes-for-select-queries) in a query. This way, attempts to access instance attributes omitted from the query using `attributes` will throw rather than silently failing by returning undefined. This is especially useful for scenarios where the column is expected to sometimes be null so a fallback value is provided for calculations.\n\n_Note: this is a runtime check. Types are included for the plugin itself, but the types of the returned instances will not be changed. To type checking, the instances will appear to still have omitted attributes._\n\n\n## Installation\n\n`npm install sequelize-strict-attributes`\n\nand include as a JavaScript or TypeScript module (types included):\n\n```typescript\nimport sequelizeStrictAttributes from 'sequelize-strict-attributes';\n```\n\n…or a CommonJS module:\n\n```javascript\nconst sequelizeStrictAttributes = require('sequelize-strict-attributes');\n```\n\nSupports the latest stable Sequelize, version 6.\n\n\n## Usage\n\nCall the plugin with the active Sequelize instance immediately after it's instantiated.\n\n```javascript\nconst sequelize = new Sequelize(…);\nsequelizeStrictAttributes(sequelize);\n```\n\nFrom this point on, any `Model.findAll` or `Model.findOne` query that specifies `attributes:`—and does not use `raw: true`—will throw if you try to access an attribute not included in the select list.\n\n### Example\n\nFor example, given a model that looks something like this:\n\n```javascript\nconst Cart = sequelize.define(\"Cart\", {\n  subtotal: DataTypes.STRING,\n  tax: DataTypes.INTEGER,\n});\n```\n\nAnd an instance fetched like this:\n\n```javascript\nconst cart = await Cart.findOne({\n  attributes: [\"subtotal\"],\n});\n```\n\nWhen accessing the omitted attribute to determine if `tax` needs to be calculated, the program will throw:\n\n```javascript\nif (cart.tax === null) { // <-- Throws!\n  cart.tax = cart.subtotal * TAX_RATE;\n} \n```\n\n```javascript\nif (cart.get(\"tax\") === null) { // <-- Also throws\n```\n\n### Includes\n\nIncluded models will similarly be restricted if their attributes are specified on the `include`.\n\n```javascript\nconst cart = await Cart.findOne({\n  attributes: [],\n  include: {\n    model: Customer,\n    attributes: [\"name\"],\n  },\n});\n\nawait sendReceiptEmail({\n  name: cart.Customer.name,\n  email: cart.Customer.email, // <-- Throws here!\n});\n```\n\n\n### Setting attributes\n\nSetting the attribute directly or using `Model::set` will still work. These changes can be saved as expected, though you won't be able to read them back on the same instance, even after a `.reload()`. (Though shortcuts like addition–assignment will naturally throw.)\n\n\n## Motivation\n\nDisallowing access of attributes that were excluded from a select is a common feature of other ORMs for good reason (eg [Prisma](https://www.prisma.io/docs/concepts/components/prisma-client/select-fields#select-specific-fields) excludes it from the returned type, [ActiveRecord](https://guides.rubyonrails.org/active_record_querying.html#selecting-specific-fields) and [Django](https://docs.djangoproject.com/en/dev/ref/models/querysets/#values) throw errors on access). However, the Sequelize authors [declined to support it](https://github.com/sequelize/sequelize/issues/12108) in the core library. In lieu of core support, this plugin will help guard against the hazard.\n\n\n## Author\n\n[Alec Perkins](https://alecperkins.net)\n\n\n## License\n\nThis package is licensed under the [MIT License](https://opensource.org/licenses/MIT).\n\nSee `./LICENSE` for more information.\n","readmeFilename":"README.md","description":"Plugin that configures Sequelize to throw when accessing attributes omitted from a select.","homepage":"https://alecperkins.net/sequelize-strict-attributes","keywords":["sequelize","orm","attributes","plugin","safety"],"repository":{"type":"git","url":"git+https://github.com/alecperkins/sequelize-strict-attributes.git"},"bugs":{"url":"https://github.com/alecperkins/sequelize-strict-attributes/issues"}}