@cyberskill/shared 2.7.0 → 2.8.0
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/dist/node/mongo/mongo.util.cjs +2 -2
- package/dist/node/mongo/mongo.util.d.ts +9 -0
- package/dist/node/mongo/mongo.util.js +77 -60
- package/dist/util/object/object.util.cjs +1 -1
- package/dist/util/object/object.util.d.ts +8 -3
- package/dist/util/object/object.util.js +51 -45
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("lodash-es"),B=require("migrate-mongo"),K=require("mongoose"),Q=require("mongoose-aggregate-paginate-v2"),W=require("mongoose-paginate-v2"),$=require("uuid"),H=require("./mongo.constant.cjs"),V=require("../../util/object/object.util.cjs"),k=require("../../util/common/common.util.cjs"),F=require("../fs/fs.util.cjs"),A=require("../path/path.constant.cjs"),J=require("../../util/validate/validate.util.cjs"),j=require("../../util/string/string.util.cjs"),D=require("../../constant/response-status.cjs"),d=require("../log/log.util.cjs");var X=Object.defineProperty,Y=Object.defineProperties,Z=Object.getOwnPropertyDescriptors,G=Object.getOwnPropertySymbols,ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable,U=(s,t,e)=>t in s?X(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,O=(s,t)=>{for(var e in t||(t={}))ee.call(t,e)&&U(s,e,t[e]);if(G)for(var e of G(t))te.call(t,e)&&U(s,e,t[e]);return s},P=(s,t)=>Y(s,Z(t)),re=(s,t,e)=>U(s,typeof t!="symbol"?t+"":t,e),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("lodash-es"),B=require("migrate-mongo"),K=require("mongoose"),Q=require("mongoose-aggregate-paginate-v2"),W=require("mongoose-paginate-v2"),$=require("uuid"),H=require("./mongo.constant.cjs"),V=require("../../util/object/object.util.cjs"),k=require("../../util/common/common.util.cjs"),F=require("../fs/fs.util.cjs"),A=require("../path/path.constant.cjs"),J=require("../../util/validate/validate.util.cjs"),j=require("../../util/string/string.util.cjs"),D=require("../../constant/response-status.cjs"),d=require("../log/log.util.cjs");var X=Object.defineProperty,Y=Object.defineProperties,Z=Object.getOwnPropertyDescriptors,G=Object.getOwnPropertySymbols,ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable,U=(s,t,e)=>t in s?X(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,O=(s,t)=>{for(var e in t||(t={}))ee.call(t,e)&&U(s,e,t[e]);if(G)for(var e of G(t))te.call(t,e)&&U(s,e,t[e]);return s},P=(s,t)=>Y(s,Z(t)),re=(s,t,e)=>U(s,typeof t!="symbol"?t+"":t,e),l=(s,t,e)=>new Promise((r,n)=>{var c=i=>{try{u(e.next(i))}catch(a){n(a)}},o=i=>{try{u(e.throw(i))}catch(a){n(a)}},u=i=>i.done?r(i.value):Promise.resolve(i.value).then(c,o);u((e=e.apply(s,t)).next())});function ne(s){return s===s.toUpperCase()?s.charAt(0).toUpperCase()+s.slice(1).toLowerCase():s}const M={createGenericFields(){return{id:$.v4(),isDel:!1,createdAt:new Date,updatedAt:new Date}},applyPlugins(s,t){t.filter(e=>typeof e=="function").forEach(e=>s.plugin(e))},applyMiddlewares(s,t){t.forEach(({method:e,pre:r,post:n})=>{e&&r&&s.pre(e,r),e&&n&&s.post(e,n)})},createGenericSchema(s){return new s.Schema({id:{type:String,default:$.v4,unique:!0},isDel:{type:Boolean,default:!1}},{timestamps:!0})},createSchema({mongoose:s,schema:t,virtuals:e=[],standalone:r=!1}){const n=new s.Schema(t,{toJSON:{virtuals:!0},toObject:{virtuals:!0}});return e.forEach(({name:c,options:o,get:u})=>{if(M.isDynamicVirtual(o)){const i=n.statics;i._dynamicVirtuals||(i._dynamicVirtuals=[]),i._dynamicVirtuals.push({name:c,options:o});const a=n.virtual(c);u?a.get(u):a.get(function(){var f;return((f=this._populated)==null?void 0:f[c])||(o!=null&&o.count?0:o!=null&&o.justOne?null:[])})}else{const i=n.virtual(c,o);u&&i.get(u)}}),r||n.add(M.createGenericSchema(s)),n},createModel({mongoose:s,name:t,schema:e,virtuals:r=[],pagination:n=!0,aggregate:c=!0,middlewares:o=[]}){if(!t)throw new Error("Model name is required.");if(s.models[t])return s.models[t];const u=M.createSchema({mongoose:s,schema:e,virtuals:r});return(n||c)&&M.applyPlugins(u,[n&&W,c&&Q]),M.applyMiddlewares(u,o),s.model(t,u)},validator:{isRequired(){return function(s){return l(this,null,function*(){return!J.validate.isEmpty(s)})}},isUnique(s){return function(t){return l(this,null,function*(){if(!Array.isArray(s)||s.length===0)throw new Error("Fields must be a non-empty array of strings.");const e={$or:s.map(n=>({[n]:t}))};return!(yield this.constructor.exists(e))})}},matchesRegex(s){return function(t){return l(this,null,function*(){if(!Array.isArray(s)||s.some(e=>!(e instanceof RegExp)))throw new Error("regexArray must be an array of valid RegExp objects.");return s.every(e=>e.test(t))})}}},migrate:P(O({},B),{setConfig:s=>{const t=`// This file is automatically generated by the Cyberskill CLI.
|
|
2
2
|
module.exports = ${JSON.stringify(s,null,4)}`;F.writeFileSync(A.PATH.MIGRATE_MONGO_CONFIG,t);const e=`
|
|
3
3
|
${A.MIGRATE_MONGO_CONFIG}
|
|
4
4
|
`;F.pathExistsSync(A.PATH.GIT_IGNORE)?F.readFileSync(A.PATH.GIT_IGNORE,"utf-8").split(`
|
|
5
|
-
`).includes(A.MIGRATE_MONGO_CONFIG)||F.appendFileSync(A.PATH.GIT_IGNORE,e):F.writeFileSync(A.PATH.GIT_IGNORE,e)}}),regexify(s,t){if(!s)return{};let e=q.cloneDeep(s);if(!t||t.length===0)return e;for(const r of t){const n=r.toString().split("."),c=V.getNestedValue(e,n);if(typeof c=="string"&&c.length>0){const o={$regex:`.*${k.regexSearchMapper(c)}.*`,$options:"i"};e=V.setNestedValue(e,n,o)}}return e},isDynamicVirtual(s){return!!(s&&typeof s.ref=="function")},getNewRecords(s,t,e){return a(this,null,function*(){const r=yield s.findAll({});return r.success?t.filter(c=>!r.result.some(o=>e(o,c))):t})},getExistingRecords(s,t,e){return a(this,null,function*(){const r=yield s.findAll({});return r.success?r.result.filter(c=>t.some(o=>e(c,o))):[]})}};function se(s){return s!==null&&typeof s=="object"&&"toObject"in s&&typeof s.toObject=="function"}function I(s,t){if(!s||!t||t.length===0)return s;const e=new Set(t.map(r=>r.name));if(Array.isArray(s)){const r=s.filter(n=>{if(typeof n=="string")return!e.has(n);if(typeof n=="object"&&n!==null){const c=n;return!e.has(c.path||c.populate||"")}return!0});return r.length>0?r:void 0}if(typeof s=="string")return e.has(s)?void 0:s;if(typeof s=="object"&&s!==null){const r=s,n=r.path||r.populate||"";return e.has(n)?void 0:s}return s}function ce(s,t,e){if(!s.length||!t||!(e!=null&&e.ref))return[];const r=new Map;return s.forEach(n=>{try{const c=e.ref(n);if(c==null)return;const o=typeof c=="string"?c:String(c);if(o&&o.trim()!==""){const u=ne(o);r.has(u)||r.set(u,[]),r.get(u).push(n)}}catch(c){d.catchError(new Error(`Dynamic ref function failed for virtual "${t}": ${c instanceof Error?c.message:String(c)}`))}}),Array.from(r.entries()).map(([n,c])=>({model:n,docs:c}))}function z(s,t,e,r,n){return a(this,null,function*(){if(!t.length||!e.length||!r)return t;const c=e.filter(i=>{if(Array.isArray(r))return r.length>0&&r.some(l=>typeof l=="string"?l===i.name:l.path===i.name);if(typeof r=="string")return r===i.name;if(typeof r=="object"&&r!==null){const l=r;return l.path&&l.path===i.name||l.populate&&l.populate===i.name}return!1});if(c.length===0)return t;const o=q.cloneDeep(t.map(i=>se(i)?i.toObject():i));o.forEach(i=>{c.forEach(({name:l,options:f})=>{if(!(l in i)){const S=i;S[l]=f.count?0:f.justOne?null:[]}})});const u=new Map;for(const i of c){const{name:l,options:f}=i,S=ce(o,l,f);for(const h of S){u.has(h.model)||u.set(h.model,{virtuals:[],localValueSets:new Map,docsByLocalValue:new Map});const y=u.get(h.model);y.virtuals.find(T=>T.name===l)||(y.virtuals.push(i),y.localValueSets.set(l,new Set));const N=y.localValueSets.get(l);h.docs.forEach(T=>{const x=T[f.localField];if(x!=null){const _=String(x);N.add(_);let R=-1;const v=T;v.id!==void 0?R=o.findIndex(b=>b.id===v.id):v._id!==void 0&&(R=o.findIndex(b=>{var E,m,p,g;return((m=(E=b._id)==null?void 0:E.toString)==null?void 0:m.call(E))===((g=(p=v._id)==null?void 0:p.toString)==null?void 0:g.call(p))})),R!==-1&&(y.docsByLocalValue.has(_)||y.docsByLocalValue.set(_,[]),y.docsByLocalValue.get(_).push(R))}})}}return yield Promise.all(Array.from(u.entries()).map(i=>a(null,[i],function*([l,f]){const S=s.models[l];if(!S)return;const h=new Set;if(f.localValueSets.forEach(_=>{_.forEach(R=>h.add(R))}),h.size===0)return;const y=[...new Set(f.virtuals.map(_=>_.options.foreignField))],N=Array.from(h);let T;y.length===1?T={[String(y[0])]:{$in:N}}:T={$or:y.map(_=>({[_]:{$in:N}}))};const x=yield S.find(T,n).lean();for(const _ of f.virtuals){const{name:R,options:v}=_,b=x.filter(E=>{const m=E[v.foreignField];return m!=null&&h.has(String(m))});if(v.count){const E=new Map;b.forEach(m=>{var p;const g=(p=m[v.foreignField])==null?void 0:p.toString();g&&E.set(g,(E.get(g)||0)+1)}),f.localValueSets.get(R).forEach(m=>{const p=f.docsByLocalValue.get(m)||[],g=E.get(m)||0;p.forEach(w=>{const C=o[w];C[R]===void 0&&(C[R]=g)})})}else{const E=new Map;b.forEach(m=>{var p;const g=(p=m[v.foreignField])==null?void 0:p.toString();g&&(E.has(g)||E.set(g,[]),E.get(g).push(m))}),f.localValueSets.get(R).forEach(m=>{const p=f.docsByLocalValue.get(m)||[],g=E.get(m)||[],w=v.justOne?g[0]||null:g;p.forEach(C=>{const L=o[C];L[R]=w})})}}}))),o})}class oe{constructor(t,e){re(this,"collection"),this.collection=t.collection(e)}createOne(t){return a(this,null,function*(){try{const e=O(O({},M.createGenericFields()),t);return(yield this.collection.insertOne(e)).acknowledged?{success:!0,message:"Document created successfully",result:e}:{success:!1,message:"Document creation failed",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}}catch(e){return d.catchError(e)}})}createMany(t){return a(this,null,function*(){try{const e=t.map(n=>O(O({},M.createGenericFields()),n)),r=yield this.collection.insertMany(e);return r.insertedCount===0?{success:!1,message:"No documents were inserted",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:`${r.insertedCount} documents created successfully`,result:e}}catch(e){return d.catchError(e)}})}findOne(t){return a(this,null,function*(){try{const e=yield this.collection.findOne(t);return e?{success:!0,message:"Document found",result:e}:{success:!1,message:"Document not found",code:D.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(e){return d.catchError(e)}})}findAll(){return a(this,arguments,function*(t={}){try{return{success:!0,message:"Documents retrieved successfully",result:yield this.collection.find(t).toArray()}}catch(e){return d.catchError(e)}})}count(){return a(this,arguments,function*(t={}){try{const e=yield this.collection.countDocuments(t);return{success:!0,message:`${e} documents counted successfully`,result:e}}catch(e){return d.catchError(e)}})}updateOne(t,e){return a(this,null,function*(){try{const r=yield this.collection.updateOne(t,{$set:e});return r.matchedCount===0?{success:!1,message:"No documents matched the filter",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:"Document updated successfully",result:r}}catch(r){return d.catchError(r)}})}updateMany(t,e){return a(this,null,function*(){try{const r=yield this.collection.updateMany(t,{$set:e});return r.matchedCount===0?{success:!1,message:"No documents matched the filter",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:"Documents updated successfully",result:r}}catch(r){return d.catchError(r)}})}deleteOne(t){return a(this,null,function*(){try{const e=yield this.collection.deleteOne(t);return e.deletedCount===0?{success:!1,message:"No documents matched the filter",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:"Document deleted successfully",result:e}}catch(e){return d.catchError(e)}})}deleteMany(t){return a(this,null,function*(){try{const e=yield this.collection.deleteMany(t);return e.deletedCount===0?{success:!1,message:"No documents matched the filter",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:"Documents deleted successfully",result:e}}catch(e){return d.catchError(e)}})}}class ue{constructor(t){this.model=t}getModelName(){return this.model.modelName}getDynamicVirtuals(){return this.model.schema.statics._dynamicVirtuals}populateDynamicVirtualsForDocument(t,e){return a(this,null,function*(){const r=this.getDynamicVirtuals();if(r&&r.length>0){const n=yield z(this.model.base,[t],r,e);return n&&n[0]?n[0]:t}return t})}populateDynamicVirtualsForDocuments(t,e){return a(this,null,function*(){const r=this.getDynamicVirtuals();return r&&r.length>0&&t.length>0?yield z(this.model.base,t,r,e):t})}findOne(){return a(this,arguments,function*(t={},e={},r={},n){try{const c=V.normalizeMongoFilter(t),o=this.model.findOne(c,e,r),u=this.getDynamicVirtuals(),i=I(n,u);i&&o.populate(i);const l=yield o.exec();return l?{success:!0,result:yield this.populateDynamicVirtualsForDocument(l,n)}:{success:!1,message:`No ${this.getModelName()} found.`,code:D.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(c){return d.catchError(c)}})}findAll(){return a(this,arguments,function*(t={},e={},r={},n){try{const c=V.normalizeMongoFilter(t),o=this.model.find(c,e,r),u=this.getDynamicVirtuals(),i=I(n,u);i&&o.populate(i);const l=yield o.exec();return{success:!0,result:yield this.populateDynamicVirtualsForDocuments(l,n)}}catch(c){return d.catchError(c)}})}findPaging(){return a(this,arguments,function*(t={},e={}){try{const r=V.normalizeMongoFilter(t),n=this.getDynamicVirtuals(),c=O({},e);e.populate&&(c.populate=I(e.populate,n));const o=yield this.model.paginate(r,c),u=yield this.populateDynamicVirtualsForDocuments(o.docs,e.populate);return{success:!0,result:P(O({},o),{docs:u})}}catch(r){return d.catchError(r)}})}findPagingAggregate(t){return a(this,arguments,function*(e,r={}){try{const n=this.getDynamicVirtuals(),c=O({},r);r.populate&&(c.populate=I(r.populate,n));const o=yield this.model.aggregatePaginate(this.model.aggregate(e),c),u=yield this.populateDynamicVirtualsForDocuments(o.docs,r.populate);return{success:!0,result:P(O({},o),{docs:u})}}catch(n){return d.catchError(n)}})}count(){return a(this,arguments,function*(t={}){try{const e=V.normalizeMongoFilter(t);return{success:!0,result:yield this.model.countDocuments(e)}}catch(e){return d.catchError(e)}})}createOne(t){return a(this,null,function*(){try{return{success:!0,result:yield this.model.create(t)}}catch(e){return d.catchError(e)}})}createMany(t){return a(this,arguments,function*(e,r={}){try{return{success:!0,result:(yield this.model.insertMany(e,r)).map(o=>o instanceof K.Document?o.toObject():null).filter(o=>o!==null)}}catch(n){return d.catchError(n)}})}updateOne(){return a(this,arguments,function*(t={},e={},r={}){try{const n=V.normalizeMongoFilter(t),c=yield this.model.findOneAndUpdate(n,e,O({new:!0},r)).exec();return c?{success:!0,result:c}:{success:!1,message:`Failed to update ${this.getModelName()}.`,code:D.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(n){return d.catchError(n)}})}updateMany(){return a(this,arguments,function*(t={},e={},r={}){try{const n=V.normalizeMongoFilter(t);return{success:!0,result:yield this.model.updateMany(n,e,r).exec()}}catch(n){return d.catchError(n)}})}deleteOne(){return a(this,arguments,function*(t={},e={}){try{const r=V.normalizeMongoFilter(t),n=yield this.model.findOneAndDelete(r,e).exec();return n?{success:!0,result:n}:{success:!1,message:`No ${this.getModelName()} found to delete.`,code:D.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(r){return d.catchError(r)}})}deleteMany(){return a(this,arguments,function*(t={},e={}){try{const r=V.normalizeMongoFilter(t),n=yield this.model.deleteMany(r,e).exec();return n.deletedCount===0?{success:!1,message:"No documents found to delete.",code:D.RESPONSE_STATUS.NOT_FOUND.CODE}:{success:!0,result:n}}catch(r){return d.catchError(r)}})}createShortId(t,e=4){return a(this,null,function*(){try{const n=Array.from({length:10},(u,i)=>j.generateShortId(t,i+e)),o=(yield Promise.all(n.map(u=>this.model.exists({shortId:u})))).findIndex(u=>!u);if(o!==-1){const u=n[o];if(u)return{success:!0,result:u}}return{success:!1,message:"Failed to create a unique shortId",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}}catch(r){return d.catchError(r)}})}createSlugQuery({slug:t,field:e,isObject:r,haveHistory:n=!1,filter:c}){const o=O({},c!=null?c:{});return r?P(O({},o),{$or:[{[`slug.${e}`]:t},...n?[{slugHistory:{$elemMatch:{[`slug.${e}`]:t}}}]:[]]}):P(O({},o),{$or:[{slug:t},...n?[{slugHistory:t}]:[]]})}createUniqueSlug(t){return a(this,arguments,function*({slug:e,field:r,isObject:n,haveHistory:c,filter:o}){if(!e||typeof e!="string")throw new Error("Invalid slug provided: must be a non-empty string");const u=j.generateSlug(e);if(!(yield this.model.exists(this.createSlugQuery({slug:u,field:r,isObject:n,haveHistory:c,filter:o}))))return u;for(let S=1;S<=H.MONGO_SLUG_MAX_ATTEMPTS;S++){const h=`${u}-${S}`;if(!(yield this.model.exists(this.createSlugQuery({slug:h,field:r,isObject:n,haveHistory:c,filter:o}))))return h}const l=Date.now(),f=Math.random().toString(36).substring(2,8);return`${u}-${l}-${f}`})}createSlug(t){return a(this,arguments,function*({field:e,from:r,filter:n,haveHistory:c}){try{const o=r[e];return q.isObject(o)?{success:!0,result:Object.fromEntries(yield Promise.all(Object.entries(o).map(f=>a(this,[f],function*([S,h]){const y=yield this.createUniqueSlug({slug:h,field:S,isObject:!0,haveHistory:c,filter:n});return[S,y]}))))}:{success:!0,result:yield this.createUniqueSlug({slug:o,field:e,isObject:!1,haveHistory:c,filter:n})}}catch(o){return d.catchError(o)}})}checkSlug(t){return a(this,arguments,function*({slug:e,field:r,from:n,filter:c,haveHistory:o}){try{const u=n[r];if(q.isObject(u)){const h=Object.values(u).map(N=>j.generateSlug(N));return(yield Promise.all(h.map(N=>this.model.exists(this.createSlugQuery({slug:N,field:r,isObject:!0,haveHistory:o,filter:c}))))).some(N=>N)?{success:!0,result:!0}:{success:!0,result:!1}}const l=j.generateSlug(e);return{success:!0,result:(yield this.model.exists(this.createSlugQuery({slug:l,field:r,isObject:!1,filter:c})))!==null}}catch(u){return d.catchError(u)}})}aggregate(t){return a(this,null,function*(){try{return{success:!0,result:yield this.model.aggregate(t)}}catch(e){return d.catchError(e)}})}}exports.MongoController=oe;exports.MongooseController=ue;exports.mongo=M;
|
|
5
|
+
`).includes(A.MIGRATE_MONGO_CONFIG)||F.appendFileSync(A.PATH.GIT_IGNORE,e):F.writeFileSync(A.PATH.GIT_IGNORE,e)}}),regexify(s,t){if(!s)return{};let e=q.cloneDeep(s);if(!t||t.length===0)return e;for(const r of t){const n=r.toString().split("."),c=V.getNestedValue(e,n);if(typeof c=="string"&&c.length>0){const o={$regex:`.*${k.regexSearchMapper(c)}.*`,$options:"i"};e=V.setNestedValue(e,n,o)}}return e},isDynamicVirtual(s){return!!(s&&typeof s.ref=="function")},getNewRecords(s,t,e){return l(this,null,function*(){const r=yield s.findAll({});return r.success?t.filter(c=>!r.result.some(o=>e(o,c))):t})},getExistingRecords(s,t,e){return l(this,null,function*(){const r=yield s.findAll({});return r.success?r.result.filter(c=>t.some(o=>e(c,o))):[]})}};function se(s){return s!==null&&typeof s=="object"&&"toObject"in s&&typeof s.toObject=="function"}function I(s,t){if(!s||!t||t.length===0)return s;const e=new Set(t.map(r=>r.name));if(Array.isArray(s)){const r=s.filter(n=>{if(typeof n=="string")return!e.has(n);if(typeof n=="object"&&n!==null){const c=n;return!e.has(c.path||c.populate||"")}return!0});return r.length>0?r:void 0}if(typeof s=="string")return e.has(s)?void 0:s;if(typeof s=="object"&&s!==null){const r=s,n=r.path||r.populate||"";return e.has(n)?void 0:s}return s}function ce(s,t,e){if(!s.length||!t||!(e!=null&&e.ref))return[];const r=new Map;return s.forEach(n=>{try{const c=e.ref(n);if(c==null)return;const o=typeof c=="string"?c:String(c);if(o&&o.trim()!==""){const u=ne(o);r.has(u)||r.set(u,[]),r.get(u).push(n)}}catch(c){d.catchError(new Error(`Dynamic ref function failed for virtual "${t}": ${c instanceof Error?c.message:String(c)}`))}}),Array.from(r.entries()).map(([n,c])=>({model:n,docs:c}))}function z(s,t,e,r,n){return l(this,null,function*(){if(!t.length||!e.length||!r)return t;const c=e.filter(i=>{if(Array.isArray(r))return r.length>0&&r.some(a=>typeof a=="string"?a===i.name:a.path===i.name);if(typeof r=="string")return r===i.name;if(typeof r=="object"&&r!==null){const a=r;return a.path&&a.path===i.name||a.populate&&a.populate===i.name}return!1});if(c.length===0)return t;const o=q.cloneDeep(t.map(i=>se(i)?i.toObject():i));o.forEach(i=>{c.forEach(({name:a,options:f})=>{if(!(a in i)){const S=i;S[a]=f.count?0:f.justOne?null:[]}})});const u=new Map;for(const i of c){const{name:a,options:f}=i,S=ce(o,a,f);for(const h of S){u.has(h.model)||u.set(h.model,{virtuals:[],localValueSets:new Map,docsByLocalValue:new Map});const y=u.get(h.model);y.virtuals.find(T=>T.name===a)||(y.virtuals.push(i),y.localValueSets.set(a,new Set));const N=y.localValueSets.get(a);h.docs.forEach(T=>{const x=T[f.localField];if(x!=null){const _=String(x);N.add(_);let R=-1;const v=T;v.id!==void 0?R=o.findIndex(b=>b.id===v.id):v._id!==void 0&&(R=o.findIndex(b=>{var E,m,p,g;return((m=(E=b._id)==null?void 0:E.toString)==null?void 0:m.call(E))===((g=(p=v._id)==null?void 0:p.toString)==null?void 0:g.call(p))})),R!==-1&&(y.docsByLocalValue.has(_)||y.docsByLocalValue.set(_,[]),y.docsByLocalValue.get(_).push(R))}})}}return yield Promise.all(Array.from(u.entries()).map(i=>l(null,[i],function*([a,f]){const S=s.models[a];if(!S)return;const h=new Set;if(f.localValueSets.forEach(_=>{_.forEach(R=>h.add(R))}),h.size===0)return;const y=[...new Set(f.virtuals.map(_=>_.options.foreignField))],N=Array.from(h);let T;y.length===1?T={[String(y[0])]:{$in:N}}:T={$or:y.map(_=>({[_]:{$in:N}}))};const x=yield S.find(T,n).lean();for(const _ of f.virtuals){const{name:R,options:v}=_,b=x.filter(E=>{const m=E[v.foreignField];return m!=null&&h.has(String(m))});if(v.count){const E=new Map;b.forEach(m=>{var p;const g=(p=m[v.foreignField])==null?void 0:p.toString();g&&E.set(g,(E.get(g)||0)+1)}),f.localValueSets.get(R).forEach(m=>{const p=f.docsByLocalValue.get(m)||[],g=E.get(m)||0;p.forEach(w=>{const C=o[w];C[R]===void 0&&(C[R]=g)})})}else{const E=new Map;b.forEach(m=>{var p;const g=(p=m[v.foreignField])==null?void 0:p.toString();g&&(E.has(g)||E.set(g,[]),E.get(g).push(m))}),f.localValueSets.get(R).forEach(m=>{const p=f.docsByLocalValue.get(m)||[],g=E.get(m)||[],w=v.justOne?g[0]||null:g;p.forEach(C=>{const L=o[C];L[R]=w})})}}}))),o})}class oe{constructor(t,e){re(this,"collection"),this.collection=t.collection(e)}createOne(t){return l(this,null,function*(){try{const e=O(O({},M.createGenericFields()),t);return(yield this.collection.insertOne(e)).acknowledged?{success:!0,message:"Document created successfully",result:e}:{success:!1,message:"Document creation failed",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}}catch(e){return d.catchError(e)}})}createMany(t){return l(this,null,function*(){try{const e=t.map(n=>O(O({},M.createGenericFields()),n)),r=yield this.collection.insertMany(e);return r.insertedCount===0?{success:!1,message:"No documents were inserted",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:`${r.insertedCount} documents created successfully`,result:e}}catch(e){return d.catchError(e)}})}findOne(t){return l(this,null,function*(){try{const e=yield this.collection.findOne(t);return e?{success:!0,message:"Document found",result:e}:{success:!1,message:"Document not found",code:D.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(e){return d.catchError(e)}})}findAll(){return l(this,arguments,function*(t={}){try{return{success:!0,message:"Documents retrieved successfully",result:yield this.collection.find(t).toArray()}}catch(e){return d.catchError(e)}})}count(){return l(this,arguments,function*(t={}){try{const e=yield this.collection.countDocuments(t);return{success:!0,message:`${e} documents counted successfully`,result:e}}catch(e){return d.catchError(e)}})}updateOne(t,e){return l(this,null,function*(){try{const r=yield this.collection.updateOne(t,{$set:e});return r.matchedCount===0?{success:!1,message:"No documents matched the filter",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:"Document updated successfully",result:r}}catch(r){return d.catchError(r)}})}updateMany(t,e){return l(this,null,function*(){try{const r=yield this.collection.updateMany(t,{$set:e});return r.matchedCount===0?{success:!1,message:"No documents matched the filter",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:"Documents updated successfully",result:r}}catch(r){return d.catchError(r)}})}deleteOne(t){return l(this,null,function*(){try{const e=yield this.collection.deleteOne(t);return e.deletedCount===0?{success:!1,message:"No documents matched the filter",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:"Document deleted successfully",result:e}}catch(e){return d.catchError(e)}})}deleteMany(t){return l(this,null,function*(){try{const e=yield this.collection.deleteMany(t);return e.deletedCount===0?{success:!1,message:"No documents matched the filter",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:"Documents deleted successfully",result:e}}catch(e){return d.catchError(e)}})}}class ue{constructor(t){this.model=t}getModelName(){return this.model.modelName}getDynamicVirtuals(){return this.model.schema.statics._dynamicVirtuals}populateDynamicVirtualsForDocument(t,e){return l(this,null,function*(){const r=this.getDynamicVirtuals();if(r&&r.length>0){const n=yield z(this.model.base,[t],r,e);return n&&n[0]?n[0]:t}return t})}populateDynamicVirtualsForDocuments(t,e){return l(this,null,function*(){const r=this.getDynamicVirtuals();return r&&r.length>0&&t.length>0?yield z(this.model.base,t,r,e):t})}findOne(){return l(this,arguments,function*(t={},e={},r={},n){try{const c=V.normalizeMongoFilter(t),o=this.model.findOne(c,e,r),u=this.getDynamicVirtuals(),i=I(n,u);i&&o.populate(i);const a=yield o.exec();return a?{success:!0,result:yield this.populateDynamicVirtualsForDocument(a,n)}:{success:!1,message:`No ${this.getModelName()} found.`,code:D.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(c){return d.catchError(c)}})}findAll(){return l(this,arguments,function*(t={},e={},r={},n){try{const c=V.normalizeMongoFilter(t),o=this.model.find(c,e,r),u=this.getDynamicVirtuals(),i=I(n,u);i&&o.populate(i);const a=yield o.exec();return{success:!0,result:yield this.populateDynamicVirtualsForDocuments(a,n)}}catch(c){return d.catchError(c)}})}findPaging(){return l(this,arguments,function*(t={},e={}){try{const r=V.normalizeMongoFilter(t),n=this.getDynamicVirtuals(),c=O({},e);e.populate&&(c.populate=I(e.populate,n));const o=yield this.model.paginate(r,c),u=yield this.populateDynamicVirtualsForDocuments(o.docs,e.populate);return{success:!0,result:P(O({},o),{docs:u})}}catch(r){return d.catchError(r)}})}findPagingAggregate(t){return l(this,arguments,function*(e,r={}){try{const n=this.getDynamicVirtuals(),c=O({},r);r.populate&&(c.populate=I(r.populate,n));const o=yield this.model.aggregatePaginate(this.model.aggregate(e),c),u=yield this.populateDynamicVirtualsForDocuments(o.docs,r.populate);return{success:!0,result:P(O({},o),{docs:u})}}catch(n){return d.catchError(n)}})}count(){return l(this,arguments,function*(t={}){try{const e=V.normalizeMongoFilter(t);return{success:!0,result:yield this.model.countDocuments(e)}}catch(e){return d.catchError(e)}})}createOne(t){return l(this,null,function*(){try{return{success:!0,result:yield this.model.create(t)}}catch(e){return d.catchError(e)}})}createMany(t){return l(this,arguments,function*(e,r={}){try{return{success:!0,result:(yield this.model.insertMany(e,r)).map(o=>o instanceof K.Document?o.toObject():null).filter(o=>o!==null)}}catch(n){return d.catchError(n)}})}updateOne(){return l(this,arguments,function*(t={},e={},r={}){try{const n=V.normalizeMongoFilter(t),c=yield this.model.findOneAndUpdate(n,e,O({new:!0},r)).exec();return c?{success:!0,result:c}:{success:!1,message:`Failed to update ${this.getModelName()}.`,code:D.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(n){return d.catchError(n)}})}updateMany(){return l(this,arguments,function*(t={},e={},r={}){try{const n=V.normalizeMongoFilter(t);return{success:!0,result:yield this.model.updateMany(n,e,r).exec()}}catch(n){return d.catchError(n)}})}deleteOne(){return l(this,arguments,function*(t={},e={}){try{const r=V.normalizeMongoFilter(t),n=yield this.model.findOneAndDelete(r,e).exec();return n?{success:!0,result:n}:{success:!1,message:`No ${this.getModelName()} found to delete.`,code:D.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(r){return d.catchError(r)}})}deleteMany(){return l(this,arguments,function*(t={},e={}){try{const r=V.normalizeMongoFilter(t),n=yield this.model.deleteMany(r,e).exec();return n.deletedCount===0?{success:!1,message:"No documents found to delete.",code:D.RESPONSE_STATUS.NOT_FOUND.CODE}:{success:!0,result:n}}catch(r){return d.catchError(r)}})}createShortId(t,e=4){return l(this,null,function*(){try{const n=Array.from({length:10},(u,i)=>j.generateShortId(t,i+e)),o=(yield Promise.all(n.map(u=>this.model.exists({shortId:u})))).findIndex(u=>!u);if(o!==-1){const u=n[o];if(u)return{success:!0,result:u}}return{success:!1,message:"Failed to create a unique shortId",code:D.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}}catch(r){return d.catchError(r)}})}createSlugQuery({slug:t,field:e,isObject:r,haveHistory:n=!1,filter:c}){const o=O({},c!=null?c:{});return r?P(O({},o),{$or:[{[`slug.${e}`]:t},...n?[{slugHistory:{$elemMatch:{[`slug.${e}`]:t}}}]:[]]}):P(O({},o),{$or:[{slug:t},...n?[{slugHistory:t}]:[]]})}createUniqueSlug(t){return l(this,arguments,function*({slug:e,field:r,isObject:n,haveHistory:c,filter:o}){if(!e||typeof e!="string")throw new Error("Invalid slug provided: must be a non-empty string");const u=j.generateSlug(e);if(!(yield this.model.exists(this.createSlugQuery({slug:u,field:r,isObject:n,haveHistory:c,filter:o}))))return u;for(let S=1;S<=H.MONGO_SLUG_MAX_ATTEMPTS;S++){const h=`${u}-${S}`;if(!(yield this.model.exists(this.createSlugQuery({slug:h,field:r,isObject:n,haveHistory:c,filter:o}))))return h}const a=Date.now(),f=Math.random().toString(36).substring(2,8);return`${u}-${a}-${f}`})}createSlug(t){return l(this,arguments,function*({field:e,from:r,filter:n,haveHistory:c}){try{const o=r[e];return q.isObject(o)?{success:!0,result:Object.fromEntries(yield Promise.all(Object.entries(o).map(f=>l(this,[f],function*([S,h]){const y=yield this.createUniqueSlug({slug:h,field:S,isObject:!0,haveHistory:c,filter:n});return[S,y]}))))}:{success:!0,result:yield this.createUniqueSlug({slug:o,field:e,isObject:!1,haveHistory:c,filter:n})}}catch(o){return d.catchError(o)}})}checkSlug(t){return l(this,arguments,function*({slug:e,field:r,from:n,filter:c,haveHistory:o}){try{const u=n[r];if(q.isObject(u)){const h=Object.values(u).map(N=>j.generateSlug(N));return(yield Promise.all(h.map(N=>this.model.exists(this.createSlugQuery({slug:N,field:r,isObject:!0,haveHistory:o,filter:c}))))).some(N=>N)?{success:!0,result:!0}:{success:!0,result:!1}}const a=j.generateSlug(e);return{success:!0,result:(yield this.model.exists(this.createSlugQuery({slug:a,field:r,isObject:!1,filter:c})))!==null}}catch(u){return d.catchError(u)}})}aggregate(t){return l(this,null,function*(){try{return{success:!0,result:yield this.model.aggregate(t)}}catch(e){return d.catchError(e)}})}distinct(t){return l(this,arguments,function*(e,r={},n={}){try{return{success:!0,result:yield this.model.distinct(e,r,n)}}catch(c){return d.catchError(c)}})}}exports.MongoController=oe;exports.MongooseController=ue;exports.mongo=M;
|
|
@@ -613,4 +613,13 @@ export declare class MongooseController<T extends Partial<C_Document>> {
|
|
|
613
613
|
* @returns A promise that resolves to a standardized response with the aggregation results.
|
|
614
614
|
*/
|
|
615
615
|
aggregate(pipeline: T_PipelineStage[]): Promise<I_Return<T[]>>;
|
|
616
|
+
/**
|
|
617
|
+
* Retrieves distinct values for the specified key from the collection.
|
|
618
|
+
*
|
|
619
|
+
* @param key - The field for which to return distinct values.
|
|
620
|
+
* @param filter - The filter query to apply (optional).
|
|
621
|
+
* @param options - Additional options for the distinct operation (optional).
|
|
622
|
+
* @returns A promise that resolves to a standardized response with the array of distinct values.
|
|
623
|
+
*/
|
|
624
|
+
distinct(key: string, filter?: T_FilterQuery<T>, options?: T_QueryOptions<T>): Promise<I_Return<unknown[]>>;
|
|
616
625
|
}
|
|
@@ -20,18 +20,18 @@ var ue = Object.defineProperty, ce = Object.defineProperties, ie = Object.getOwn
|
|
|
20
20
|
for (var e of U(t))
|
|
21
21
|
le.call(t, e) && T(n, e, t[e]);
|
|
22
22
|
return n;
|
|
23
|
-
}, F = (n, t) => ce(n, ie(t)), ae = (n, t, e) => T(n, typeof t != "symbol" ? t + "" : t, e),
|
|
23
|
+
}, F = (n, t) => ce(n, ie(t)), ae = (n, t, e) => T(n, typeof t != "symbol" ? t + "" : t, e), l = (n, t, e) => new Promise((r, s) => {
|
|
24
24
|
var u = (o) => {
|
|
25
25
|
try {
|
|
26
26
|
i(e.next(o));
|
|
27
|
-
} catch (
|
|
28
|
-
s(
|
|
27
|
+
} catch (a) {
|
|
28
|
+
s(a);
|
|
29
29
|
}
|
|
30
30
|
}, c = (o) => {
|
|
31
31
|
try {
|
|
32
32
|
i(e.throw(o));
|
|
33
|
-
} catch (
|
|
34
|
-
s(
|
|
33
|
+
} catch (a) {
|
|
34
|
+
s(a);
|
|
35
35
|
}
|
|
36
36
|
}, i = (o) => o.done ? r(o.value) : Promise.resolve(o.value).then(u, c);
|
|
37
37
|
i((e = e.apply(n, t)).next());
|
|
@@ -126,8 +126,8 @@ const x = {
|
|
|
126
126
|
name: u,
|
|
127
127
|
options: c
|
|
128
128
|
});
|
|
129
|
-
const
|
|
130
|
-
i ?
|
|
129
|
+
const a = s.virtual(u);
|
|
130
|
+
i ? a.get(i) : a.get(function() {
|
|
131
131
|
var f;
|
|
132
132
|
return ((f = this._populated) == null ? void 0 : f[u]) || (c != null && c.count ? 0 : c != null && c.justOne ? null : []);
|
|
133
133
|
});
|
|
@@ -186,7 +186,7 @@ const x = {
|
|
|
186
186
|
*/
|
|
187
187
|
isRequired() {
|
|
188
188
|
return function(n) {
|
|
189
|
-
return
|
|
189
|
+
return l(this, null, function* () {
|
|
190
190
|
return !se.isEmpty(n);
|
|
191
191
|
});
|
|
192
192
|
};
|
|
@@ -202,7 +202,7 @@ const x = {
|
|
|
202
202
|
*/
|
|
203
203
|
isUnique(n) {
|
|
204
204
|
return function(t) {
|
|
205
|
-
return
|
|
205
|
+
return l(this, null, function* () {
|
|
206
206
|
if (!Array.isArray(n) || n.length === 0)
|
|
207
207
|
throw new Error("Fields must be a non-empty array of strings.");
|
|
208
208
|
const e = { $or: n.map((s) => ({ [s]: t })) };
|
|
@@ -221,7 +221,7 @@ const x = {
|
|
|
221
221
|
*/
|
|
222
222
|
matchesRegex(n) {
|
|
223
223
|
return function(t) {
|
|
224
|
-
return
|
|
224
|
+
return l(this, null, function* () {
|
|
225
225
|
if (!Array.isArray(n) || n.some((e) => !(e instanceof RegExp)))
|
|
226
226
|
throw new Error("regexArray must be an array of valid RegExp objects.");
|
|
227
227
|
return n.every((e) => e.test(t));
|
|
@@ -296,7 +296,7 @@ ${L}
|
|
|
296
296
|
* @returns Array of records that don't exist in the database
|
|
297
297
|
*/
|
|
298
298
|
getNewRecords(n, t, e) {
|
|
299
|
-
return
|
|
299
|
+
return l(this, null, function* () {
|
|
300
300
|
const r = yield n.findAll({});
|
|
301
301
|
return r.success ? t.filter(
|
|
302
302
|
(u) => !r.result.some(
|
|
@@ -313,7 +313,7 @@ ${L}
|
|
|
313
313
|
* @returns Array of existing records that match the filter criteria
|
|
314
314
|
*/
|
|
315
315
|
getExistingRecords(n, t, e) {
|
|
316
|
-
return
|
|
316
|
+
return l(this, null, function* () {
|
|
317
317
|
const r = yield n.findAll({});
|
|
318
318
|
return r.success ? r.result.filter(
|
|
319
319
|
(u) => t.some(
|
|
@@ -370,17 +370,17 @@ function me(n, t, e) {
|
|
|
370
370
|
}), Array.from(r.entries()).map(([s, u]) => ({ model: s, docs: u }));
|
|
371
371
|
}
|
|
372
372
|
function z(n, t, e, r, s) {
|
|
373
|
-
return
|
|
373
|
+
return l(this, null, function* () {
|
|
374
374
|
if (!t.length || !e.length || !r)
|
|
375
375
|
return t;
|
|
376
376
|
const u = e.filter((o) => {
|
|
377
377
|
if (Array.isArray(r))
|
|
378
|
-
return r.length > 0 && r.some((
|
|
378
|
+
return r.length > 0 && r.some((a) => typeof a == "string" ? a === o.name : a.path === o.name);
|
|
379
379
|
if (typeof r == "string")
|
|
380
380
|
return r === o.name;
|
|
381
381
|
if (typeof r == "object" && r !== null) {
|
|
382
|
-
const
|
|
383
|
-
return
|
|
382
|
+
const a = r;
|
|
383
|
+
return a.path && a.path === o.name || a.populate && a.populate === o.name;
|
|
384
384
|
}
|
|
385
385
|
return !1;
|
|
386
386
|
});
|
|
@@ -390,16 +390,16 @@ function z(n, t, e, r, s) {
|
|
|
390
390
|
(o) => fe(o) ? o.toObject() : o
|
|
391
391
|
));
|
|
392
392
|
c.forEach((o) => {
|
|
393
|
-
u.forEach(({ name:
|
|
394
|
-
if (!(
|
|
393
|
+
u.forEach(({ name: a, options: f }) => {
|
|
394
|
+
if (!(a in o)) {
|
|
395
395
|
const O = o;
|
|
396
|
-
O[
|
|
396
|
+
O[a] = f.count ? 0 : f.justOne ? null : [];
|
|
397
397
|
}
|
|
398
398
|
});
|
|
399
399
|
});
|
|
400
400
|
const i = /* @__PURE__ */ new Map();
|
|
401
401
|
for (const o of u) {
|
|
402
|
-
const { name:
|
|
402
|
+
const { name: a, options: f } = o, O = me(c, a, f);
|
|
403
403
|
for (const m of O) {
|
|
404
404
|
i.has(m.model) || i.set(m.model, {
|
|
405
405
|
virtuals: [],
|
|
@@ -407,8 +407,8 @@ function z(n, t, e, r, s) {
|
|
|
407
407
|
docsByLocalValue: /* @__PURE__ */ new Map()
|
|
408
408
|
});
|
|
409
409
|
const g = i.get(m.model);
|
|
410
|
-
g.virtuals.find((V) => V.name ===
|
|
411
|
-
const v = g.localValueSets.get(
|
|
410
|
+
g.virtuals.find((V) => V.name === a) || (g.virtuals.push(o), g.localValueSets.set(a, /* @__PURE__ */ new Set()));
|
|
411
|
+
const v = g.localValueSets.get(a);
|
|
412
412
|
m.docs.forEach((V) => {
|
|
413
413
|
const A = V[f.localField];
|
|
414
414
|
if (A != null) {
|
|
@@ -424,8 +424,8 @@ function z(n, t, e, r, s) {
|
|
|
424
424
|
});
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
|
-
return yield Promise.all(Array.from(i.entries()).map((o) =>
|
|
428
|
-
const O = n.models[
|
|
427
|
+
return yield Promise.all(Array.from(i.entries()).map((o) => l(null, [o], function* ([a, f]) {
|
|
428
|
+
const O = n.models[a];
|
|
429
429
|
if (!O)
|
|
430
430
|
return;
|
|
431
431
|
const m = /* @__PURE__ */ new Set();
|
|
@@ -491,7 +491,7 @@ class Me {
|
|
|
491
491
|
* @returns A promise that resolves to a standardized response with the created document.
|
|
492
492
|
*/
|
|
493
493
|
createOne(t) {
|
|
494
|
-
return
|
|
494
|
+
return l(this, null, function* () {
|
|
495
495
|
try {
|
|
496
496
|
const e = S(S({}, x.createGenericFields()), t);
|
|
497
497
|
return (yield this.collection.insertOne(e)).acknowledged ? {
|
|
@@ -516,7 +516,7 @@ class Me {
|
|
|
516
516
|
* @returns A promise that resolves to a standardized response with the created documents.
|
|
517
517
|
*/
|
|
518
518
|
createMany(t) {
|
|
519
|
-
return
|
|
519
|
+
return l(this, null, function* () {
|
|
520
520
|
try {
|
|
521
521
|
const e = t.map((s) => S(S({}, x.createGenericFields()), s)), r = yield this.collection.insertMany(e);
|
|
522
522
|
return r.insertedCount === 0 ? {
|
|
@@ -540,7 +540,7 @@ class Me {
|
|
|
540
540
|
* @returns A promise that resolves to a standardized response with the found document.
|
|
541
541
|
*/
|
|
542
542
|
findOne(t) {
|
|
543
|
-
return
|
|
543
|
+
return l(this, null, function* () {
|
|
544
544
|
try {
|
|
545
545
|
const e = yield this.collection.findOne(t);
|
|
546
546
|
return e ? { success: !0, message: "Document found", result: e } : { success: !1, message: "Document not found", code: R.NOT_FOUND.CODE };
|
|
@@ -556,7 +556,7 @@ class Me {
|
|
|
556
556
|
* @returns A promise that resolves to a standardized response with the found documents.
|
|
557
557
|
*/
|
|
558
558
|
findAll() {
|
|
559
|
-
return
|
|
559
|
+
return l(this, arguments, function* (t = {}) {
|
|
560
560
|
try {
|
|
561
561
|
return {
|
|
562
562
|
success: !0,
|
|
@@ -575,7 +575,7 @@ class Me {
|
|
|
575
575
|
* @returns A promise that resolves to a standardized response with the document count.
|
|
576
576
|
*/
|
|
577
577
|
count() {
|
|
578
|
-
return
|
|
578
|
+
return l(this, arguments, function* (t = {}) {
|
|
579
579
|
try {
|
|
580
580
|
const e = yield this.collection.countDocuments(t);
|
|
581
581
|
return {
|
|
@@ -596,7 +596,7 @@ class Me {
|
|
|
596
596
|
* @returns A promise that resolves to a standardized response with the update result.
|
|
597
597
|
*/
|
|
598
598
|
updateOne(t, e) {
|
|
599
|
-
return
|
|
599
|
+
return l(this, null, function* () {
|
|
600
600
|
try {
|
|
601
601
|
const r = yield this.collection.updateOne(t, {
|
|
602
602
|
$set: e
|
|
@@ -623,7 +623,7 @@ class Me {
|
|
|
623
623
|
* @returns A promise that resolves to a standardized response with the update result.
|
|
624
624
|
*/
|
|
625
625
|
updateMany(t, e) {
|
|
626
|
-
return
|
|
626
|
+
return l(this, null, function* () {
|
|
627
627
|
try {
|
|
628
628
|
const r = yield this.collection.updateMany(t, {
|
|
629
629
|
$set: e
|
|
@@ -649,7 +649,7 @@ class Me {
|
|
|
649
649
|
* @returns A promise that resolves to a standardized response with the delete result.
|
|
650
650
|
*/
|
|
651
651
|
deleteOne(t) {
|
|
652
|
-
return
|
|
652
|
+
return l(this, null, function* () {
|
|
653
653
|
try {
|
|
654
654
|
const e = yield this.collection.deleteOne(t);
|
|
655
655
|
return e.deletedCount === 0 ? {
|
|
@@ -673,7 +673,7 @@ class Me {
|
|
|
673
673
|
* @returns A promise that resolves to a standardized response with the delete result.
|
|
674
674
|
*/
|
|
675
675
|
deleteMany(t) {
|
|
676
|
-
return
|
|
676
|
+
return l(this, null, function* () {
|
|
677
677
|
try {
|
|
678
678
|
const e = yield this.collection.deleteMany(t);
|
|
679
679
|
return e.deletedCount === 0 ? {
|
|
@@ -724,7 +724,7 @@ class we {
|
|
|
724
724
|
* @returns The document with dynamic virtuals populated.
|
|
725
725
|
*/
|
|
726
726
|
populateDynamicVirtualsForDocument(t, e) {
|
|
727
|
-
return
|
|
727
|
+
return l(this, null, function* () {
|
|
728
728
|
const r = this.getDynamicVirtuals();
|
|
729
729
|
if (r && r.length > 0) {
|
|
730
730
|
const s = yield z(this.model.base, [t], r, e);
|
|
@@ -741,7 +741,7 @@ class we {
|
|
|
741
741
|
* @returns The documents with dynamic virtuals populated.
|
|
742
742
|
*/
|
|
743
743
|
populateDynamicVirtualsForDocuments(t, e) {
|
|
744
|
-
return
|
|
744
|
+
return l(this, null, function* () {
|
|
745
745
|
const r = this.getDynamicVirtuals();
|
|
746
746
|
return r && r.length > 0 && t.length > 0 ? yield z(this.model.base, t, r, e) : t;
|
|
747
747
|
});
|
|
@@ -757,12 +757,12 @@ class we {
|
|
|
757
757
|
* @returns A promise that resolves to a standardized response with the found document.
|
|
758
758
|
*/
|
|
759
759
|
findOne() {
|
|
760
|
-
return
|
|
760
|
+
return l(this, arguments, function* (t = {}, e = {}, r = {}, s) {
|
|
761
761
|
try {
|
|
762
762
|
const u = b(t), c = this.model.findOne(u, e, r), i = this.getDynamicVirtuals(), o = j(s, i);
|
|
763
763
|
o && c.populate(o);
|
|
764
|
-
const
|
|
765
|
-
return
|
|
764
|
+
const a = yield c.exec();
|
|
765
|
+
return a ? { success: !0, result: yield this.populateDynamicVirtualsForDocument(a, s) } : {
|
|
766
766
|
success: !1,
|
|
767
767
|
message: `No ${this.getModelName()} found.`,
|
|
768
768
|
code: R.NOT_FOUND.CODE
|
|
@@ -783,12 +783,12 @@ class we {
|
|
|
783
783
|
* @returns A promise that resolves to a standardized response with the found documents.
|
|
784
784
|
*/
|
|
785
785
|
findAll() {
|
|
786
|
-
return
|
|
786
|
+
return l(this, arguments, function* (t = {}, e = {}, r = {}, s) {
|
|
787
787
|
try {
|
|
788
788
|
const u = b(t), c = this.model.find(u, e, r), i = this.getDynamicVirtuals(), o = j(s, i);
|
|
789
789
|
o && c.populate(o);
|
|
790
|
-
const
|
|
791
|
-
return { success: !0, result: yield this.populateDynamicVirtualsForDocuments(
|
|
790
|
+
const a = yield c.exec();
|
|
791
|
+
return { success: !0, result: yield this.populateDynamicVirtualsForDocuments(a, s) };
|
|
792
792
|
} catch (u) {
|
|
793
793
|
return d(u);
|
|
794
794
|
}
|
|
@@ -803,7 +803,7 @@ class we {
|
|
|
803
803
|
* @returns A promise that resolves to a standardized response with paginated results.
|
|
804
804
|
*/
|
|
805
805
|
findPaging() {
|
|
806
|
-
return
|
|
806
|
+
return l(this, arguments, function* (t = {}, e = {}) {
|
|
807
807
|
try {
|
|
808
808
|
const r = b(t), s = this.getDynamicVirtuals(), u = S({}, e);
|
|
809
809
|
e.populate && (u.populate = j(e.populate, s));
|
|
@@ -822,7 +822,7 @@ class we {
|
|
|
822
822
|
* @returns A promise that resolves to a standardized response with paginated aggregation results.
|
|
823
823
|
*/
|
|
824
824
|
findPagingAggregate(t) {
|
|
825
|
-
return
|
|
825
|
+
return l(this, arguments, function* (e, r = {}) {
|
|
826
826
|
try {
|
|
827
827
|
const s = this.getDynamicVirtuals(), u = S({}, r);
|
|
828
828
|
r.populate && (u.populate = j(r.populate, s));
|
|
@@ -843,7 +843,7 @@ class we {
|
|
|
843
843
|
* @returns A promise that resolves to a standardized response with the document count.
|
|
844
844
|
*/
|
|
845
845
|
count() {
|
|
846
|
-
return
|
|
846
|
+
return l(this, arguments, function* (t = {}) {
|
|
847
847
|
try {
|
|
848
848
|
const e = b(t);
|
|
849
849
|
return { success: !0, result: yield this.model.countDocuments(e) };
|
|
@@ -859,7 +859,7 @@ class we {
|
|
|
859
859
|
* @returns A promise that resolves to a standardized response with the created document.
|
|
860
860
|
*/
|
|
861
861
|
createOne(t) {
|
|
862
|
-
return
|
|
862
|
+
return l(this, null, function* () {
|
|
863
863
|
try {
|
|
864
864
|
return { success: !0, result: yield this.model.create(t) };
|
|
865
865
|
} catch (e) {
|
|
@@ -875,7 +875,7 @@ class we {
|
|
|
875
875
|
* @returns A promise that resolves to a standardized response with the created documents.
|
|
876
876
|
*/
|
|
877
877
|
createMany(t) {
|
|
878
|
-
return
|
|
878
|
+
return l(this, arguments, function* (e, r = {}) {
|
|
879
879
|
try {
|
|
880
880
|
return { success: !0, result: (yield this.model.insertMany(e, r)).map((c) => c instanceof W ? c.toObject() : null).filter((c) => c !== null) };
|
|
881
881
|
} catch (s) {
|
|
@@ -892,7 +892,7 @@ class we {
|
|
|
892
892
|
* @returns A promise that resolves to a standardized response with the updated document.
|
|
893
893
|
*/
|
|
894
894
|
updateOne() {
|
|
895
|
-
return
|
|
895
|
+
return l(this, arguments, function* (t = {}, e = {}, r = {}) {
|
|
896
896
|
try {
|
|
897
897
|
const s = b(t), u = yield this.model.findOneAndUpdate(s, e, S({
|
|
898
898
|
new: !0
|
|
@@ -916,7 +916,7 @@ class we {
|
|
|
916
916
|
* @returns A promise that resolves to a standardized response with the update result.
|
|
917
917
|
*/
|
|
918
918
|
updateMany() {
|
|
919
|
-
return
|
|
919
|
+
return l(this, arguments, function* (t = {}, e = {}, r = {}) {
|
|
920
920
|
try {
|
|
921
921
|
const s = b(t);
|
|
922
922
|
return { success: !0, result: yield this.model.updateMany(s, e, r).exec() };
|
|
@@ -933,7 +933,7 @@ class we {
|
|
|
933
933
|
* @returns A promise that resolves to a standardized response with the deleted document.
|
|
934
934
|
*/
|
|
935
935
|
deleteOne() {
|
|
936
|
-
return
|
|
936
|
+
return l(this, arguments, function* (t = {}, e = {}) {
|
|
937
937
|
try {
|
|
938
938
|
const r = b(t), s = yield this.model.findOneAndDelete(r, e).exec();
|
|
939
939
|
return s ? { success: !0, result: s } : {
|
|
@@ -954,7 +954,7 @@ class we {
|
|
|
954
954
|
* @returns A promise that resolves to a standardized response with the delete result.
|
|
955
955
|
*/
|
|
956
956
|
deleteMany() {
|
|
957
|
-
return
|
|
957
|
+
return l(this, arguments, function* (t = {}, e = {}) {
|
|
958
958
|
try {
|
|
959
959
|
const r = b(t), s = yield this.model.deleteMany(r, e).exec();
|
|
960
960
|
return s.deletedCount === 0 ? {
|
|
@@ -976,7 +976,7 @@ class we {
|
|
|
976
976
|
* @returns A promise that resolves to a standardized response with the unique short ID.
|
|
977
977
|
*/
|
|
978
978
|
createShortId(t, e = 4) {
|
|
979
|
-
return
|
|
979
|
+
return l(this, null, function* () {
|
|
980
980
|
try {
|
|
981
981
|
const s = Array.from({ length: 10 }, (i, o) => ne(t, o + e)), c = (yield Promise.all(
|
|
982
982
|
s.map((i) => this.model.exists({ shortId: i }))
|
|
@@ -1033,7 +1033,7 @@ class we {
|
|
|
1033
1033
|
* @returns A promise that resolves to a unique slug string.
|
|
1034
1034
|
*/
|
|
1035
1035
|
createUniqueSlug(t) {
|
|
1036
|
-
return
|
|
1036
|
+
return l(this, arguments, function* ({ slug: e, field: r, isObject: s, haveHistory: u, filter: c }) {
|
|
1037
1037
|
if (!e || typeof e != "string")
|
|
1038
1038
|
throw new Error("Invalid slug provided: must be a non-empty string");
|
|
1039
1039
|
const i = I(e);
|
|
@@ -1048,8 +1048,8 @@ class we {
|
|
|
1048
1048
|
)))
|
|
1049
1049
|
return m;
|
|
1050
1050
|
}
|
|
1051
|
-
const
|
|
1052
|
-
return `${i}-${
|
|
1051
|
+
const a = Date.now(), f = Math.random().toString(36).substring(2, 8);
|
|
1052
|
+
return `${i}-${a}-${f}`;
|
|
1053
1053
|
});
|
|
1054
1054
|
}
|
|
1055
1055
|
/**
|
|
@@ -1063,12 +1063,12 @@ class we {
|
|
|
1063
1063
|
* @returns A promise that resolves to a standardized response with the created slug(s).
|
|
1064
1064
|
*/
|
|
1065
1065
|
createSlug(t) {
|
|
1066
|
-
return
|
|
1066
|
+
return l(this, arguments, function* ({ field: e, from: r, filter: s, haveHistory: u }) {
|
|
1067
1067
|
try {
|
|
1068
1068
|
const c = r[e];
|
|
1069
1069
|
return $(c) ? { success: !0, result: Object.fromEntries(
|
|
1070
1070
|
yield Promise.all(
|
|
1071
|
-
Object.entries(c).map((f) =>
|
|
1071
|
+
Object.entries(c).map((f) => l(this, [f], function* ([O, m]) {
|
|
1072
1072
|
const g = yield this.createUniqueSlug({
|
|
1073
1073
|
slug: m,
|
|
1074
1074
|
field: O,
|
|
@@ -1103,7 +1103,7 @@ class we {
|
|
|
1103
1103
|
* @returns A promise that resolves to a standardized response indicating whether the slug exists.
|
|
1104
1104
|
*/
|
|
1105
1105
|
checkSlug(t) {
|
|
1106
|
-
return
|
|
1106
|
+
return l(this, arguments, function* ({ slug: e, field: r, from: s, filter: u, haveHistory: c }) {
|
|
1107
1107
|
try {
|
|
1108
1108
|
const i = s[r];
|
|
1109
1109
|
if ($(i)) {
|
|
@@ -1120,9 +1120,9 @@ class we {
|
|
|
1120
1120
|
)
|
|
1121
1121
|
)).some((v) => v) ? { success: !0, result: !0 } : { success: !0, result: !1 };
|
|
1122
1122
|
}
|
|
1123
|
-
const
|
|
1123
|
+
const a = I(e);
|
|
1124
1124
|
return { success: !0, result: (yield this.model.exists(this.createSlugQuery({
|
|
1125
|
-
slug:
|
|
1125
|
+
slug: a,
|
|
1126
1126
|
field: r,
|
|
1127
1127
|
isObject: !1,
|
|
1128
1128
|
filter: u
|
|
@@ -1139,7 +1139,7 @@ class we {
|
|
|
1139
1139
|
* @returns A promise that resolves to a standardized response with the aggregation results.
|
|
1140
1140
|
*/
|
|
1141
1141
|
aggregate(t) {
|
|
1142
|
-
return
|
|
1142
|
+
return l(this, null, function* () {
|
|
1143
1143
|
try {
|
|
1144
1144
|
return { success: !0, result: yield this.model.aggregate(t) };
|
|
1145
1145
|
} catch (e) {
|
|
@@ -1147,6 +1147,23 @@ class we {
|
|
|
1147
1147
|
}
|
|
1148
1148
|
});
|
|
1149
1149
|
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Retrieves distinct values for the specified key from the collection.
|
|
1152
|
+
*
|
|
1153
|
+
* @param key - The field for which to return distinct values.
|
|
1154
|
+
* @param filter - The filter query to apply (optional).
|
|
1155
|
+
* @param options - Additional options for the distinct operation (optional).
|
|
1156
|
+
* @returns A promise that resolves to a standardized response with the array of distinct values.
|
|
1157
|
+
*/
|
|
1158
|
+
distinct(t) {
|
|
1159
|
+
return l(this, arguments, function* (e, r = {}, s = {}) {
|
|
1160
|
+
try {
|
|
1161
|
+
return { success: !0, result: yield this.model.distinct(e, r, s) };
|
|
1162
|
+
} catch (u) {
|
|
1163
|
+
return d(u);
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1150
1167
|
}
|
|
1151
1168
|
export {
|
|
1152
1169
|
Me as MongoController,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("lodash-es");var
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("lodash-es");var g=Object.defineProperty,v=Object.defineProperties,O=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,b=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable,l=(r,e,t)=>e in r?g(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,c=(r,e)=>{for(var t in e||(e={}))b.call(e,t)&&l(r,t,e[t]);if(u)for(var t of u(e))h.call(e,t)&&l(r,t,e[t]);return r},f=(r,e)=>v(r,O(e));function _(r){try{return JSON.parse(r),!0}catch(e){return!1}}function j(r,e){return e.reduce((t,n)=>{if(t&&typeof t=="object"&&n in t)return t[n]},r)}function p(r,e,t){if(e.length===0)return r;const[n,...o]=e;if(o.length===0)return f(c({},r),{[n]:t});const s=r[n];return f(c({},r),{[n]:p(typeof s=="object"&&s!==null?s:{},o,t)})}function w(...r){if(r.length===0)return{};const e=r.filter(o=>o!=null).map(o=>typeof o!="object"?{}:o);if(e.length===0)return{};if(e.length===1)return e[0];if(e.every(i.isArray))return[].concat(...e);if(e.every(o=>typeof o=="object"&&o!==null&&!i.isArray(o)))return i.mergeWith({},...e,(o,s)=>{if(i.isArray(o)&&i.isArray(s))return o.concat(s)});if(e.every(o=>typeof o!="object"||o===null))throw new Error("deepMerge: Cannot merge primitive values. All arguments must be objects or arrays.");const t=e.some(i.isArray),n=e.some(o=>typeof o=="object"&&o!==null&&!i.isArray(o));throw t&&n?new Error("deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects."):new Error("deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type.")}function a(r){if(!r||typeof r!="object")return r;const e={};for(const[t,n]of Object.entries(r))if(n&&typeof n=="object"&&!Array.isArray(n))if(Object.keys(n).some(s=>s.startsWith("$")))e[t]=a(n);else{const s=a(n);for(const[y,d]of Object.entries(s)){const m=`${t}.${y}`;e[m]=d}}else e[t]=n;return e}exports.deepMerge=w;exports.getNestedValue=j;exports.isJSON=_;exports.normalizeMongoFilter=a;exports.setNestedValue=p;
|
|
@@ -73,11 +73,12 @@ export declare function deepMerge<T extends Record<string, unknown>>(...args: (T
|
|
|
73
73
|
export declare function deepMerge<T extends unknown[]>(...args: (T | null | undefined)[]): T;
|
|
74
74
|
/**
|
|
75
75
|
* Normalizes MongoDB filters to support both dot notation strings and nested objects.
|
|
76
|
-
* This function converts nested object filters to dot notation format
|
|
77
|
-
* consistent behavior across different filter input formats.
|
|
76
|
+
* This function converts nested object filters to dot notation format while preserving
|
|
77
|
+
* MongoDB operators to ensure consistent behavior across different filter input formats.
|
|
78
78
|
*
|
|
79
79
|
* @param filter - The filter object to normalize.
|
|
80
|
-
* @returns A normalized filter object with nested objects converted to dot notation
|
|
80
|
+
* @returns A normalized filter object with nested objects converted to dot notation,
|
|
81
|
+
* while preserving MongoDB operators as nested objects.
|
|
81
82
|
*
|
|
82
83
|
* @example
|
|
83
84
|
* ```typescript
|
|
@@ -85,6 +86,10 @@ export declare function deepMerge<T extends unknown[]>(...args: (T | null | unde
|
|
|
85
86
|
* normalizeMongoFilter({ "location.countryId": "240" })
|
|
86
87
|
* normalizeMongoFilter({ location: { countryId: "240" } })
|
|
87
88
|
* // Both return: { "location.countryId": "240" }
|
|
89
|
+
*
|
|
90
|
+
* // MongoDB operators are preserved:
|
|
91
|
+
* normalizeMongoFilter({ id: { $in: ["240", "59"] } })
|
|
92
|
+
* // Returns: { id: { $in: ["240", "59"] } }
|
|
88
93
|
* ```
|
|
89
94
|
*/
|
|
90
95
|
export declare function normalizeMongoFilter<T extends Record<string, unknown>>(filter: T): T;
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { isArray as i, mergeWith as
|
|
2
|
-
var
|
|
3
|
-
for (var
|
|
4
|
-
|
|
5
|
-
if (
|
|
6
|
-
for (var
|
|
7
|
-
_.call(e,
|
|
1
|
+
import { isArray as i, mergeWith as m } from "lodash-es";
|
|
2
|
+
var v = Object.defineProperty, O = Object.defineProperties, b = Object.getOwnPropertyDescriptors, a = Object.getOwnPropertySymbols, h = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable, u = (r, e, t) => e in r ? v(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, f = (r, e) => {
|
|
3
|
+
for (var t in e || (e = {}))
|
|
4
|
+
h.call(e, t) && u(r, t, e[t]);
|
|
5
|
+
if (a)
|
|
6
|
+
for (var t of a(e))
|
|
7
|
+
_.call(e, t) && u(r, t, e[t]);
|
|
8
8
|
return r;
|
|
9
|
-
}, c = (r, e) =>
|
|
10
|
-
function
|
|
9
|
+
}, c = (r, e) => O(r, b(e));
|
|
10
|
+
function w(r) {
|
|
11
11
|
try {
|
|
12
12
|
return JSON.parse(r), !0;
|
|
13
13
|
} catch (e) {
|
|
14
14
|
return !1;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
return e.reduce((
|
|
19
|
-
if (
|
|
20
|
-
return n
|
|
17
|
+
function P(r, e) {
|
|
18
|
+
return e.reduce((t, n) => {
|
|
19
|
+
if (t && typeof t == "object" && n in t)
|
|
20
|
+
return t[n];
|
|
21
21
|
}, r);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function g(r, e, t) {
|
|
24
24
|
if (e.length === 0)
|
|
25
25
|
return r;
|
|
26
|
-
const [
|
|
27
|
-
if (
|
|
26
|
+
const [n, ...o] = e;
|
|
27
|
+
if (o.length === 0)
|
|
28
28
|
return c(f({}, r), {
|
|
29
|
-
[
|
|
29
|
+
[n]: t
|
|
30
30
|
});
|
|
31
|
-
const s = r[
|
|
31
|
+
const s = r[n];
|
|
32
32
|
return c(f({}, r), {
|
|
33
|
-
[
|
|
33
|
+
[n]: g(
|
|
34
34
|
typeof s == "object" && s !== null ? s : {},
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
o,
|
|
36
|
+
t
|
|
37
37
|
)
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function A(...r) {
|
|
41
41
|
if (r.length === 0)
|
|
42
42
|
return {};
|
|
43
|
-
const e = r.filter((
|
|
43
|
+
const e = r.filter((o) => o != null).map((o) => typeof o != "object" ? {} : o);
|
|
44
44
|
if (e.length === 0)
|
|
45
45
|
return {};
|
|
46
46
|
if (e.length === 1)
|
|
@@ -48,44 +48,50 @@ function P(...r) {
|
|
|
48
48
|
if (e.every(i))
|
|
49
49
|
return [].concat(...e);
|
|
50
50
|
if (e.every(
|
|
51
|
-
(
|
|
51
|
+
(o) => typeof o == "object" && o !== null && !i(o)
|
|
52
52
|
))
|
|
53
|
-
return
|
|
54
|
-
if (i(
|
|
55
|
-
return
|
|
53
|
+
return m({}, ...e, (o, s) => {
|
|
54
|
+
if (i(o) && i(s))
|
|
55
|
+
return o.concat(s);
|
|
56
56
|
});
|
|
57
|
-
if (e.every((
|
|
57
|
+
if (e.every((o) => typeof o != "object" || o === null))
|
|
58
58
|
throw new Error(
|
|
59
59
|
"deepMerge: Cannot merge primitive values. All arguments must be objects or arrays."
|
|
60
60
|
);
|
|
61
|
-
const
|
|
62
|
-
(
|
|
61
|
+
const t = e.some(i), n = e.some(
|
|
62
|
+
(o) => typeof o == "object" && o !== null && !i(o)
|
|
63
63
|
);
|
|
64
|
-
throw
|
|
64
|
+
throw t && n ? new Error(
|
|
65
65
|
"deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects."
|
|
66
66
|
) : new Error(
|
|
67
67
|
"deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type."
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function l(r) {
|
|
71
71
|
if (!r || typeof r != "object")
|
|
72
72
|
return r;
|
|
73
73
|
const e = {};
|
|
74
|
-
for (const [
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
e[
|
|
74
|
+
for (const [t, n] of Object.entries(r))
|
|
75
|
+
if (n && typeof n == "object" && !Array.isArray(n))
|
|
76
|
+
if (Object.keys(n).some(
|
|
77
|
+
(s) => s.startsWith("$")
|
|
78
|
+
))
|
|
79
|
+
e[t] = l(n);
|
|
80
|
+
else {
|
|
81
|
+
const s = l(n);
|
|
82
|
+
for (const [p, y] of Object.entries(s)) {
|
|
83
|
+
const d = `${t}.${p}`;
|
|
84
|
+
e[d] = y;
|
|
85
|
+
}
|
|
80
86
|
}
|
|
81
|
-
|
|
82
|
-
e[
|
|
87
|
+
else
|
|
88
|
+
e[t] = n;
|
|
83
89
|
return e;
|
|
84
90
|
}
|
|
85
91
|
export {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
A as deepMerge,
|
|
93
|
+
P as getNestedValue,
|
|
94
|
+
w as isJSON,
|
|
95
|
+
l as normalizeMongoFilter,
|
|
96
|
+
g as setNestedValue
|
|
91
97
|
};
|