coll-fns 1.3.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,6 +47,8 @@ Stop repeating business logic all over your code base. Define hooks on collectio
47
47
  - [`insert(Coll, doc)`](#insertcoll-doc)
48
48
  - [`update(Coll, selector, modifier, options)`](#updatecoll-selector-modifier-options)
49
49
  - [`remove(Coll, selector)`](#removecoll-selector)
50
+ - [`registerSoftRemove(Coll, options)`](#registersoftremovecoll-options)
51
+ - [`softRemove(Coll, selector, keepModifier, options)`](#softremovecoll-selector-keepmodifier-options)
50
52
  - [`configurePool(options)`](#configurepooloptions)
51
53
  - [Default behavior](#default-behavior)
52
54
  - [Options](#options)
@@ -1214,6 +1216,106 @@ remove(Users, { inactive: true });
1214
1216
  3. Remove the documents
1215
1217
  4. Fire `onRemoved` hooks asynchronously with each removed document
1216
1218
 
1219
+ ## `registerSoftRemove(Coll, options)`
1220
+
1221
+ Register soft-remove behavior for a collection. This is a startup-time registration step similar to joins/hooks registration.
1222
+
1223
+ `registerSoftRemove` defines which targeted documents should be kept when `softRemove` is called, and optionally how those kept documents should be updated.
1224
+
1225
+ ```js
1226
+ import { registerSoftRemove } from "coll-fns";
1227
+
1228
+ registerSoftRemove(Projects, {
1229
+ /* Optional. Fields fetched before evaluating keep predicates. */
1230
+ fields: { _id: 1, ownerId: 1, archived: 1 },
1231
+
1232
+ /* Optional predicate. If true, the doc is kept. */
1233
+ when(project) {
1234
+ return project.archived;
1235
+ },
1236
+
1237
+ /* Optional predicate by references.
1238
+ * Return [Coll, selector] pairs to test with exists(). */
1239
+ docToCollSelectorPairs(project) {
1240
+ return [
1241
+ [Tasks, { projectId: project._id, status: { $ne: "done" } }],
1242
+ [Invoices, { projectId: project._id }],
1243
+ ];
1244
+ },
1245
+
1246
+ /* Optional default modifier applied to kept docs by softRemove(). */
1247
+ keepModifier: { $set: { archived: true, removedAt: new Date() } },
1248
+ });
1249
+ ```
1250
+
1251
+ **Options**
1252
+
1253
+ - `fields`: fields to fetch before keep checks (merged with `_id` internally).
1254
+ - `when(doc)`: optional predicate; truthy means keep.
1255
+ - `docToCollSelectorPairs(doc)`: optional function returning `[[Coll, selector], ...]`; if any selector matches at least one doc, keep.
1256
+ - `keepModifier`: optional default modifier used by `softRemove` for kept docs (can also be provided per call).
1257
+
1258
+ At least one of `when` or `docToCollSelectorPairs` must be provided.
1259
+
1260
+ ## `softRemove(Coll, selector, keepModifier, options)`
1261
+
1262
+ Run a remove operation that can keep some matched documents (and optionally update those kept documents).
1263
+
1264
+ ```js
1265
+ import { softRemove } from "coll-fns";
1266
+
1267
+ /* Remove removable projects; archive the ones that must be kept. */
1268
+ const result = await softRemove(
1269
+ Projects,
1270
+ { workspaceId },
1271
+ { $set: { archived: true, removedAt: new Date() } },
1272
+ { detailed: true }
1273
+ );
1274
+
1275
+ // { removed: number, updated: number|null }
1276
+ ```
1277
+
1278
+ `keepModifier` can also be a function, including an async function. This is useful when the modifier must be built from runtime context.
1279
+
1280
+ ```js
1281
+ await softRemove(
1282
+ Posts,
1283
+ { _id: postId },
1284
+ () => ({
1285
+ $set: {
1286
+ removedAt: new Date(),
1287
+ removedBy: Meteor.userId(),
1288
+ status: "archived",
1289
+ },
1290
+ }),
1291
+ { detailed: true }
1292
+ );
1293
+ ```
1294
+
1295
+ If no `keepModifier` is passed, the default one from `registerSoftRemove` is used.
1296
+ If neither is defined, kept docs are simply excluded from removal.
1297
+
1298
+ ```js
1299
+ /* Uses the registered default keepModifier */
1300
+ await softRemove(Projects, { workspaceId });
1301
+ ```
1302
+
1303
+ **Execution flow**
1304
+
1305
+ 1. Fetch docs targeted by `selector`.
1306
+ 2. Evaluate keep predicates per doc (`when` and/or `docToCollSelectorPairs`).
1307
+ 3. Remove docs not marked to keep.
1308
+ 4. If a keep modifier exists, update kept docs with it.
1309
+
1310
+ `softRemove` uses `coll-fns` `remove(...)` and `update(...)` internally.
1311
+ That means the usual hooks (`beforeRemove`/`onRemoved`, `beforeUpdate`/`onUpdated`) are still applied in the corresponding branch.
1312
+
1313
+ **Options**
1314
+
1315
+ - `detailed` (default `false`):
1316
+ - `false`: returns total affected count (`removed + updated`).
1317
+ - `true`: returns `{ removed, updated }`.
1318
+
1217
1319
  ## `configurePool(options)`
1218
1320
 
1219
1321
  After hooks can generate significant background work, especially when they trigger cascading writes and more after hooks.
package/dist/coll-fns.cjs CHANGED
@@ -1,2 +1,2 @@
1
- function n(){return n=Object.assign?Object.assign.bind():function(n){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var t in e)({}).hasOwnProperty.call(e,t)&&(n[t]=e[t])}return n},n.apply(null,arguments)}function r(n,r){if(null==n)return{};var e={};for(var t in n)if({}.hasOwnProperty.call(n,t)){if(-1!==r.indexOf(t))continue;e[t]=n[t]}return e}function e(n){var r=function(n){if("object"!=typeof n||!n)return n;var r=n[Symbol.toPrimitive];if(void 0!==r){var e=r.call(n,"string");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(n)}(n);return"symbol"==typeof r?r:r+""}var t={count:function(){throw new Error("'count' method must be defined with 'setProtocol'.")},findList:function(){throw new Error("'findList' method must be defined with 'setProtocol'.")},getName:function(){return""},getTransform:function(){},insert:function(){throw new Error("'insert' method must be defined with 'setProtocol'.")},remove:function(){throw new Error("'remove' method must be defined with 'setProtocol'.")},update:function(){throw new Error("'update' method must be defined with 'setProtocol'.")}},o=t;function i(n){return n?"function"==typeof n?n(o):"object"==typeof n?n:o:o}var u=function(){},f=function(n){return{}.toString.call(n).split(" ")[1].slice(0,-1).toLowerCase()},c=function(n){return Array.isArray(n)},l=function(n){return"function"==typeof n},a=function(n){return n&&!c(n)&&"object"===f(n)};function d(n){return l(null==n?void 0:n.then)}function s(n,r){return p(function(r){var e=r[0];return[n[e]||e,r[1]]},r)}function v(n,r){var e=n.split("."),t=e[0],o=function(n,r){(null==r||r>n.length)&&(r=n.length);for(var e=0,t=Array(r);e<r;e++)t[e]=n[e];return t}(e).slice(1),i=r[t];if(o.length<1)return i;var u=o.join(".");return a(i)?v(u,i):c(i)?i.flatMap(function(n){var r=v(u,n);return c(r)?r:[r]}):i}function m(n,r){if(void 0===r&&(r=u),c(n)){var e=n;return e.some(d)?Promise.all(e).then(function(n){return r(n,!0)}):r(e,!1)}return d(n)?n.then(function(n){return r(n,!0)}):r(n,!1)}function p(n,r){if(void 0===r)return function(r){return p(n,r)};if(c(r))return r.map(n);if(!a(r))throw new TypeError("'map' only works on array or plain object");return Object.fromEntries(Object.entries(r).map(n))}function h(n,r){if(void 0===r)return function(r){return h(n,r)};if(c(r))return r.filter(n);if(!a(r))throw new TypeError("'filter' only works on array or plain object");return Object.fromEntries(Object.entries(r).filter(n))}function y(n,r){queueMicrotask(function(){try{var e=function(r,e){try{var t=Promise.resolve(n()).then(function(){})}catch(n){return e(n)}return t&&t.then?t.then(void 0,e):t}(0,function(n){l(r)&&r(n)});return Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(n){return Promise.reject(n)}})}var b=["array","function","object"],w=b.join("', '"),g=new Map,j=null;function x(n){return g.get(n)||{}}function _(){return j}var E=["+"];function O(n,r){return void 0===r&&(r=!1),a(n)?r?P(n):n:n?void 0:{}}function P(r,e){var t;if(!r)return r;var o=Object.keys(r);return o.some(function(n){return n.startsWith("$")})?e?((t={})[e]=r,t):r:o.reduce(function(t,o){var i=o.indexOf(".");if(i>=0){var u=o.slice(0,i),f=r[u];if(f&&!a(f))return t}var c,l=r[o],d=e?[e,o].join("."):o;return a(l)?n({},t,P(l,d)):n({},t,((c={})[d]=!!l,c))},void 0)}function k(t,o){var i;if(void 0===o&&(o={}),!a(t))return{_:O(t)};var u=function(t,o){void 0===o&&(o={});var i=Object.keys(o),u=_();if(u){var f=t[u],c=r(t,[u].map(e));return n(f?{"+":h(function(n){return i.includes(n[0])},f)}:{"+":void 0},c)}return Object.entries(t).reduce(function(r,e){var t,o,u=e[0],f=e[1];return i.includes(u)?n({},r,{"+":n({},r["+"]||{},(o={},o[u]=f,o))}):n({},r,((t={})[u]=f,t))},{})}(t,o),f=u["+"],c=r(u,E);if(!f)return{_:O(c,!0),"+":void 0};if(!c||null==(i=Object.keys(c))||!i.length)return{_:O(c,!0),"+":f};var l=Object.keys(f).reduce(function(r,e){var t,i=o[e],u=i.on,f=i.fields,c=Array.isArray(u)?((t={})[u[0]]=1,t):void 0;return c||f?n({},r,c,f):r},c);return{_:O(l,!0),"+":f}}function C(n,r){if(!A(n)&&!A(r))return n||r?T(I(n),I(r)):{}}function T(r,e){void 0===r&&(r={}),void 0===e&&(e={});for(var t=n({},r),o=0,i=Object.entries(e||{});o<i.length;o++){var u=i[o],f=u[0],c=u[1],l=t[f];t[f]=a(l)&&a(c)?T(l,c):c}return t}function A(n){return void 0===n||!!n&&!a(n)}function I(n){return a(n)?h(function(n){return n[1]},n):{}}function N(r,e){var t,o,i,u;if(!a(e))return e;var f=_(),c=f?null==(t=e[f])?void 0:t[r]:e[r];if("number"!=typeof c)return e;if(Infinity===c)return e;var l=c-1;return n({},e,f?((u={})[f]=n({},e[f],((i={})[r]=l,i)),u):((o={})[r]=l,o))}var M=["fields","transform"],S=["_key","Coll","on","single","postFetch","limit"],F=["_key","Coll","on","single","postFetch","limit"];function L(e,t,o){void 0===t&&(t={}),void 0===o&&(o={});var u=i(),d=u.count,s=u.findList,p=u.getTransform,h=x(e),y=p(e),b=o.fields,w=o.transform,g=void 0===w?y:w,j=r(o,M),_=function(n){return l(g)?g(n):n},E=k(b,h),P=E._,C=E["+"],T=void 0===C?{}:C,A=Object.keys(T);return!h||null==A||!A.length||b&&!a(b)?m(s(e,t,n({},j,{fields:P,transform:null})),function(n){return n.map(_)}):m(s(e,t,n({},j,{fields:P,transform:null})),function(t){var i=A.reduce(function(r,e){var t,o=h[e];if(!o)return r;var i=f(o.on),u=n({},o,{_key:e});return n({},r,((t={})[i]=[].concat(r[i]||[],[u]),t))},{}),u=i.array,s=i.object,p=void 0===s?[]:s,y=i.function,w=void 0===y?[]:y;return m((void 0===u?[]:u).reduce(function(t,i){var u=i._key,s=i.Coll,p=i.on,h=i.single,y=i.postFetch,w=r(i,S);return m(t,function(r){var t,i,j=p[0],_=p[1],E=p[2],P=void 0===E?{}:E,C=c(j),A=C?r.flatMap(function(n){return n[j[0]]}):r.map(function(n){return n[j]}),I=c(_),M=n({},P,I?((t={})[_[0]]={$elemMatch:{$in:A}},t):((i={})[_]={$in:A},i)),S=s===e&&T[u]>1;return m(S&&d(e,M),function(e){var t,i=S&&!e,d=S?N(u,b):T[u],p=k(d,x(s)||{})._,E=!p||Object.keys(p).length<=0,P=a(d)&&!E&&"_id"!==_?n({},d,((t={})[_]=1,t)):d,A=n({},o,w,{fields:O(P),limit:void 0,transform:S?g:void 0});return m(i?[]:L(s,M,A),function(e){var t=I?{}:e.reduce(function(r,e){var t,o=v(_,e);return c(o)?o.reduce(function(r,t){var o;return n({},r,((o={})[t]=[].concat(r[t]||[],[e]),o))},r):n({},r,((t={})[o]=[].concat(r[o]||[],[e]),t))},{});return r.map(function(r){var o,i,c,a,d=[];I?d=e.filter(function(n){var e,t=n[_[0]]||[];return C?(e=t,(r[j[0]]||[]).some(function(n){return e.indexOf(n)>=0})):t.includes(r[j])}):C?(i="_id",c=(r[j[0]]||[]).flatMap(function(n){return t[n]||[]}),a=l(i)?i:"string"===f(i)?function(n){return n[i]}:function(n){return n},d=c.reduce(function(n,r){var e=a(r);return n.find(function(n){return a(n)===e})?n:[].concat(n,[r])},[])):d=t[r[j]]||[];var s=h?d[0]:d,v=l(y)?y(s,r):s;return n({},r,((o={})[u]=v,o))})})})})},t),function(n){return m(p.map(function(n){return R({Coll:e,join:n,fields:T[n._key],subSelector:n.on,options:j,parentFields:b})}),function(r){return m(n.map(function(n){var t=r.reduce(function(n,r){return r(n)},n);return m(w.reduce(function(r,t){var o=t.on;return m([r,R({Coll:e,join:t,fields:T[t._key],subSelector:l(o)?o(n):o,options:j,parentFields:b})],function(n){return(0,n[1])(n[0])})},t),function(n){return _(n)})}),function(n){return n})})})})}function J(r,e,t){return void 0===t&&(t={}),m(L(r,e,n({},t,{limit:1})),function(n){return n[0]})}function R(e){var t=e.Coll,o=e.join,u=o._key,f=o.Coll,c=o.single,a=o.postFetch,d=o.limit,s=r(o,F),v=e.fields,p=e.subSelector,h=e.options,y=e.parentFields,b=i(),w=f===t;return m(w&&(0,b.count)(t,p),function(r){var e=w&&(!v||!r),t=w?N(u,y):v,o=n({},h,s,{fields:O(t),limit:c?1:d||void 0});return m(e?[]:L(f,p,o),function(r){return function(e){var t,o=c?r[0]:r,i=l(a)?a(o,e):o;return n({},e,((t={})[u]=i,t))}})})}var U="drop",$="shift",z=!1,q=W({maxConcurrent:10,maxPending:250});function D(){return z=!0,q}function W(n){var r=function(n){try{if(d.size>=t)throw new Error("Max concurrent calls reached");var e=function(r,e){try{var t=function(r,e){try{var t=function(){d.add(n);var r=n.args;return Promise.resolve(n.fn.apply(void 0,void 0===r?[]:r)).then(function(){})}()}catch(n){return e(n)}return t&&t.then?t.then(void 0,e):t}(0,function(r){!function(n,r){var e=l(u)?u:console.error;Promise.resolve().then(function(){return e(n,r)}).catch(function(n){return console.error(n)})}(r,n)})}catch(n){return e(!0,n)}return t&&t.then?t.then(e.bind(null,!1),e.bind(null,!0)):e(!1,t)}(0,function(e,o){if(d.delete(n),function(){if(!(d.size>=t)){var n=a.shift();n&&r(n)}}(),e)throw o;return o});return Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(n){return Promise.reject(n)}},e=n.maxConcurrent,t=void 0===e?10:e,o=n.maxPending,i=void 0===o?250:o,u=n.onError,f=n.onOverflow,c=void 0===f?B:f;!function(n){void 0===n&&(n={});var r=n.maxConcurrent,e=n.maxPending,t=n.onOverflow;if(!(Number.isFinite(r)&&Number.isInteger(r)&&r>=1))throw new TypeError("'maxConcurrent' must be a finite positive integer.");if(!(Infinity===e||Number.isInteger(e)&&e>=0))throw new TypeError("'maxPending' must be a positive integer or `Infinity`");if(!l(t)&&![U,$].includes(t))throw new TypeError("'onOverflow' must be either a function or one of '"+U+"' or '"+$+"'")}({maxConcurrent:t,maxPending:i,onError:u,onOverflow:c});var a=[],d=new Set;function s(n){d.size<t?r(n):a.length<i?a.push(n):function(n){c!==U&&(c===$?(a.shift(),a.length<i&&s(n)):l(c)?function(n){var r=[].concat(a,[n]),e=c([].concat(a),n);if(void 0!==e){if(!Array.isArray(e))throw new TypeError("'onOverflow' must return an array");var t=e.reduce(function(n,e){var t=e._id,o=r.find(function(n){return n._id===t});return o?n.includes(o)?n:[].concat(n,[o]):n},[]);a=t}}(n):console.error("Invalid 'onOverflow'"))}(n)}return{add:function(n){s({_id:Symbol(),fn:n,args:Array.from([].slice.call(arguments,1))})},clear:function(){a=[]}}}function B(){console.warn("'maxPending' limit reached. Call is dropped")}var G,H=function(n){void 0===n&&(n={});try{var r,e=[].slice.call(arguments,1),t=n.hookType,o=n.fn,i=n.onError,u=n.unless,f=n.when;return l(o)?Promise.resolve(function(n,i){try{var c=function(){function n(n){return r?n:Promise.resolve(o.apply(void 0,e))}if(!(null==u?void 0:u.apply(void 0,e))&&(!f||f.apply(void 0,e))){var i=function(){if(!Q.includes(t))return Promise.resolve(o.apply(void 0,e)).then(function(n){return r=1,n})}();return i&&i.then?i.then(n):n(i)}}()}catch(n){return i(n)}return c&&c.then?c.then(void 0,i):c}(0,function(r){if(!l(i))throw r;i(r,n)})):Promise.resolve()}catch(n){return Promise.reject(n)}},K=["beforeInsert","beforeUpdate","beforeRemove","onInserted","onUpdated","onRemoved"],Q=["onInserted","onUpdated","onRemoved"],V=new Map;function X(n,r){var e=V.get(n)||{};return r?e[r]:e}function Y(n,r){var e=X(n,r);if(e)return function(n,r){if(void 0===n&&(n=[]),void 0===r&&(r=!1),n.length){var e=function(n){return void 0===n&&(n=[]),n.reduce(function(n,r){return{fields:C(n.fields,r.fields),before:n.before||r.before}},{fields:null,before:void 0})}(n);return{before:e.before,fields:e.fields,fn:function(){var e=[].slice.call(arguments);if(!r)return m(n.map(function(n){return H.apply(void 0,[n].concat(e))}));n.forEach(function(n){return Z.apply(void 0,[n].concat(e))})}}}}(e,Q.includes(r))}function Z(n){void 0===n&&(n={});var r=null!=G?G:G||(G=D());r.add.apply(r,[H,n].concat([].slice.call(arguments,1)))}function nn(n,r){var e;null==(e=console)||e.error("Error in '"+r.hookType+"' hook of '"+r.collName+"' collection:",n)}var rn=["multi"],en=["multi"],tn=["multi"],on={__proto__:null,meteorAsync:{count:function(n,r,e){var t=n.rawCollection();return t.countDocuments?t.countDocuments(r):n.find(r,e).countAsync()},findList:function(n,r,e){return n.find(r,e).fetchAsync()},getName:function(n){return n._name||""},getTransform:function(n){return n._transform},insert:function(n,r){return n.insertAsync(r)},remove:function(n,r){return n.removeAsync(r)},update:function(r,e,t,o){return r.updateAsync(e,t,n({multi:!0},o))}},meteorSync:{count:function(n,r,e){return n.find(r,e).count()},findList:function(n,r,e){return n.find(r,e).fetch()},getName:function(n){return n._name||""},getTransform:function(n){return n._transform},insert:function(n,r){return n.insert(r)},remove:function(n,r){return n.remove(r)},update:function(r,e,t,o){return r.update(e,t,n({multi:!0},o))}},node:{count:function(n,r,e){return void 0===r&&(r={}),void 0===e&&(e={}),n.countDocuments(r||{},e)},findList:function(n,r,e){void 0===r&&(r={}),void 0===e&&(e={});var t=s({fields:"projection"},e||{});return n.find(r||{},t).toArray()},getName:function(n){return n.collectionName||""},getTransform:function(n){return"function"==typeof(null==n?void 0:n.transform)?n.transform:void 0},insert:function(n,r,e){return n.insertOne(r,e).then(function(n){return null==n?void 0:n.insertedId})},remove:function(n,e,t){void 0===e&&(e={}),void 0===t&&(t={});var o=t||{},i=o.multi,u=void 0===i||i,f=r(o,en);return(u?n.deleteMany(e||{},f):n.deleteOne(e||{},f)).then(function(n){var r;return null!=(r=null==n?void 0:n.deletedCount)?r:0})},update:function(n,e,t,o){void 0===e&&(e={}),void 0===t&&(t={}),void 0===o&&(o={});var i=o||{},u=i.multi,f=void 0===u||u,c=r(i,tn);return(f?n.updateMany(e||{},t||{},c):n.updateOne(e||{},t||{},c)).then(function(n){var r,e;return null!=(r=null!=(e=null==n?void 0:n.modifiedCount)?e:null==n?void 0:n.upsertedCount)?r:0})}}};exports.configurePool=function(n){if(void 0===n&&(n={}),z)throw new Error("'configurePool' must be called at startup before processing hooks");q=W(n)},exports.count=function(n,r,e){return m((0,i().count)(n,r,e),function(n){return n})},exports.exists=function(n,r){return m(J(n,r,{fields:{_id:1}}),function(n){return!!n})},exports.fetchIds=function(r,e,t){return m(L(r,e,n({},t,{fields:{_id:1}})),function(n){return n.map(function(n){return n._id})})},exports.fetchList=L,exports.fetchOne=J,exports.flattenFields=P,exports.getJoinPrefix=_,exports.getJoins=x,exports.hook=function(r,e){Object.entries(e).forEach(function(e){var t=e[0],o=e[1];if(!c(o))throw new TypeError("'"+t+"' hooks must be an array");o.forEach(function(e){return function(r,e,t){var o;if(!K.includes(e))throw new TypeError("'"+e+"' is not a valid hook type");if(!l(null==t?void 0:t.fn))throw new TypeError("'hook' must be a function or contain a 'fn' key");var u=i().getName,f=X(r),c=f[e]||[],a=n({onError:Q.includes(e)?nn:void 0},t,{Coll:r,collName:u(r),hookType:e}),d=[].concat(c,[a]);V.set(r,n({},f,((o={})[e]=d,o)))}(r,t,e)})})},exports.insert=function(n,r){var e=i(),t=Y(n,"beforeInsert");return m(l(null==t?void 0:t.fn)&&t.fn(r),function(){var t=Y(n,"onInserted");return m(e.insert(n,r),function(r){if(!t)return r;var e=t.fields,o=t.fn,i=e?Object.keys(e):[];return m(1===i.length&&"_id"===i[0]?{_id:r}:J(n,{_id:r},{fields:e}),function(n){return y(function(){return o(n)},function(n){var r;return null==(r=console)?void 0:r.error("'onInserted' error:",n)}),r})})})},exports.join=function(r,e){e?(Object.entries(e).forEach(function(n){var r=n[0],e=n[1],t=e.on,o=e.fields;if(!e.Coll)throw new Error("Collection 'Coll' for '"+r+"' join is required.");if(!t)throw new Error("Join '"+r+"' has no 'on' condition specified.");var i=f(t);if(!b.includes(i))throw new Error("Join '"+r+"' has an unrecognized 'on' condition type of '"+i+"'. Should be one of '"+w+"'.");l(t)&&!o&&function(){var n;console&&console.warn&&(n=console).warn.apply(n,[].slice.call(arguments))}("Join '"+r+"' is defined with a function 'on', but no 'fields' are explicitly specified. This could lead to failed joins if the keys necessary for the join are not specified at query time.")}),g.set(r,n({},g.get(r),e))):g.set(r,void 0)},exports.protocols=on,exports.remove=function(n,r){var e=i(),t=Y(n,"beforeRemove"),o=Y(n,"onRemoved"),u=function(){var n=[].slice.call(arguments).filter(function(n){return n});return n.length?n.reduce(function(n,r){return C(n,r.fields)},null):null}(t,o);return m(null===u?[]:L(n,r,{fields:u}),function(i){return m(l(null==t?void 0:t.fn)&&t.fn(i),function(){var t=e.remove(n,r);return t&&l(null==o?void 0:o.fn)?(y(function(){return i.forEach(function(n){return o.fn(n)})},function(n){var r;return null==(r=console)?void 0:r.error("'onRemoved' error:",n)}),t):t})})},exports.setJoinPrefix=function(n){j=n},exports.setProtocol=function(r){void 0===r&&(r={}),o=n({},t,r)},exports.update=function(e,t,o,u){var f=void 0===u?{}:u,c=f.multi,a=void 0===c||c,d=r(f,rn),s=i(),v=Y(e,"beforeUpdate"),p=Y(e,"onUpdated"),h=n({multi:a},d),b=function(n,r){if(!n&&!r)return null;if(!r)return null==n?void 0:n.fields;var e=r.before?r.fields:{_id:1};return n?C(n.fields,e):e}(v,p);return m(null===b?[]:L(e,t,{fields:b,limit:a?void 0:1}),function(n){return m(l(null==v?void 0:v.fn)&&v.fn(n,o),function(){return m(s.update(e,t,o,h),function(r){if(!r||!l(null==p?void 0:p.fn))return r;var t=function(n){return void 0===n&&(n=[]),Object.fromEntries(n.map(function(n){return[n._id,n]}))}(n);return m(L(e,{_id:{$in:Object.keys(t)}},{fields:p.fields}),function(n){return y(function(){return n.forEach(function(n){p.fn(n,t[n._id])})},function(n){var r;return null==(r=console)?void 0:r.error("'onUpdated' error:",n)}),r})})})})};
1
+ function n(){return n=Object.assign?Object.assign.bind():function(n){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var t in e)({}).hasOwnProperty.call(e,t)&&(n[t]=e[t])}return n},n.apply(null,arguments)}function r(n,r){if(null==n)return{};var e={};for(var t in n)if({}.hasOwnProperty.call(n,t)){if(-1!==r.indexOf(t))continue;e[t]=n[t]}return e}function e(n){var r=function(n){if("object"!=typeof n||!n)return n;var r=n[Symbol.toPrimitive];if(void 0!==r){var e=r.call(n,"string");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(n)}(n);return"symbol"==typeof r?r:r+""}var t={count:function(){throw new Error("'count' method must be defined with 'setProtocol'.")},findList:function(){throw new Error("'findList' method must be defined with 'setProtocol'.")},getName:function(){return""},getTransform:function(){},insert:function(){throw new Error("'insert' method must be defined with 'setProtocol'.")},remove:function(){throw new Error("'remove' method must be defined with 'setProtocol'.")},update:function(){throw new Error("'update' method must be defined with 'setProtocol'.")}},o=t;function i(n){return n?"function"==typeof n?n(o):"object"==typeof n?n:o:o}var u=function(){},f=function(n){return{}.toString.call(n).split(" ")[1].slice(0,-1).toLowerCase()},c=function(n){return Array.isArray(n)},l=function(n){return"function"==typeof n},a=function(n){return n&&!c(n)&&"object"===f(n)};function d(n){return l(null==n?void 0:n.then)}function s(n,r){return p(function(r){var e=r[0];return[n[e]||e,r[1]]},r)}function v(n,r){var e=n.split("."),t=e[0],o=function(n,r){(null==r||r>n.length)&&(r=n.length);for(var e=0,t=Array(r);e<r;e++)t[e]=n[e];return t}(e).slice(1),i=r[t];if(o.length<1)return i;var u=o.join(".");return a(i)?v(u,i):c(i)?i.flatMap(function(n){var r=v(u,n);return c(r)?r:[r]}):i}function m(n,r){if(void 0===r&&(r=u),c(n)){var e=n;return e.some(d)?Promise.all(e).then(function(n){return r(n,!0)}):r(e,!1)}return d(n)?n.then(function(n){return r(n,!0)}):r(n,!1)}function p(n,r){if(void 0===r)return function(r){return p(n,r)};if(c(r))return r.map(n);if(!a(r))throw new TypeError("'map' only works on array or plain object");return Object.fromEntries(Object.entries(r).map(n))}function h(n,r){if(void 0===r)return function(r){return h(n,r)};if(c(r))return r.filter(n);if(!a(r))throw new TypeError("'filter' only works on array or plain object");return Object.fromEntries(Object.entries(r).filter(n))}function y(n,r){queueMicrotask(function(){try{var e=function(r,e){try{var t=Promise.resolve(n()).then(function(){})}catch(n){return e(n)}return t&&t.then?t.then(void 0,e):t}(0,function(n){l(r)&&r(n)});return Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(n){return Promise.reject(n)}})}var w=["array","function","object"],b=w.join("', '"),g=new Map,j=null;function _(n){return g.get(n)||{}}function E(){return j}var x=["+"];function P(n,r){return void 0===r&&(r=!1),a(n)?r?O(n):n:n?void 0:{}}function O(r,e){var t;if(!r)return r;var o=Object.keys(r);return o.some(function(n){return n.startsWith("$")})?e?((t={})[e]=r,t):r:o.reduce(function(t,o){var i=o.indexOf(".");if(i>=0){var u=o.slice(0,i),f=r[u];if(f&&!a(f))return t}var c,l=r[o],d=e?[e,o].join("."):o;return a(l)?n({},t,O(l,d)):n({},t,((c={})[d]=!!l,c))},void 0)}function k(t,o){var i;if(void 0===o&&(o={}),!a(t))return{_:P(t)};var u=function(t,o){void 0===o&&(o={});var i=Object.keys(o),u=E();if(u){var f=t[u],c=r(t,[u].map(e));return n(f?{"+":h(function(n){return i.includes(n[0])},f)}:{"+":void 0},c)}return Object.entries(t).reduce(function(r,e){var t,o,u=e[0],f=e[1];return i.includes(u)?n({},r,{"+":n({},r["+"]||{},(o={},o[u]=f,o))}):n({},r,((t={})[u]=f,t))},{})}(t,o),f=u["+"],c=r(u,x);if(!f)return{_:P(c,!0),"+":void 0};if(!c||null==(i=Object.keys(c))||!i.length)return{_:P(c,!0),"+":f};var l=Object.keys(f).reduce(function(r,e){var t,i=o[e],u=i.on,f=i.fields,c=Array.isArray(u)?((t={})[u[0]]=1,t):void 0;return c||f?n({},r,c,f):r},c);return{_:P(l,!0),"+":f}}function C(n,r){if(!A(n)&&!A(r))return n||r?T(M(n),M(r)):{}}function T(r,e){void 0===r&&(r={}),void 0===e&&(e={});for(var t=n({},r),o=0,i=Object.entries(e||{});o<i.length;o++){var u=i[o],f=u[0],c=u[1],l=t[f];t[f]=a(l)&&a(c)?T(l,c):c}return t}function A(n){return void 0===n||!!n&&!a(n)}function M(n){return a(n)?h(function(n){return n[1]},n):{}}function S(r,e){var t,o,i,u;if(!a(e))return e;var f=E(),c=f?null==(t=e[f])?void 0:t[r]:e[r];if("number"!=typeof c)return e;if(Infinity===c)return e;var l=c-1;return n({},e,f?((u={})[f]=n({},e[f],((i={})[r]=l,i)),u):((o={})[r]=l,o))}var I=["fields","transform"],N=["_key","Coll","on","single","postFetch","limit"],R=["_key","Coll","on","single","postFetch","limit"];function F(e,t,o){void 0===t&&(t={}),void 0===o&&(o={});var u=i(),d=u.count,s=u.findList,p=u.getTransform,h=_(e),y=p(e),w=o.fields,b=o.transform,g=void 0===b?y:b,j=r(o,I),E=function(n){return l(g)?g(n):n},x=k(w,h),O=x._,C=x["+"],T=void 0===C?{}:C,A=Object.keys(T);return!h||null==A||!A.length||w&&!a(w)?m(s(e,t,n({},j,{fields:O,transform:null})),function(n){return n.map(E)}):m(s(e,t,n({},j,{fields:O,transform:null})),function(t){var i=A.reduce(function(r,e){var t,o=h[e];if(!o)return r;var i=f(o.on),u=n({},o,{_key:e});return n({},r,((t={})[i]=[].concat(r[i]||[],[u]),t))},{}),u=i.array,s=i.object,p=void 0===s?[]:s,y=i.function,b=void 0===y?[]:y;return m((void 0===u?[]:u).reduce(function(t,i){var u=i._key,s=i.Coll,p=i.on,h=i.single,y=i.postFetch,b=r(i,N);return m(t,function(r){var t,i,j=p[0],E=p[1],x=p[2],O=void 0===x?{}:x,C=c(j),A=C?r.flatMap(function(n){return n[j[0]]}):r.map(function(n){return n[j]}),M=c(E),I=n({},O,M?((t={})[E[0]]={$elemMatch:{$in:A}},t):((i={})[E]={$in:A},i)),N=s===e&&T[u]>1;return m(N&&d(e,I),function(e){var t,i=N&&!e,d=N?S(u,w):T[u],p=k(d,_(s)||{})._,x=!p||Object.keys(p).length<=0,O=a(d)&&!x&&"_id"!==E?n({},d,((t={})[E]=1,t)):d,A=n({},o,b,{fields:P(O),limit:void 0,transform:N?g:void 0});return m(i?[]:F(s,I,A),function(e){var t=M?{}:e.reduce(function(r,e){var t,o=v(E,e);return c(o)?o.reduce(function(r,t){var o;return n({},r,((o={})[t]=[].concat(r[t]||[],[e]),o))},r):n({},r,((t={})[o]=[].concat(r[o]||[],[e]),t))},{});return r.map(function(r){var o,i,c,a,d=[];M?d=e.filter(function(n){var e,t=n[E[0]]||[];return C?(e=t,(r[j[0]]||[]).some(function(n){return e.indexOf(n)>=0})):t.includes(r[j])}):C?(i="_id",c=(r[j[0]]||[]).flatMap(function(n){return t[n]||[]}),a=l(i)?i:"string"===f(i)?function(n){return n[i]}:function(n){return n},d=c.reduce(function(n,r){var e=a(r);return n.find(function(n){return a(n)===e})?n:[].concat(n,[r])},[])):d=t[r[j]]||[];var s=h?d[0]:d,v=l(y)?y(s,r):s;return n({},r,((o={})[u]=v,o))})})})})},t),function(n){return m(p.map(function(n){return J({Coll:e,join:n,fields:T[n._key],subSelector:n.on,options:j,parentFields:w})}),function(r){return m(n.map(function(n){var t=r.reduce(function(n,r){return r(n)},n);return m(b.reduce(function(r,t){var o=t.on;return m([r,J({Coll:e,join:t,fields:T[t._key],subSelector:l(o)?o(n):o,options:j,parentFields:w})],function(n){return(0,n[1])(n[0])})},t),function(n){return E(n)})}),function(n){return n})})})})}function L(r,e,t){return void 0===t&&(t={}),m(F(r,e,n({},t,{limit:1})),function(n){return n[0]})}function $(n,r){return m(L(n,r,{fields:{_id:1}}),function(n){return!!n})}function J(e){var t=e.Coll,o=e.join,u=o._key,f=o.Coll,c=o.single,a=o.postFetch,d=o.limit,s=r(o,R),v=e.fields,p=e.subSelector,h=e.options,y=e.parentFields,w=i(),b=f===t;return m(b&&(0,w.count)(t,p),function(r){var e=b&&(!v||!r),t=b?S(u,y):v,o=n({},h,s,{fields:P(t),limit:c?1:d||void 0});return m(e?[]:F(f,p,o),function(r){return function(e){var t,o=c?r[0]:r,i=l(a)?a(o,e):o;return n({},e,((t={})[u]=i,t))}})})}var U="drop",D="shift",z=!1,K=W({maxConcurrent:10,maxPending:250});function q(){return z=!0,K}function W(n){var r=function(n){try{if(d.size>=t)throw new Error("Max concurrent calls reached");var e=function(r,e){try{var t=function(r,e){try{var t=function(){d.add(n);var r=n.args;return Promise.resolve(n.fn.apply(void 0,void 0===r?[]:r)).then(function(){})}()}catch(n){return e(n)}return t&&t.then?t.then(void 0,e):t}(0,function(r){!function(n,r){var e=l(u)?u:console.error;Promise.resolve().then(function(){return e(n,r)}).catch(function(n){return console.error(n)})}(r,n)})}catch(n){return e(!0,n)}return t&&t.then?t.then(e.bind(null,!1),e.bind(null,!0)):e(!1,t)}(0,function(e,o){if(d.delete(n),function(){if(!(d.size>=t)){var n=a.shift();n&&r(n)}}(),e)throw o;return o});return Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(n){return Promise.reject(n)}},e=n.maxConcurrent,t=void 0===e?10:e,o=n.maxPending,i=void 0===o?250:o,u=n.onError,f=n.onOverflow,c=void 0===f?B:f;!function(n){void 0===n&&(n={});var r=n.maxConcurrent,e=n.maxPending,t=n.onOverflow;if(!(Number.isFinite(r)&&Number.isInteger(r)&&r>=1))throw new TypeError("'maxConcurrent' must be a finite positive integer.");if(!(Infinity===e||Number.isInteger(e)&&e>=0))throw new TypeError("'maxPending' must be a positive integer or `Infinity`");if(!l(t)&&![U,D].includes(t))throw new TypeError("'onOverflow' must be either a function or one of '"+U+"' or '"+D+"'")}({maxConcurrent:t,maxPending:i,onError:u,onOverflow:c});var a=[],d=new Set;function s(n){d.size<t?r(n):a.length<i?a.push(n):function(n){c!==U&&(c===D?(a.shift(),a.length<i&&s(n)):l(c)?function(n){var r=[].concat(a,[n]),e=c([].concat(a),n);if(void 0!==e){if(!Array.isArray(e))throw new TypeError("'onOverflow' must return an array");var t=e.reduce(function(n,e){var t=e._id,o=r.find(function(n){return n._id===t});return o?n.includes(o)?n:[].concat(n,[o]):n},[]);a=t}}(n):console.error("Invalid 'onOverflow'"))}(n)}return{add:function(n){s({_id:Symbol(),fn:n,args:Array.from([].slice.call(arguments,1))})},clear:function(){a=[]}}}function B(){console.warn("'maxPending' limit reached. Call is dropped")}var G,H=function(n){void 0===n&&(n={});try{var r,e=[].slice.call(arguments,1),t=n.hookType,o=n.fn,i=n.onError,u=n.unless,f=n.when;return l(o)?Promise.resolve(function(n,i){try{var c=function(){function n(n){return r?n:Promise.resolve(o.apply(void 0,e))}if(!(null==u?void 0:u.apply(void 0,e))&&(!f||f.apply(void 0,e))){var i=function(){if(!V.includes(t))return Promise.resolve(o.apply(void 0,e)).then(function(n){return r=1,n})}();return i&&i.then?i.then(n):n(i)}}()}catch(n){return i(n)}return c&&c.then?c.then(void 0,i):c}(0,function(r){if(!l(i))throw r;i(r,n)})):Promise.resolve()}catch(n){return Promise.reject(n)}},Q=["beforeInsert","beforeUpdate","beforeRemove","onInserted","onUpdated","onRemoved"],V=["onInserted","onUpdated","onRemoved"],X=new Map;function Y(n,r){var e=X.get(n)||{};return r?e[r]:e}function Z(n,r){var e=Y(n,r);if(e)return function(n,r){if(void 0===n&&(n=[]),void 0===r&&(r=!1),n.length){var e=function(n){return void 0===n&&(n=[]),n.reduce(function(n,r){return{fields:C(n.fields,r.fields),before:n.before||r.before}},{fields:null,before:void 0})}(n);return{before:e.before,fields:e.fields,fn:function(){var e=[].slice.call(arguments);if(!r)return m(n.map(function(n){return H.apply(void 0,[n].concat(e))}));n.forEach(function(n){return nn.apply(void 0,[n].concat(e))})}}}}(e,V.includes(r))}function nn(n){void 0===n&&(n={});var r=null!=G?G:G||(G=q());r.add.apply(r,[H,n].concat([].slice.call(arguments,1)))}function rn(n,r){var e;null==(e=console)||e.error("Error in '"+r.hookType+"' hook of '"+r.collName+"' collection:",n)}function en(n,r){var e=i(),t=Z(n,"beforeRemove"),o=Z(n,"onRemoved"),u=function(){var n=[].slice.call(arguments).filter(function(n){return n});return n.length?n.reduce(function(n,r){return C(n,r.fields)},null):null}(t,o);return m(null===u?[]:F(n,r,{fields:u}),function(i){return m(l(null==t?void 0:t.fn)&&t.fn(i),function(){return m(e.remove(n,r),function(n){return n&&l(null==o?void 0:o.fn)?(y(function(){return i.forEach(function(n){return o.fn(n)})},function(n){var r;return null==(r=console)?void 0:r.error("'onRemoved' error:",n)}),n):n})})})}var tn=["multi"];function on(e,t,o,u){var f=void 0===u?{}:u,c=f.multi,a=void 0===c||c,d=r(f,tn),s=i(),v=Z(e,"beforeUpdate"),p=Z(e,"onUpdated"),h=n({multi:a},d),w=function(n,r){if(!n&&!r)return null;if(!r)return null==n?void 0:n.fields;var e=r.before?r.fields:{_id:1};return n?C(n.fields,e):e}(v,p);return m(null===w?[]:F(e,t,{fields:w,limit:a?void 0:1}),function(n){return m(l(null==v?void 0:v.fn)&&v.fn(n,o),function(){return m(s.update(e,t,o,h),function(r){if(!r||!l(null==p?void 0:p.fn))return r;var t=function(n){return void 0===n&&(n=[]),Object.fromEntries(n.map(function(n){return[n._id,n]}))}(n);return m(F(e,{_id:{$in:Object.keys(t)}},{fields:p.fields}),function(n){return y(function(){return n.forEach(function(n){p.fn(n,t[n._id])})},function(n){var r;return null==(r=console)?void 0:r.error("'onUpdated' error:",n)}),r})})})})}var un=new Map;function fn(n){return!n||a(n)}function cn(n){return Array.isArray(n)&&2===n.length&&a(n[0])&&(a(r=n[1])||"string"==typeof r);var r}var ln=["multi"],an=["multi"],dn={__proto__:null,meteorAsync:{count:function(n,r,e){var t=n.rawCollection();return t.countDocuments?t.countDocuments(r):n.find(r,e).countAsync()},findList:function(n,r,e){return n.find(r,e).fetchAsync()},getName:function(n){return n._name||""},getTransform:function(n){return n._transform},insert:function(n,r){return n.insertAsync(r)},remove:function(n,r){return n.removeAsync(r)},update:function(r,e,t,o){return r.updateAsync(e,t,n({multi:!0},o))}},meteorSync:{count:function(n,r,e){return n.find(r,e).count()},findList:function(n,r,e){return n.find(r,e).fetch()},getName:function(n){return n._name||""},getTransform:function(n){return n._transform},insert:function(n,r){return n.insert(r)},remove:function(n,r){return n.remove(r)},update:function(r,e,t,o){return r.update(e,t,n({multi:!0},o))}},node:{count:function(n,r,e){return void 0===r&&(r={}),void 0===e&&(e={}),n.countDocuments(r||{},e)},findList:function(n,r,e){void 0===r&&(r={}),void 0===e&&(e={});var t=s({fields:"projection"},e||{});return n.find(r||{},t).toArray()},getName:function(n){return n.collectionName||""},getTransform:function(n){return"function"==typeof(null==n?void 0:n.transform)?n.transform:void 0},insert:function(n,r,e){return n.insertOne(r,e).then(function(n){return null==n?void 0:n.insertedId})},remove:function(n,e,t){void 0===e&&(e={}),void 0===t&&(t={});var o=t||{},i=o.multi,u=void 0===i||i,f=r(o,ln);return(u?n.deleteMany(e||{},f):n.deleteOne(e||{},f)).then(function(n){var r;return null!=(r=null==n?void 0:n.deletedCount)?r:0})},update:function(n,e,t,o){void 0===e&&(e={}),void 0===t&&(t={}),void 0===o&&(o={});var i=o||{},u=i.multi,f=void 0===u||u,c=r(i,an);return(f?n.updateMany(e||{},t||{},c):n.updateOne(e||{},t||{},c)).then(function(n){var r,e;return null!=(r=null!=(e=null==n?void 0:n.modifiedCount)?e:null==n?void 0:n.upsertedCount)?r:0})}}};exports.configurePool=function(n){if(void 0===n&&(n={}),z)throw new Error("'configurePool' must be called at startup before processing hooks");K=W(n)},exports.count=function(n,r,e){return m((0,i().count)(n,r,e),function(n){return n})},exports.exists=$,exports.fetchIds=function(r,e,t){return m(F(r,e,n({},t,{fields:{_id:1}})),function(n){return n.map(function(n){return n._id})})},exports.fetchList=F,exports.fetchOne=L,exports.flattenFields=O,exports.getJoinPrefix=E,exports.getJoins=_,exports.hook=function(r,e){Object.entries(e).forEach(function(e){var t=e[0],o=e[1];if(!c(o))throw new TypeError("'"+t+"' hooks must be an array");o.forEach(function(e){return function(r,e,t){var o;if(!Q.includes(e))throw new TypeError("'"+e+"' is not a valid hook type");if(!l(null==t?void 0:t.fn))throw new TypeError("'hook' must be a function or contain a 'fn' key");var u=i().getName,f=Y(r),c=f[e]||[],a=n({onError:V.includes(e)?rn:void 0},t,{Coll:r,collName:u(r),hookType:e}),d=[].concat(c,[a]);X.set(r,n({},f,((o={})[e]=d,o)))}(r,t,e)})})},exports.insert=function(n,r){var e=i(),t=Z(n,"beforeInsert");return m(l(null==t?void 0:t.fn)&&t.fn(r),function(){var t=Z(n,"onInserted");return m(e.insert(n,r),function(r){if(!t)return r;var e=t.fields,o=t.fn,i=e?Object.keys(e):[];return m(1===i.length&&"_id"===i[0]?{_id:r}:L(n,{_id:r},{fields:e}),function(n){return y(function(){return o(n)},function(n){var r;return null==(r=console)?void 0:r.error("'onInserted' error:",n)}),r})})})},exports.join=function(r,e){e?(Object.entries(e).forEach(function(n){var r=n[0],e=n[1],t=e.on,o=e.fields;if(!e.Coll)throw new Error("Collection 'Coll' for '"+r+"' join is required.");if(!t)throw new Error("Join '"+r+"' has no 'on' condition specified.");var i=f(t);if(!w.includes(i))throw new Error("Join '"+r+"' has an unrecognized 'on' condition type of '"+i+"'. Should be one of '"+b+"'.");l(t)&&!o&&function(){var n;console&&console.warn&&(n=console).warn.apply(n,[].slice.call(arguments))}("Join '"+r+"' is defined with a function 'on', but no 'fields' are explicitly specified. This could lead to failed joins if the keys necessary for the join are not specified at query time.")}),g.set(r,n({},g.get(r),e))):g.set(r,void 0)},exports.protocols=dn,exports.registerSoftRemove=function(n,r){var e=void 0===r?{}:r,t=e.docToCollSelectorPairs,o=e.fields,u=void 0===o?{_id:1}:o,f=e.keepModifier,c=e.when;if(!a(n))throw new TypeError("Collection must be an object");var d=i().getName(n);if(un.has(n))throw new Error("'registerSoftRemove' already exists for collection '"+d+"'");if(![t,c].some(l))throw new TypeError("'"+d+"' 'registerSoftRemove' must provide at least one predicate.");un.set(n,{fields:u,defaultKeepModifier:f,shouldKeepDoc:function(n){return m(l(c)&&c(n),function(r){return!!r||!!l(t)&&m(function(n,r){return m(n(r),function(n){if(!Array.isArray(n)||!n.every(cn))throw new TypeError("'docToCollSelectorPairs' should return an array of '[Coll, selector]' tuples");return n})}(t,n),function(n){return m(function(n){return void 0===n&&(n=[]),m(n.map(function(n){return $(n[0],n[1])}),function(n){return n.some(function(n){return n})})}(n),function(n){return!!n})})})}})},exports.remove=en,exports.setJoinPrefix=function(n){j=n},exports.setProtocol=function(r){void 0===r&&(r={}),o=n({},t,r)},exports.softRemove=function(r,e,t,o){void 0===e&&(e={});var u=(void 0===o?{}:o).detailed,f=void 0!==u&&u,c=function(n){var r=un.get(n);if(!r){var e=i().getName(n);throw new Error("'softRemove' must be registered with 'registerSoftRemove' before using it with collection '"+e+"'")}return r}(r),d=c.fields,s=c.shouldKeepDoc,v=c.defaultKeepModifier;function p(n){var r=n.removed,e=void 0===r?0:r,t=n.updated,o=void 0===t?null:t;return f?{removed:e,updated:o}:(null!=e?e:0)+(null!=o?o:0)}return m(F(r,e,{fields:n({},null!=d?d:{},{_id:1}),transform:null}),function(n){return m(n.map(function(n){return m(s(n),function(r){return r?n._id:null})}),function(n){var o=n.filter(function(n){return null!==n});return o.length?m(function(n){if(fn(n))return n||null;if(l(n))return m(n(),function(n){if(fn(n))return n||null;throw new TypeError("'keepModifier' must be a valid modifier, a falsy value or a function that returns one of those.")});throw new TypeError("'keepModifier' must be a valid modifier, a falsy value or a function that returns one of those.")}(null!=t?t:v),function(n){return m([en(r,{$and:[a(e)?e:{_id:e},{_id:{$nin:o}}]}),n?on(r,{_id:{$in:o}},n):null],function(n){return p({removed:n[0],updated:n[1]})})}):m(en(r,e),function(n){return p({removed:n})})})})},exports.update=on;
2
2
  //# sourceMappingURL=coll-fns.cjs.map