@cyberskill/shared 1.217.0 → 2.0.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.
Files changed (87) hide show
  1. package/README.md +330 -222
  2. package/dist/config/config.util.d.ts +17 -0
  3. package/dist/config/env/env.util.d.ts +26 -0
  4. package/dist/config/eslint/index.d.ts +4 -0
  5. package/dist/config/graphql-codegen/graphql-codegen.util.d.ts +23 -0
  6. package/dist/config/vitest/vitest.e2e.cjs +1 -1
  7. package/dist/config/vitest/vitest.e2e.d.ts +16 -0
  8. package/dist/config/vitest/vitest.e2e.js +1 -1
  9. package/dist/config/vitest/vitest.unit.cjs +1 -1
  10. package/dist/config/vitest/vitest.unit.d.ts +18 -0
  11. package/dist/config/vitest/vitest.unit.js +1 -1
  12. package/dist/constant/common.d.ts +4 -0
  13. package/dist/constant/index.d.ts +3 -0
  14. package/dist/node/apollo-server/apollo-server.util.d.ts +14 -0
  15. package/dist/node/command/command.type.d.ts +26 -6
  16. package/dist/node/command/command.util.d.ts +50 -0
  17. package/dist/node/express/express.util.d.ts +47 -0
  18. package/dist/node/fs/fs.type.d.ts +6 -0
  19. package/dist/node/fs/fs.util.d.ts +48 -1
  20. package/dist/node/log/log.type.d.ts +6 -1
  21. package/dist/node/log/log.util.cjs +1 -1
  22. package/dist/node/log/log.util.d.ts +30 -2
  23. package/dist/node/log/log.util.js +33 -20
  24. package/dist/node/mongo/mongo.constant.d.ts +5 -0
  25. package/dist/node/mongo/mongo.type.d.ts +4 -4
  26. package/dist/node/mongo/mongo.util.cjs +5 -5
  27. package/dist/node/mongo/mongo.util.d.ts +337 -3
  28. package/dist/node/mongo/mongo.util.js +406 -79
  29. package/dist/node/package/package.type.d.ts +2 -2
  30. package/dist/node/package/package.util.cjs +1 -1
  31. package/dist/node/package/package.util.d.ts +52 -1
  32. package/dist/node/package/package.util.js +97 -92
  33. package/dist/node/path/path.constant.d.ts +9 -0
  34. package/dist/node/path/path.util.d.ts +24 -0
  35. package/dist/node/storage/storage.util.d.ts +44 -0
  36. package/dist/node/storage/storage.util.js +39 -0
  37. package/dist/node/upload/upload.util.d.ts +21 -0
  38. package/dist/node/ws/ts.util.d.ts +16 -0
  39. package/dist/react/apollo-client/apollo-client.component.d.ts +19 -1
  40. package/dist/react/apollo-client/apollo-client.component.js +1 -4
  41. package/dist/react/apollo-client/apollo-client.constant.d.ts +5 -0
  42. package/dist/react/apollo-client/apollo-client.context.d.ts +15 -0
  43. package/dist/react/apollo-client/apollo-client.hook.d.ts +12 -0
  44. package/dist/react/apollo-client/apollo-client.util.d.ts +48 -0
  45. package/dist/react/apollo-client/apollo-client.util.js +9 -0
  46. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.d.ts +19 -1
  47. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js +1 -4
  48. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.d.ts +10 -0
  49. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.d.ts +10 -0
  50. package/dist/react/apollo-error/apollo-error.component.cjs +1 -1
  51. package/dist/react/apollo-error/apollo-error.component.d.ts +17 -0
  52. package/dist/react/apollo-error/apollo-error.component.js +10 -10
  53. package/dist/react/apollo-error/apollo-error.hook.d.ts +12 -0
  54. package/dist/react/apollo-error/apollo-error.provider.d.ts +15 -0
  55. package/dist/react/apollo-error/apollo-error.util.d.ts +17 -0
  56. package/dist/react/i18next/i18next.hook.d.ts +9 -0
  57. package/dist/react/i18next/i18next.util.d.ts +10 -0
  58. package/dist/react/loading/loading.component.d.ts +21 -0
  59. package/dist/react/loading/loading.hook.d.ts +12 -0
  60. package/dist/react/loading/loading.provider.d.ts +15 -0
  61. package/dist/react/log/log.util.d.ts +17 -0
  62. package/dist/react/next-intl/next-intl.constant.d.ts +9 -0
  63. package/dist/react/next-intl/next-intl.hoc.d.ts +16 -0
  64. package/dist/react/next-intl/next-intl.hook.d.ts +21 -0
  65. package/dist/react/next-intl/next-intl.provider.d.ts +21 -0
  66. package/dist/react/storage/storage.hook.d.ts +19 -0
  67. package/dist/react/storage/storage.hook.js +28 -30
  68. package/dist/react/storage/storage.util.d.ts +39 -0
  69. package/dist/react/storage/storage.util.js +33 -0
  70. package/dist/react/userback/userback.component.d.ts +18 -0
  71. package/dist/typescript/common.type.d.ts +6 -0
  72. package/dist/typescript/index.d.ts +3 -0
  73. package/dist/util/common/common.util.d.ts +19 -7
  74. package/dist/util/common/index.d.ts +3 -0
  75. package/dist/util/index.d.ts +3 -0
  76. package/dist/util/object/object.util.d.ts +25 -12
  77. package/dist/util/serializer/serializer.type.d.ts +1 -1
  78. package/dist/util/serializer/serializer.util.d.ts +8 -0
  79. package/dist/util/serializer/serializer.util.js +4 -4
  80. package/dist/util/string/string.util.cjs +1 -1
  81. package/dist/util/string/string.util.d.ts +30 -17
  82. package/dist/util/string/string.util.js +14 -16
  83. package/dist/util/validate/validate.util.d.ts +9 -3
  84. package/dist/util/validate/validate.util.js +5 -3
  85. package/package.json +7 -5
  86. /package/dist/node_modules/.pnpm/{vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.14_@vitest_browser@3.2.4_jiti@2.4.2_j_5b4f3b6d03b5e1745ce439b75ce4a42f → vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.15_@vitest_browser@3.2.4_jiti@2.4.2_j_e4a333d8aa4b05d17db10875e249d94f}/node_modules/vitest/dist/config.cjs +0 -0
  87. /package/dist/node_modules/.pnpm/{vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.14_@vitest_browser@3.2.4_jiti@2.4.2_j_5b4f3b6d03b5e1745ce439b75ce4a42f → vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.15_@vitest_browser@3.2.4_jiti@2.4.2_j_e4a333d8aa4b05d17db10875e249d94f}/node_modules/vitest/dist/config.js +0 -0
@@ -1,5 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("lodash-es"),v=require("migrate-mongo"),q=require("mongoose"),A=require("mongoose-aggregate-paginate-v2"),b=require("mongoose-paginate-v2"),T=require("uuid"),D=require("../../util/object/object.util.cjs"),x=require("../../util/common/common.util.cjs"),y=require("../fs/fs.util.cjs"),f=require("../path/path.constant.cjs"),C=require("../../util/validate/validate.util.cjs"),S=require("../../util/string/string.util.cjs"),d=require("../../constant/response-status.cjs"),i=require("../log/log.util.cjs");var I=Object.defineProperty,M=Object.defineProperties,w=Object.getOwnPropertyDescriptors,P=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable,_=(n,t,e)=>t in n?I(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,h=(n,t)=>{for(var e in t||(t={}))j.call(t,e)&&_(n,e,t[e]);if(P)for(var e of P(t))F.call(t,e)&&_(n,e,t[e]);return n},R=(n,t)=>M(n,w(t)),G=(n,t,e)=>_(n,typeof t!="symbol"?t+"":t,e),o=(n,t,e)=>new Promise((r,s)=>{var u=a=>{try{l(e.next(a))}catch(m){s(m)}},c=a=>{try{l(e.throw(a))}catch(m){s(m)}},l=a=>a.done?r(a.value):Promise.resolve(a.value).then(u,c);l((e=e.apply(n,t)).next())});const g={createGenericFields(){return{id:T.v4(),isDel:!1,createdAt:new Date,updatedAt:new Date}},applyPlugins(n,t){t.filter(e=>typeof e=="function").forEach(e=>n.plugin(e))},applyMiddlewares(n,t){t.forEach(({method:e,pre:r,post:s})=>{e&&r&&n.pre(e,r),e&&s&&n.post(e,s)})},createGenericSchema(n){return new n.Schema({id:{type:String,default:T.v4,unique:!0},isDel:{type:Boolean,default:!1}},{timestamps:!0})},createSchema({mongoose:n,schema:t,virtuals:e=[],standalone:r=!1}){const s=new n.Schema(t);return e.forEach(({name:u,options:c,get:l})=>{const a=s.virtual(u,c);l&&a.get(l)}),r||s.add(g.createGenericSchema(n)),s},createModel({mongoose:n,name:t,schema:e,pagination:r=!1,aggregate:s=!1,virtuals:u=[],middlewares:c=[]}){if(!t)throw new Error("Model name is required.");if(n.models[t])return n.models[t];const l=g.createSchema({mongoose:n,schema:e,virtuals:u});return g.applyPlugins(l,[r&&b,s&&A]),g.applyMiddlewares(l,c),n.model(t,l)},validator:{isRequired(){return function(n){return o(this,null,function*(){return!C.validate.isEmpty(n)})}},isUnique(n){return function(t){return o(this,null,function*(){if(!Array.isArray(n)||n.length===0)throw new Error("Fields must be a non-empty array of strings.");const e={$or:n.map(s=>({[s]:t}))};return!(yield this.constructor.exists(e))})}},matchesRegex(n){return function(t){return o(this,null,function*(){if(!Array.isArray(n)||n.some(e=>!(e instanceof RegExp)))throw new Error("regexArray must be an array of valid RegExp objects.");return n.every(e=>e.test(t))})}}},migrate:R(h({},v),{setConfig:n=>{const t=`// This file is automatically generated by the Cyberskill CLI.
2
- module.exports = ${JSON.stringify(n,null,4)}`;y.writeFileSync(f.PATH.MIGRATE_MONGO_CONFIG,t);const e=`
3
- ${f.MIGRATE_MONGO_CONFIG}
4
- `;y.pathExistsSync(f.PATH.GIT_IGNORE)?y.readFileSync(f.PATH.GIT_IGNORE,"utf-8").split(`
5
- `).includes(f.MIGRATE_MONGO_CONFIG)||y.appendFileSync(f.PATH.GIT_IGNORE,e):y.writeFileSync(f.PATH.GIT_IGNORE,e)}}),regexify(n,t){if(!n)return{};let e=p.cloneDeep(n);if(!t||t.length===0)return e;for(const r of t){const s=r.toString().split("."),u=D.getNestedValue(e,s);if(typeof u=="string"&&u.length>0){const c={$regex:`.*${x.regexSearchMapper(u)}.*`,$options:"i"};e=D.setNestedValue(e,s,c)}}return e}};class U{constructor(t,e){G(this,"collection"),this.collection=t.collection(e)}createOne(t){return o(this,null,function*(){try{const e=h(h({},g.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 i.catchError(e)}})}createMany(t){return o(this,null,function*(){try{const e=t.map(s=>h(h({},g.createGenericFields()),s)),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 i.catchError(e)}})}findOne(t){return o(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 i.catchError(e)}})}findAll(){return o(this,arguments,function*(t={}){try{return{success:!0,message:"Documents retrieved successfully",result:yield this.collection.find(t).toArray()}}catch(e){return i.catchError(e)}})}count(){return o(this,arguments,function*(t={}){try{return{success:!0,message:"Count retrieved successfully",result:yield this.collection.countDocuments(t)}}catch(e){return i.catchError(e)}})}updateOne(t,e){return o(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 i.catchError(r)}})}updateMany(t,e){return o(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 i.catchError(r)}})}deleteOne(t){return o(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 i.catchError(e)}})}deleteMany(t){return o(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 i.catchError(e)}})}}class ${constructor(t){this.model=t}getModelName(){return this.model.modelName}findOne(){return o(this,arguments,function*(t={},e={},r={},s){try{const u=this.model.findOne(t,e,r);s&&u.populate(s);const c=yield u.exec();return c?{success:!0,result:c}:{success:!1,message:`No ${this.getModelName()} found.`,code:d.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(u){return i.catchError(u)}})}findAll(){return o(this,arguments,function*(t={},e={},r={},s){try{const u=this.model.find(t,e,r);return s&&u.populate(s),{success:!0,result:yield u.exec()}}catch(u){return i.catchError(u)}})}findPaging(){return o(this,arguments,function*(t={},e={}){try{return{success:!0,result:yield this.model.paginate(t,e)}}catch(r){return i.catchError(r)}})}findPagingAggregate(t){return o(this,arguments,function*(e,r={}){try{return{success:!0,result:yield this.model.aggregatePaginate(this.model.aggregate(e),r)}}catch(s){return i.catchError(s)}})}count(){return o(this,arguments,function*(t={}){try{return{success:!0,result:yield this.model.countDocuments(t)}}catch(e){return i.catchError(e)}})}createOne(t){return o(this,null,function*(){try{return{success:!0,result:yield this.model.create(t)}}catch(e){return i.catchError(e)}})}createMany(t){return o(this,arguments,function*(e,r={}){try{return{success:!0,result:(yield this.model.insertMany(e,r)).map(c=>c instanceof q.Document?c.toObject():null).filter(c=>c!==null)}}catch(s){return i.catchError(s)}})}updateOne(){return o(this,arguments,function*(t={},e={},r={}){try{const s=yield this.model.findOneAndUpdate(t,e,h({new:!0},r)).exec();return s?{success:!0,result:s}:{success:!1,message:`Failed to update ${this.getModelName()}.`,code:d.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(s){return i.catchError(s)}})}updateMany(){return o(this,arguments,function*(t={},e={},r={}){try{return{success:!0,result:yield this.model.updateMany(t,e,r).exec()}}catch(s){return i.catchError(s)}})}deleteOne(){return o(this,arguments,function*(t={},e={}){try{const r=yield this.model.findOneAndDelete(t,e).exec();return r?{success:!0,result:r}:{success:!1,message:`No ${this.getModelName()} found to delete.`,code:d.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(r){return i.catchError(r)}})}deleteMany(){return o(this,arguments,function*(t={},e={}){try{const r=yield this.model.deleteMany(t,e).exec();return r.deletedCount===0?{success:!1,message:"No documents found to delete.",code:d.RESPONSE_STATUS.NOT_FOUND.CODE}:{success:!0,result:r}}catch(r){return i.catchError(r)}})}createShortId(t,e=4){return o(this,null,function*(){try{const s=new Set;for(let u=0;u<10;u++){const c=S.generateShortId(t,u+e);if(!s.has(c)&&(s.add(c),!(yield this.model.exists({shortId:c}))))return{success:!0,result:c}}return{success:!1,message:"Failed to create a unique shortId",code:d.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}}catch(r){return i.catchError(r)}})}createSlugQuery({slug:t,field:e,isObject:r,filter:s}){const u=h({},s!=null?s:{});return r?R(h({},u),{$or:[{[`slug.${e}`]:t},{slugHistory:{$elemMatch:{[`slug.${e}`]:t}}}]}):R(h({},u),{$or:[{slug:t},{slugHistory:t}]})}createUniqueSlug(t){return o(this,arguments,function*({slug:e,field:r,isObject:s,filter:u}){const c=S.generateSlug(e);let l=c,a=1;for(;yield this.model.exists(this.createSlugQuery({slug:l,field:r,isObject:s,filter:u}));)l=`${c}-${a++}`;return l})}createSlug(t){return o(this,arguments,function*({field:e,from:r,filter:s}){try{const u=r[e];return p.isObject(u)?{success:!0,result:Object.fromEntries(yield Promise.all(Object.entries(u).map(m=>o(this,[m],function*([E,O]){const N=yield this.createUniqueSlug({slug:O,field:E,isObject:!0,filter:s});return[E,N]}))))}:{success:!0,result:yield this.createUniqueSlug({slug:u,field:e,isObject:!1,filter:s})}}catch(u){return i.catchError(u)}})}checkSlug(t){return o(this,arguments,function*({slug:e,field:r,from:s,filter:u}){try{const c=s[r];if(p.isObject(c)){for(const E of Object.values(c)){const O=S.generateSlug(E);if(yield this.model.exists(this.createSlugQuery({slug:O,field:r,isObject:!0,filter:u})))return{success:!0,result:!0}}return{success:!0,result:!1}}const a=S.generateSlug(e);return{success:!0,result:(yield this.model.exists(this.createSlugQuery({slug:a,field:r,isObject:!1,filter:u})))!==null}}catch(c){return i.catchError(c)}})}aggregate(t){return o(this,null,function*(){try{return{success:!0,result:yield this.model.aggregate(t)}}catch(e){return i.catchError(e)}})}}exports.aggregatePaginate=A;exports.mongoosePaginate=b;exports.MongoController=U;exports.MongooseController=$;exports.mongo=g;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("lodash-es"),C=require("migrate-mongo"),x=require("mongoose"),b=require("mongoose-aggregate-paginate-v2"),v=require("mongoose-paginate-v2"),P=require("uuid"),D=require("../../util/object/object.util.cjs"),I=require("../../util/common/common.util.cjs"),p=require("../fs/fs.util.cjs"),g=require("../path/path.constant.cjs"),q=require("../../util/validate/validate.util.cjs"),_=require("../../util/string/string.util.cjs"),d=require("../../constant/response-status.cjs"),i=require("../log/log.util.cjs");var M=Object.defineProperty,w=Object.defineProperties,j=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,N=(n,t,e)=>t in n?M(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,f=(n,t)=>{for(var e in t||(t={}))F.call(t,e)&&N(n,e,t[e]);if(A)for(var e of A(t))G.call(t,e)&&N(n,e,t[e]);return n},T=(n,t)=>w(n,j(t)),U=(n,t,e)=>N(n,typeof t!="symbol"?t+"":t,e),o=(n,t,e)=>new Promise((r,s)=>{var c=a=>{try{l(e.next(a))}catch(m){s(m)}},u=a=>{try{l(e.throw(a))}catch(m){s(m)}},l=a=>a.done?r(a.value):Promise.resolve(a.value).then(c,u);l((e=e.apply(n,t)).next())});const y={createGenericFields(){return{id:P.v4(),isDel:!1,createdAt:new Date,updatedAt:new Date}},applyPlugins(n,t){t.filter(e=>typeof e=="function").forEach(e=>n.plugin(e))},applyMiddlewares(n,t){t.forEach(({method:e,pre:r,post:s})=>{e&&r&&n.pre(e,r),e&&s&&n.post(e,s)})},createGenericSchema(n){return new n.Schema({id:{type:String,default:P.v4,unique:!0},isDel:{type:Boolean,default:!1}},{timestamps:!0})},createSchema({mongoose:n,schema:t,virtuals:e=[],standalone:r=!1}){const s=new n.Schema(t);return e.forEach(({name:c,options:u,get:l})=>{const a=s.virtual(c,u);l&&a.get(l)}),r||s.add(y.createGenericSchema(n)),s},createModel({mongoose:n,name:t,schema:e,pagination:r=!1,aggregate:s=!1,virtuals:c=[],middlewares:u=[]}){if(!t)throw new Error("Model name is required.");if(n.models[t])return n.models[t];const l=y.createSchema({mongoose:n,schema:e,virtuals:c});return y.applyPlugins(l,[r&&v,s&&b]),y.applyMiddlewares(l,u),n.model(t,l)},validator:{isRequired(){return function(n){return o(this,null,function*(){return!q.validate.isEmpty(n)})}},isUnique(n){return function(t){return o(this,null,function*(){if(!Array.isArray(n)||n.length===0)throw new Error("Fields must be a non-empty array of strings.");const e={$or:n.map(s=>({[s]:t}))};return!(yield this.constructor.exists(e))})}},matchesRegex(n){return function(t){return o(this,null,function*(){if(!Array.isArray(n)||n.some(e=>!(e instanceof RegExp)))throw new Error("regexArray must be an array of valid RegExp objects.");return n.every(e=>e.test(t))})}}},migrate:T(f({},C),{setConfig:n=>{const t=`// This file is automatically generated by the Cyberskill CLI.
2
+ module.exports = ${JSON.stringify(n,null,4)}`;p.writeFileSync(g.PATH.MIGRATE_MONGO_CONFIG,t);const e=`
3
+ ${g.MIGRATE_MONGO_CONFIG}
4
+ `;p.pathExistsSync(g.PATH.GIT_IGNORE)?p.readFileSync(g.PATH.GIT_IGNORE,"utf-8").split(`
5
+ `).includes(g.MIGRATE_MONGO_CONFIG)||p.appendFileSync(g.PATH.GIT_IGNORE,e):p.writeFileSync(g.PATH.GIT_IGNORE,e)}}),regexify(n,t){if(!n)return{};let e=R.cloneDeep(n);if(!t||t.length===0)return e;for(const r of t){const s=r.toString().split("."),c=D.getNestedValue(e,s);if(typeof c=="string"&&c.length>0){const u={$regex:`.*${I.regexSearchMapper(c)}.*`,$options:"i"};e=D.setNestedValue(e,s,u)}}return e}};class ${constructor(t,e){U(this,"collection"),this.collection=t.collection(e)}createOne(t){return o(this,null,function*(){try{const e=f(f({},y.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 i.catchError(e)}})}createMany(t){return o(this,null,function*(){try{const e=t.map(s=>f(f({},y.createGenericFields()),s)),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 i.catchError(e)}})}findOne(t){return o(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 i.catchError(e)}})}findAll(){return o(this,arguments,function*(t={}){try{return{success:!0,message:"Documents retrieved successfully",result:yield this.collection.find(t).toArray()}}catch(e){return i.catchError(e)}})}count(){return o(this,arguments,function*(t={}){try{return{success:!0,message:"Count retrieved successfully",result:yield this.collection.countDocuments(t)}}catch(e){return i.catchError(e)}})}updateOne(t,e){return o(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 i.catchError(r)}})}updateMany(t,e){return o(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 i.catchError(r)}})}deleteOne(t){return o(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 i.catchError(e)}})}deleteMany(t){return o(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 i.catchError(e)}})}}class V{constructor(t){this.model=t}getModelName(){return this.model.modelName}findOne(){return o(this,arguments,function*(t={},e={},r={},s){try{const c=this.model.findOne(t,e,r);s&&c.populate(s);const u=yield c.exec();return u?{success:!0,result:u}:{success:!1,message:`No ${this.getModelName()} found.`,code:d.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(c){return i.catchError(c)}})}findAll(){return o(this,arguments,function*(t={},e={},r={},s){try{const c=this.model.find(t,e,r);return s&&c.populate(s),{success:!0,result:yield c.exec()}}catch(c){return i.catchError(c)}})}findPaging(){return o(this,arguments,function*(t={},e={}){try{return{success:!0,result:yield this.model.paginate(t,e)}}catch(r){return i.catchError(r)}})}findPagingAggregate(t){return o(this,arguments,function*(e,r={}){try{return{success:!0,result:yield this.model.aggregatePaginate(this.model.aggregate(e),r)}}catch(s){return i.catchError(s)}})}count(){return o(this,arguments,function*(t={}){try{return{success:!0,result:yield this.model.countDocuments(t)}}catch(e){return i.catchError(e)}})}createOne(t){return o(this,null,function*(){try{return{success:!0,result:yield this.model.create(t)}}catch(e){return i.catchError(e)}})}createMany(t){return o(this,arguments,function*(e,r={}){try{return{success:!0,result:(yield this.model.insertMany(e,r)).map(u=>u instanceof x.Document?u.toObject():null).filter(u=>u!==null)}}catch(s){return i.catchError(s)}})}updateOne(){return o(this,arguments,function*(t={},e={},r={}){try{const s=yield this.model.findOneAndUpdate(t,e,f({new:!0},r)).exec();return s?{success:!0,result:s}:{success:!1,message:`Failed to update ${this.getModelName()}.`,code:d.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(s){return i.catchError(s)}})}updateMany(){return o(this,arguments,function*(t={},e={},r={}){try{return{success:!0,result:yield this.model.updateMany(t,e,r).exec()}}catch(s){return i.catchError(s)}})}deleteOne(){return o(this,arguments,function*(t={},e={}){try{const r=yield this.model.findOneAndDelete(t,e).exec();return r?{success:!0,result:r}:{success:!1,message:`No ${this.getModelName()} found to delete.`,code:d.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(r){return i.catchError(r)}})}deleteMany(){return o(this,arguments,function*(t={},e={}){try{const r=yield this.model.deleteMany(t,e).exec();return r.deletedCount===0?{success:!1,message:"No documents found to delete.",code:d.RESPONSE_STATUS.NOT_FOUND.CODE}:{success:!0,result:r}}catch(r){return i.catchError(r)}})}createShortId(t,e=4){return o(this,null,function*(){try{const s=Array.from({length:10},(l,a)=>_.generateShortId(t,a+e)),u=(yield Promise.all(s.map(l=>this.model.exists({shortId:l})))).findIndex(l=>!l);if(u!==-1){const l=s[u];if(l)return{success:!0,result:l}}return{success:!1,message:"Failed to create a unique shortId",code:d.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}}catch(r){return i.catchError(r)}})}createSlugQuery({slug:t,field:e,isObject:r,filter:s}){const c=f({},s!=null?s:{});return r?T(f({},c),{$or:[{[`slug.${e}`]:t},{slugHistory:{$elemMatch:{[`slug.${e}`]:t}}}]}):T(f({},c),{$or:[{slug:t},{slugHistory:t}]})}createUniqueSlug(t){return o(this,arguments,function*({slug:e,field:r,isObject:s,filter:c}){const u=_.generateSlug(e),a=Array.from({length:100},(h,S)=>S===0?u:`${u}-${S}`),E=(yield Promise.all(a.map(h=>this.model.exists(this.createSlugQuery({slug:h,field:r,isObject:s,filter:c}))))).findIndex(h=>!h);if(E!==-1){const h=a[E];if(h)return h}return`${u}-${Date.now()}`})}createSlug(t){return o(this,arguments,function*({field:e,from:r,filter:s}){try{const c=r[e];return R.isObject(c)?{success:!0,result:Object.fromEntries(yield Promise.all(Object.entries(c).map(m=>o(this,[m],function*([E,h]){const S=yield this.createUniqueSlug({slug:h,field:E,isObject:!0,filter:s});return[E,S]}))))}:{success:!0,result:yield this.createUniqueSlug({slug:c,field:e,isObject:!1,filter:s})}}catch(c){return i.catchError(c)}})}checkSlug(t){return o(this,arguments,function*({slug:e,field:r,from:s,filter:c}){try{const u=s[r];if(R.isObject(u)){const h=Object.values(u).map(O=>_.generateSlug(O));return(yield Promise.all(h.map(O=>this.model.exists(this.createSlugQuery({slug:O,field:r,isObject:!0,filter:c}))))).some(O=>O)?{success:!0,result:!0}:{success:!0,result:!1}}const a=_.generateSlug(e);return{success:!0,result:(yield this.model.exists(this.createSlugQuery({slug:a,field:r,isObject:!1,filter:c})))!==null}}catch(u){return i.catchError(u)}})}aggregate(t){return o(this,null,function*(){try{return{success:!0,result:yield this.model.aggregate(t)}}catch(e){return i.catchError(e)}})}}exports.aggregatePaginate=b;exports.mongoosePaginate=v;exports.MongoController=$;exports.MongooseController=V;exports.mongo=y;
@@ -3,12 +3,47 @@ import { default as migrate } from 'migrate-mongo';
3
3
  import { default as aggregatePaginate } from 'mongoose-aggregate-paginate-v2';
4
4
  import { default as mongoosePaginate } from 'mongoose-paginate-v2';
5
5
  import { I_Return } from '../../typescript/index.js';
6
- import { C_Db, C_Document, I_CreateModelOptions, I_CreateSchemaOptions, I_DeleteOptionsExtended, I_ExtendedModel, I_GenericDocument, I_Input_CheckSlug, I_Input_CreateSlug, I_Input_GenerateSlug, I_MongooseModelMiddleware, I_UpdateOptionsExtended, T_AggregatePaginateResult, T_DeleteResult, T_Filter, T_FilterQuery, T_Input_Populate, T_InsertManyOptions, T_MongoosePlugin, T_MongooseShema, T_PaginateOptionsWithPopulate, T_PaginateResult, T_PipelineStage, T_ProjectionType, T_QueryOptions, T_UpdateQuery, T_UpdateResult, T_WithId } from './mongo.type.js';
6
+ import { C_Db, C_Document, I_CreateModelOptions, I_CreateSchemaOptions, I_DeleteOptionsExtended, I_ExtendedModel, I_GenericDocument, I_Input_CheckSlug, I_Input_CreateSlug, I_Input_GenerateSlug, I_MongooseModelMiddleware, I_PaginateOptionsWithPopulate, I_UpdateOptionsExtended, T_AggregatePaginateResult, T_DeleteResult, T_Filter, T_FilterQuery, T_Input_Populate, T_InsertManyOptions, T_MongoosePlugin, T_MongooseShema, T_PaginateResult, T_PipelineStage, T_ProjectionType, T_QueryOptions, T_UpdateQuery, T_UpdateResult, T_WithId } from './mongo.type.js';
7
7
  export { aggregatePaginate, mongoosePaginate };
8
+ /**
9
+ * MongoDB utility object providing comprehensive database operations and utilities.
10
+ * This object contains methods for creating generic fields, applying plugins and middlewares,
11
+ * creating schemas and models, validation functions, migration utilities, and regex filtering.
12
+ */
8
13
  export declare const mongo: {
14
+ /**
15
+ * Creates generic fields that are commonly used across MongoDB documents.
16
+ * This function generates standard fields including a UUID, deletion flag, and timestamps
17
+ * that can be applied to any document schema.
18
+ *
19
+ * @returns An object containing generic document fields (id, isDel, createdAt, updatedAt).
20
+ */
9
21
  createGenericFields(): I_GenericDocument;
22
+ /**
23
+ * Applies plugins to a Mongoose schema.
24
+ * This function filters out falsy plugins and applies the remaining valid plugins
25
+ * to the provided schema.
26
+ *
27
+ * @param schema - The Mongoose schema to apply plugins to.
28
+ * @param plugins - An array of plugin functions or false values to filter and apply.
29
+ */
10
30
  applyPlugins<T>(schema: T_MongooseShema<T>, plugins: Array<T_MongoosePlugin | false>): void;
31
+ /**
32
+ * Applies middleware functions to a Mongoose schema.
33
+ * This function configures pre and post middleware for specified methods on the schema.
34
+ *
35
+ * @param schema - The Mongoose schema to apply middleware to.
36
+ * @param middlewares - An array of middleware configurations with method, pre, and post functions.
37
+ */
11
38
  applyMiddlewares<T extends Partial<C_Document>>(schema: T_MongooseShema<T>, middlewares: I_MongooseModelMiddleware<T>[]): void;
39
+ /**
40
+ * Creates a generic Mongoose schema with common fields.
41
+ * This function creates a base schema with UUID field and deletion flag,
42
+ * configured with automatic timestamps.
43
+ *
44
+ * @param mongoose - The Mongoose instance to create the schema with.
45
+ * @returns A Mongoose schema with generic document fields.
46
+ */
12
47
  createGenericSchema(mongoose: typeof mongooseRaw): mongooseRaw.Schema<I_GenericDocument, mongooseRaw.Model<I_GenericDocument, any, any, any, mongooseRaw.Document<unknown, any, I_GenericDocument, any> & I_GenericDocument & Required<{
13
48
  _id: unknown;
14
49
  }> & {
@@ -18,18 +53,86 @@ export declare const mongo: {
18
53
  }> & {
19
54
  __v: number;
20
55
  }>;
56
+ /**
57
+ * Creates a Mongoose schema with optional virtual fields and generic fields.
58
+ * This function creates a new Mongoose schema from the provided schema definition,
59
+ * optionally adds virtual fields, and includes generic fields (unless standalone is true).
60
+ *
61
+ * @param options - Configuration options including mongoose instance, schema definition, virtuals, and standalone flag.
62
+ * @param options.mongoose - The Mongoose instance to use for schema creation.
63
+ * @param options.schema - The schema definition object.
64
+ * @param options.virtuals - Optional array of virtual field configurations.
65
+ * @param options.standalone - Whether to exclude generic fields (default: false).
66
+ * @returns A configured Mongoose schema.
67
+ */
21
68
  createSchema<T>({ mongoose, schema, virtuals, standalone, }: I_CreateSchemaOptions<T>): T_MongooseShema<T>;
69
+ /**
70
+ * Creates a Mongoose model with plugins, middleware, and pagination support.
71
+ * This function creates a model from a schema with optional pagination and aggregation plugins,
72
+ * and applies any specified middleware. If a model with the same name already exists, it returns the existing model.
73
+ *
74
+ * @param options - Configuration options including mongoose instance, model name, schema, and feature flags.
75
+ * @param options.mongoose - The Mongoose instance to use for model creation.
76
+ * @param options.name - The name of the model to create.
77
+ * @param options.schema - The schema definition for the model.
78
+ * @param options.pagination - Whether to enable pagination plugin (default: false).
79
+ * @param options.aggregate - Whether to enable aggregation pagination plugin (default: false).
80
+ * @param options.virtuals - Optional array of virtual field configurations.
81
+ * @param options.middlewares - Optional array of middleware configurations.
82
+ * @returns A configured Mongoose model with extended functionality.
83
+ * @throws {Error} When the model name is not provided.
84
+ */
22
85
  createModel<T extends Partial<C_Document>>({ mongoose: currentMongooseInstance, name, schema, pagination, aggregate, virtuals, middlewares, }: I_CreateModelOptions<T>): I_ExtendedModel<T>;
86
+ /**
87
+ * Validation utilities for Mongoose schemas.
88
+ * This object provides common validation functions that can be used in Mongoose schema definitions.
89
+ */
23
90
  validator: {
91
+ /**
92
+ * Creates a required field validator.
93
+ * This function returns a validator that checks if a field value is not empty
94
+ * using the validate.isEmpty utility.
95
+ *
96
+ * @returns A validation function that returns true if the field is not empty.
97
+ */
24
98
  isRequired<T>(): (this: T, value: unknown) => Promise<boolean>;
99
+ /**
100
+ * Creates a unique field validator.
101
+ * This function returns a validator that checks if a field value is unique
102
+ * across the specified fields in the collection.
103
+ *
104
+ * @param fields - An array of field names to check for uniqueness.
105
+ * @returns A validation function that returns true if the value is unique across the specified fields.
106
+ * @throws {Error} When fields is not a non-empty array of strings.
107
+ */
25
108
  isUnique<T extends {
26
109
  constructor: {
27
110
  exists: (query: Record<string, unknown>) => Promise<unknown>;
28
111
  };
29
112
  }>(fields: string[]): (this: T, value: unknown) => Promise<boolean>;
113
+ /**
114
+ * Creates a regex pattern validator.
115
+ * This function returns a validator that checks if a string value matches
116
+ * all provided regular expressions.
117
+ *
118
+ * @param regexArray - An array of regular expressions to test against the value.
119
+ * @returns A validation function that returns true if the value matches all regex patterns.
120
+ * @throws {Error} When regexArray is not an array of valid RegExp objects.
121
+ */
30
122
  matchesRegex(regexArray: RegExp[]): (value: string) => Promise<boolean>;
31
123
  };
124
+ /**
125
+ * Migration utilities for MongoDB.
126
+ * This object extends the migrate-mongo library with additional configuration utilities.
127
+ */
32
128
  migrate: {
129
+ /**
130
+ * Sets the migration configuration and updates .gitignore.
131
+ * This function creates a migration configuration file and ensures it's properly
132
+ * excluded from version control.
133
+ *
134
+ * @param options - Migration configuration options to write to the config file.
135
+ */
33
136
  setConfig: (options: Partial<migrate.config.Config>) => void;
34
137
  init(): Promise<void>;
35
138
  create(description: string): Promise<string>;
@@ -39,37 +142,230 @@ export declare const mongo: {
39
142
  database: typeof migrate.database;
40
143
  config: typeof migrate.config;
41
144
  };
145
+ /**
146
+ * Converts string values in a filter to regex patterns for case-insensitive search.
147
+ * This function recursively processes a filter object and converts string values in specified fields
148
+ * to MongoDB regex patterns that support accented character matching.
149
+ *
150
+ * @param filter - The filter object to process.
151
+ * @param fields - An array of field names to convert to regex patterns.
152
+ * @returns A new filter object with string values converted to regex patterns.
153
+ */
42
154
  regexify<T>(filter?: T_FilterQuery<T>, fields?: (keyof T | string)[]): T_FilterQuery<T>;
43
155
  };
156
+ /**
157
+ * MongoDB native driver controller for direct database operations.
158
+ * This class provides a simplified interface for MongoDB operations using the native driver,
159
+ * with automatic generic field generation and standardized response formatting.
160
+ */
44
161
  export declare class MongoController<D extends Partial<C_Document>> {
45
162
  private collection;
163
+ /**
164
+ * Creates a new MongoDB controller instance.
165
+ *
166
+ * @param db - The MongoDB database instance.
167
+ * @param collectionName - The name of the collection to operate on.
168
+ */
46
169
  constructor(db: C_Db, collectionName: string);
170
+ /**
171
+ * Creates a single document in the collection.
172
+ * This method adds generic fields (id, isDel, timestamps) to the document before insertion.
173
+ *
174
+ * @param document - The document to create, with or without generic fields.
175
+ * @returns A promise that resolves to a standardized response with the created document.
176
+ */
47
177
  createOne(document: D | Partial<D>): Promise<I_Return<D | Partial<D>>>;
178
+ /**
179
+ * Creates multiple documents in the collection.
180
+ * This method adds generic fields to each document before bulk insertion.
181
+ *
182
+ * @param documents - An array of documents to create.
183
+ * @returns A promise that resolves to a standardized response with the created documents.
184
+ */
48
185
  createMany(documents: (D | Partial<D>)[]): Promise<I_Return<(D | Partial<D>)[]>>;
186
+ /**
187
+ * Finds a single document by filter criteria.
188
+ *
189
+ * @param filter - The filter criteria to find the document.
190
+ * @returns A promise that resolves to a standardized response with the found document.
191
+ */
49
192
  findOne(filter: T_Filter<D>): Promise<I_Return<T_WithId<D>>>;
193
+ /**
194
+ * Finds all documents matching the filter criteria.
195
+ *
196
+ * @param filter - The filter criteria to find documents (defaults to empty object for all documents).
197
+ * @returns A promise that resolves to a standardized response with the found documents.
198
+ */
50
199
  findAll(filter?: T_Filter<D>): Promise<I_Return<T_WithId<D>[]>>;
200
+ /**
201
+ * Counts documents matching the filter criteria.
202
+ *
203
+ * @param filter - The filter criteria to count documents (defaults to empty object for all documents).
204
+ * @returns A promise that resolves to a standardized response with the document count.
205
+ */
51
206
  count(filter?: T_Filter<D>): Promise<I_Return<number>>;
207
+ /**
208
+ * Updates a single document matching the filter criteria.
209
+ *
210
+ * @param filter - The filter criteria to find the document to update.
211
+ * @param update - The update data to apply to the document.
212
+ * @returns A promise that resolves to a standardized response with the update result.
213
+ */
52
214
  updateOne(filter: T_Filter<D>, update: Partial<D>): Promise<I_Return<T_UpdateResult>>;
215
+ /**
216
+ * Updates multiple documents matching the filter criteria.
217
+ *
218
+ * @param filter - The filter criteria to find documents to update.
219
+ * @param update - The update data to apply to the documents.
220
+ * @returns A promise that resolves to a standardized response with the update result.
221
+ */
53
222
  updateMany(filter: T_Filter<D>, update: Partial<D>): Promise<I_Return<T_UpdateResult>>;
223
+ /**
224
+ * Deletes a single document matching the filter criteria.
225
+ *
226
+ * @param filter - The filter criteria to find the document to delete.
227
+ * @returns A promise that resolves to a standardized response with the delete result.
228
+ */
54
229
  deleteOne(filter: T_Filter<D>): Promise<I_Return<T_DeleteResult>>;
230
+ /**
231
+ * Deletes multiple documents matching the filter criteria.
232
+ *
233
+ * @param filter - The filter criteria to find documents to delete.
234
+ * @returns A promise that resolves to a standardized response with the delete result.
235
+ */
55
236
  deleteMany(filter: T_Filter<D>): Promise<I_Return<T_DeleteResult>>;
56
237
  }
238
+ /**
239
+ * Mongoose controller for database operations with advanced features.
240
+ * This class provides a comprehensive interface for Mongoose operations including
241
+ * pagination, aggregation, slug generation, and short ID creation.
242
+ */
57
243
  export declare class MongooseController<T extends Partial<C_Document>> {
58
244
  private model;
245
+ /**
246
+ * Creates a new Mongoose controller instance.
247
+ *
248
+ * @param model - The Mongoose model to operate on.
249
+ */
59
250
  constructor(model: I_ExtendedModel<T>);
251
+ /**
252
+ * Gets the model name for logging and error messages.
253
+ *
254
+ * @returns The name of the model.
255
+ */
60
256
  private getModelName;
257
+ /**
258
+ * Finds a single document with optional population and projection.
259
+ *
260
+ * @param filter - The filter criteria to find the document.
261
+ * @param projection - The fields to include/exclude in the result.
262
+ * @param options - Query options for the operation.
263
+ * @param populate - Population configuration for related documents.
264
+ * @returns A promise that resolves to a standardized response with the found document.
265
+ */
61
266
  findOne(filter?: T_FilterQuery<T>, projection?: T_ProjectionType<T>, options?: T_QueryOptions<T>, populate?: T_Input_Populate): Promise<I_Return<T>>;
267
+ /**
268
+ * Finds all documents with optional population and projection.
269
+ *
270
+ * @param filter - The filter criteria to find documents.
271
+ * @param projection - The fields to include/exclude in the result.
272
+ * @param options - Query options for the operation.
273
+ * @param populate - Population configuration for related documents.
274
+ * @returns A promise that resolves to a standardized response with the found documents.
275
+ */
62
276
  findAll(filter?: T_FilterQuery<T>, projection?: T_ProjectionType<T>, options?: T_QueryOptions<T>, populate?: T_Input_Populate): Promise<I_Return<T[]>>;
63
- findPaging(filter?: T_FilterQuery<T>, options?: T_PaginateOptionsWithPopulate): Promise<I_Return<T_PaginateResult<T>>>;
64
- findPagingAggregate(pipeline: T_PipelineStage[], options?: T_PaginateOptionsWithPopulate): Promise<I_Return<T_AggregatePaginateResult<T>>>;
277
+ /**
278
+ * Finds documents with pagination support.
279
+ *
280
+ * @param filter - The filter criteria to find documents.
281
+ * @param options - Pagination options including page, limit, and population.
282
+ * @returns A promise that resolves to a standardized response with paginated results.
283
+ */
284
+ findPaging(filter?: T_FilterQuery<T>, options?: I_PaginateOptionsWithPopulate): Promise<I_Return<T_PaginateResult<T>>>;
285
+ /**
286
+ * Performs aggregation with pagination support.
287
+ *
288
+ * @param pipeline - The aggregation pipeline stages.
289
+ * @param options - Pagination options for the aggregation result.
290
+ * @returns A promise that resolves to a standardized response with paginated aggregation results.
291
+ */
292
+ findPagingAggregate(pipeline: T_PipelineStage[], options?: I_PaginateOptionsWithPopulate): Promise<I_Return<T_AggregatePaginateResult<T>>>;
293
+ /**
294
+ * Counts documents matching the filter criteria.
295
+ *
296
+ * @param filter - The filter criteria to count documents.
297
+ * @returns A promise that resolves to a standardized response with the document count.
298
+ */
65
299
  count(filter?: T_FilterQuery<T>): Promise<I_Return<number>>;
300
+ /**
301
+ * Creates a single document.
302
+ *
303
+ * @param doc - The document to create.
304
+ * @returns A promise that resolves to a standardized response with the created document.
305
+ */
66
306
  createOne(doc: T | Partial<T>): Promise<I_Return<T>>;
307
+ /**
308
+ * Creates multiple documents with bulk insertion.
309
+ *
310
+ * @param docs - An array of documents to create.
311
+ * @param options - Options for the bulk insertion operation.
312
+ * @returns A promise that resolves to a standardized response with the created documents.
313
+ */
67
314
  createMany(docs: (T | Partial<T>)[], options?: T_InsertManyOptions): Promise<I_Return<T[]>>;
315
+ /**
316
+ * Updates a single document and returns the updated version.
317
+ *
318
+ * @param filter - The filter criteria to find the document to update.
319
+ * @param update - The update data to apply.
320
+ * @param options - Options for the update operation.
321
+ * @returns A promise that resolves to a standardized response with the updated document.
322
+ */
68
323
  updateOne(filter?: T_FilterQuery<T>, update?: T_UpdateQuery<T>, options?: I_UpdateOptionsExtended): Promise<I_Return<T>>;
324
+ /**
325
+ * Updates multiple documents matching the filter criteria.
326
+ *
327
+ * @param filter - The filter criteria to find documents to update.
328
+ * @param update - The update data to apply.
329
+ * @param options - Options for the update operation.
330
+ * @returns A promise that resolves to a standardized response with the update result.
331
+ */
69
332
  updateMany(filter?: T_FilterQuery<T>, update?: T_UpdateQuery<T>, options?: I_UpdateOptionsExtended): Promise<I_Return<T_UpdateResult>>;
333
+ /**
334
+ * Deletes a single document and returns the deleted version.
335
+ *
336
+ * @param filter - The filter criteria to find the document to delete.
337
+ * @param options - Options for the delete operation.
338
+ * @returns A promise that resolves to a standardized response with the deleted document.
339
+ */
70
340
  deleteOne(filter?: T_FilterQuery<T>, options?: I_DeleteOptionsExtended): Promise<I_Return<T>>;
341
+ /**
342
+ * Deletes multiple documents matching the filter criteria.
343
+ *
344
+ * @param filter - The filter criteria to find documents to delete.
345
+ * @param options - Options for the delete operation.
346
+ * @returns A promise that resolves to a standardized response with the delete result.
347
+ */
71
348
  deleteMany(filter?: T_FilterQuery<T>, options?: I_DeleteOptionsExtended): Promise<I_Return<T_DeleteResult>>;
349
+ /**
350
+ * Creates a unique short ID based on a given ID.
351
+ * This method generates multiple short IDs with increasing lengths and finds the first available one.
352
+ *
353
+ * @param id - The base ID to generate short IDs from.
354
+ * @param length - The initial length for short ID generation (default: 4).
355
+ * @returns A promise that resolves to a standardized response with the unique short ID.
356
+ */
72
357
  createShortId(id: string, length?: number): Promise<I_Return<string>>;
358
+ /**
359
+ * Creates a query for slug existence checking.
360
+ * This method generates a query that checks for slug existence in both current and historical slug fields.
361
+ *
362
+ * @param options - Configuration for slug query generation including slug, field, and filter.
363
+ * @param options.slug - The slug string to check for existence.
364
+ * @param options.field - The field name for object-based slug checking.
365
+ * @param options.isObject - Whether the slug is stored as an object with nested fields.
366
+ * @param options.filter - Additional filter conditions to apply to the query.
367
+ * @returns A MongoDB query object for checking slug existence.
368
+ */
73
369
  createSlugQuery({ slug, field, isObject, filter }: I_Input_GenerateSlug<T>): {
74
370
  $or: ({
75
371
  [x: string]: string;
@@ -226,8 +522,46 @@ export declare class MongooseController<T extends Partial<C_Document>> {
226
522
  $comment?: string;
227
523
  $expr?: Record<string, any>;
228
524
  };
525
+ /**
526
+ * Creates a unique slug based on a given string.
527
+ * This method generates multiple slug variations and finds the first available one.
528
+ *
529
+ * @param options - Configuration for slug generation including slug, field, and filter.
530
+ * @param options.slug - The base slug string to make unique.
531
+ * @param options.field - The field name for object-based slug checking.
532
+ * @param options.isObject - Whether the slug is stored as an object with nested fields.
533
+ * @param options.filter - Additional filter conditions to apply when checking slug existence.
534
+ * @returns A promise that resolves to a unique slug string.
535
+ */
229
536
  createUniqueSlug({ slug, field, isObject, filter }: I_Input_GenerateSlug<T>): Promise<string>;
537
+ /**
538
+ * Creates a slug for a document field.
539
+ * This method handles both simple string fields and object fields with nested slug generation.
540
+ *
541
+ * @param options - Configuration for slug creation including field, source document, and filter.
542
+ * @param options.field - The field name to create a slug for.
543
+ * @param options.from - The source document containing the field value.
544
+ * @param options.filter - Additional filter conditions to apply when checking slug existence.
545
+ * @returns A promise that resolves to a standardized response with the created slug(s).
546
+ */
230
547
  createSlug<R = string>({ field, from, filter }: I_Input_CreateSlug<T>): Promise<I_Return<R>>;
548
+ /**
549
+ * Checks if a slug already exists in the collection.
550
+ * This method verifies slug existence in both current and historical slug fields.
551
+ *
552
+ * @param options - Configuration for slug checking including slug, field, source document, and filter.
553
+ * @param options.slug - The slug string to check for existence.
554
+ * @param options.field - The field name for object-based slug checking.
555
+ * @param options.from - The source document containing the field value.
556
+ * @param options.filter - Additional filter conditions to apply to the query.
557
+ * @returns A promise that resolves to a standardized response indicating whether the slug exists.
558
+ */
231
559
  checkSlug({ slug, field, from, filter }: I_Input_CheckSlug<T>): Promise<I_Return<boolean>>;
560
+ /**
561
+ * Performs aggregation operations on the collection.
562
+ *
563
+ * @param pipeline - The aggregation pipeline stages to execute.
564
+ * @returns A promise that resolves to a standardized response with the aggregation results.
565
+ */
232
566
  aggregate(pipeline: T_PipelineStage[]): Promise<I_Return<T[]>>;
233
567
  }