@cyberskill/shared 2.13.0 → 2.14.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.
@@ -1,42 +1,42 @@
1
- import { cloneDeep as B, isObject as T } from "lodash-es";
2
- import Q from "migrate-mongo";
3
- import W from "mongoose-aggregate-paginate-v2";
4
- import k from "mongoose-paginate-v2";
5
- import { v4 as G } from "uuid";
6
- import { MONGO_SLUG_MAX_ATTEMPTS as J } from "./mongo.constant.js";
7
- import { getNestedValue as X, setNestedValue as H, normalizeMongoFilter as V } from "../../util/object/object.util.js";
8
- import { regexSearchMapper as Y } from "../../util/common/common.util.js";
9
- import { writeFileSync as q, pathExistsSync as Z, readFileSync as ee, appendFileSync as te } from "../fs/fs.util.js";
10
- import { PATH as w, MIGRATE_MONGO_CONFIG as L } from "../path/path.constant.js";
11
- import { validate as re } from "../../util/validate/validate.util.js";
12
- import { generateShortId as ne, generateSlug as I } from "../../util/string/string.util.js";
13
- import { RESPONSE_STATUS as D } from "../../constant/response-status.js";
14
- import { catchError as f } from "../log/log.util.js";
15
- var se = Object.defineProperty, ue = Object.defineProperties, le = Object.getOwnPropertyDescriptors, U = Object.getOwnPropertySymbols, ce = Object.prototype.hasOwnProperty, oe = Object.prototype.propertyIsEnumerable, $ = (s, t, e) => t in s ? se(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e, v = (s, t) => {
16
- for (var e in t || (t = {}))
17
- ce.call(t, e) && $(s, e, t[e]);
18
- if (U)
19
- for (var e of U(t))
20
- oe.call(t, e) && $(s, e, t[e]);
21
- return s;
22
- }, F = (s, t) => ue(s, le(t)), ie = (s, t, e) => $(s, typeof t != "symbol" ? t + "" : t, e), a = (s, t, e) => new Promise((r, n) => {
23
- var u = (o) => {
1
+ import { cloneDeep as J, isObject as z } from "lodash-es";
2
+ import Y from "migrate-mongo";
3
+ import Z from "mongoose-aggregate-paginate-v2";
4
+ import tt from "mongoose-paginate-v2";
5
+ import { v4 as W } from "uuid";
6
+ import { MONGO_SLUG_MAX_ATTEMPTS as et } from "./mongo.constant.js";
7
+ import { getNestedValue as rt, setNestedValue as st, normalizeMongoFilter as F } from "../../util/object/object.util.js";
8
+ import { regexSearchMapper as nt } from "../../util/common/common.util.js";
9
+ import { writeFileSync as k, pathExistsSync as it, readFileSync as ot, appendFileSync as lt } from "../fs/fs.util.js";
10
+ import { PATH as I, MIGRATE_MONGO_CONFIG as B } from "../path/path.constant.js";
11
+ import { validate as ct } from "../../util/validate/validate.util.js";
12
+ import { generateShortId as ut, generateSlug as G } from "../../util/string/string.util.js";
13
+ import { RESPONSE_STATUS as A } from "../../constant/response-status.js";
14
+ import { catchError as D } from "../log/log.util.js";
15
+ var at = Object.defineProperty, ft = Object.defineProperties, dt = Object.getOwnPropertyDescriptors, K = Object.getOwnPropertySymbols, pt = Object.prototype.hasOwnProperty, mt = Object.prototype.propertyIsEnumerable, L = (n, e, t) => e in n ? at(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, N = (n, e) => {
16
+ for (var t in e || (e = {}))
17
+ pt.call(e, t) && L(n, t, e[t]);
18
+ if (K)
19
+ for (var t of K(e))
20
+ mt.call(e, t) && L(n, t, e[t]);
21
+ return n;
22
+ }, $ = (n, e) => ft(n, dt(e)), ht = (n, e, t) => L(n, typeof e != "symbol" ? e + "" : e, t), v = (n, e, t) => new Promise((r, s) => {
23
+ var i = (c) => {
24
24
  try {
25
- c(e.next(o));
26
- } catch (i) {
27
- n(i);
25
+ l(t.next(c));
26
+ } catch (a) {
27
+ s(a);
28
28
  }
29
- }, l = (o) => {
29
+ }, o = (c) => {
30
30
  try {
31
- c(e.throw(o));
32
- } catch (i) {
33
- n(i);
31
+ l(t.throw(c));
32
+ } catch (a) {
33
+ s(a);
34
34
  }
35
- }, c = (o) => o.done ? r(o.value) : Promise.resolve(o.value).then(u, l);
36
- c((e = e.apply(s, t)).next());
35
+ }, l = (c) => c.done ? r(c.value) : Promise.resolve(c.value).then(i, o);
36
+ l((t = t.apply(n, e)).next());
37
37
  });
38
- function ae(s) {
39
- return s === s.toUpperCase() ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : s;
38
+ function w(n) {
39
+ return n === n.toUpperCase() ? n.charAt(0).toUpperCase() + n.slice(1).toLowerCase() : n;
40
40
  }
41
41
  const x = {
42
42
  /**
@@ -48,7 +48,7 @@ const x = {
48
48
  */
49
49
  createGenericFields() {
50
50
  return {
51
- id: G(),
51
+ id: W(),
52
52
  isDel: !1,
53
53
  createdAt: /* @__PURE__ */ new Date(),
54
54
  updatedAt: /* @__PURE__ */ new Date()
@@ -62,8 +62,8 @@ const x = {
62
62
  * @param schema - The Mongoose schema to apply plugins to.
63
63
  * @param plugins - An array of plugin functions or false values to filter and apply.
64
64
  */
65
- applyPlugins(s, t) {
66
- t.filter((e) => typeof e == "function").forEach((e) => s.plugin(e));
65
+ applyPlugins(n, e) {
66
+ e.filter((t) => typeof t == "function").forEach((t) => n.plugin(t));
67
67
  },
68
68
  /**
69
69
  * Applies middleware functions to a Mongoose schema.
@@ -72,9 +72,9 @@ const x = {
72
72
  * @param schema - The Mongoose schema to apply middleware to.
73
73
  * @param middlewares - An array of middleware configurations with method, pre, and post functions.
74
74
  */
75
- applyMiddlewares(s, t) {
76
- t.forEach(({ method: e, pre: r, post: n }) => {
77
- e && r && s.pre(e, r), e && n && s.post(e, n);
75
+ applyMiddlewares(n, e) {
76
+ e.forEach(({ method: t, pre: r, post: s }) => {
77
+ t && r && n.pre(t, r), t && s && n.post(t, s);
78
78
  });
79
79
  },
80
80
  /**
@@ -85,10 +85,10 @@ const x = {
85
85
  * @param mongoose - The Mongoose instance to create the schema with.
86
86
  * @returns A Mongoose schema with generic document fields.
87
87
  */
88
- createGenericSchema(s) {
89
- return new s.Schema(
88
+ createGenericSchema(n) {
89
+ return new n.Schema(
90
90
  {
91
- id: { type: String, default: G, unique: !0 },
91
+ id: { type: String, default: W, unique: !0 },
92
92
  isDel: { type: Boolean, default: !1 }
93
93
  },
94
94
  { timestamps: !0 }
@@ -107,34 +107,34 @@ const x = {
107
107
  * @returns A configured Mongoose schema.
108
108
  */
109
109
  createSchema({
110
- mongoose: s,
111
- schema: t,
112
- virtuals: e = [],
110
+ mongoose: n,
111
+ schema: e,
112
+ virtuals: t = [],
113
113
  standalone: r = !1
114
114
  }) {
115
- const n = new s.Schema(t, {
115
+ const s = new n.Schema(e, {
116
116
  toJSON: { virtuals: !0 },
117
117
  // So `res.json()` and other `JSON.stringify()` functions include virtuals
118
118
  toObject: { virtuals: !0 }
119
119
  // So `console.log()` and other functions that use `toObject()` include virtuals
120
120
  });
121
- return e.forEach(({ name: u, options: l, get: c }) => {
122
- if (x.isDynamicVirtual(l)) {
123
- const o = n.statics;
124
- o._dynamicVirtuals || (o._dynamicVirtuals = []), o._dynamicVirtuals.push({
125
- name: u,
126
- options: l
121
+ return t.forEach(({ name: i, options: o, get: l }) => {
122
+ if (x.isDynamicVirtual(o)) {
123
+ const c = s.statics;
124
+ c._dynamicVirtuals || (c._dynamicVirtuals = []), c._dynamicVirtuals.push({
125
+ name: i,
126
+ options: o
127
127
  });
128
- const i = n.virtual(u);
129
- c ? i.get(c) : i.get(function() {
130
- var d;
131
- return ((d = this._populated) == null ? void 0 : d[u]) || (l != null && l.count ? 0 : l != null && l.justOne ? null : []);
128
+ const a = s.virtual(i);
129
+ l ? a.get(l) : a.get(function() {
130
+ var u;
131
+ return ((u = this._populated) == null ? void 0 : u[i]) || (o != null && o.count ? 0 : o != null && o.justOne ? null : []);
132
132
  });
133
133
  } else {
134
- const o = n.virtual(u, l);
135
- c && o.get(c);
134
+ const c = s.virtual(i, o);
135
+ l && c.get(l);
136
136
  }
137
- }), r || n.add(x.createGenericSchema(s)), n;
137
+ }), r || s.add(x.createGenericSchema(n)), s;
138
138
  },
139
139
  /**
140
140
  * Creates a Mongoose model with plugins, middleware, and pagination support.
@@ -153,23 +153,25 @@ const x = {
153
153
  * @throws {Error} When the model name is not provided.
154
154
  */
155
155
  createModel({
156
- mongoose: s,
157
- name: t,
158
- schema: e,
156
+ mongoose: n,
157
+ name: e,
158
+ schema: t,
159
159
  virtuals: r = [],
160
- pagination: n = !0,
161
- aggregate: u = !0,
162
- middlewares: l = []
160
+ pagination: s = !0,
161
+ aggregate: i = !0,
162
+ middlewares: o = []
163
163
  }) {
164
- if (!t)
164
+ if (!e)
165
165
  throw new Error("Model name is required.");
166
- if (s.models[t])
167
- return s.models[t];
168
- const c = x.createSchema({ mongoose: s, schema: e, virtuals: r });
169
- return (n || u) && x.applyPlugins(c, [
170
- n && k,
171
- u && W
172
- ]), x.applyMiddlewares(c, l), s.model(t, c);
166
+ if (n.models[e])
167
+ return n.models[e];
168
+ const l = x.createSchema({ mongoose: n, schema: t, virtuals: r });
169
+ (s || i) && x.applyPlugins(l, [
170
+ s && tt,
171
+ i && Z
172
+ ]), x.applyMiddlewares(l, o);
173
+ const c = n.model(e, l);
174
+ return r.length > 0 && (c._virtualConfigs = r), c;
173
175
  },
174
176
  /**
175
177
  * Validation utilities for Mongoose schemas.
@@ -184,9 +186,9 @@ const x = {
184
186
  * @returns A validation function that returns true if the field is not empty.
185
187
  */
186
188
  isRequired() {
187
- return function(s) {
188
- return a(this, null, function* () {
189
- return !re.isEmpty(s);
189
+ return function(n) {
190
+ return v(this, null, function* () {
191
+ return !ct.isEmpty(n);
190
192
  });
191
193
  };
192
194
  },
@@ -199,13 +201,13 @@ const x = {
199
201
  * @returns A validation function that returns true if the value is unique across the specified fields.
200
202
  * @throws {Error} When fields is not a non-empty array of strings.
201
203
  */
202
- isUnique(s) {
203
- return function(t) {
204
- return a(this, null, function* () {
205
- if (!Array.isArray(s) || s.length === 0)
204
+ isUnique(n) {
205
+ return function(e) {
206
+ return v(this, null, function* () {
207
+ if (!Array.isArray(n) || n.length === 0)
206
208
  throw new Error("Fields must be a non-empty array of strings.");
207
- const e = { $or: s.map((n) => ({ [n]: t })) };
208
- return !(yield this.constructor.exists(e));
209
+ const t = { $or: n.map((s) => ({ [s]: e })) };
210
+ return !(yield this.constructor.exists(t));
209
211
  });
210
212
  };
211
213
  },
@@ -218,12 +220,12 @@ const x = {
218
220
  * @returns A validation function that returns true if the value matches all regex patterns.
219
221
  * @throws {Error} When regexArray is not an array of valid RegExp objects.
220
222
  */
221
- matchesRegex(s) {
222
- return function(t) {
223
- return a(this, null, function* () {
224
- if (!Array.isArray(s) || s.some((e) => !(e instanceof RegExp)))
223
+ matchesRegex(n) {
224
+ return function(e) {
225
+ return v(this, null, function* () {
226
+ if (!Array.isArray(n) || n.some((t) => !(t instanceof RegExp)))
225
227
  throw new Error("regexArray must be an array of valid RegExp objects.");
226
- return s.every((e) => e.test(t));
228
+ return n.every((t) => t.test(e));
227
229
  });
228
230
  };
229
231
  }
@@ -232,7 +234,7 @@ const x = {
232
234
  * Migration utilities for MongoDB.
233
235
  * This object extends the migrate-mongo library with additional configuration utilities.
234
236
  */
235
- migrate: F(v({}, Q), {
237
+ migrate: $(N({}, Y), {
236
238
  /**
237
239
  * Sets the migration configuration and updates .gitignore.
238
240
  * This function creates a migration configuration file and ensures it's properly
@@ -240,15 +242,15 @@ const x = {
240
242
  *
241
243
  * @param options - Migration configuration options to write to the config file.
242
244
  */
243
- setConfig: (s) => {
244
- const t = `// This file is automatically generated by the Cyberskill CLI.
245
- module.exports = ${JSON.stringify(s, null, 4)}`;
246
- q(w.MIGRATE_MONGO_CONFIG, t);
247
- const e = `
248
- ${L}
245
+ setConfig: (n) => {
246
+ const e = `// This file is automatically generated by the Cyberskill CLI.
247
+ module.exports = ${JSON.stringify(n, null, 4)}`;
248
+ k(I.MIGRATE_MONGO_CONFIG, e);
249
+ const t = `
250
+ ${B}
249
251
  `;
250
- Z(w.GIT_IGNORE) ? ee(w.GIT_IGNORE, "utf-8").split(`
251
- `).includes(L) || te(w.GIT_IGNORE, e) : q(w.GIT_IGNORE, e);
252
+ it(I.GIT_IGNORE) ? ot(I.GIT_IGNORE, "utf-8").split(`
253
+ `).includes(B) || lt(I.GIT_IGNORE, t) : k(I.GIT_IGNORE, t);
252
254
  }
253
255
  }),
254
256
  /**
@@ -260,23 +262,23 @@ ${L}
260
262
  * @param fields - An array of field names to convert to regex patterns.
261
263
  * @returns A new filter object with string values converted to regex patterns.
262
264
  */
263
- regexify(s, t) {
264
- if (!s)
265
+ regexify(n, e) {
266
+ if (!n)
265
267
  return {};
266
- let e = B(s);
267
- if (!t || t.length === 0)
268
- return e;
269
- for (const r of t) {
270
- const n = r.toString().split("."), u = X(e, n);
271
- if (typeof u == "string" && u.length > 0) {
272
- const l = {
273
- $regex: `.*${Y(u)}.*`,
268
+ let t = J(n);
269
+ if (!e || e.length === 0)
270
+ return t;
271
+ for (const r of e) {
272
+ const s = r.toString().split("."), i = rt(t, s);
273
+ if (typeof i == "string" && i.length > 0) {
274
+ const o = {
275
+ $regex: `.*${nt(i)}.*`,
274
276
  $options: "i"
275
277
  };
276
- e = H(e, n, l);
278
+ t = st(t, s, o);
277
279
  }
278
280
  }
279
- return e;
281
+ return t;
280
282
  },
281
283
  /**
282
284
  * Checks if a virtual options object has a dynamic ref function.
@@ -284,8 +286,8 @@ ${L}
284
286
  * @param options - The virtual options to check.
285
287
  * @returns True if the options contain a dynamic ref function.
286
288
  */
287
- isDynamicVirtual(s) {
288
- return !!(s && typeof s.ref == "function");
289
+ isDynamicVirtual(n) {
290
+ return !!(n && typeof n.ref == "function");
289
291
  },
290
292
  /**
291
293
  * Generic utility function to get new records from the database
@@ -294,14 +296,14 @@ ${L}
294
296
  * @param filterFn - Function to determine if a record already exists
295
297
  * @returns Array of records that don't exist in the database
296
298
  */
297
- getNewRecords(s, t, e) {
298
- return a(this, null, function* () {
299
- const r = yield s.findAll({});
300
- return r.success ? t.filter(
301
- (u) => !r.result.some(
302
- (l) => e(l, u)
299
+ getNewRecords(n, e, t) {
300
+ return v(this, null, function* () {
301
+ const r = yield n.findAll({});
302
+ return r.success ? e.filter(
303
+ (i) => !r.result.some(
304
+ (o) => t(o, i)
303
305
  )
304
- ) : t;
306
+ ) : e;
305
307
  });
306
308
  },
307
309
  /**
@@ -311,171 +313,489 @@ ${L}
311
313
  * @param filterFn - Function to determine if a record exists
312
314
  * @returns Array of existing records that match the filter criteria
313
315
  */
314
- getExistingRecords(s, t, e) {
315
- return a(this, null, function* () {
316
- const r = yield s.findAll({});
316
+ getExistingRecords(n, e, t) {
317
+ return v(this, null, function* () {
318
+ const r = yield n.findAll({});
317
319
  return r.success ? r.result.filter(
318
- (u) => t.some(
319
- (l) => e(u, l)
320
+ (i) => e.some(
321
+ (o) => t(i, o)
320
322
  )
321
323
  ) : [];
322
324
  });
323
325
  }
324
326
  };
325
- function C(s, t) {
326
- if (!s || !t || t.length === 0)
327
- return s;
328
- const e = new Set(t.map((r) => r.name));
329
- if (Array.isArray(s)) {
330
- const r = s.filter((n) => {
331
- if (typeof n == "string")
332
- return !e.has(n);
333
- if (typeof n == "object" && n !== null) {
334
- const u = n;
335
- return !e.has(u.path || u.populate || "");
327
+ function C(n, e) {
328
+ if (!n || !e || e.length === 0)
329
+ return n;
330
+ const t = new Set(e.map((r) => r.name));
331
+ if (Array.isArray(n)) {
332
+ const r = n.filter((s) => {
333
+ if (typeof s == "string")
334
+ return !Array.from(t).some(
335
+ (i) => s === i || s.startsWith(`${i}.`)
336
+ );
337
+ if (typeof s == "object" && s !== null) {
338
+ const i = s, o = i.path || i.populate || "";
339
+ return !Array.from(t).some(
340
+ (l) => o === l || o.startsWith(`${l}.`)
341
+ );
336
342
  }
337
343
  return !0;
338
344
  });
339
345
  return r.length > 0 ? r : void 0;
340
346
  }
341
- if (typeof s == "string")
342
- return e.has(s) ? void 0 : s;
343
- if (typeof s == "object" && s !== null) {
344
- const r = s, n = r.path || r.populate || "";
345
- return e.has(n) ? void 0 : s;
347
+ if (typeof n == "string")
348
+ return Array.from(t).some(
349
+ (r) => n === r || n.startsWith(`${r}.`)
350
+ ) ? void 0 : n;
351
+ if (typeof n == "object" && n !== null) {
352
+ const r = n, s = r.path || r.populate || "";
353
+ return Array.from(t).some(
354
+ (i) => s === i || s.startsWith(`${i}.`)
355
+ ) ? void 0 : n;
346
356
  }
347
- return s;
357
+ return n;
348
358
  }
349
- function de(s, t, e) {
350
- if (!s.length || !t || !(e != null && e.ref))
359
+ function yt(n, e, t) {
360
+ if (!n.length || !e || !(t != null && t.ref))
351
361
  return [];
352
362
  const r = /* @__PURE__ */ new Map();
353
- return s.forEach((n) => {
363
+ return n.forEach((s) => {
354
364
  try {
355
- const u = e.ref(n);
356
- if (u == null)
365
+ const i = t.ref(s);
366
+ if (i == null)
357
367
  return;
358
- const l = typeof u == "string" ? u : String(u);
359
- if (l && l.trim() !== "") {
360
- const c = ae(l);
361
- r.has(c) || r.set(c, []), r.get(c).push(n);
368
+ const o = typeof i == "string" ? i : String(i);
369
+ if (o && o.trim() !== "") {
370
+ const l = w(o);
371
+ r.has(l) || r.set(l, []), r.get(l).push(s);
362
372
  }
363
- } catch (u) {
364
- f(new Error(`Dynamic ref function failed for virtual "${t}": ${u instanceof Error ? u.message : String(u)}`));
373
+ } catch (i) {
374
+ D(new Error(`Dynamic ref function failed for virtual "${e}": ${i instanceof Error ? i.message : String(i)}`));
365
375
  }
366
- }), Array.from(r.entries()).map(([n, u]) => ({ model: n, docs: u }));
376
+ }), Array.from(r.entries()).map(([s, i]) => ({ model: s, docs: i }));
367
377
  }
368
- function fe(s) {
369
- return s !== null && typeof s == "object" && "toObject" in s && typeof s.toObject == "function";
378
+ function gt(n) {
379
+ return n !== null && typeof n == "object" && "toObject" in n && typeof n.toObject == "function";
370
380
  }
371
- function z(s, t, e, r, n) {
372
- return a(this, null, function* () {
373
- if (!t.length || !e.length || !r)
374
- return t;
375
- const u = e.filter((o) => {
381
+ function U(n, e, t, r, s) {
382
+ return v(this, null, function* () {
383
+ if (!e.length || !t)
384
+ return e;
385
+ const i = Array.isArray(t) ? t : [t];
386
+ for (const o of i)
387
+ typeof o == "string" ? yield X(n, e, o, r, s) : o && typeof o == "object" && (yield vt(n, e, o, r, s));
388
+ return e;
389
+ });
390
+ }
391
+ function X(n, e, t, r, s) {
392
+ return v(this, null, function* () {
393
+ var i, o, l, c;
394
+ const a = t.split(".");
395
+ if (a.length < 2) {
396
+ for (const h of e)
397
+ yield q(n, h, t, r, void 0, s);
398
+ return;
399
+ }
400
+ const u = a[0];
401
+ if (!u || u.trim() === "")
402
+ return;
403
+ const m = a.slice(1).join(".");
404
+ for (const h of e) {
405
+ const _ = h, b = _[u];
406
+ if (b && typeof b == "object") {
407
+ let g = s;
408
+ const p = g;
409
+ if (s && s.schema && s.schema.virtuals) {
410
+ const f = s.schema.virtuals[u];
411
+ if (f && f.options && f.options.ref) {
412
+ let O;
413
+ if (typeof f.options.ref == "function" ? O = f.options.ref(_) : typeof f.options.ref == "string" && (O = f.options.ref), O) {
414
+ const d = w(O);
415
+ n.models[d] && (g = n.models[d]);
416
+ }
417
+ }
418
+ }
419
+ if (!g) {
420
+ const f = (o = (i = s == null ? void 0 : s.schema) == null ? void 0 : i.statics) != null ? o : {}, d = ((s == null ? void 0 : s._virtualConfigs) || f._dynamicVirtuals || []).find((y) => y.name === u);
421
+ if (d && d.options && d.options.ref) {
422
+ let y;
423
+ if (typeof d.options.ref == "function" ? y = d.options.ref(_) : typeof d.options.ref == "string" && (y = d.options.ref), y) {
424
+ const j = w(y);
425
+ n.models[j] && (g = n.models[j]);
426
+ }
427
+ }
428
+ }
429
+ if (g === p) {
430
+ const f = (c = (l = s == null ? void 0 : s.schema) == null ? void 0 : l.statics) != null ? c : {}, d = ((s == null ? void 0 : s._virtualConfigs) || f._dynamicVirtuals || []).find((y) => y.name === u);
431
+ if (d && d.options && d.options.ref) {
432
+ let y;
433
+ if (typeof d.options.ref == "function" ? y = d.options.ref(_) : typeof d.options.ref == "string" && (y = d.options.ref), y) {
434
+ const j = w(y);
435
+ n.models[j] && (g = n.models[j]);
436
+ }
437
+ }
438
+ }
439
+ if (Array.isArray(b))
440
+ for (const f of b)
441
+ f && typeof f == "object" && (yield q(n, f, m, r, u, g));
442
+ else b && typeof b == "object" && (yield q(n, b, m, r, u, g));
443
+ }
444
+ }
445
+ });
446
+ }
447
+ function vt(n, e, t, r, s) {
448
+ return v(this, null, function* () {
449
+ const { path: i, populate: o } = t;
450
+ if (!i)
451
+ return;
452
+ if (!o) {
453
+ yield X(n, e, i, r, s);
454
+ return;
455
+ }
456
+ const l = i;
457
+ for (const c of e) {
458
+ const a = c, u = a[l];
459
+ let m = s;
460
+ if (s && s.schema && s.schema.virtuals) {
461
+ const h = s.schema.virtuals[l];
462
+ if (h && h.options && h.options.ref) {
463
+ let _;
464
+ if (typeof h.options.ref == "function" ? _ = h.options.ref(a) : typeof h.options.ref == "string" && (_ = h.options.ref), _) {
465
+ const b = w(_);
466
+ n.models[b] && (m = n.models[b]);
467
+ }
468
+ }
469
+ }
470
+ if (!m && typeof u == "object" && u && "entityType" in u) {
471
+ const h = w(String(u.entityType));
472
+ n.models[h] && (m = n.models[h]);
473
+ }
474
+ if (u && typeof u == "object")
475
+ if (Array.isArray(u))
476
+ for (const h of u)
477
+ h && typeof h == "object" && (yield U(n, [h], o, r, m));
478
+ else u && typeof u == "object" && (yield U(n, [u], o, r, m));
479
+ }
480
+ });
481
+ }
482
+ function T(n, e, t, r) {
483
+ if (!t || !e || !e.schema)
484
+ return;
485
+ const s = t.split(".");
486
+ let i = e.schema;
487
+ for (let o = 0; o < s.length; o++) {
488
+ const l = s[o];
489
+ if (i && i.virtuals && l) {
490
+ const c = i.virtuals[l];
491
+ if (c && c.options && c.options.ref) {
492
+ let a;
493
+ if (typeof c.options.ref == "function" ? a = c.options.ref(r) : typeof c.options.ref == "string" && (a = c.options.ref), a && typeof a == "string") {
494
+ if (o === s.length - 1)
495
+ return a;
496
+ const u = n.models[a];
497
+ if (u && u.schema) {
498
+ i = u.schema;
499
+ continue;
500
+ }
501
+ }
502
+ }
503
+ }
504
+ if (i && i.paths && l) {
505
+ const c = i.paths[l];
506
+ if (c && c.schema) {
507
+ i = c.schema;
508
+ continue;
509
+ }
510
+ }
511
+ return;
512
+ }
513
+ }
514
+ function Ot(n, e) {
515
+ if (e)
516
+ for (const t of Object.keys(n.models)) {
517
+ const r = n.models[t], s = r == null ? void 0 : r.schema;
518
+ if (s && (s.paths && s.paths[e] || s.virtuals && s.virtuals[e]))
519
+ return r;
520
+ }
521
+ }
522
+ function _t(n, e) {
523
+ const t = (e || "").split(".")[0] || "";
524
+ if (t)
525
+ for (const r of Object.keys(n.models)) {
526
+ const s = n.models[r], i = s == null ? void 0 : s.schema;
527
+ if (i && (i.paths && i.paths[t] || i.virtuals && i.virtuals[t]))
528
+ return s;
529
+ }
530
+ }
531
+ function q(n, e, t, r, s, i) {
532
+ return v(this, null, function* () {
533
+ var o, l;
534
+ let c = e.__t;
535
+ if (!c) {
536
+ if (i) {
537
+ const g = s ? `${s}.${t}` : t, p = (g || "").split(".")[0] || "";
538
+ let f = i;
539
+ if (!!!((o = f == null ? void 0 : f.schema) != null && o.paths && f.schema.paths[p] || (l = f == null ? void 0 : f.schema) != null && l.virtuals && f.schema.virtuals[p])) {
540
+ const y = _t(n, g);
541
+ y && (f = y);
542
+ }
543
+ const d = T(n, f, g, e);
544
+ if (d)
545
+ c = d;
546
+ else {
547
+ const y = (g.includes(".") ? g.split(".").pop() : g) || "";
548
+ if (y) {
549
+ const j = Ot(n, y);
550
+ if (j) {
551
+ const R = T(n, j, g, e);
552
+ R && (c = R);
553
+ }
554
+ }
555
+ }
556
+ }
557
+ if (r && r.length > 0) {
558
+ const g = t.split(".").pop() || "", p = r.find((f) => f.name === g);
559
+ if (p && p.options.ref) {
560
+ let f;
561
+ typeof p.options.ref == "function" ? f = p.options.ref(e) : typeof p.options.ref == "string" && (f = p.options.ref), f && typeof f == "string" && (c = f);
562
+ }
563
+ }
564
+ if (!c) {
565
+ for (const [g, p] of Object.entries(e))
566
+ if (g === "entityType" && typeof p == "string") {
567
+ c = p;
568
+ break;
569
+ }
570
+ if (c && n.models[c]) {
571
+ const g = n.models[c];
572
+ if (g && g.schema) {
573
+ const p = g.schema, f = t.split(".").pop() || "", O = (y, j = "root") => {
574
+ if (!y || !y.virtuals)
575
+ return;
576
+ const R = y.virtuals;
577
+ for (const S of Object.keys(R))
578
+ if (S === f) {
579
+ const E = R[S];
580
+ if (E && E.options && E.options.ref) {
581
+ let V;
582
+ if (typeof E.options.ref == "function" ? V = E.options.ref(e) : typeof E.options.ref == "string" && (V = E.options.ref), V && typeof V == "string")
583
+ return V;
584
+ }
585
+ }
586
+ if (y.paths)
587
+ for (const S of Object.keys(y.paths)) {
588
+ const E = y.paths[S];
589
+ if (E && E.schema) {
590
+ const V = O(E.schema, `${j}.${S}`);
591
+ if (V)
592
+ return V;
593
+ }
594
+ }
595
+ }, d = O(p);
596
+ d && (c = d);
597
+ }
598
+ }
599
+ }
600
+ if (!c) {
601
+ const g = t.split(".").pop() || "";
602
+ if (i && i.schema) {
603
+ const p = i.schema, f = (d, y = "root") => {
604
+ if (!d || !d.virtuals)
605
+ return;
606
+ const j = d.virtuals;
607
+ for (const R of Object.keys(j))
608
+ if (R === g) {
609
+ const S = j[R];
610
+ if (S && S.options && S.options.ref) {
611
+ let E;
612
+ if (typeof S.options.ref == "function" ? E = S.options.ref(e) : typeof S.options.ref == "string" && (E = S.options.ref), E && typeof E == "string")
613
+ return E;
614
+ }
615
+ }
616
+ if (d.paths)
617
+ for (const R of Object.keys(d.paths)) {
618
+ const S = d.paths[R];
619
+ if (S && S.schema) {
620
+ const E = f(S.schema, `${y}.${R}`);
621
+ if (E)
622
+ return E;
623
+ }
624
+ }
625
+ }, O = f(p);
626
+ O && (c = O);
627
+ }
628
+ if (!c && i) {
629
+ const p = T(n, i, t, e);
630
+ p && (c = p);
631
+ }
632
+ if (!c && r && r.length > 0) {
633
+ const p = r.find((f) => f.name === g);
634
+ if (p && p.options.ref) {
635
+ let f;
636
+ typeof p.options.ref == "function" ? f = p.options.ref(e) : typeof p.options.ref == "string" && (f = p.options.ref), f && typeof f == "string" && (c = f);
637
+ }
638
+ }
639
+ }
640
+ if (!c) {
641
+ const g = t.split(".").pop() || "", p = g ? g.charAt(0).toUpperCase() + g.slice(1) : "";
642
+ p && n.models[p] && (c = p);
643
+ }
644
+ }
645
+ const a = n.models[c];
646
+ if (!a)
647
+ return;
648
+ const u = `${t}Id`, m = `${t}Ids`, h = e[u] || e[m] || e[t];
649
+ if (!h)
650
+ return;
651
+ const _ = Array.isArray(h) ? h : [h], b = yield a.find({ id: { $in: _ } }).lean();
652
+ b.length > 0 && (Array.isArray(h) ? e[t] = b : e[t] = b[0]);
653
+ });
654
+ }
655
+ function Q(n, e, t, r, s, i) {
656
+ return v(this, null, function* () {
657
+ if (!e.length || !t.length || !r)
658
+ return e;
659
+ const o = t.filter((a) => {
376
660
  if (Array.isArray(r))
377
- return r.length > 0 && r.some((i) => typeof i == "string" ? i === o.name : i.path === o.name);
661
+ return r.length > 0 && r.some((u) => {
662
+ if (typeof u == "string")
663
+ return u === a.name || u.startsWith(`${a.name}.`);
664
+ if (u && typeof u == "object") {
665
+ const m = u, h = m.path || m.populate || "";
666
+ return h === a.name || h.startsWith(`${a.name}.`);
667
+ }
668
+ return !1;
669
+ });
378
670
  if (typeof r == "string")
379
- return r === o.name;
671
+ return r === a.name || r.startsWith(`${a.name}.`);
380
672
  if (typeof r == "object" && r !== null) {
381
- const i = r;
382
- return i.path && i.path === o.name || i.populate && i.populate === o.name;
673
+ const u = r, m = u.path || u.populate || "";
674
+ return m === a.name || m.startsWith(`${a.name}.`);
383
675
  }
384
676
  return !1;
385
677
  });
386
- if (u.length === 0)
387
- return t;
388
- const l = B(t.map((o) => fe(o) ? o.toObject() : o));
389
- l.forEach((o) => {
390
- u.forEach(({ name: i, options: d }) => {
391
- i in o || (o[i] = d.count ? 0 : d.justOne ? null : []);
678
+ if (o.length === 0)
679
+ return e;
680
+ const l = J(e.map((a) => gt(a) ? a.toObject() : a));
681
+ l.forEach((a) => {
682
+ o.forEach(({ name: u, options: m }) => {
683
+ u in a || (a[u] = m.count ? 0 : m.justOne ? null : []);
392
684
  });
393
685
  });
394
686
  const c = /* @__PURE__ */ new Map();
395
- for (const o of u) {
396
- const { name: i, options: d } = o, h = de(l, i, d);
397
- for (const m of h) {
398
- c.has(m.model) || c.set(m.model, {
687
+ for (const a of o) {
688
+ const { name: u, options: m } = a, h = yt(l, u, m);
689
+ for (const _ of h) {
690
+ c.has(_.model) || c.set(_.model, {
399
691
  virtuals: [],
400
692
  localValueSets: /* @__PURE__ */ new Map(),
401
693
  docsByLocalValue: /* @__PURE__ */ new Map()
402
694
  });
403
- const y = c.get(m.model);
404
- y.virtuals.find((N) => N.name === i) || (y.virtuals.push(o), y.localValueSets.set(i, /* @__PURE__ */ new Set()));
405
- const R = y.localValueSets.get(i);
406
- m.docs.forEach((N) => {
407
- const j = N[d.localField];
408
- if (j != null) {
409
- const E = String(j);
410
- R.add(E);
411
- let S = -1;
412
- const b = N;
413
- b.id !== void 0 ? S = l.findIndex((M) => M.id === b.id) : b._id !== void 0 && (S = l.findIndex((M) => {
414
- var O, g, _, p;
415
- return ((g = (O = M._id) == null ? void 0 : O.toString) == null ? void 0 : g.call(O)) === ((p = (_ = b._id) == null ? void 0 : _.toString) == null ? void 0 : p.call(_));
416
- })), S !== -1 && (y.docsByLocalValue.has(E) || y.docsByLocalValue.set(E, []), y.docsByLocalValue.get(E).push(S));
695
+ const b = c.get(_.model);
696
+ b.virtuals.find((p) => p.name === u) || (b.virtuals.push(a), b.localValueSets.set(u, /* @__PURE__ */ new Set()));
697
+ const g = b.localValueSets.get(u);
698
+ _.docs.forEach((p) => {
699
+ const f = p[m.localField];
700
+ if (f != null) {
701
+ const O = String(f);
702
+ g.add(O);
703
+ let d = -1;
704
+ const y = p;
705
+ y.id !== void 0 ? d = l.findIndex((j) => j.id === y.id) : y._id !== void 0 && (d = l.findIndex((j) => {
706
+ var R, S, E, V;
707
+ return ((S = (R = j._id) == null ? void 0 : R.toString) == null ? void 0 : S.call(R)) === ((V = (E = y._id) == null ? void 0 : E.toString) == null ? void 0 : V.call(E));
708
+ })), d !== -1 && (b.docsByLocalValue.has(O) || b.docsByLocalValue.set(O, []), b.docsByLocalValue.get(O).push(d));
417
709
  }
418
710
  });
419
711
  }
420
712
  }
421
- return yield Promise.all(Array.from(c.entries()).map((o) => a(null, [o], function* ([i, d]) {
422
- const h = s.models[i];
713
+ if (yield Promise.all(Array.from(c.entries()).map((a) => v(null, [a], function* ([u, m]) {
714
+ const h = n.models[u];
423
715
  if (!h)
424
716
  return;
425
- const m = /* @__PURE__ */ new Set();
426
- if (d.localValueSets.forEach((E) => {
427
- E.forEach((S) => m.add(S));
428
- }), m.size === 0)
717
+ const _ = /* @__PURE__ */ new Set();
718
+ if (m.localValueSets.forEach((O) => {
719
+ O.forEach((d) => _.add(d));
720
+ }), _.size === 0)
429
721
  return;
430
- const y = [...new Set(d.virtuals.map((E) => E.options.foreignField))], R = Array.from(m);
431
- let N;
432
- y.length === 1 ? N = { [String(y[0])]: { $in: R } } : N = { $or: y.map((E) => ({ [E]: { $in: R } })) };
433
- const j = yield h.find(N, n).lean();
434
- for (const E of d.virtuals) {
435
- const { name: S, options: b } = E, M = j.filter((O) => {
436
- const g = O[b.foreignField];
437
- return g != null && m.has(String(g));
722
+ const b = [...new Set(m.virtuals.map((O) => O.options.foreignField))], g = Array.from(_);
723
+ let p;
724
+ b.length === 1 ? p = { [String(b[0])]: { $in: g } } : p = { $or: b.map((O) => ({ [O]: { $in: g } })) };
725
+ const f = yield h.find(p, s).lean();
726
+ for (const O of m.virtuals) {
727
+ const { name: d, options: y } = O, j = f.filter((R) => {
728
+ const S = R[y.foreignField];
729
+ return S != null && _.has(String(S));
438
730
  });
439
- if (b.count) {
440
- const O = /* @__PURE__ */ new Map();
441
- M.forEach((g) => {
442
- var _;
443
- const p = (_ = g[b.foreignField]) == null ? void 0 : _.toString();
444
- p && O.set(p, (O.get(p) || 0) + 1);
445
- }), d.localValueSets.get(S).forEach((g) => {
446
- const _ = d.docsByLocalValue.get(g) || [], p = O.get(g) || 0;
447
- _.forEach((A) => {
448
- const P = l[A];
449
- P[S] === void 0 && (P[S] = p);
731
+ if (y.count) {
732
+ const R = /* @__PURE__ */ new Map();
733
+ j.forEach((S) => {
734
+ var E;
735
+ const V = (E = S[y.foreignField]) == null ? void 0 : E.toString();
736
+ V && R.set(V, (R.get(V) || 0) + 1);
737
+ }), m.localValueSets.get(d).forEach((S) => {
738
+ const E = m.docsByLocalValue.get(S) || [], V = R.get(S) || 0;
739
+ E.forEach((P) => {
740
+ const M = l[P];
741
+ M[d] === void 0 && (M[d] = V);
450
742
  });
451
743
  });
452
744
  } else {
453
- const O = /* @__PURE__ */ new Map();
454
- M.forEach((g) => {
455
- var _;
456
- const p = (_ = g[b.foreignField]) == null ? void 0 : _.toString();
457
- p && (O.has(p) || O.set(p, []), O.get(p).push(g));
458
- }), d.localValueSets.get(S).forEach((g) => {
459
- const _ = d.docsByLocalValue.get(g) || [], p = O.get(g) || [], A = b.justOne ? p[0] || null : p;
460
- _.forEach((P) => {
461
- const K = l[P];
462
- K[S] = A;
745
+ const R = /* @__PURE__ */ new Map();
746
+ j.forEach((S) => {
747
+ var E;
748
+ const V = (E = S[y.foreignField]) == null ? void 0 : E.toString();
749
+ V && (R.has(V) || R.set(V, []), R.get(V).push(S));
750
+ }), m.localValueSets.get(d).forEach((S) => {
751
+ const E = m.docsByLocalValue.get(S) || [], V = R.get(S) || [], P = y.justOne ? V[0] || null : V;
752
+ E.forEach((M) => {
753
+ const H = l[M];
754
+ H[d] = P;
463
755
  });
464
756
  });
465
757
  }
466
758
  }
467
- }))), l;
759
+ }))), r) {
760
+ const u = ((m) => {
761
+ const h = Array.isArray(m) ? m : [m], _ = /* @__PURE__ */ new Map(), b = [];
762
+ for (const p of h)
763
+ if (typeof p == "string")
764
+ if (p.includes(".")) {
765
+ const f = p.split("."), O = f[0] || "", d = f.slice(1).join(".");
766
+ O && (_.has(O) || _.set(O, []), d && _.get(O).push(d));
767
+ } else
768
+ b.push(p);
769
+ else if (p && typeof p == "object") {
770
+ const f = p;
771
+ if (f.path && f.path.includes(".")) {
772
+ const O = f.path.split("."), d = O[0] || "", y = O.slice(1).join(".");
773
+ d && (_.has(d) || _.set(d, []), y && _.get(d).push(y), f.populate && _.get(d).push(f.populate));
774
+ } else
775
+ b.push(p);
776
+ }
777
+ const g = [...b];
778
+ return _.forEach((p, f) => {
779
+ const O = [];
780
+ for (const d of p)
781
+ (typeof d == "string" || d && typeof d == "object") && O.push(d);
782
+ O.length > 0 ? g.push({ path: f, populate: O }) : g.push(f);
783
+ }), g;
784
+ })(r);
785
+ yield U(n, l, u, t, i);
786
+ }
787
+ return l;
468
788
  });
469
789
  }
470
- class Ve {
790
+ class Pt {
471
791
  /**
472
792
  * Creates a new MongoDB controller instance.
473
793
  *
474
794
  * @param db - The MongoDB database instance.
475
795
  * @param collectionName - The name of the collection to operate on.
476
796
  */
477
- constructor(t, e) {
478
- ie(this, "collection"), this.collection = t.collection(e);
797
+ constructor(e, t) {
798
+ ht(this, "collection"), this.collection = e.collection(t);
479
799
  }
480
800
  /**
481
801
  * Creates a single document in the collection.
@@ -484,21 +804,21 @@ class Ve {
484
804
  * @param document - The document to create, with or without generic fields.
485
805
  * @returns A promise that resolves to a standardized response with the created document.
486
806
  */
487
- createOne(t) {
488
- return a(this, null, function* () {
807
+ createOne(e) {
808
+ return v(this, null, function* () {
489
809
  try {
490
- const e = v(v({}, x.createGenericFields()), t);
491
- return (yield this.collection.insertOne(e)).acknowledged ? {
810
+ const t = N(N({}, x.createGenericFields()), e);
811
+ return (yield this.collection.insertOne(t)).acknowledged ? {
492
812
  success: !0,
493
813
  message: "Document created successfully",
494
- result: e
814
+ result: t
495
815
  } : {
496
816
  success: !1,
497
817
  message: "Document creation failed",
498
- code: D.INTERNAL_SERVER_ERROR.CODE
818
+ code: A.INTERNAL_SERVER_ERROR.CODE
499
819
  };
500
- } catch (e) {
501
- return f(e);
820
+ } catch (t) {
821
+ return D(t);
502
822
  }
503
823
  });
504
824
  }
@@ -509,21 +829,21 @@ class Ve {
509
829
  * @param documents - An array of documents to create.
510
830
  * @returns A promise that resolves to a standardized response with the created documents.
511
831
  */
512
- createMany(t) {
513
- return a(this, null, function* () {
832
+ createMany(e) {
833
+ return v(this, null, function* () {
514
834
  try {
515
- const e = t.map((n) => v(v({}, x.createGenericFields()), n)), r = yield this.collection.insertMany(e);
835
+ const t = e.map((s) => N(N({}, x.createGenericFields()), s)), r = yield this.collection.insertMany(t);
516
836
  return r.insertedCount === 0 ? {
517
837
  success: !1,
518
838
  message: "No documents were inserted",
519
- code: D.INTERNAL_SERVER_ERROR.CODE
839
+ code: A.INTERNAL_SERVER_ERROR.CODE
520
840
  } : {
521
841
  success: !0,
522
842
  message: `${r.insertedCount} documents created successfully`,
523
- result: e
843
+ result: t
524
844
  };
525
- } catch (e) {
526
- return f(e);
845
+ } catch (t) {
846
+ return D(t);
527
847
  }
528
848
  });
529
849
  }
@@ -533,13 +853,13 @@ class Ve {
533
853
  * @param filter - The filter criteria to find the document.
534
854
  * @returns A promise that resolves to a standardized response with the found document.
535
855
  */
536
- findOne(t) {
537
- return a(this, null, function* () {
856
+ findOne(e) {
857
+ return v(this, null, function* () {
538
858
  try {
539
- const e = yield this.collection.findOne(t);
540
- return e ? { success: !0, message: "Document found", result: e } : { success: !1, message: "Document not found", code: D.NOT_FOUND.CODE };
541
- } catch (e) {
542
- return f(e);
859
+ const t = yield this.collection.findOne(e);
860
+ return t ? { success: !0, message: "Document found", result: t } : { success: !1, message: "Document not found", code: A.NOT_FOUND.CODE };
861
+ } catch (t) {
862
+ return D(t);
543
863
  }
544
864
  });
545
865
  }
@@ -550,15 +870,15 @@ class Ve {
550
870
  * @returns A promise that resolves to a standardized response with the found documents.
551
871
  */
552
872
  findAll() {
553
- return a(this, arguments, function* (t = {}) {
873
+ return v(this, arguments, function* (e = {}) {
554
874
  try {
555
875
  return {
556
876
  success: !0,
557
877
  message: "Documents retrieved successfully",
558
- result: yield this.collection.find(t).toArray()
878
+ result: yield this.collection.find(e).toArray()
559
879
  };
560
- } catch (e) {
561
- return f(e);
880
+ } catch (t) {
881
+ return D(t);
562
882
  }
563
883
  });
564
884
  }
@@ -569,16 +889,16 @@ class Ve {
569
889
  * @returns A promise that resolves to a standardized response with the document count.
570
890
  */
571
891
  count() {
572
- return a(this, arguments, function* (t = {}) {
892
+ return v(this, arguments, function* (e = {}) {
573
893
  try {
574
- const e = yield this.collection.countDocuments(t);
894
+ const t = yield this.collection.countDocuments(e);
575
895
  return {
576
896
  success: !0,
577
- message: `${e} documents counted successfully`,
578
- result: e
897
+ message: `${t} documents counted successfully`,
898
+ result: t
579
899
  };
580
- } catch (e) {
581
- return f(e);
900
+ } catch (t) {
901
+ return D(t);
582
902
  }
583
903
  });
584
904
  }
@@ -589,23 +909,23 @@ class Ve {
589
909
  * @param update - The update data to apply to the document.
590
910
  * @returns A promise that resolves to a standardized response with the update result.
591
911
  */
592
- updateOne(t, e) {
593
- return a(this, null, function* () {
912
+ updateOne(e, t) {
913
+ return v(this, null, function* () {
594
914
  try {
595
- const r = yield this.collection.updateOne(t, {
596
- $set: e
915
+ const r = yield this.collection.updateOne(e, {
916
+ $set: t
597
917
  });
598
918
  return r.matchedCount === 0 ? {
599
919
  success: !1,
600
920
  message: "No documents matched the filter",
601
- code: D.INTERNAL_SERVER_ERROR.CODE
921
+ code: A.INTERNAL_SERVER_ERROR.CODE
602
922
  } : {
603
923
  success: !0,
604
924
  message: "Document updated successfully",
605
925
  result: r
606
926
  };
607
927
  } catch (r) {
608
- return f(r);
928
+ return D(r);
609
929
  }
610
930
  });
611
931
  }
@@ -616,23 +936,23 @@ class Ve {
616
936
  * @param update - The update data to apply to the documents.
617
937
  * @returns A promise that resolves to a standardized response with the update result.
618
938
  */
619
- updateMany(t, e) {
620
- return a(this, null, function* () {
939
+ updateMany(e, t) {
940
+ return v(this, null, function* () {
621
941
  try {
622
- const r = yield this.collection.updateMany(t, {
623
- $set: e
942
+ const r = yield this.collection.updateMany(e, {
943
+ $set: t
624
944
  });
625
945
  return r.matchedCount === 0 ? {
626
946
  success: !1,
627
947
  message: "No documents matched the filter",
628
- code: D.INTERNAL_SERVER_ERROR.CODE
948
+ code: A.INTERNAL_SERVER_ERROR.CODE
629
949
  } : {
630
950
  success: !0,
631
951
  message: "Documents updated successfully",
632
952
  result: r
633
953
  };
634
954
  } catch (r) {
635
- return f(r);
955
+ return D(r);
636
956
  }
637
957
  });
638
958
  }
@@ -642,21 +962,21 @@ class Ve {
642
962
  * @param filter - The filter criteria to find the document to delete.
643
963
  * @returns A promise that resolves to a standardized response with the delete result.
644
964
  */
645
- deleteOne(t) {
646
- return a(this, null, function* () {
965
+ deleteOne(e) {
966
+ return v(this, null, function* () {
647
967
  try {
648
- const e = yield this.collection.deleteOne(t);
649
- return e.deletedCount === 0 ? {
968
+ const t = yield this.collection.deleteOne(e);
969
+ return t.deletedCount === 0 ? {
650
970
  success: !1,
651
971
  message: "No documents matched the filter",
652
- code: D.INTERNAL_SERVER_ERROR.CODE
972
+ code: A.INTERNAL_SERVER_ERROR.CODE
653
973
  } : {
654
974
  success: !0,
655
975
  message: "Document deleted successfully",
656
- result: e
976
+ result: t
657
977
  };
658
- } catch (e) {
659
- return f(e);
978
+ } catch (t) {
979
+ return D(t);
660
980
  }
661
981
  });
662
982
  }
@@ -666,33 +986,33 @@ class Ve {
666
986
  * @param filter - The filter criteria to find documents to delete.
667
987
  * @returns A promise that resolves to a standardized response with the delete result.
668
988
  */
669
- deleteMany(t) {
670
- return a(this, null, function* () {
989
+ deleteMany(e) {
990
+ return v(this, null, function* () {
671
991
  try {
672
- const e = yield this.collection.deleteMany(t);
673
- return e.deletedCount === 0 ? {
992
+ const t = yield this.collection.deleteMany(e);
993
+ return t.deletedCount === 0 ? {
674
994
  success: !1,
675
995
  message: "No documents matched the filter",
676
- code: D.INTERNAL_SERVER_ERROR.CODE
996
+ code: A.INTERNAL_SERVER_ERROR.CODE
677
997
  } : {
678
998
  success: !0,
679
999
  message: "Documents deleted successfully",
680
- result: e
1000
+ result: t
681
1001
  };
682
- } catch (e) {
683
- return f(e);
1002
+ } catch (t) {
1003
+ return D(t);
684
1004
  }
685
1005
  });
686
1006
  }
687
1007
  }
688
- class xe {
1008
+ class Mt {
689
1009
  /**
690
1010
  * Creates a new Mongoose controller instance.
691
1011
  *
692
1012
  * @param model - The Mongoose model to operate on.
693
1013
  */
694
- constructor(t) {
695
- this.model = t;
1014
+ constructor(e) {
1015
+ this.model = e;
696
1016
  }
697
1017
  /**
698
1018
  * Gets the model name for logging and error messages.
@@ -703,11 +1023,19 @@ class xe {
703
1023
  return this.model.modelName;
704
1024
  }
705
1025
  /**
706
- * Gets the dynamic virtuals configuration from the model schema.
1026
+ * Gets the dynamic virtuals configuration from the model instance.
707
1027
  *
708
1028
  * @returns Array of dynamic virtual configurations or undefined if none exist.
709
1029
  */
710
1030
  getDynamicVirtuals() {
1031
+ if (this.model._virtualConfigs) {
1032
+ const r = this.model._virtualConfigs.filter((s) => {
1033
+ var i;
1034
+ return typeof ((i = s.options) == null ? void 0 : i.ref) == "function";
1035
+ });
1036
+ if (r.length > 0)
1037
+ return r;
1038
+ }
711
1039
  return this.model.schema.statics._dynamicVirtuals;
712
1040
  }
713
1041
  /**
@@ -717,14 +1045,14 @@ class xe {
717
1045
  * @param populate - The populate options to determine which virtuals to populate.
718
1046
  * @returns The document with dynamic virtuals populated.
719
1047
  */
720
- populateDynamicVirtualsForDocument(t, e) {
721
- return a(this, null, function* () {
1048
+ populateDynamicVirtualsForDocument(e, t) {
1049
+ return v(this, null, function* () {
722
1050
  const r = this.getDynamicVirtuals();
723
1051
  if (r && r.length > 0) {
724
- const n = yield z(this.model.base, [t], r, e);
725
- return n && n[0] ? n[0] : t;
1052
+ const s = yield Q(this.model.base, [e], r, t, void 0, this.model);
1053
+ return s && s[0] ? s[0] : e;
726
1054
  }
727
- return t;
1055
+ return e;
728
1056
  });
729
1057
  }
730
1058
  /**
@@ -734,10 +1062,10 @@ class xe {
734
1062
  * @param populate - The populate options to determine which virtuals to populate.
735
1063
  * @returns The documents with dynamic virtuals populated.
736
1064
  */
737
- populateDynamicVirtualsForDocuments(t, e) {
738
- return a(this, null, function* () {
1065
+ populateDynamicVirtualsForDocuments(e, t) {
1066
+ return v(this, null, function* () {
739
1067
  const r = this.getDynamicVirtuals();
740
- return r && r.length > 0 && t.length > 0 ? yield z(this.model.base, t, r, e) : t;
1068
+ return r && r.length > 0 && e.length > 0 ? yield Q(this.model.base, e, r, t, void 0, this.model) : e;
741
1069
  });
742
1070
  }
743
1071
  /**
@@ -751,22 +1079,22 @@ class xe {
751
1079
  * @returns A promise that resolves to a standardized response with the found document.
752
1080
  */
753
1081
  findOne() {
754
- return a(this, arguments, function* (t = {}, e = {}, r = {}, n) {
755
- var u, l;
1082
+ return v(this, arguments, function* (e = {}, t = {}, r = {}, s) {
1083
+ var i, o;
756
1084
  try {
757
- const c = V(t), o = this.model.findOne(c, e, r), i = this.getDynamicVirtuals(), d = C(n, i);
758
- d && o.populate(d);
759
- const h = yield o.exec();
760
- if (!h)
1085
+ const l = F(e), c = this.model.findOne(l, t, r), a = this.getDynamicVirtuals(), u = C(s, a);
1086
+ u && c.populate(u);
1087
+ const m = yield c.exec();
1088
+ if (!m)
761
1089
  return {
762
1090
  success: !1,
763
1091
  message: `No ${this.getModelName()} found.`,
764
- code: D.NOT_FOUND.CODE
1092
+ code: A.NOT_FOUND.CODE
765
1093
  };
766
- const m = yield this.populateDynamicVirtualsForDocument(h, n);
767
- return { success: !0, result: (l = (u = m == null ? void 0 : m.toObject) == null ? void 0 : u.call(m)) != null ? l : m };
768
- } catch (c) {
769
- return f(c);
1094
+ const h = yield this.populateDynamicVirtualsForDocument(m, s);
1095
+ return { success: !0, result: (o = (i = h == null ? void 0 : h.toObject) == null ? void 0 : i.call(h)) != null ? o : h };
1096
+ } catch (l) {
1097
+ return D(l);
770
1098
  }
771
1099
  });
772
1100
  }
@@ -781,17 +1109,17 @@ class xe {
781
1109
  * @returns A promise that resolves to a standardized response with the found documents.
782
1110
  */
783
1111
  findAll() {
784
- return a(this, arguments, function* (t = {}, e = {}, r = {}, n) {
1112
+ return v(this, arguments, function* (e = {}, t = {}, r = {}, s) {
785
1113
  try {
786
- const u = V(t), l = this.model.find(u, e, r), c = this.getDynamicVirtuals(), o = C(n, c);
787
- o && l.populate(o);
788
- const i = yield l.exec();
789
- return { success: !0, result: (yield this.populateDynamicVirtualsForDocuments(i, n)).map((h) => {
790
- var m, y;
791
- return (y = (m = h == null ? void 0 : h.toObject) == null ? void 0 : m.call(h)) != null ? y : h;
1114
+ const i = F(e), o = this.model.find(i, t, r), l = this.getDynamicVirtuals(), c = C(s, l);
1115
+ c && o.populate(c);
1116
+ const a = yield o.exec();
1117
+ return { success: !0, result: (yield this.populateDynamicVirtualsForDocuments(a, s)).map((m) => {
1118
+ var h, _;
1119
+ return (_ = (h = m == null ? void 0 : m.toObject) == null ? void 0 : h.call(m)) != null ? _ : m;
792
1120
  }) };
793
- } catch (u) {
794
- return f(u);
1121
+ } catch (i) {
1122
+ return D(i);
795
1123
  }
796
1124
  });
797
1125
  }
@@ -804,17 +1132,24 @@ class xe {
804
1132
  * @returns A promise that resolves to a standardized response with paginated results.
805
1133
  */
806
1134
  findPaging() {
807
- return a(this, arguments, function* (t = {}, e = {}) {
1135
+ return v(this, arguments, function* (e = {}, t = {}) {
808
1136
  try {
809
- const r = V(t), n = this.getDynamicVirtuals(), u = v({}, e);
810
- e.populate && (u.populate = C(e.populate, n));
811
- const l = yield this.model.paginate(r, u), c = yield this.populateDynamicVirtualsForDocuments(l.docs, e.populate);
812
- return { success: !0, result: F(v({}, l), { docs: c.map((o) => {
813
- var i, d;
814
- return (d = (i = o == null ? void 0 : o.toObject) == null ? void 0 : i.call(o)) != null ? d : o;
1137
+ const r = F(e), s = this.getDynamicVirtuals(), i = N({}, t);
1138
+ t.populate && (i.populate = C(t.populate, s));
1139
+ const o = yield this.model.paginate(r, i);
1140
+ if (s && s.length > 0) {
1141
+ const l = yield this.populateDynamicVirtualsForDocuments(o.docs, t.populate);
1142
+ return { success: !0, result: $(N({}, o), { docs: l.map((c) => {
1143
+ var a, u;
1144
+ return (u = (a = c == null ? void 0 : c.toObject) == null ? void 0 : a.call(c)) != null ? u : c;
1145
+ }) }) };
1146
+ }
1147
+ return { success: !0, result: $(N({}, o), { docs: o.docs.map((l) => {
1148
+ var c, a;
1149
+ return (a = (c = l == null ? void 0 : l.toObject) == null ? void 0 : c.call(l)) != null ? a : l;
815
1150
  }) }) };
816
1151
  } catch (r) {
817
- return f(r);
1152
+ return D(r);
818
1153
  }
819
1154
  });
820
1155
  }
@@ -825,21 +1160,21 @@ class xe {
825
1160
  * @param options - Pagination options for the aggregation result.
826
1161
  * @returns A promise that resolves to a standardized response with paginated aggregation results.
827
1162
  */
828
- findPagingAggregate(t) {
829
- return a(this, arguments, function* (e, r = {}) {
1163
+ findPagingAggregate(e) {
1164
+ return v(this, arguments, function* (t, r = {}) {
830
1165
  try {
831
- const n = this.getDynamicVirtuals(), u = v({}, r);
832
- r.populate && (u.populate = C(r.populate, n));
833
- const l = yield this.model.aggregatePaginate(
834
- this.model.aggregate(e),
835
- u
836
- ), c = yield this.populateDynamicVirtualsForDocuments(l.docs, r.populate);
837
- return { success: !0, result: F(v({}, l), { docs: c.map((o) => {
838
- var i, d;
839
- return (d = (i = o == null ? void 0 : o.toObject) == null ? void 0 : i.call(o)) != null ? d : o;
1166
+ const s = this.getDynamicVirtuals(), i = N({}, r);
1167
+ r.populate && (i.populate = C(r.populate, s));
1168
+ const o = yield this.model.aggregatePaginate(
1169
+ this.model.aggregate(t),
1170
+ i
1171
+ ), l = yield this.populateDynamicVirtualsForDocuments(o.docs, r.populate);
1172
+ return { success: !0, result: $(N({}, o), { docs: l.map((c) => {
1173
+ var a, u;
1174
+ return (u = (a = c == null ? void 0 : c.toObject) == null ? void 0 : a.call(c)) != null ? u : c;
840
1175
  }) }) };
841
- } catch (n) {
842
- return f(n);
1176
+ } catch (s) {
1177
+ return D(s);
843
1178
  }
844
1179
  });
845
1180
  }
@@ -850,12 +1185,12 @@ class xe {
850
1185
  * @returns A promise that resolves to a standardized response with the document count.
851
1186
  */
852
1187
  count() {
853
- return a(this, arguments, function* (t = {}) {
1188
+ return v(this, arguments, function* (e = {}) {
854
1189
  try {
855
- const e = V(t);
856
- return { success: !0, result: yield this.model.countDocuments(e) };
857
- } catch (e) {
858
- return f(e);
1190
+ const t = F(e);
1191
+ return { success: !0, result: yield this.model.countDocuments(t) };
1192
+ } catch (t) {
1193
+ return D(t);
859
1194
  }
860
1195
  });
861
1196
  }
@@ -865,14 +1200,14 @@ class xe {
865
1200
  * @param doc - The document to create.
866
1201
  * @returns A promise that resolves to a standardized response with the created document.
867
1202
  */
868
- createOne(t) {
869
- return a(this, null, function* () {
870
- var e, r;
1203
+ createOne(e) {
1204
+ return v(this, null, function* () {
1205
+ var t, r;
871
1206
  try {
872
- const n = yield this.model.create(t);
873
- return { success: !0, result: (r = (e = n == null ? void 0 : n.toObject) == null ? void 0 : e.call(n)) != null ? r : n };
874
- } catch (n) {
875
- return f(n);
1207
+ const s = yield this.model.create(e);
1208
+ return { success: !0, result: (r = (t = s == null ? void 0 : s.toObject) == null ? void 0 : t.call(s)) != null ? r : s };
1209
+ } catch (s) {
1210
+ return D(s);
876
1211
  }
877
1212
  });
878
1213
  }
@@ -883,15 +1218,15 @@ class xe {
883
1218
  * @param options - Options for the bulk insertion operation.
884
1219
  * @returns A promise that resolves to a standardized response with the created documents.
885
1220
  */
886
- createMany(t) {
887
- return a(this, arguments, function* (e, r = {}) {
1221
+ createMany(e) {
1222
+ return v(this, arguments, function* (t, r = {}) {
888
1223
  try {
889
- return { success: !0, result: (yield this.model.insertMany(e, r)).map((u) => {
890
- var l, c;
891
- return (c = (l = u == null ? void 0 : u.toObject) == null ? void 0 : l.call(u)) != null ? c : u;
1224
+ return { success: !0, result: (yield this.model.insertMany(t, r)).map((i) => {
1225
+ var o, l;
1226
+ return (l = (o = i == null ? void 0 : i.toObject) == null ? void 0 : o.call(i)) != null ? l : i;
892
1227
  }) };
893
- } catch (n) {
894
- return f(n);
1228
+ } catch (s) {
1229
+ return D(s);
895
1230
  }
896
1231
  });
897
1232
  }
@@ -904,19 +1239,19 @@ class xe {
904
1239
  * @returns A promise that resolves to a standardized response with the updated document.
905
1240
  */
906
1241
  updateOne() {
907
- return a(this, arguments, function* (t = {}, e = {}, r = {}) {
908
- var n, u;
1242
+ return v(this, arguments, function* (e = {}, t = {}, r = {}) {
1243
+ var s, i;
909
1244
  try {
910
- const l = V(t), c = yield this.model.findOneAndUpdate(l, e, v({
1245
+ const o = F(e), l = yield this.model.findOneAndUpdate(o, t, N({
911
1246
  new: !0
912
1247
  }, r)).exec();
913
- return c ? { success: !0, result: (u = (n = c == null ? void 0 : c.toObject) == null ? void 0 : n.call(c)) != null ? u : c } : {
1248
+ return l ? { success: !0, result: (i = (s = l == null ? void 0 : l.toObject) == null ? void 0 : s.call(l)) != null ? i : l } : {
914
1249
  success: !1,
915
1250
  message: `Failed to update ${this.getModelName()}.`,
916
- code: D.NOT_FOUND.CODE
1251
+ code: A.NOT_FOUND.CODE
917
1252
  };
918
- } catch (l) {
919
- return f(l);
1253
+ } catch (o) {
1254
+ return D(o);
920
1255
  }
921
1256
  });
922
1257
  }
@@ -929,12 +1264,12 @@ class xe {
929
1264
  * @returns A promise that resolves to a standardized response with the update result.
930
1265
  */
931
1266
  updateMany() {
932
- return a(this, arguments, function* (t = {}, e = {}, r = {}) {
1267
+ return v(this, arguments, function* (e = {}, t = {}, r = {}) {
933
1268
  try {
934
- const n = V(t);
935
- return { success: !0, result: yield this.model.updateMany(n, e, r).exec() };
936
- } catch (n) {
937
- return f(n);
1269
+ const s = F(e);
1270
+ return { success: !0, result: yield this.model.updateMany(s, t, r).exec() };
1271
+ } catch (s) {
1272
+ return D(s);
938
1273
  }
939
1274
  });
940
1275
  }
@@ -946,17 +1281,17 @@ class xe {
946
1281
  * @returns A promise that resolves to a standardized response with the deleted document.
947
1282
  */
948
1283
  deleteOne() {
949
- return a(this, arguments, function* (t = {}, e = {}) {
950
- var r, n;
1284
+ return v(this, arguments, function* (e = {}, t = {}) {
1285
+ var r, s;
951
1286
  try {
952
- const u = V(t), l = yield this.model.findOneAndDelete(u, e).exec();
953
- return l ? { success: !0, result: (n = (r = l == null ? void 0 : l.toObject) == null ? void 0 : r.call(l)) != null ? n : l } : {
1287
+ const i = F(e), o = yield this.model.findOneAndDelete(i, t).exec();
1288
+ return o ? { success: !0, result: (s = (r = o == null ? void 0 : o.toObject) == null ? void 0 : r.call(o)) != null ? s : o } : {
954
1289
  success: !1,
955
1290
  message: `No ${this.getModelName()} found to delete.`,
956
- code: D.NOT_FOUND.CODE
1291
+ code: A.NOT_FOUND.CODE
957
1292
  };
958
- } catch (u) {
959
- return f(u);
1293
+ } catch (i) {
1294
+ return D(i);
960
1295
  }
961
1296
  });
962
1297
  }
@@ -968,16 +1303,16 @@ class xe {
968
1303
  * @returns A promise that resolves to a standardized response with the delete result.
969
1304
  */
970
1305
  deleteMany() {
971
- return a(this, arguments, function* (t = {}, e = {}) {
1306
+ return v(this, arguments, function* (e = {}, t = {}) {
972
1307
  try {
973
- const r = V(t), n = yield this.model.deleteMany(r, e).exec();
974
- return n.deletedCount === 0 ? {
1308
+ const r = F(e), s = yield this.model.deleteMany(r, t).exec();
1309
+ return s.deletedCount === 0 ? {
975
1310
  success: !1,
976
1311
  message: "No documents found to delete.",
977
- code: D.NOT_FOUND.CODE
978
- } : { success: !0, result: n };
1312
+ code: A.NOT_FOUND.CODE
1313
+ } : { success: !0, result: s };
979
1314
  } catch (r) {
980
- return f(r);
1315
+ return D(r);
981
1316
  }
982
1317
  });
983
1318
  }
@@ -989,24 +1324,24 @@ class xe {
989
1324
  * @param length - The initial length for short ID generation (default: 4).
990
1325
  * @returns A promise that resolves to a standardized response with the unique short ID.
991
1326
  */
992
- createShortId(t, e = 4) {
993
- return a(this, null, function* () {
1327
+ createShortId(e, t = 4) {
1328
+ return v(this, null, function* () {
994
1329
  try {
995
- const n = Array.from({ length: 10 }, (c, o) => ne(t, o + e)), l = (yield Promise.all(
996
- n.map((c) => this.model.exists({ shortId: c }))
997
- )).findIndex((c) => !c);
998
- if (l !== -1) {
999
- const c = n[l];
1000
- if (c)
1001
- return { success: !0, result: c };
1330
+ const s = Array.from({ length: 10 }, (l, c) => ut(e, c + t)), o = (yield Promise.all(
1331
+ s.map((l) => this.model.exists({ shortId: l }))
1332
+ )).findIndex((l) => !l);
1333
+ if (o !== -1) {
1334
+ const l = s[o];
1335
+ if (l)
1336
+ return { success: !0, result: l };
1002
1337
  }
1003
1338
  return {
1004
1339
  success: !1,
1005
1340
  message: "Failed to create a unique shortId",
1006
- code: D.INTERNAL_SERVER_ERROR.CODE
1341
+ code: A.INTERNAL_SERVER_ERROR.CODE
1007
1342
  };
1008
1343
  } catch (r) {
1009
- return f(r);
1344
+ return D(r);
1010
1345
  }
1011
1346
  });
1012
1347
  }
@@ -1022,17 +1357,17 @@ class xe {
1022
1357
  * @param options.filter - Additional filter conditions to apply to the query.
1023
1358
  * @returns A MongoDB query object for checking slug existence.
1024
1359
  */
1025
- createSlugQuery({ slug: t, field: e, isObject: r, haveHistory: n = !1, filter: u }) {
1026
- const l = v({}, u != null ? u : {});
1027
- return r ? F(v({}, l), {
1360
+ createSlugQuery({ slug: e, field: t, isObject: r, haveHistory: s = !1, filter: i }) {
1361
+ const o = N({}, i != null ? i : {});
1362
+ return r ? $(N({}, o), {
1028
1363
  $or: [
1029
- { [`slug.${e}`]: t },
1030
- ...n ? [{ slugHistory: { $elemMatch: { [`slug.${e}`]: t } } }] : []
1364
+ { [`slug.${t}`]: e },
1365
+ ...s ? [{ slugHistory: { $elemMatch: { [`slug.${t}`]: e } } }] : []
1031
1366
  ]
1032
- }) : F(v({}, l), {
1367
+ }) : $(N({}, o), {
1033
1368
  $or: [
1034
- { slug: t },
1035
- ...n ? [{ slugHistory: t }] : []
1369
+ { slug: e },
1370
+ ...s ? [{ slugHistory: e }] : []
1036
1371
  ]
1037
1372
  });
1038
1373
  }
@@ -1048,24 +1383,24 @@ class xe {
1048
1383
  * @param options.filter - Additional filter conditions to apply when checking slug existence.
1049
1384
  * @returns A promise that resolves to a unique slug string.
1050
1385
  */
1051
- createUniqueSlug(t) {
1052
- return a(this, arguments, function* ({ slug: e, field: r, isObject: n, haveHistory: u, filter: l }) {
1053
- if (!e || typeof e != "string")
1386
+ createUniqueSlug(e) {
1387
+ return v(this, arguments, function* ({ slug: t, field: r, isObject: s, haveHistory: i, filter: o }) {
1388
+ if (!t || typeof t != "string")
1054
1389
  throw new Error("Invalid slug provided: must be a non-empty string");
1055
- const c = I(e);
1390
+ const l = G(t);
1056
1391
  if (!(yield this.model.exists(
1057
- this.createSlugQuery({ slug: c, field: r, isObject: n, haveHistory: u, filter: l })
1392
+ this.createSlugQuery({ slug: l, field: r, isObject: s, haveHistory: i, filter: o })
1058
1393
  )))
1059
- return c;
1060
- for (let h = 1; h <= J; h++) {
1061
- const m = `${c}-${h}`;
1394
+ return l;
1395
+ for (let m = 1; m <= et; m++) {
1396
+ const h = `${l}-${m}`;
1062
1397
  if (!(yield this.model.exists(
1063
- this.createSlugQuery({ slug: m, field: r, isObject: n, haveHistory: u, filter: l })
1398
+ this.createSlugQuery({ slug: h, field: r, isObject: s, haveHistory: i, filter: o })
1064
1399
  )))
1065
- return m;
1400
+ return h;
1066
1401
  }
1067
- const i = Date.now(), d = Math.random().toString(36).substring(2, 8);
1068
- return `${c}-${i}-${d}`;
1402
+ const a = Date.now(), u = Math.random().toString(36).substring(2, 8);
1403
+ return `${l}-${a}-${u}`;
1069
1404
  });
1070
1405
  }
1071
1406
  /**
@@ -1079,32 +1414,32 @@ class xe {
1079
1414
  * @param options.filter - Additional filter conditions to apply when checking slug existence.
1080
1415
  * @returns A promise that resolves to a standardized response with the created slug(s).
1081
1416
  */
1082
- createSlug(t) {
1083
- return a(this, arguments, function* ({ field: e, from: r, filter: n, haveHistory: u }) {
1417
+ createSlug(e) {
1418
+ return v(this, arguments, function* ({ field: t, from: r, filter: s, haveHistory: i }) {
1084
1419
  try {
1085
- const l = r[e];
1086
- return T(l) ? { success: !0, result: Object.fromEntries(
1420
+ const o = r[t];
1421
+ return z(o) ? { success: !0, result: Object.fromEntries(
1087
1422
  yield Promise.all(
1088
- Object.entries(l).map((d) => a(this, [d], function* ([h, m]) {
1089
- const y = yield this.createUniqueSlug({
1090
- slug: m,
1091
- field: h,
1423
+ Object.entries(o).map((u) => v(this, [u], function* ([m, h]) {
1424
+ const _ = yield this.createUniqueSlug({
1425
+ slug: h,
1426
+ field: m,
1092
1427
  isObject: !0,
1093
- haveHistory: u,
1094
- filter: n
1428
+ haveHistory: i,
1429
+ filter: s
1095
1430
  });
1096
- return [h, y];
1431
+ return [m, _];
1097
1432
  }))
1098
1433
  )
1099
1434
  ) } : { success: !0, result: yield this.createUniqueSlug({
1100
- slug: l,
1101
- field: e,
1435
+ slug: o,
1436
+ field: t,
1102
1437
  isObject: !1,
1103
- haveHistory: u,
1104
- filter: n
1438
+ haveHistory: i,
1439
+ filter: s
1105
1440
  }) };
1106
- } catch (l) {
1107
- return f(l);
1441
+ } catch (o) {
1442
+ return D(o);
1108
1443
  }
1109
1444
  });
1110
1445
  }
@@ -1120,33 +1455,33 @@ class xe {
1120
1455
  * @param options.filter - Additional filter conditions to apply to the query.
1121
1456
  * @returns A promise that resolves to a standardized response indicating whether the slug exists.
1122
1457
  */
1123
- checkSlug(t) {
1124
- return a(this, arguments, function* ({ slug: e, field: r, from: n, filter: u, haveHistory: l }) {
1458
+ checkSlug(e) {
1459
+ return v(this, arguments, function* ({ slug: t, field: r, from: s, filter: i, haveHistory: o }) {
1125
1460
  try {
1126
- const c = n[r];
1127
- if (T(c)) {
1128
- const m = Object.values(c).map((R) => I(R));
1461
+ const l = s[r];
1462
+ if (z(l)) {
1463
+ const h = Object.values(l).map((b) => G(b));
1129
1464
  return (yield Promise.all(
1130
- m.map(
1131
- (R) => this.model.exists(this.createSlugQuery({
1132
- slug: R,
1465
+ h.map(
1466
+ (b) => this.model.exists(this.createSlugQuery({
1467
+ slug: b,
1133
1468
  field: r,
1134
1469
  isObject: !0,
1135
- haveHistory: l,
1136
- filter: u
1470
+ haveHistory: o,
1471
+ filter: i
1137
1472
  }))
1138
1473
  )
1139
- )).some((R) => R) ? { success: !0, result: !0 } : { success: !0, result: !1 };
1474
+ )).some((b) => b) ? { success: !0, result: !0 } : { success: !0, result: !1 };
1140
1475
  }
1141
- const i = I(e);
1476
+ const a = G(t);
1142
1477
  return { success: !0, result: (yield this.model.exists(this.createSlugQuery({
1143
- slug: i,
1478
+ slug: a,
1144
1479
  field: r,
1145
1480
  isObject: !1,
1146
- filter: u
1481
+ filter: i
1147
1482
  }))) !== null };
1148
- } catch (c) {
1149
- return f(c);
1483
+ } catch (l) {
1484
+ return D(l);
1150
1485
  }
1151
1486
  });
1152
1487
  }
@@ -1156,12 +1491,12 @@ class xe {
1156
1491
  * @param pipeline - The aggregation pipeline stages to execute.
1157
1492
  * @returns A promise that resolves to a standardized response with the aggregation results.
1158
1493
  */
1159
- aggregate(t) {
1160
- return a(this, null, function* () {
1494
+ aggregate(e) {
1495
+ return v(this, null, function* () {
1161
1496
  try {
1162
- return { success: !0, result: yield this.model.aggregate(t) };
1163
- } catch (e) {
1164
- return f(e);
1497
+ return { success: !0, result: yield this.model.aggregate(e) };
1498
+ } catch (t) {
1499
+ return D(t);
1165
1500
  }
1166
1501
  });
1167
1502
  }
@@ -1173,18 +1508,18 @@ class xe {
1173
1508
  * @param options - Additional options for the distinct operation (optional).
1174
1509
  * @returns A promise that resolves to a standardized response with the array of distinct values.
1175
1510
  */
1176
- distinct(t) {
1177
- return a(this, arguments, function* (e, r = {}, n = {}) {
1511
+ distinct(e) {
1512
+ return v(this, arguments, function* (t, r = {}, s = {}) {
1178
1513
  try {
1179
- return { success: !0, result: yield this.model.distinct(e, r, n) };
1180
- } catch (u) {
1181
- return f(u);
1514
+ return { success: !0, result: yield this.model.distinct(t, r, s) };
1515
+ } catch (i) {
1516
+ return D(i);
1182
1517
  }
1183
1518
  });
1184
1519
  }
1185
1520
  }
1186
1521
  export {
1187
- Ve as MongoController,
1188
- xe as MongooseController,
1522
+ Pt as MongoController,
1523
+ Mt as MongooseController,
1189
1524
  x as mongo
1190
1525
  };