/**
 * Skipped minification because the original files appears to be already minified.
 * Original file: /npm/@casl/mongoose@8.0.5/dist/es6c/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var t=require("@casl/ability/extra");var n=require("@casl/ability");var r=require("mongoose");function e(t){const n=t.conditions;return t.inverted?{$nor:[n]}:n}const o={$expr:{$eq:[0,1]}};class c{constructor(t,n){this.t=t;this.o=n}ofType(n){const r=t.rulesToQuery(this.t,this.o,n,e);return r===null?o:r}}function s(t,n="read"){return new c(t,n)}function i(t,n,r){const e=n.detectSubjectType({constructor:t.model});if(!e)throw new TypeError(`Cannot detect subject type of "${t.model.modelName}" to return accessible records`);const o=s(n,r).ofType(e);return t.and([o])}function u(t,n){return i(this.where(),t,n)}function f(t,n){return i(this,t,n)}function a(t){t.query.accessibleBy=f;t.statics.accessibleBy=u}const l=t=>Object.keys(t.paths);function h(t,r){const e=r.getFields(t);if(!r||!("except"in r))return e;const o=n.wrapArray(r.except);return e.filter(t=>o.indexOf(t)===-1)}function p(){let t;return(r,e)=>{if(!t){const o=e&&"only"in e?n.wrapArray(e.only):h(r,e);t=()=>o}return t}}function d(n,r){const e=Object.assign({getFields:l},r);const o=p();function c(r,c){return new t.AccessibleFields(r,c||"read",o(n,e)).of(this)}function s(r,c){const s={constructor:this};return new t.AccessibleFields(r,c||"read",o(n,e)).of(s)}n.statics.accessibleFieldsBy=s;n.method("accessibleFieldsBy",c)}const w=t=>{const n=typeof t==="string"?r.models[t]:t;if(!n)throw new Error(`Unknown mongoose model "${t}"`);return"schema"in n?Object.keys(n.schema.paths):[]};function b(n,r="read"){return new t.AccessibleFields(n,r,w)}exports.accessibleBy=s;exports.accessibleFieldsBy=b;exports.accessibleFieldsPlugin=d;exports.accessibleRecordsPlugin=a;exports.getSchemaPaths=l;
//# sourceMappingURL=index.js.map
