diff --git a/packages/casl-mongoose/package.json b/packages/casl-mongoose/package.json index bffc966d1..649c1b45d 100644 --- a/packages/casl-mongoose/package.json +++ b/packages/casl-mongoose/package.json @@ -40,14 +40,14 @@ "license": "MIT", "peerDependencies": { "@casl/ability": "^3.0.0 || ^4.0.0 || ^5.1.0", - "mongoose": "^5.12.0" + "mongoose": "^6.0.0" }, "devDependencies": { "@casl/ability": "^5.1.0", "@casl/dx": "workspace:^1.0.0", "chai": "^4.1.0", "chai-spies": "^1.0.0", - "mongoose": "^5.12.0" + "mongoose": "^6.0.0" }, "files": [ "dist", diff --git a/packages/casl-mongoose/spec/accessible_records.spec.ts b/packages/casl-mongoose/spec/accessible_records.spec.ts index ae3a03b14..b0ff7264b 100644 --- a/packages/casl-mongoose/spec/accessible_records.spec.ts +++ b/packages/casl-mongoose/spec/accessible_records.spec.ts @@ -75,7 +75,7 @@ describe('Accessible Records Plugin', () => { }) describe('when ability disallow to perform an action', () => { - let query: mongoose.DocumentQuery + let query: mongoose.QueryWithHelpers beforeEach(() => { query = Post.find().accessibleBy(ability, 'notAllowedAction') diff --git a/packages/casl-mongoose/src/accessible_records.ts b/packages/casl-mongoose/src/accessible_records.ts index 84bd1d358..8ffdb7f07 100644 --- a/packages/casl-mongoose/src/accessible_records.ts +++ b/packages/casl-mongoose/src/accessible_records.ts @@ -1,5 +1,5 @@ import { Normalize, AnyMongoAbility, Generics, ForbiddenError, getDefaultErrorMessage } from '@casl/ability'; -import type { Schema, DocumentQuery, Model, Document } from 'mongoose'; +import type { Schema, QueryWithHelpers, Model, Document } from 'mongoose'; import mongoose from 'mongoose'; import { toMongoQuery } from './mongo'; @@ -7,7 +7,7 @@ function failedQuery( ability: AnyMongoAbility, action: string, modelName: string, - query: DocumentQuery + query: QueryWithHelpers ) { query.where({ __forbiddenByCasl__: 1 }); // eslint-disable-line const anyQuery: any = query; @@ -28,13 +28,13 @@ function failedQuery( type GetAccessibleRecords = ( ability: U, action?: Normalize['abilities']>[0] -) => DocumentQuery; +) => QueryWithHelpers; function accessibleBy( this: any, ability: T, action?: Normalize['abilities']>[0] -): DocumentQuery { +): QueryWithHelpers { let modelName: string | undefined = this.modelName; if (!modelName) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 827d483be..f3c8260a9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -87,13 +87,13 @@ importers: '@casl/dx': workspace:^1.0.0 chai: ^4.1.0 chai-spies: ^1.0.0 - mongoose: ^5.12.0 + mongoose: ^6.0.0 devDependencies: '@casl/ability': link:../casl-ability '@casl/dx': link:../dx chai: 4.3.4 chai-spies: 1.0.0_chai@4.3.4 - mongoose: 5.12.7 + mongoose: 6.0.10 packages/casl-prisma: specifiers: @@ -1986,12 +1986,6 @@ packages: '@babel/types': 7.14.1 dev: false - /@types/bson/4.0.3: - resolution: {integrity: sha512-mVRvYnTOZJz3ccpxhr3wgxVmSeiYinW+zlzQz3SXWaJmD1DuL05Jeq7nKw3SnbKmbleW5qrLG5vdyWe/A9sXhw==} - dependencies: - '@types/node': 15.0.2 - dev: true - /@types/debug/0.0.29: resolution: {integrity: sha1-oeUUrfvZLwOiJLpU1pMRHb8fN1Q=} dev: true @@ -2042,13 +2036,6 @@ packages: resolution: {integrity: sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==} dev: false - /@types/mongodb/3.6.12: - resolution: {integrity: sha512-49aEzQD5VdHPxyd5dRyQdqEveAg9LanwrH8RQipnMuulwzKmODXIZRp0umtxi1eBUfEusRkoy8AVOMr+kVuFog==} - dependencies: - '@types/bson': 4.0.3 - '@types/node': 15.0.2 - dev: true - /@types/node/14.14.41: resolution: {integrity: sha512-dueRKfaJL4RTtSa7bWeTK1M+VH+Gns73oCgzvYfHZywRCoPSd8EkXBL0mZ9unPTveBn+D9phZBaxuzpwjWkW0g==} dev: true @@ -2104,6 +2091,17 @@ packages: resolution: {integrity: sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw==} dev: false + /@types/webidl-conversions/6.1.1: + resolution: {integrity: sha512-XAahCdThVuCFDQLT7R7Pk/vqeObFNL3YqRyFZg+AqAP/W1/w3xHaIxuW7WszQqTbIBOPRcItYJIou3i/mppu3Q==} + dev: true + + /@types/whatwg-url/8.2.1: + resolution: {integrity: sha512-2YubE1sjj5ifxievI5Ge1sckb9k/Er66HyR2c+3+I6VDUUg1TLPdYYTEbQ+DjRkS4nTxMJhgWfSfMRD2sl2EYQ==} + dependencies: + '@types/node': 15.0.2 + '@types/webidl-conversions': 6.1.1 + dev: true + /@types/yargs-parser/20.2.0: resolution: {integrity: sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA==} @@ -2817,6 +2815,10 @@ packages: /balanced-match/1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} + /base64-js/1.5.1: + resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} + dev: true + /before-after-hook/2.2.1: resolution: {integrity: sha512-/6FKxSTWoJdbsLDF8tdIjaRiFXiE6UHsEHE3OPI/cwPURCVi1ukP0gmLn7XWEiFk5TcwQjjY5PWsU+j+tgXgmw==} dev: false @@ -2826,17 +2828,6 @@ packages: engines: {node: '>=8'} dev: true - /bl/2.2.1: - resolution: {integrity: sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==} - dependencies: - readable-stream: 2.3.7 - safe-buffer: 5.2.1 - dev: true - - /bluebird/3.5.1: - resolution: {integrity: sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==} - dev: true - /bottleneck/2.19.5: resolution: {integrity: sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==} dev: false @@ -2881,15 +2872,24 @@ packages: node-int64: 0.4.0 dev: false - /bson/1.1.6: - resolution: {integrity: sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==} - engines: {node: '>=0.6.19'} + /bson/4.5.3: + resolution: {integrity: sha512-qVX7LX79Mtj7B3NPLzCfBiCP6RAsjiV8N63DjlaVVpZW+PFoDTxQ4SeDbSpcqgE6mXksM5CAwZnXxxxn/XwC0g==} + engines: {node: '>=6.9.0'} + dependencies: + buffer: 5.7.1 dev: true /buffer-from/1.1.1: resolution: {integrity: sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==} dev: false + /buffer/5.7.1: + resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==} + dependencies: + base64-js: 1.5.1 + ieee754: 1.2.1 + dev: true + /builtin-modules/3.2.0: resolution: {integrity: sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==} engines: {node: '>=6'} @@ -3187,6 +3187,7 @@ packages: /core-util-is/1.0.2: resolution: {integrity: sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=} + dev: false /cosmiconfig/7.0.0: resolution: {integrity: sha512-pondGvTuVYDk++upghXJabWzL6Kxu6f26ljFw64Swq9v6sQPUL3EUlVDV56diOjpCayKihL6hVe8exIACU4XcA==} @@ -3254,12 +3255,6 @@ packages: dependencies: ms: 2.0.0 - /debug/3.1.0: - resolution: {integrity: sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==} - dependencies: - ms: 2.0.0 - dev: true - /debug/4.3.1: resolution: {integrity: sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==} engines: {node: '>=6.0'} @@ -3344,8 +3339,8 @@ packages: engines: {node: '>=0.4.0'} dev: false - /denque/1.5.0: - resolution: {integrity: sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ==} + /denque/2.0.1: + resolution: {integrity: sha512-tfiWc6BQLXNLpNiR5iGd0Ocu3P3VpxfzFiqubLgMfhfOw9WyvgJBd46CClNn9k3qfbjvT//0cf7AlYRX/OslMQ==} engines: {node: '>=0.10'} dev: true @@ -4136,6 +4131,10 @@ packages: safer-buffer: 2.1.2 dev: false + /ieee754/1.2.1: + resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} + dev: true + /ignore-walk/3.0.3: resolution: {integrity: sha512-m7o6xuOaT1aqheYHKf8W6J5pYH85ZI9w077erOzLje3JsB1gkafkAhHHY19dqjulgIZHFm32Cp5uNZgcQqdJKw==} dependencies: @@ -4195,6 +4194,7 @@ packages: /inherits/2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} + dev: false /ini/1.3.8: resolution: {integrity: sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==} @@ -4372,6 +4372,7 @@ packages: /isarray/1.0.0: resolution: {integrity: sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=} + dev: false /isexe/2.0.0: resolution: {integrity: sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=} @@ -5392,86 +5393,55 @@ packages: engines: {node: '>=0.10.0'} dev: false - /mongodb/3.6.6: - resolution: {integrity: sha512-WlirMiuV1UPbej5JeCMqE93JRfZ/ZzqE7nJTwP85XzjAF4rRSeq2bGCb1cjfoHLOF06+HxADaPGqT0g3SbVT1w==} - engines: {node: '>=4'} - peerDependencies: - aws4: '*' - bson-ext: '*' - kerberos: '*' - mongodb-client-encryption: '*' - mongodb-extjson: '*' - snappy: '*' - peerDependenciesMeta: - aws4: - optional: true - bson-ext: - optional: true - kerberos: - optional: true - mongodb-client-encryption: - optional: true - mongodb-extjson: - optional: true - snappy: - optional: true + /mongodb-connection-string-url/2.1.0: + resolution: {integrity: sha512-Qf9Zw7KGiRljWvMrrUFDdVqo46KIEiDuCzvEN97rh/PcKzk2bd6n9KuzEwBwW9xo5glwx69y1mI6s+jFUD/aIQ==} dependencies: - bl: 2.2.1 - bson: 1.1.6 - denque: 1.5.0 - optional-require: 1.0.3 - safe-buffer: 5.2.1 - optionalDependencies: - saslprep: 1.0.3 + '@types/whatwg-url': 8.2.1 + whatwg-url: 9.1.0 dev: true - /mongoose-legacy-pluralize/1.0.2_mongoose@5.12.7: - resolution: {integrity: sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==} - peerDependencies: - mongoose: '*' + /mongodb/4.1.2: + resolution: {integrity: sha512-pHCKDoOy1h6mVurziJmXmTMPatYWOx8pbnyFgSgshja9Y36Q+caHUzTDY6rrIy9HCSrjnbXmx3pCtvNZHmR8xg==} + engines: {node: '>=12.9.0'} dependencies: - mongoose: 5.12.7 + bson: 4.5.3 + denque: 2.0.1 + mongodb-connection-string-url: 2.1.0 + optionalDependencies: + saslprep: 1.0.3 dev: true - /mongoose/5.12.7: - resolution: {integrity: sha512-BniNwACn7uflK2h+M3juvyLH5nn9JDFgnB5KE2EwWFwSrRyhSpPnCtanRKJW3OtMCJyPccMIjtGZxHNW7JfnIw==} - engines: {node: '>=4.0.0'} + /mongoose/6.0.10: + resolution: {integrity: sha512-p/wiEDUXoQuyb/xQx8QW/YGN92ZsojJ5E/DDgMCUU0WOGxc5uhcWoZ7ijLu6Ssjq8UkwVSv+jzkYp4Wbr+NqBg==} + engines: {node: '>=12.0.0'} dependencies: - '@types/mongodb': 3.6.12 - bson: 1.1.6 + bson: 4.5.3 kareem: 2.3.2 - mongodb: 3.6.6 - mongoose-legacy-pluralize: 1.0.2_mongoose@5.12.7 - mpath: 0.8.3 - mquery: 3.2.5 + mongodb: 4.1.2 + mpath: 0.8.4 + mquery: 4.0.0 ms: 2.1.2 regexp-clone: 1.0.0 - safe-buffer: 5.2.1 sift: 13.5.2 sliced: 1.0.1 transitivePeerDependencies: - - aws4 - - bson-ext - - kerberos - - mongodb-client-encryption - - mongodb-extjson - - snappy + - supports-color dev: true - /mpath/0.8.3: - resolution: {integrity: sha512-eb9rRvhDltXVNL6Fxd2zM9D4vKBxjVVQNLNijlj7uoXUy19zNDsIif5zR+pWmPCWNKwAtqyo4JveQm4nfD5+eA==} + /mpath/0.8.4: + resolution: {integrity: sha512-DTxNZomBcTWlrMW76jy1wvV37X/cNNxPW1y2Jzd4DZkAaC5ZGsm8bfGfNOthcDuRJujXLqiuS6o3Tpy0JEoh7g==} engines: {node: '>=4.0.0'} dev: true - /mquery/3.2.5: - resolution: {integrity: sha512-VjOKHHgU84wij7IUoZzFRU07IAxd5kWJaDmyUzQlbjHjyoeK5TNeeo8ZsFDtTYnSgpW6n/nMNIHvE3u8Lbrf4A==} - engines: {node: '>=4.0.0'} + /mquery/4.0.0: + resolution: {integrity: sha512-nGjm89lHja+T/b8cybAby6H0YgA4qYC/lx6UlwvHGqvTq8bDaNeCwl1sY8uRELrNbVWJzIihxVd+vphGGn1vBw==} + engines: {node: '>=12.0.0'} dependencies: - bluebird: 3.5.1 - debug: 3.1.0 + debug: 4.3.1 regexp-clone: 1.0.0 - safe-buffer: 5.1.2 sliced: 1.0.1 + transitivePeerDependencies: + - supports-color dev: true /ms/2.0.0: @@ -5684,11 +5654,6 @@ packages: mimic-fn: 2.1.0 dev: false - /optional-require/1.0.3: - resolution: {integrity: sha512-RV2Zp2MY2aeYK5G+B/Sps8lW5NHAzE5QClbFP15j+PWmP+T9PxlJXBOOLoSAdgwFvS4t0aMR4vpedMkbHfh0nA==} - engines: {node: '>=4'} - dev: true - /optionator/0.8.3: resolution: {integrity: sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA==} engines: {node: '>= 0.8.0'} @@ -5959,6 +5924,7 @@ packages: /process-nextick-args/2.0.1: resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==} + dev: false /progress/2.0.3: resolution: {integrity: sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==} @@ -5987,7 +5953,6 @@ packages: /punycode/2.1.1: resolution: {integrity: sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==} engines: {node: '>=6'} - dev: false /q/1.5.1: resolution: {integrity: sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=} @@ -6098,6 +6063,7 @@ packages: safe-buffer: 5.1.2 string_decoder: 1.1.1 util-deprecate: 1.0.2 + dev: false /readable-stream/3.6.0: resolution: {integrity: sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==} @@ -6302,6 +6268,7 @@ packages: /safe-buffer/5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} + dev: false /safer-buffer/2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} @@ -6613,6 +6580,7 @@ packages: resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==} dependencies: safe-buffer: 5.1.2 + dev: false /string_decoder/1.3.0: resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} @@ -6829,6 +6797,13 @@ packages: punycode: 2.1.1 dev: false + /tr46/2.1.0: + resolution: {integrity: sha512-15Ih7phfcdP5YxqiB+iDtLoaTz4Nd35+IiAv0kQ5FNKHzXgdWqPoTIqEDDJmXceQt4JZk6lVPT8lnDlPpGDppw==} + engines: {node: '>=8'} + dependencies: + punycode: 2.1.1 + dev: true + /traverse/0.6.6: resolution: {integrity: sha1-y99WD9e5r2MlAv7UD5GMFX6pcTc=} dev: false @@ -7033,6 +7008,7 @@ packages: /util-deprecate/1.0.2: resolution: {integrity: sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=} + dev: false /uuid/3.4.0: resolution: {integrity: sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==} @@ -7094,7 +7070,6 @@ packages: /webidl-conversions/6.1.0: resolution: {integrity: sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w==} engines: {node: '>=10.4'} - dev: false /whatwg-encoding/1.0.5: resolution: {integrity: sha512-b5lim54JOPN9HtzvK9HFXvBma/rnfFeqsic0hSpjtDbVxR3dJKLc+KB4V6GgiGOvl7CY/KNh8rxSo9DKQrnUEw==} @@ -7115,6 +7090,14 @@ packages: webidl-conversions: 6.1.0 dev: false + /whatwg-url/9.1.0: + resolution: {integrity: sha512-CQ0UcrPHyomtlOCot1TL77WyMIm/bCwrJ2D6AOKGwEczU9EpyoqAokfqrf/MioU9kHcMsmJZcg1egXix2KYEsA==} + engines: {node: '>=12'} + dependencies: + tr46: 2.1.0 + webidl-conversions: 6.1.0 + dev: true + /which-boxed-primitive/1.0.2: resolution: {integrity: sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==} dependencies: