@cyberskill/shared 2.11.0 → 2.13.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,45 +1,44 @@
1
- import { cloneDeep as K, isObject as G } from "lodash-es";
2
- import W from "migrate-mongo";
3
- import k from "mongoose-aggregate-paginate-v2";
4
- import J from "mongoose-paginate-v2";
5
- import { v4 as q } from "uuid";
6
- import { MONGO_SLUG_MAX_ATTEMPTS as X } from "./mongo.constant.js";
7
- import { C_Document as b } from "./mongo.type.js";
8
- import { getNestedValue as H, setNestedValue as Y, normalizeMongoFilter as x } from "../../util/object/object.util.js";
9
- import { regexSearchMapper as Z } from "../../util/common/common.util.js";
10
- import { writeFileSync as L, pathExistsSync as ee, readFileSync as te, appendFileSync as re } from "../fs/fs.util.js";
11
- import { PATH as M, MIGRATE_MONGO_CONFIG as U } from "../path/path.constant.js";
12
- import { validate as se } from "../../util/validate/validate.util.js";
13
- import { generateShortId as ne, generateSlug as $ } from "../../util/string/string.util.js";
14
- import { RESPONSE_STATUS as R } from "../../constant/response-status.js";
15
- import { catchError as d } from "../log/log.util.js";
16
- var ce = Object.defineProperty, ue = Object.defineProperties, oe = Object.getOwnPropertyDescriptors, z = Object.getOwnPropertySymbols, ie = Object.prototype.hasOwnProperty, le = Object.prototype.propertyIsEnumerable, T = (n, t, e) => t in n ? ce(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, S = (n, t) => {
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) => {
17
16
  for (var e in t || (t = {}))
18
- ie.call(t, e) && T(n, e, t[e]);
19
- if (z)
20
- for (var e of z(t))
21
- le.call(t, e) && T(n, e, t[e]);
22
- return n;
23
- }, j = (n, t) => ue(n, oe(t)), ae = (n, t, e) => T(n, typeof t != "symbol" ? t + "" : t, e), l = (n, t, e) => new Promise((r, s) => {
24
- var c = (i) => {
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) => {
25
24
  try {
26
- o(e.next(i));
27
- } catch (a) {
28
- s(a);
25
+ c(e.next(o));
26
+ } catch (i) {
27
+ n(i);
29
28
  }
30
- }, u = (i) => {
29
+ }, l = (o) => {
31
30
  try {
32
- o(e.throw(i));
33
- } catch (a) {
34
- s(a);
31
+ c(e.throw(o));
32
+ } catch (i) {
33
+ n(i);
35
34
  }
36
- }, o = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(c, u);
37
- o((e = e.apply(n, t)).next());
35
+ }, c = (o) => o.done ? r(o.value) : Promise.resolve(o.value).then(u, l);
36
+ c((e = e.apply(s, t)).next());
38
37
  });
39
- function de(n) {
40
- return n === n.toUpperCase() ? n.charAt(0).toUpperCase() + n.slice(1).toLowerCase() : n;
38
+ function ae(s) {
39
+ return s === s.toUpperCase() ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : s;
41
40
  }
42
- const w = {
41
+ const x = {
43
42
  /**
44
43
  * Creates generic fields that are commonly used across MongoDB documents.
45
44
  * This function generates standard fields including a UUID, deletion flag, and timestamps
@@ -49,7 +48,7 @@ const w = {
49
48
  */
50
49
  createGenericFields() {
51
50
  return {
52
- id: q(),
51
+ id: G(),
53
52
  isDel: !1,
54
53
  createdAt: /* @__PURE__ */ new Date(),
55
54
  updatedAt: /* @__PURE__ */ new Date()
@@ -63,8 +62,8 @@ const w = {
63
62
  * @param schema - The Mongoose schema to apply plugins to.
64
63
  * @param plugins - An array of plugin functions or false values to filter and apply.
65
64
  */
66
- applyPlugins(n, t) {
67
- t.filter((e) => typeof e == "function").forEach((e) => n.plugin(e));
65
+ applyPlugins(s, t) {
66
+ t.filter((e) => typeof e == "function").forEach((e) => s.plugin(e));
68
67
  },
69
68
  /**
70
69
  * Applies middleware functions to a Mongoose schema.
@@ -73,9 +72,9 @@ const w = {
73
72
  * @param schema - The Mongoose schema to apply middleware to.
74
73
  * @param middlewares - An array of middleware configurations with method, pre, and post functions.
75
74
  */
76
- applyMiddlewares(n, t) {
77
- t.forEach(({ method: e, pre: r, post: s }) => {
78
- e && r && n.pre(e, r), e && s && n.post(e, s);
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);
79
78
  });
80
79
  },
81
80
  /**
@@ -86,10 +85,10 @@ const w = {
86
85
  * @param mongoose - The Mongoose instance to create the schema with.
87
86
  * @returns A Mongoose schema with generic document fields.
88
87
  */
89
- createGenericSchema(n) {
90
- return new n.Schema(
88
+ createGenericSchema(s) {
89
+ return new s.Schema(
91
90
  {
92
- id: { type: String, default: q, unique: !0 },
91
+ id: { type: String, default: G, unique: !0 },
93
92
  isDel: { type: Boolean, default: !1 }
94
93
  },
95
94
  { timestamps: !0 }
@@ -108,34 +107,34 @@ const w = {
108
107
  * @returns A configured Mongoose schema.
109
108
  */
110
109
  createSchema({
111
- mongoose: n,
110
+ mongoose: s,
112
111
  schema: t,
113
112
  virtuals: e = [],
114
113
  standalone: r = !1
115
114
  }) {
116
- const s = new n.Schema(t, {
115
+ const n = new s.Schema(t, {
117
116
  toJSON: { virtuals: !0 },
118
117
  // So `res.json()` and other `JSON.stringify()` functions include virtuals
119
118
  toObject: { virtuals: !0 }
120
119
  // So `console.log()` and other functions that use `toObject()` include virtuals
121
120
  });
122
- return e.forEach(({ name: c, options: u, get: o }) => {
123
- if (w.isDynamicVirtual(u)) {
124
- const i = s.statics;
125
- i._dynamicVirtuals || (i._dynamicVirtuals = []), i._dynamicVirtuals.push({
126
- name: c,
127
- options: u
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
128
127
  });
129
- const a = s.virtual(c);
130
- o ? a.get(o) : a.get(function() {
131
- var f;
132
- return ((f = this._populated) == null ? void 0 : f[c]) || (u != null && u.count ? 0 : u != null && u.justOne ? null : []);
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 : []);
133
132
  });
134
133
  } else {
135
- const i = s.virtual(c, u);
136
- o && i.get(o);
134
+ const o = n.virtual(u, l);
135
+ c && o.get(c);
137
136
  }
138
- }), r || s.add(w.createGenericSchema(n)), s;
137
+ }), r || n.add(x.createGenericSchema(s)), n;
139
138
  },
140
139
  /**
141
140
  * Creates a Mongoose model with plugins, middleware, and pagination support.
@@ -154,23 +153,23 @@ const w = {
154
153
  * @throws {Error} When the model name is not provided.
155
154
  */
156
155
  createModel({
157
- mongoose: n,
156
+ mongoose: s,
158
157
  name: t,
159
158
  schema: e,
160
159
  virtuals: r = [],
161
- pagination: s = !0,
162
- aggregate: c = !0,
163
- middlewares: u = []
160
+ pagination: n = !0,
161
+ aggregate: u = !0,
162
+ middlewares: l = []
164
163
  }) {
165
164
  if (!t)
166
165
  throw new Error("Model name is required.");
167
- if (n.models[t])
168
- return n.models[t];
169
- const o = w.createSchema({ mongoose: n, schema: e, virtuals: r });
170
- return (s || c) && w.applyPlugins(o, [
171
- s && J,
172
- c && k
173
- ]), w.applyMiddlewares(o, u), n.model(t, o);
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);
174
173
  },
175
174
  /**
176
175
  * Validation utilities for Mongoose schemas.
@@ -185,9 +184,9 @@ const w = {
185
184
  * @returns A validation function that returns true if the field is not empty.
186
185
  */
187
186
  isRequired() {
188
- return function(n) {
189
- return l(this, null, function* () {
190
- return !se.isEmpty(n);
187
+ return function(s) {
188
+ return a(this, null, function* () {
189
+ return !re.isEmpty(s);
191
190
  });
192
191
  };
193
192
  },
@@ -200,12 +199,12 @@ const w = {
200
199
  * @returns A validation function that returns true if the value is unique across the specified fields.
201
200
  * @throws {Error} When fields is not a non-empty array of strings.
202
201
  */
203
- isUnique(n) {
202
+ isUnique(s) {
204
203
  return function(t) {
205
- return l(this, null, function* () {
206
- if (!Array.isArray(n) || n.length === 0)
204
+ return a(this, null, function* () {
205
+ if (!Array.isArray(s) || s.length === 0)
207
206
  throw new Error("Fields must be a non-empty array of strings.");
208
- const e = { $or: n.map((s) => ({ [s]: t })) };
207
+ const e = { $or: s.map((n) => ({ [n]: t })) };
209
208
  return !(yield this.constructor.exists(e));
210
209
  });
211
210
  };
@@ -219,12 +218,12 @@ const w = {
219
218
  * @returns A validation function that returns true if the value matches all regex patterns.
220
219
  * @throws {Error} When regexArray is not an array of valid RegExp objects.
221
220
  */
222
- matchesRegex(n) {
221
+ matchesRegex(s) {
223
222
  return function(t) {
224
- return l(this, null, function* () {
225
- if (!Array.isArray(n) || n.some((e) => !(e instanceof RegExp)))
223
+ return a(this, null, function* () {
224
+ if (!Array.isArray(s) || s.some((e) => !(e instanceof RegExp)))
226
225
  throw new Error("regexArray must be an array of valid RegExp objects.");
227
- return n.every((e) => e.test(t));
226
+ return s.every((e) => e.test(t));
228
227
  });
229
228
  };
230
229
  }
@@ -233,7 +232,7 @@ const w = {
233
232
  * Migration utilities for MongoDB.
234
233
  * This object extends the migrate-mongo library with additional configuration utilities.
235
234
  */
236
- migrate: j(S({}, W), {
235
+ migrate: F(v({}, Q), {
237
236
  /**
238
237
  * Sets the migration configuration and updates .gitignore.
239
238
  * This function creates a migration configuration file and ensures it's properly
@@ -241,15 +240,15 @@ const w = {
241
240
  *
242
241
  * @param options - Migration configuration options to write to the config file.
243
242
  */
244
- setConfig: (n) => {
243
+ setConfig: (s) => {
245
244
  const t = `// This file is automatically generated by the Cyberskill CLI.
246
- module.exports = ${JSON.stringify(n, null, 4)}`;
247
- L(M.MIGRATE_MONGO_CONFIG, t);
245
+ module.exports = ${JSON.stringify(s, null, 4)}`;
246
+ q(w.MIGRATE_MONGO_CONFIG, t);
248
247
  const e = `
249
- ${U}
248
+ ${L}
250
249
  `;
251
- ee(M.GIT_IGNORE) ? te(M.GIT_IGNORE, "utf-8").split(`
252
- `).includes(U) || re(M.GIT_IGNORE, e) : L(M.GIT_IGNORE, e);
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);
253
252
  }
254
253
  }),
255
254
  /**
@@ -261,20 +260,20 @@ ${U}
261
260
  * @param fields - An array of field names to convert to regex patterns.
262
261
  * @returns A new filter object with string values converted to regex patterns.
263
262
  */
264
- regexify(n, t) {
265
- if (!n)
263
+ regexify(s, t) {
264
+ if (!s)
266
265
  return {};
267
- let e = K(n);
266
+ let e = B(s);
268
267
  if (!t || t.length === 0)
269
268
  return e;
270
269
  for (const r of t) {
271
- const s = r.toString().split("."), c = H(e, s);
272
- if (typeof c == "string" && c.length > 0) {
273
- const u = {
274
- $regex: `.*${Z(c)}.*`,
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)}.*`,
275
274
  $options: "i"
276
275
  };
277
- e = Y(e, s, u);
276
+ e = H(e, n, l);
278
277
  }
279
278
  }
280
279
  return e;
@@ -285,8 +284,8 @@ ${U}
285
284
  * @param options - The virtual options to check.
286
285
  * @returns True if the options contain a dynamic ref function.
287
286
  */
288
- isDynamicVirtual(n) {
289
- return !!(n && typeof n.ref == "function");
287
+ isDynamicVirtual(s) {
288
+ return !!(s && typeof s.ref == "function");
290
289
  },
291
290
  /**
292
291
  * Generic utility function to get new records from the database
@@ -295,12 +294,12 @@ ${U}
295
294
  * @param filterFn - Function to determine if a record already exists
296
295
  * @returns Array of records that don't exist in the database
297
296
  */
298
- getNewRecords(n, t, e) {
299
- return l(this, null, function* () {
300
- const r = yield n.findAll({});
297
+ getNewRecords(s, t, e) {
298
+ return a(this, null, function* () {
299
+ const r = yield s.findAll({});
301
300
  return r.success ? t.filter(
302
- (c) => !r.result.some(
303
- (u) => e(u, c)
301
+ (u) => !r.result.some(
302
+ (l) => e(l, u)
304
303
  )
305
304
  ) : t;
306
305
  });
@@ -312,160 +311,163 @@ ${U}
312
311
  * @param filterFn - Function to determine if a record exists
313
312
  * @returns Array of existing records that match the filter criteria
314
313
  */
315
- getExistingRecords(n, t, e) {
316
- return l(this, null, function* () {
317
- const r = yield n.findAll({});
314
+ getExistingRecords(s, t, e) {
315
+ return a(this, null, function* () {
316
+ const r = yield s.findAll({});
318
317
  return r.success ? r.result.filter(
319
- (c) => t.some(
320
- (u) => e(c, u)
318
+ (u) => t.some(
319
+ (l) => e(u, l)
321
320
  )
322
321
  ) : [];
323
322
  });
324
323
  }
325
324
  };
326
- function I(n, t) {
327
- if (!n || !t || t.length === 0)
328
- return n;
325
+ function C(s, t) {
326
+ if (!s || !t || t.length === 0)
327
+ return s;
329
328
  const e = new Set(t.map((r) => r.name));
330
- if (Array.isArray(n)) {
331
- const r = n.filter((s) => {
332
- if (typeof s == "string")
333
- return !e.has(s);
334
- if (typeof s == "object" && s !== null) {
335
- const c = s;
336
- return !e.has(c.path || c.populate || "");
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 || "");
337
336
  }
338
337
  return !0;
339
338
  });
340
339
  return r.length > 0 ? r : void 0;
341
340
  }
342
- if (typeof n == "string")
343
- return e.has(n) ? void 0 : n;
344
- if (typeof n == "object" && n !== null) {
345
- const r = n, s = r.path || r.populate || "";
346
- return e.has(s) ? void 0 : n;
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
346
  }
348
- return n;
347
+ return s;
349
348
  }
350
- function fe(n, t, e) {
351
- if (!n.length || !t || !(e != null && e.ref))
349
+ function de(s, t, e) {
350
+ if (!s.length || !t || !(e != null && e.ref))
352
351
  return [];
353
352
  const r = /* @__PURE__ */ new Map();
354
- return n.forEach((s) => {
353
+ return s.forEach((n) => {
355
354
  try {
356
- const c = e.ref(s);
357
- if (c == null)
355
+ const u = e.ref(n);
356
+ if (u == null)
358
357
  return;
359
- const u = typeof c == "string" ? c : String(c);
360
- if (u && u.trim() !== "") {
361
- const o = de(u);
362
- r.has(o) || r.set(o, []), r.get(o).push(s);
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);
363
362
  }
364
- } catch (c) {
365
- d(new Error(`Dynamic ref function failed for virtual "${t}": ${c instanceof Error ? c.message : String(c)}`));
363
+ } catch (u) {
364
+ f(new Error(`Dynamic ref function failed for virtual "${t}": ${u instanceof Error ? u.message : String(u)}`));
366
365
  }
367
- }), Array.from(r.entries()).map(([s, c]) => ({ model: s, docs: c }));
366
+ }), Array.from(r.entries()).map(([n, u]) => ({ model: n, docs: u }));
368
367
  }
369
- function B(n, t, e, r, s) {
370
- return l(this, null, function* () {
368
+ function fe(s) {
369
+ return s !== null && typeof s == "object" && "toObject" in s && typeof s.toObject == "function";
370
+ }
371
+ function z(s, t, e, r, n) {
372
+ return a(this, null, function* () {
371
373
  if (!t.length || !e.length || !r)
372
374
  return t;
373
- const c = e.filter((i) => {
375
+ const u = e.filter((o) => {
374
376
  if (Array.isArray(r))
375
- return r.length > 0 && r.some((a) => typeof a == "string" ? a === i.name : a.path === i.name);
377
+ return r.length > 0 && r.some((i) => typeof i == "string" ? i === o.name : i.path === o.name);
376
378
  if (typeof r == "string")
377
- return r === i.name;
379
+ return r === o.name;
378
380
  if (typeof r == "object" && r !== null) {
379
- const a = r;
380
- return a.path && a.path === i.name || a.populate && a.populate === i.name;
381
+ const i = r;
382
+ return i.path && i.path === o.name || i.populate && i.populate === o.name;
381
383
  }
382
384
  return !1;
383
385
  });
384
- if (c.length === 0)
386
+ if (u.length === 0)
385
387
  return t;
386
- const u = K(t);
387
- u.forEach((i) => {
388
- c.forEach(({ name: a, options: f }) => {
389
- a in i || (i[a] = f.count ? 0 : f.justOne ? null : []);
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 : []);
390
392
  });
391
393
  });
392
- const o = /* @__PURE__ */ new Map();
393
- for (const i of c) {
394
- const { name: a, options: f } = i, h = fe(u, a, f);
394
+ const c = /* @__PURE__ */ new Map();
395
+ for (const o of u) {
396
+ const { name: i, options: d } = o, h = de(l, i, d);
395
397
  for (const m of h) {
396
- o.has(m.model) || o.set(m.model, {
398
+ c.has(m.model) || c.set(m.model, {
397
399
  virtuals: [],
398
400
  localValueSets: /* @__PURE__ */ new Map(),
399
401
  docsByLocalValue: /* @__PURE__ */ new Map()
400
402
  });
401
- const p = o.get(m.model);
402
- p.virtuals.find((V) => V.name === a) || (p.virtuals.push(i), p.localValueSets.set(a, /* @__PURE__ */ new Set()));
403
- const v = p.localValueSets.get(a);
404
- m.docs.forEach((V) => {
405
- const A = V[f.localField];
406
- if (A != null) {
407
- const _ = String(A);
408
- v.add(_);
409
- let D = -1;
410
- const N = V;
411
- N.id !== void 0 ? D = u.findIndex((F) => F.id === N.id) : N._id !== void 0 && (D = u.findIndex((F) => {
412
- var O, y, E, g;
413
- return ((y = (O = F._id) == null ? void 0 : O.toString) == null ? void 0 : y.call(O)) === ((g = (E = N._id) == null ? void 0 : E.toString) == null ? void 0 : g.call(E));
414
- })), D !== -1 && (p.docsByLocalValue.has(_) || p.docsByLocalValue.set(_, []), p.docsByLocalValue.get(_).push(D));
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));
415
417
  }
416
418
  });
417
419
  }
418
420
  }
419
- return yield Promise.all(Array.from(o.entries()).map((i) => l(null, [i], function* ([a, f]) {
420
- const h = n.models[a];
421
+ return yield Promise.all(Array.from(c.entries()).map((o) => a(null, [o], function* ([i, d]) {
422
+ const h = s.models[i];
421
423
  if (!h)
422
424
  return;
423
425
  const m = /* @__PURE__ */ new Set();
424
- if (f.localValueSets.forEach((_) => {
425
- _.forEach((D) => m.add(D));
426
+ if (d.localValueSets.forEach((E) => {
427
+ E.forEach((S) => m.add(S));
426
428
  }), m.size === 0)
427
429
  return;
428
- const p = [...new Set(f.virtuals.map((_) => _.options.foreignField))], v = Array.from(m);
429
- let V;
430
- p.length === 1 ? V = { [String(p[0])]: { $in: v } } : V = { $or: p.map((_) => ({ [_]: { $in: v } })) };
431
- const A = yield h.find(V, s).lean();
432
- for (const _ of f.virtuals) {
433
- const { name: D, options: N } = _, F = A.filter((O) => {
434
- const y = O[N.foreignField];
435
- return y != null && m.has(String(y));
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));
436
438
  });
437
- if (N.count) {
439
+ if (b.count) {
438
440
  const O = /* @__PURE__ */ new Map();
439
- F.forEach((y) => {
440
- var E;
441
- const g = (E = y[N.foreignField]) == null ? void 0 : E.toString();
442
- g && O.set(g, (O.get(g) || 0) + 1);
443
- }), f.localValueSets.get(D).forEach((y) => {
444
- const E = f.docsByLocalValue.get(y) || [], g = O.get(y) || 0;
445
- E.forEach((C) => {
446
- const P = u[C];
447
- P[D] === void 0 && (P[D] = g);
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);
448
450
  });
449
451
  });
450
452
  } else {
451
453
  const O = /* @__PURE__ */ new Map();
452
- F.forEach((y) => {
453
- var E;
454
- const g = (E = y[N.foreignField]) == null ? void 0 : E.toString();
455
- g && (O.has(g) || O.set(g, []), O.get(g).push(y));
456
- }), f.localValueSets.get(D).forEach((y) => {
457
- const E = f.docsByLocalValue.get(y) || [], g = O.get(y) || [], C = N.justOne ? g[0] || null : g;
458
- E.forEach((P) => {
459
- const Q = u[P];
460
- Q[D] = C;
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;
461
463
  });
462
464
  });
463
465
  }
464
466
  }
465
- }))), u;
467
+ }))), l;
466
468
  });
467
469
  }
468
- class xe {
470
+ class Ve {
469
471
  /**
470
472
  * Creates a new MongoDB controller instance.
471
473
  *
@@ -473,7 +475,7 @@ class xe {
473
475
  * @param collectionName - The name of the collection to operate on.
474
476
  */
475
477
  constructor(t, e) {
476
- ae(this, "collection"), this.collection = t.collection(e);
478
+ ie(this, "collection"), this.collection = t.collection(e);
477
479
  }
478
480
  /**
479
481
  * Creates a single document in the collection.
@@ -483,9 +485,9 @@ class xe {
483
485
  * @returns A promise that resolves to a standardized response with the created document.
484
486
  */
485
487
  createOne(t) {
486
- return l(this, null, function* () {
488
+ return a(this, null, function* () {
487
489
  try {
488
- const e = S(S({}, w.createGenericFields()), t);
490
+ const e = v(v({}, x.createGenericFields()), t);
489
491
  return (yield this.collection.insertOne(e)).acknowledged ? {
490
492
  success: !0,
491
493
  message: "Document created successfully",
@@ -493,10 +495,10 @@ class xe {
493
495
  } : {
494
496
  success: !1,
495
497
  message: "Document creation failed",
496
- code: R.INTERNAL_SERVER_ERROR.CODE
498
+ code: D.INTERNAL_SERVER_ERROR.CODE
497
499
  };
498
500
  } catch (e) {
499
- return d(e);
501
+ return f(e);
500
502
  }
501
503
  });
502
504
  }
@@ -508,20 +510,20 @@ class xe {
508
510
  * @returns A promise that resolves to a standardized response with the created documents.
509
511
  */
510
512
  createMany(t) {
511
- return l(this, null, function* () {
513
+ return a(this, null, function* () {
512
514
  try {
513
- const e = t.map((s) => S(S({}, w.createGenericFields()), s)), r = yield this.collection.insertMany(e);
515
+ const e = t.map((n) => v(v({}, x.createGenericFields()), n)), r = yield this.collection.insertMany(e);
514
516
  return r.insertedCount === 0 ? {
515
517
  success: !1,
516
518
  message: "No documents were inserted",
517
- code: R.INTERNAL_SERVER_ERROR.CODE
519
+ code: D.INTERNAL_SERVER_ERROR.CODE
518
520
  } : {
519
521
  success: !0,
520
522
  message: `${r.insertedCount} documents created successfully`,
521
523
  result: e
522
524
  };
523
525
  } catch (e) {
524
- return d(e);
526
+ return f(e);
525
527
  }
526
528
  });
527
529
  }
@@ -532,12 +534,12 @@ class xe {
532
534
  * @returns A promise that resolves to a standardized response with the found document.
533
535
  */
534
536
  findOne(t) {
535
- return l(this, null, function* () {
537
+ return a(this, null, function* () {
536
538
  try {
537
539
  const e = yield this.collection.findOne(t);
538
- return e ? { success: !0, message: "Document found", result: e } : { success: !1, message: "Document not found", code: R.NOT_FOUND.CODE };
540
+ return e ? { success: !0, message: "Document found", result: e } : { success: !1, message: "Document not found", code: D.NOT_FOUND.CODE };
539
541
  } catch (e) {
540
- return d(e);
542
+ return f(e);
541
543
  }
542
544
  });
543
545
  }
@@ -548,7 +550,7 @@ class xe {
548
550
  * @returns A promise that resolves to a standardized response with the found documents.
549
551
  */
550
552
  findAll() {
551
- return l(this, arguments, function* (t = {}) {
553
+ return a(this, arguments, function* (t = {}) {
552
554
  try {
553
555
  return {
554
556
  success: !0,
@@ -556,7 +558,7 @@ class xe {
556
558
  result: yield this.collection.find(t).toArray()
557
559
  };
558
560
  } catch (e) {
559
- return d(e);
561
+ return f(e);
560
562
  }
561
563
  });
562
564
  }
@@ -567,7 +569,7 @@ class xe {
567
569
  * @returns A promise that resolves to a standardized response with the document count.
568
570
  */
569
571
  count() {
570
- return l(this, arguments, function* (t = {}) {
572
+ return a(this, arguments, function* (t = {}) {
571
573
  try {
572
574
  const e = yield this.collection.countDocuments(t);
573
575
  return {
@@ -576,7 +578,7 @@ class xe {
576
578
  result: e
577
579
  };
578
580
  } catch (e) {
579
- return d(e);
581
+ return f(e);
580
582
  }
581
583
  });
582
584
  }
@@ -588,7 +590,7 @@ class xe {
588
590
  * @returns A promise that resolves to a standardized response with the update result.
589
591
  */
590
592
  updateOne(t, e) {
591
- return l(this, null, function* () {
593
+ return a(this, null, function* () {
592
594
  try {
593
595
  const r = yield this.collection.updateOne(t, {
594
596
  $set: e
@@ -596,14 +598,14 @@ class xe {
596
598
  return r.matchedCount === 0 ? {
597
599
  success: !1,
598
600
  message: "No documents matched the filter",
599
- code: R.INTERNAL_SERVER_ERROR.CODE
601
+ code: D.INTERNAL_SERVER_ERROR.CODE
600
602
  } : {
601
603
  success: !0,
602
604
  message: "Document updated successfully",
603
605
  result: r
604
606
  };
605
607
  } catch (r) {
606
- return d(r);
608
+ return f(r);
607
609
  }
608
610
  });
609
611
  }
@@ -615,7 +617,7 @@ class xe {
615
617
  * @returns A promise that resolves to a standardized response with the update result.
616
618
  */
617
619
  updateMany(t, e) {
618
- return l(this, null, function* () {
620
+ return a(this, null, function* () {
619
621
  try {
620
622
  const r = yield this.collection.updateMany(t, {
621
623
  $set: e
@@ -623,14 +625,14 @@ class xe {
623
625
  return r.matchedCount === 0 ? {
624
626
  success: !1,
625
627
  message: "No documents matched the filter",
626
- code: R.INTERNAL_SERVER_ERROR.CODE
628
+ code: D.INTERNAL_SERVER_ERROR.CODE
627
629
  } : {
628
630
  success: !0,
629
631
  message: "Documents updated successfully",
630
632
  result: r
631
633
  };
632
634
  } catch (r) {
633
- return d(r);
635
+ return f(r);
634
636
  }
635
637
  });
636
638
  }
@@ -641,20 +643,20 @@ class xe {
641
643
  * @returns A promise that resolves to a standardized response with the delete result.
642
644
  */
643
645
  deleteOne(t) {
644
- return l(this, null, function* () {
646
+ return a(this, null, function* () {
645
647
  try {
646
648
  const e = yield this.collection.deleteOne(t);
647
649
  return e.deletedCount === 0 ? {
648
650
  success: !1,
649
651
  message: "No documents matched the filter",
650
- code: R.INTERNAL_SERVER_ERROR.CODE
652
+ code: D.INTERNAL_SERVER_ERROR.CODE
651
653
  } : {
652
654
  success: !0,
653
655
  message: "Document deleted successfully",
654
656
  result: e
655
657
  };
656
658
  } catch (e) {
657
- return d(e);
659
+ return f(e);
658
660
  }
659
661
  });
660
662
  }
@@ -665,25 +667,25 @@ class xe {
665
667
  * @returns A promise that resolves to a standardized response with the delete result.
666
668
  */
667
669
  deleteMany(t) {
668
- return l(this, null, function* () {
670
+ return a(this, null, function* () {
669
671
  try {
670
672
  const e = yield this.collection.deleteMany(t);
671
673
  return e.deletedCount === 0 ? {
672
674
  success: !1,
673
675
  message: "No documents matched the filter",
674
- code: R.INTERNAL_SERVER_ERROR.CODE
676
+ code: D.INTERNAL_SERVER_ERROR.CODE
675
677
  } : {
676
678
  success: !0,
677
679
  message: "Documents deleted successfully",
678
680
  result: e
679
681
  };
680
682
  } catch (e) {
681
- return d(e);
683
+ return f(e);
682
684
  }
683
685
  });
684
686
  }
685
687
  }
686
- class we {
688
+ class xe {
687
689
  /**
688
690
  * Creates a new Mongoose controller instance.
689
691
  *
@@ -716,11 +718,11 @@ class we {
716
718
  * @returns The document with dynamic virtuals populated.
717
719
  */
718
720
  populateDynamicVirtualsForDocument(t, e) {
719
- return l(this, null, function* () {
721
+ return a(this, null, function* () {
720
722
  const r = this.getDynamicVirtuals();
721
723
  if (r && r.length > 0) {
722
- const s = yield B(this.model.base, [t], r, e);
723
- return s && s[0] ? s[0] : t;
724
+ const n = yield z(this.model.base, [t], r, e);
725
+ return n && n[0] ? n[0] : t;
724
726
  }
725
727
  return t;
726
728
  });
@@ -733,9 +735,9 @@ class we {
733
735
  * @returns The documents with dynamic virtuals populated.
734
736
  */
735
737
  populateDynamicVirtualsForDocuments(t, e) {
736
- return l(this, null, function* () {
738
+ return a(this, null, function* () {
737
739
  const r = this.getDynamicVirtuals();
738
- return r && r.length > 0 && t.length > 0 ? yield B(this.model.base, t, r, e) : t;
740
+ return r && r.length > 0 && t.length > 0 ? yield z(this.model.base, t, r, e) : t;
739
741
  });
740
742
  }
741
743
  /**
@@ -749,18 +751,22 @@ class we {
749
751
  * @returns A promise that resolves to a standardized response with the found document.
750
752
  */
751
753
  findOne() {
752
- return l(this, arguments, function* (t = {}, e = {}, r = {}, s) {
754
+ return a(this, arguments, function* (t = {}, e = {}, r = {}, n) {
755
+ var u, l;
753
756
  try {
754
- const c = x(t), u = this.model.findOne(c, e, r), o = this.getDynamicVirtuals(), i = I(s, o);
755
- i && u.populate(i);
756
- const a = yield u.exec().then((h) => h instanceof b ? h.toObject() : h);
757
- return a ? { success: !0, result: yield this.populateDynamicVirtualsForDocument(a, s) } : {
758
- success: !1,
759
- message: `No ${this.getModelName()} found.`,
760
- code: R.NOT_FOUND.CODE
761
- };
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)
761
+ return {
762
+ success: !1,
763
+ message: `No ${this.getModelName()} found.`,
764
+ code: D.NOT_FOUND.CODE
765
+ };
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 };
762
768
  } catch (c) {
763
- return d(c);
769
+ return f(c);
764
770
  }
765
771
  });
766
772
  }
@@ -775,14 +781,17 @@ class we {
775
781
  * @returns A promise that resolves to a standardized response with the found documents.
776
782
  */
777
783
  findAll() {
778
- return l(this, arguments, function* (t = {}, e = {}, r = {}, s) {
784
+ return a(this, arguments, function* (t = {}, e = {}, r = {}, n) {
779
785
  try {
780
- const c = x(t), u = this.model.find(c, e, r), o = this.getDynamicVirtuals(), i = I(s, o);
781
- i && u.populate(i);
782
- const a = yield u.exec().then((h) => h == null ? void 0 : h.map((m) => m instanceof b ? m.toObject() : m));
783
- return { success: !0, result: yield this.populateDynamicVirtualsForDocuments(a, s) };
784
- } catch (c) {
785
- return d(c);
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;
792
+ }) };
793
+ } catch (u) {
794
+ return f(u);
786
795
  }
787
796
  });
788
797
  }
@@ -795,14 +804,17 @@ class we {
795
804
  * @returns A promise that resolves to a standardized response with paginated results.
796
805
  */
797
806
  findPaging() {
798
- return l(this, arguments, function* (t = {}, e = {}) {
807
+ return a(this, arguments, function* (t = {}, e = {}) {
799
808
  try {
800
- const r = x(t), s = this.getDynamicVirtuals(), c = S({}, e);
801
- e.populate && (c.populate = I(e.populate, s));
802
- const u = yield this.model.paginate(r, c), o = yield this.populateDynamicVirtualsForDocuments(u.docs.map((i) => i instanceof b ? i.toObject() : i), e.populate);
803
- return { success: !0, result: j(S({}, u), { docs: o }) };
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;
815
+ }) }) };
804
816
  } catch (r) {
805
- return d(r);
817
+ return f(r);
806
818
  }
807
819
  });
808
820
  }
@@ -814,17 +826,20 @@ class we {
814
826
  * @returns A promise that resolves to a standardized response with paginated aggregation results.
815
827
  */
816
828
  findPagingAggregate(t) {
817
- return l(this, arguments, function* (e, r = {}) {
829
+ return a(this, arguments, function* (e, r = {}) {
818
830
  try {
819
- const s = this.getDynamicVirtuals(), c = S({}, r);
820
- r.populate && (c.populate = I(r.populate, s));
821
- const u = yield this.model.aggregatePaginate(
831
+ const n = this.getDynamicVirtuals(), u = v({}, r);
832
+ r.populate && (u.populate = C(r.populate, n));
833
+ const l = yield this.model.aggregatePaginate(
822
834
  this.model.aggregate(e),
823
- c
824
- ), o = yield this.populateDynamicVirtualsForDocuments(u.docs.map((i) => i instanceof b ? i.toObject() : i), r.populate);
825
- return { success: !0, result: j(S({}, u), { docs: o }) };
826
- } catch (s) {
827
- return d(s);
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;
840
+ }) }) };
841
+ } catch (n) {
842
+ return f(n);
828
843
  }
829
844
  });
830
845
  }
@@ -835,12 +850,12 @@ class we {
835
850
  * @returns A promise that resolves to a standardized response with the document count.
836
851
  */
837
852
  count() {
838
- return l(this, arguments, function* (t = {}) {
853
+ return a(this, arguments, function* (t = {}) {
839
854
  try {
840
- const e = x(t);
855
+ const e = V(t);
841
856
  return { success: !0, result: yield this.model.countDocuments(e) };
842
857
  } catch (e) {
843
- return d(e);
858
+ return f(e);
844
859
  }
845
860
  });
846
861
  }
@@ -851,11 +866,13 @@ class we {
851
866
  * @returns A promise that resolves to a standardized response with the created document.
852
867
  */
853
868
  createOne(t) {
854
- return l(this, null, function* () {
869
+ return a(this, null, function* () {
870
+ var e, r;
855
871
  try {
856
- return { success: !0, result: yield this.model.create(t).then((r) => r instanceof b ? r.toObject() : r) };
857
- } catch (e) {
858
- return d(e);
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);
859
876
  }
860
877
  });
861
878
  }
@@ -867,11 +884,14 @@ class we {
867
884
  * @returns A promise that resolves to a standardized response with the created documents.
868
885
  */
869
886
  createMany(t) {
870
- return l(this, arguments, function* (e, r = {}) {
887
+ return a(this, arguments, function* (e, r = {}) {
871
888
  try {
872
- return { success: !0, result: yield this.model.insertMany(e, r).then((c) => c.map((u) => u instanceof b ? u.toObject() : u)) };
873
- } catch (s) {
874
- return d(s);
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;
892
+ }) };
893
+ } catch (n) {
894
+ return f(n);
875
895
  }
876
896
  });
877
897
  }
@@ -884,18 +904,19 @@ class we {
884
904
  * @returns A promise that resolves to a standardized response with the updated document.
885
905
  */
886
906
  updateOne() {
887
- return l(this, arguments, function* (t = {}, e = {}, r = {}) {
907
+ return a(this, arguments, function* (t = {}, e = {}, r = {}) {
908
+ var n, u;
888
909
  try {
889
- const s = x(t), c = yield this.model.findOneAndUpdate(s, e, S({
910
+ const l = V(t), c = yield this.model.findOneAndUpdate(l, e, v({
890
911
  new: !0
891
- }, r)).exec().then((u) => u instanceof b ? u.toObject() : u);
892
- return c ? { success: !0, result: c } : {
912
+ }, 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 } : {
893
914
  success: !1,
894
915
  message: `Failed to update ${this.getModelName()}.`,
895
- code: R.NOT_FOUND.CODE
916
+ code: D.NOT_FOUND.CODE
896
917
  };
897
- } catch (s) {
898
- return d(s);
918
+ } catch (l) {
919
+ return f(l);
899
920
  }
900
921
  });
901
922
  }
@@ -908,12 +929,12 @@ class we {
908
929
  * @returns A promise that resolves to a standardized response with the update result.
909
930
  */
910
931
  updateMany() {
911
- return l(this, arguments, function* (t = {}, e = {}, r = {}) {
932
+ return a(this, arguments, function* (t = {}, e = {}, r = {}) {
912
933
  try {
913
- const s = x(t);
914
- return { success: !0, result: yield this.model.updateMany(s, e, r).exec() };
915
- } catch (s) {
916
- return d(s);
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);
917
938
  }
918
939
  });
919
940
  }
@@ -925,16 +946,17 @@ class we {
925
946
  * @returns A promise that resolves to a standardized response with the deleted document.
926
947
  */
927
948
  deleteOne() {
928
- return l(this, arguments, function* (t = {}, e = {}) {
949
+ return a(this, arguments, function* (t = {}, e = {}) {
950
+ var r, n;
929
951
  try {
930
- const r = x(t), s = yield this.model.findOneAndDelete(r, e).exec().then((c) => c instanceof b ? c.toObject() : c);
931
- return s ? { success: !0, result: s } : {
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 } : {
932
954
  success: !1,
933
955
  message: `No ${this.getModelName()} found to delete.`,
934
- code: R.NOT_FOUND.CODE
956
+ code: D.NOT_FOUND.CODE
935
957
  };
936
- } catch (r) {
937
- return d(r);
958
+ } catch (u) {
959
+ return f(u);
938
960
  }
939
961
  });
940
962
  }
@@ -946,16 +968,16 @@ class we {
946
968
  * @returns A promise that resolves to a standardized response with the delete result.
947
969
  */
948
970
  deleteMany() {
949
- return l(this, arguments, function* (t = {}, e = {}) {
971
+ return a(this, arguments, function* (t = {}, e = {}) {
950
972
  try {
951
- const r = x(t), s = yield this.model.deleteMany(r, e).exec();
952
- return s.deletedCount === 0 ? {
973
+ const r = V(t), n = yield this.model.deleteMany(r, e).exec();
974
+ return n.deletedCount === 0 ? {
953
975
  success: !1,
954
976
  message: "No documents found to delete.",
955
- code: R.NOT_FOUND.CODE
956
- } : { success: !0, result: s };
977
+ code: D.NOT_FOUND.CODE
978
+ } : { success: !0, result: n };
957
979
  } catch (r) {
958
- return d(r);
980
+ return f(r);
959
981
  }
960
982
  });
961
983
  }
@@ -968,23 +990,23 @@ class we {
968
990
  * @returns A promise that resolves to a standardized response with the unique short ID.
969
991
  */
970
992
  createShortId(t, e = 4) {
971
- return l(this, null, function* () {
993
+ return a(this, null, function* () {
972
994
  try {
973
- const s = Array.from({ length: 10 }, (o, i) => ne(t, i + e)), u = (yield Promise.all(
974
- s.map((o) => this.model.exists({ shortId: o }))
975
- )).findIndex((o) => !o);
976
- if (u !== -1) {
977
- const o = s[u];
978
- if (o)
979
- return { success: !0, result: o };
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 };
980
1002
  }
981
1003
  return {
982
1004
  success: !1,
983
1005
  message: "Failed to create a unique shortId",
984
- code: R.INTERNAL_SERVER_ERROR.CODE
1006
+ code: D.INTERNAL_SERVER_ERROR.CODE
985
1007
  };
986
1008
  } catch (r) {
987
- return d(r);
1009
+ return f(r);
988
1010
  }
989
1011
  });
990
1012
  }
@@ -1000,17 +1022,17 @@ class we {
1000
1022
  * @param options.filter - Additional filter conditions to apply to the query.
1001
1023
  * @returns A MongoDB query object for checking slug existence.
1002
1024
  */
1003
- createSlugQuery({ slug: t, field: e, isObject: r, haveHistory: s = !1, filter: c }) {
1004
- const u = S({}, c != null ? c : {});
1005
- return r ? j(S({}, u), {
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), {
1006
1028
  $or: [
1007
1029
  { [`slug.${e}`]: t },
1008
- ...s ? [{ slugHistory: { $elemMatch: { [`slug.${e}`]: t } } }] : []
1030
+ ...n ? [{ slugHistory: { $elemMatch: { [`slug.${e}`]: t } } }] : []
1009
1031
  ]
1010
- }) : j(S({}, u), {
1032
+ }) : F(v({}, l), {
1011
1033
  $or: [
1012
1034
  { slug: t },
1013
- ...s ? [{ slugHistory: t }] : []
1035
+ ...n ? [{ slugHistory: t }] : []
1014
1036
  ]
1015
1037
  });
1016
1038
  }
@@ -1027,23 +1049,23 @@ class we {
1027
1049
  * @returns A promise that resolves to a unique slug string.
1028
1050
  */
1029
1051
  createUniqueSlug(t) {
1030
- return l(this, arguments, function* ({ slug: e, field: r, isObject: s, haveHistory: c, filter: u }) {
1052
+ return a(this, arguments, function* ({ slug: e, field: r, isObject: n, haveHistory: u, filter: l }) {
1031
1053
  if (!e || typeof e != "string")
1032
1054
  throw new Error("Invalid slug provided: must be a non-empty string");
1033
- const o = $(e);
1055
+ const c = I(e);
1034
1056
  if (!(yield this.model.exists(
1035
- this.createSlugQuery({ slug: o, field: r, isObject: s, haveHistory: c, filter: u })
1057
+ this.createSlugQuery({ slug: c, field: r, isObject: n, haveHistory: u, filter: l })
1036
1058
  )))
1037
- return o;
1038
- for (let h = 1; h <= X; h++) {
1039
- const m = `${o}-${h}`;
1059
+ return c;
1060
+ for (let h = 1; h <= J; h++) {
1061
+ const m = `${c}-${h}`;
1040
1062
  if (!(yield this.model.exists(
1041
- this.createSlugQuery({ slug: m, field: r, isObject: s, haveHistory: c, filter: u })
1063
+ this.createSlugQuery({ slug: m, field: r, isObject: n, haveHistory: u, filter: l })
1042
1064
  )))
1043
1065
  return m;
1044
1066
  }
1045
- const a = Date.now(), f = Math.random().toString(36).substring(2, 8);
1046
- return `${o}-${a}-${f}`;
1067
+ const i = Date.now(), d = Math.random().toString(36).substring(2, 8);
1068
+ return `${c}-${i}-${d}`;
1047
1069
  });
1048
1070
  }
1049
1071
  /**
@@ -1058,31 +1080,31 @@ class we {
1058
1080
  * @returns A promise that resolves to a standardized response with the created slug(s).
1059
1081
  */
1060
1082
  createSlug(t) {
1061
- return l(this, arguments, function* ({ field: e, from: r, filter: s, haveHistory: c }) {
1083
+ return a(this, arguments, function* ({ field: e, from: r, filter: n, haveHistory: u }) {
1062
1084
  try {
1063
- const u = r[e];
1064
- return G(u) ? { success: !0, result: Object.fromEntries(
1085
+ const l = r[e];
1086
+ return T(l) ? { success: !0, result: Object.fromEntries(
1065
1087
  yield Promise.all(
1066
- Object.entries(u).map((f) => l(this, [f], function* ([h, m]) {
1067
- const p = yield this.createUniqueSlug({
1088
+ Object.entries(l).map((d) => a(this, [d], function* ([h, m]) {
1089
+ const y = yield this.createUniqueSlug({
1068
1090
  slug: m,
1069
1091
  field: h,
1070
1092
  isObject: !0,
1071
- haveHistory: c,
1072
- filter: s
1093
+ haveHistory: u,
1094
+ filter: n
1073
1095
  });
1074
- return [h, p];
1096
+ return [h, y];
1075
1097
  }))
1076
1098
  )
1077
1099
  ) } : { success: !0, result: yield this.createUniqueSlug({
1078
- slug: u,
1100
+ slug: l,
1079
1101
  field: e,
1080
1102
  isObject: !1,
1081
- haveHistory: c,
1082
- filter: s
1103
+ haveHistory: u,
1104
+ filter: n
1083
1105
  }) };
1084
- } catch (u) {
1085
- return d(u);
1106
+ } catch (l) {
1107
+ return f(l);
1086
1108
  }
1087
1109
  });
1088
1110
  }
@@ -1099,32 +1121,32 @@ class we {
1099
1121
  * @returns A promise that resolves to a standardized response indicating whether the slug exists.
1100
1122
  */
1101
1123
  checkSlug(t) {
1102
- return l(this, arguments, function* ({ slug: e, field: r, from: s, filter: c, haveHistory: u }) {
1124
+ return a(this, arguments, function* ({ slug: e, field: r, from: n, filter: u, haveHistory: l }) {
1103
1125
  try {
1104
- const o = s[r];
1105
- if (G(o)) {
1106
- const m = Object.values(o).map((v) => $(v));
1126
+ const c = n[r];
1127
+ if (T(c)) {
1128
+ const m = Object.values(c).map((R) => I(R));
1107
1129
  return (yield Promise.all(
1108
1130
  m.map(
1109
- (v) => this.model.exists(this.createSlugQuery({
1110
- slug: v,
1131
+ (R) => this.model.exists(this.createSlugQuery({
1132
+ slug: R,
1111
1133
  field: r,
1112
1134
  isObject: !0,
1113
- haveHistory: u,
1114
- filter: c
1135
+ haveHistory: l,
1136
+ filter: u
1115
1137
  }))
1116
1138
  )
1117
- )).some((v) => v) ? { success: !0, result: !0 } : { success: !0, result: !1 };
1139
+ )).some((R) => R) ? { success: !0, result: !0 } : { success: !0, result: !1 };
1118
1140
  }
1119
- const a = $(e);
1141
+ const i = I(e);
1120
1142
  return { success: !0, result: (yield this.model.exists(this.createSlugQuery({
1121
- slug: a,
1143
+ slug: i,
1122
1144
  field: r,
1123
1145
  isObject: !1,
1124
- filter: c
1146
+ filter: u
1125
1147
  }))) !== null };
1126
- } catch (o) {
1127
- return d(o);
1148
+ } catch (c) {
1149
+ return f(c);
1128
1150
  }
1129
1151
  });
1130
1152
  }
@@ -1135,11 +1157,11 @@ class we {
1135
1157
  * @returns A promise that resolves to a standardized response with the aggregation results.
1136
1158
  */
1137
1159
  aggregate(t) {
1138
- return l(this, null, function* () {
1160
+ return a(this, null, function* () {
1139
1161
  try {
1140
1162
  return { success: !0, result: yield this.model.aggregate(t) };
1141
1163
  } catch (e) {
1142
- return d(e);
1164
+ return f(e);
1143
1165
  }
1144
1166
  });
1145
1167
  }
@@ -1152,17 +1174,17 @@ class we {
1152
1174
  * @returns A promise that resolves to a standardized response with the array of distinct values.
1153
1175
  */
1154
1176
  distinct(t) {
1155
- return l(this, arguments, function* (e, r = {}, s = {}) {
1177
+ return a(this, arguments, function* (e, r = {}, n = {}) {
1156
1178
  try {
1157
- return { success: !0, result: yield this.model.distinct(e, r, s) };
1158
- } catch (c) {
1159
- return d(c);
1179
+ return { success: !0, result: yield this.model.distinct(e, r, n) };
1180
+ } catch (u) {
1181
+ return f(u);
1160
1182
  }
1161
1183
  });
1162
1184
  }
1163
1185
  }
1164
1186
  export {
1165
- xe as MongoController,
1166
- we as MongooseController,
1167
- w as mongo
1187
+ Ve as MongoController,
1188
+ xe as MongooseController,
1189
+ x as mongo
1168
1190
  };