@cyberskill/shared 2.11.0 → 2.12.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 F, 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 se, 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 ne = Object.defineProperty, ue = Object.defineProperties, le = Object.getOwnPropertyDescriptors, U = Object.getOwnPropertySymbols, ce = Object.prototype.hasOwnProperty, oe = Object.prototype.propertyIsEnumerable, $ = (u, t, e) => t in u ? ne(u, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : u[t] = e, v = (u, 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) && $(u, e, t[e]);
18
+ if (U)
19
+ for (var e of U(t))
20
+ oe.call(t, e) && $(u, e, t[e]);
21
+ return u;
22
+ }, M = (u, t) => ue(u, le(t)), ie = (u, t, e) => $(u, typeof t != "symbol" ? t + "" : t, e), a = (u, t, e) => new Promise((r, s) => {
23
+ var n = (o) => {
25
24
  try {
26
- o(e.next(i));
27
- } catch (a) {
28
- s(a);
25
+ c(e.next(o));
26
+ } catch (i) {
27
+ s(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
+ s(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(n, l);
36
+ c((e = e.apply(u, 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(u) {
39
+ return u === u.toUpperCase() ? u.charAt(0).toUpperCase() + u.slice(1).toLowerCase() : u;
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(u, t) {
66
+ t.filter((e) => typeof e == "function").forEach((e) => u.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) {
75
+ applyMiddlewares(u, t) {
77
76
  t.forEach(({ method: e, pre: r, post: s }) => {
78
- e && r && n.pre(e, r), e && s && n.post(e, s);
77
+ e && r && u.pre(e, r), e && s && u.post(e, s);
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(u) {
89
+ return new u.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: u,
112
111
  schema: t,
113
112
  virtuals: e = [],
114
113
  standalone: r = !1
115
114
  }) {
116
- const s = new n.Schema(t, {
115
+ const s = new u.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: n, options: l, get: c }) => {
122
+ if (x.isDynamicVirtual(l)) {
123
+ const o = s.statics;
124
+ o._dynamicVirtuals || (o._dynamicVirtuals = []), o._dynamicVirtuals.push({
125
+ name: n,
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 = s.virtual(n);
129
+ c ? i.get(c) : i.get(function() {
130
+ var d;
131
+ return ((d = this._populated) == null ? void 0 : d[n]) || (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 = s.virtual(n, l);
135
+ c && o.get(c);
137
136
  }
138
- }), r || s.add(w.createGenericSchema(n)), s;
137
+ }), r || s.add(x.createGenericSchema(u)), s;
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: u,
158
157
  name: t,
159
158
  schema: e,
160
159
  virtuals: r = [],
161
160
  pagination: s = !0,
162
- aggregate: c = !0,
163
- middlewares: u = []
161
+ aggregate: n = !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 (u.models[t])
167
+ return u.models[t];
168
+ const c = x.createSchema({ mongoose: u, schema: e, virtuals: r });
169
+ return (s || n) && x.applyPlugins(c, [
170
+ s && k,
171
+ n && W
172
+ ]), x.applyMiddlewares(c, l), u.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(u) {
188
+ return a(this, null, function* () {
189
+ return !re.isEmpty(u);
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(u) {
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(u) || u.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: u.map((s) => ({ [s]: 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(u) {
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(u) || u.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 u.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: M(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: (u) => {
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(u, null, 4)}`;
246
+ q(F.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(F.GIT_IGNORE) ? ee(F.GIT_IGNORE, "utf-8").split(`
251
+ `).includes(L) || te(F.GIT_IGNORE, e) : q(F.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(u, t) {
264
+ if (!u)
266
265
  return {};
267
- let e = K(n);
266
+ let e = B(u);
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 s = r.toString().split("."), n = X(e, s);
271
+ if (typeof n == "string" && n.length > 0) {
272
+ const l = {
273
+ $regex: `.*${Y(n)}.*`,
275
274
  $options: "i"
276
275
  };
277
- e = Y(e, s, u);
276
+ e = H(e, s, 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(u) {
288
+ return !!(u && typeof u.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(u, t, e) {
298
+ return a(this, null, function* () {
299
+ const r = yield u.findAll({});
301
300
  return r.success ? t.filter(
302
- (c) => !r.result.some(
303
- (u) => e(u, c)
301
+ (n) => !r.result.some(
302
+ (l) => e(l, n)
304
303
  )
305
304
  ) : t;
306
305
  });
@@ -312,160 +311,160 @@ ${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(u, t, e) {
315
+ return a(this, null, function* () {
316
+ const r = yield u.findAll({});
318
317
  return r.success ? r.result.filter(
319
- (c) => t.some(
320
- (u) => e(c, u)
318
+ (n) => t.some(
319
+ (l) => e(n, 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(u, t) {
326
+ if (!u || !t || t.length === 0)
327
+ return u;
329
328
  const e = new Set(t.map((r) => r.name));
330
- if (Array.isArray(n)) {
331
- const r = n.filter((s) => {
329
+ if (Array.isArray(u)) {
330
+ const r = u.filter((s) => {
332
331
  if (typeof s == "string")
333
332
  return !e.has(s);
334
333
  if (typeof s == "object" && s !== null) {
335
- const c = s;
336
- return !e.has(c.path || c.populate || "");
334
+ const n = s;
335
+ return !e.has(n.path || n.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 u == "string")
342
+ return e.has(u) ? void 0 : u;
343
+ if (typeof u == "object" && u !== null) {
344
+ const r = u, s = r.path || r.populate || "";
345
+ return e.has(s) ? void 0 : u;
347
346
  }
348
- return n;
347
+ return u;
349
348
  }
350
- function fe(n, t, e) {
351
- if (!n.length || !t || !(e != null && e.ref))
349
+ function de(u, t, e) {
350
+ if (!u.length || !t || !(e != null && e.ref))
352
351
  return [];
353
352
  const r = /* @__PURE__ */ new Map();
354
- return n.forEach((s) => {
353
+ return u.forEach((s) => {
355
354
  try {
356
- const c = e.ref(s);
357
- if (c == null)
355
+ const n = e.ref(s);
356
+ if (n == 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 n == "string" ? n : String(n);
359
+ if (l && l.trim() !== "") {
360
+ const c = ae(l);
361
+ r.has(c) || r.set(c, []), r.get(c).push(s);
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 (n) {
364
+ f(new Error(`Dynamic ref function failed for virtual "${t}": ${n instanceof Error ? n.message : String(n)}`));
366
365
  }
367
- }), Array.from(r.entries()).map(([s, c]) => ({ model: s, docs: c }));
366
+ }), Array.from(r.entries()).map(([s, n]) => ({ model: s, docs: n }));
368
367
  }
369
- function B(n, t, e, r, s) {
370
- return l(this, null, function* () {
368
+ function z(u, t, e, r, s) {
369
+ return a(this, null, function* () {
371
370
  if (!t.length || !e.length || !r)
372
371
  return t;
373
- const c = e.filter((i) => {
372
+ const n = e.filter((o) => {
374
373
  if (Array.isArray(r))
375
- return r.length > 0 && r.some((a) => typeof a == "string" ? a === i.name : a.path === i.name);
374
+ return r.length > 0 && r.some((i) => typeof i == "string" ? i === o.name : i.path === o.name);
376
375
  if (typeof r == "string")
377
- return r === i.name;
376
+ return r === o.name;
378
377
  if (typeof r == "object" && r !== null) {
379
- const a = r;
380
- return a.path && a.path === i.name || a.populate && a.populate === i.name;
378
+ const i = r;
379
+ return i.path && i.path === o.name || i.populate && i.populate === o.name;
381
380
  }
382
381
  return !1;
383
382
  });
384
- if (c.length === 0)
383
+ if (n.length === 0)
385
384
  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 : []);
385
+ const l = B(t);
386
+ l.forEach((o) => {
387
+ n.forEach(({ name: i, options: d }) => {
388
+ i in o || (o[i] = d.count ? 0 : d.justOne ? null : []);
390
389
  });
391
390
  });
392
- const o = /* @__PURE__ */ new Map();
393
- for (const i of c) {
394
- const { name: a, options: f } = i, h = fe(u, a, f);
391
+ const c = /* @__PURE__ */ new Map();
392
+ for (const o of n) {
393
+ const { name: i, options: d } = o, h = de(l, i, d);
395
394
  for (const m of h) {
396
- o.has(m.model) || o.set(m.model, {
395
+ c.has(m.model) || c.set(m.model, {
397
396
  virtuals: [],
398
397
  localValueSets: /* @__PURE__ */ new Map(),
399
398
  docsByLocalValue: /* @__PURE__ */ new Map()
400
399
  });
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));
400
+ const y = c.get(m.model);
401
+ y.virtuals.find((N) => N.name === i) || (y.virtuals.push(o), y.localValueSets.set(i, /* @__PURE__ */ new Set()));
402
+ const R = y.localValueSets.get(i);
403
+ m.docs.forEach((N) => {
404
+ const j = N[d.localField];
405
+ if (j != null) {
406
+ const E = String(j);
407
+ R.add(E);
408
+ let S = -1;
409
+ const b = N;
410
+ b.id !== void 0 ? S = l.findIndex((w) => w.id === b.id) : b._id !== void 0 && (S = l.findIndex((w) => {
411
+ var O, g, _, p;
412
+ return ((g = (O = w._id) == null ? void 0 : O.toString) == null ? void 0 : g.call(O)) === ((p = (_ = b._id) == null ? void 0 : _.toString) == null ? void 0 : p.call(_));
413
+ })), S !== -1 && (y.docsByLocalValue.has(E) || y.docsByLocalValue.set(E, []), y.docsByLocalValue.get(E).push(S));
415
414
  }
416
415
  });
417
416
  }
418
417
  }
419
- return yield Promise.all(Array.from(o.entries()).map((i) => l(null, [i], function* ([a, f]) {
420
- const h = n.models[a];
418
+ return yield Promise.all(Array.from(c.entries()).map((o) => a(null, [o], function* ([i, d]) {
419
+ const h = u.models[i];
421
420
  if (!h)
422
421
  return;
423
422
  const m = /* @__PURE__ */ new Set();
424
- if (f.localValueSets.forEach((_) => {
425
- _.forEach((D) => m.add(D));
423
+ if (d.localValueSets.forEach((E) => {
424
+ E.forEach((S) => m.add(S));
426
425
  }), m.size === 0)
427
426
  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));
427
+ const y = [...new Set(d.virtuals.map((E) => E.options.foreignField))], R = Array.from(m);
428
+ let N;
429
+ y.length === 1 ? N = { [String(y[0])]: { $in: R } } : N = { $or: y.map((E) => ({ [E]: { $in: R } })) };
430
+ const j = yield h.find(N, s).lean();
431
+ for (const E of d.virtuals) {
432
+ const { name: S, options: b } = E, w = j.filter((O) => {
433
+ const g = O[b.foreignField];
434
+ return g != null && m.has(String(g));
436
435
  });
437
- if (N.count) {
436
+ if (b.count) {
438
437
  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);
438
+ w.forEach((g) => {
439
+ var _;
440
+ const p = (_ = g[b.foreignField]) == null ? void 0 : _.toString();
441
+ p && O.set(p, (O.get(p) || 0) + 1);
442
+ }), d.localValueSets.get(S).forEach((g) => {
443
+ const _ = d.docsByLocalValue.get(g) || [], p = O.get(g) || 0;
444
+ _.forEach((A) => {
445
+ const P = l[A];
446
+ P[S] === void 0 && (P[S] = p);
448
447
  });
449
448
  });
450
449
  } else {
451
450
  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;
451
+ w.forEach((g) => {
452
+ var _;
453
+ const p = (_ = g[b.foreignField]) == null ? void 0 : _.toString();
454
+ p && (O.has(p) || O.set(p, []), O.get(p).push(g));
455
+ }), d.localValueSets.get(S).forEach((g) => {
456
+ const _ = d.docsByLocalValue.get(g) || [], p = O.get(g) || [], A = b.justOne ? p[0] || null : p;
457
+ _.forEach((P) => {
458
+ const K = l[P];
459
+ K[S] = A;
461
460
  });
462
461
  });
463
462
  }
464
463
  }
465
- }))), u;
464
+ }))), l;
466
465
  });
467
466
  }
468
- class xe {
467
+ class Ne {
469
468
  /**
470
469
  * Creates a new MongoDB controller instance.
471
470
  *
@@ -473,7 +472,7 @@ class xe {
473
472
  * @param collectionName - The name of the collection to operate on.
474
473
  */
475
474
  constructor(t, e) {
476
- ae(this, "collection"), this.collection = t.collection(e);
475
+ ie(this, "collection"), this.collection = t.collection(e);
477
476
  }
478
477
  /**
479
478
  * Creates a single document in the collection.
@@ -483,9 +482,9 @@ class xe {
483
482
  * @returns A promise that resolves to a standardized response with the created document.
484
483
  */
485
484
  createOne(t) {
486
- return l(this, null, function* () {
485
+ return a(this, null, function* () {
487
486
  try {
488
- const e = S(S({}, w.createGenericFields()), t);
487
+ const e = v(v({}, x.createGenericFields()), t);
489
488
  return (yield this.collection.insertOne(e)).acknowledged ? {
490
489
  success: !0,
491
490
  message: "Document created successfully",
@@ -493,10 +492,10 @@ class xe {
493
492
  } : {
494
493
  success: !1,
495
494
  message: "Document creation failed",
496
- code: R.INTERNAL_SERVER_ERROR.CODE
495
+ code: D.INTERNAL_SERVER_ERROR.CODE
497
496
  };
498
497
  } catch (e) {
499
- return d(e);
498
+ return f(e);
500
499
  }
501
500
  });
502
501
  }
@@ -508,20 +507,20 @@ class xe {
508
507
  * @returns A promise that resolves to a standardized response with the created documents.
509
508
  */
510
509
  createMany(t) {
511
- return l(this, null, function* () {
510
+ return a(this, null, function* () {
512
511
  try {
513
- const e = t.map((s) => S(S({}, w.createGenericFields()), s)), r = yield this.collection.insertMany(e);
512
+ const e = t.map((s) => v(v({}, x.createGenericFields()), s)), r = yield this.collection.insertMany(e);
514
513
  return r.insertedCount === 0 ? {
515
514
  success: !1,
516
515
  message: "No documents were inserted",
517
- code: R.INTERNAL_SERVER_ERROR.CODE
516
+ code: D.INTERNAL_SERVER_ERROR.CODE
518
517
  } : {
519
518
  success: !0,
520
519
  message: `${r.insertedCount} documents created successfully`,
521
520
  result: e
522
521
  };
523
522
  } catch (e) {
524
- return d(e);
523
+ return f(e);
525
524
  }
526
525
  });
527
526
  }
@@ -532,12 +531,12 @@ class xe {
532
531
  * @returns A promise that resolves to a standardized response with the found document.
533
532
  */
534
533
  findOne(t) {
535
- return l(this, null, function* () {
534
+ return a(this, null, function* () {
536
535
  try {
537
536
  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 };
537
+ return e ? { success: !0, message: "Document found", result: e } : { success: !1, message: "Document not found", code: D.NOT_FOUND.CODE };
539
538
  } catch (e) {
540
- return d(e);
539
+ return f(e);
541
540
  }
542
541
  });
543
542
  }
@@ -548,7 +547,7 @@ class xe {
548
547
  * @returns A promise that resolves to a standardized response with the found documents.
549
548
  */
550
549
  findAll() {
551
- return l(this, arguments, function* (t = {}) {
550
+ return a(this, arguments, function* (t = {}) {
552
551
  try {
553
552
  return {
554
553
  success: !0,
@@ -556,7 +555,7 @@ class xe {
556
555
  result: yield this.collection.find(t).toArray()
557
556
  };
558
557
  } catch (e) {
559
- return d(e);
558
+ return f(e);
560
559
  }
561
560
  });
562
561
  }
@@ -567,7 +566,7 @@ class xe {
567
566
  * @returns A promise that resolves to a standardized response with the document count.
568
567
  */
569
568
  count() {
570
- return l(this, arguments, function* (t = {}) {
569
+ return a(this, arguments, function* (t = {}) {
571
570
  try {
572
571
  const e = yield this.collection.countDocuments(t);
573
572
  return {
@@ -576,7 +575,7 @@ class xe {
576
575
  result: e
577
576
  };
578
577
  } catch (e) {
579
- return d(e);
578
+ return f(e);
580
579
  }
581
580
  });
582
581
  }
@@ -588,7 +587,7 @@ class xe {
588
587
  * @returns A promise that resolves to a standardized response with the update result.
589
588
  */
590
589
  updateOne(t, e) {
591
- return l(this, null, function* () {
590
+ return a(this, null, function* () {
592
591
  try {
593
592
  const r = yield this.collection.updateOne(t, {
594
593
  $set: e
@@ -596,14 +595,14 @@ class xe {
596
595
  return r.matchedCount === 0 ? {
597
596
  success: !1,
598
597
  message: "No documents matched the filter",
599
- code: R.INTERNAL_SERVER_ERROR.CODE
598
+ code: D.INTERNAL_SERVER_ERROR.CODE
600
599
  } : {
601
600
  success: !0,
602
601
  message: "Document updated successfully",
603
602
  result: r
604
603
  };
605
604
  } catch (r) {
606
- return d(r);
605
+ return f(r);
607
606
  }
608
607
  });
609
608
  }
@@ -615,7 +614,7 @@ class xe {
615
614
  * @returns A promise that resolves to a standardized response with the update result.
616
615
  */
617
616
  updateMany(t, e) {
618
- return l(this, null, function* () {
617
+ return a(this, null, function* () {
619
618
  try {
620
619
  const r = yield this.collection.updateMany(t, {
621
620
  $set: e
@@ -623,14 +622,14 @@ class xe {
623
622
  return r.matchedCount === 0 ? {
624
623
  success: !1,
625
624
  message: "No documents matched the filter",
626
- code: R.INTERNAL_SERVER_ERROR.CODE
625
+ code: D.INTERNAL_SERVER_ERROR.CODE
627
626
  } : {
628
627
  success: !0,
629
628
  message: "Documents updated successfully",
630
629
  result: r
631
630
  };
632
631
  } catch (r) {
633
- return d(r);
632
+ return f(r);
634
633
  }
635
634
  });
636
635
  }
@@ -641,20 +640,20 @@ class xe {
641
640
  * @returns A promise that resolves to a standardized response with the delete result.
642
641
  */
643
642
  deleteOne(t) {
644
- return l(this, null, function* () {
643
+ return a(this, null, function* () {
645
644
  try {
646
645
  const e = yield this.collection.deleteOne(t);
647
646
  return e.deletedCount === 0 ? {
648
647
  success: !1,
649
648
  message: "No documents matched the filter",
650
- code: R.INTERNAL_SERVER_ERROR.CODE
649
+ code: D.INTERNAL_SERVER_ERROR.CODE
651
650
  } : {
652
651
  success: !0,
653
652
  message: "Document deleted successfully",
654
653
  result: e
655
654
  };
656
655
  } catch (e) {
657
- return d(e);
656
+ return f(e);
658
657
  }
659
658
  });
660
659
  }
@@ -665,25 +664,25 @@ class xe {
665
664
  * @returns A promise that resolves to a standardized response with the delete result.
666
665
  */
667
666
  deleteMany(t) {
668
- return l(this, null, function* () {
667
+ return a(this, null, function* () {
669
668
  try {
670
669
  const e = yield this.collection.deleteMany(t);
671
670
  return e.deletedCount === 0 ? {
672
671
  success: !1,
673
672
  message: "No documents matched the filter",
674
- code: R.INTERNAL_SERVER_ERROR.CODE
673
+ code: D.INTERNAL_SERVER_ERROR.CODE
675
674
  } : {
676
675
  success: !0,
677
676
  message: "Documents deleted successfully",
678
677
  result: e
679
678
  };
680
679
  } catch (e) {
681
- return d(e);
680
+ return f(e);
682
681
  }
683
682
  });
684
683
  }
685
684
  }
686
- class we {
685
+ class Ve {
687
686
  /**
688
687
  * Creates a new Mongoose controller instance.
689
688
  *
@@ -716,10 +715,10 @@ class we {
716
715
  * @returns The document with dynamic virtuals populated.
717
716
  */
718
717
  populateDynamicVirtualsForDocument(t, e) {
719
- return l(this, null, function* () {
718
+ return a(this, null, function* () {
720
719
  const r = this.getDynamicVirtuals();
721
720
  if (r && r.length > 0) {
722
- const s = yield B(this.model.base, [t], r, e);
721
+ const s = yield z(this.model.base, [t], r, e);
723
722
  return s && s[0] ? s[0] : t;
724
723
  }
725
724
  return t;
@@ -733,9 +732,9 @@ class we {
733
732
  * @returns The documents with dynamic virtuals populated.
734
733
  */
735
734
  populateDynamicVirtualsForDocuments(t, e) {
736
- return l(this, null, function* () {
735
+ return a(this, null, function* () {
737
736
  const r = this.getDynamicVirtuals();
738
- return r && r.length > 0 && t.length > 0 ? yield B(this.model.base, t, r, e) : t;
737
+ return r && r.length > 0 && t.length > 0 ? yield z(this.model.base, t, r, e) : t;
739
738
  });
740
739
  }
741
740
  /**
@@ -749,18 +748,22 @@ class we {
749
748
  * @returns A promise that resolves to a standardized response with the found document.
750
749
  */
751
750
  findOne() {
752
- return l(this, arguments, function* (t = {}, e = {}, r = {}, s) {
751
+ return a(this, arguments, function* (t = {}, e = {}, r = {}, s) {
752
+ var n, l;
753
753
  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
- };
754
+ const c = V(t), o = this.model.findOne(c, e, r), i = this.getDynamicVirtuals(), d = C(s, i);
755
+ d && o.populate(d);
756
+ const h = yield o.exec();
757
+ if (!h)
758
+ return {
759
+ success: !1,
760
+ message: `No ${this.getModelName()} found.`,
761
+ code: D.NOT_FOUND.CODE
762
+ };
763
+ const m = yield this.populateDynamicVirtualsForDocument(h, s);
764
+ return { success: !0, result: (l = (n = m == null ? void 0 : m.toObject) == null ? void 0 : n.call(m)) != null ? l : m };
762
765
  } catch (c) {
763
- return d(c);
766
+ return f(c);
764
767
  }
765
768
  });
766
769
  }
@@ -775,14 +778,17 @@ class we {
775
778
  * @returns A promise that resolves to a standardized response with the found documents.
776
779
  */
777
780
  findAll() {
778
- return l(this, arguments, function* (t = {}, e = {}, r = {}, s) {
781
+ return a(this, arguments, function* (t = {}, e = {}, r = {}, s) {
779
782
  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);
783
+ const n = V(t), l = this.model.find(n, e, r), c = this.getDynamicVirtuals(), o = C(s, c);
784
+ o && l.populate(o);
785
+ const i = yield l.exec();
786
+ return { success: !0, result: (yield this.populateDynamicVirtualsForDocuments(i, s)).map((h) => {
787
+ var m, y;
788
+ return (y = (m = h == null ? void 0 : h.toObject) == null ? void 0 : m.call(h)) != null ? y : h;
789
+ }) };
790
+ } catch (n) {
791
+ return f(n);
786
792
  }
787
793
  });
788
794
  }
@@ -795,14 +801,17 @@ class we {
795
801
  * @returns A promise that resolves to a standardized response with paginated results.
796
802
  */
797
803
  findPaging() {
798
- return l(this, arguments, function* (t = {}, e = {}) {
804
+ return a(this, arguments, function* (t = {}, e = {}) {
799
805
  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 }) };
806
+ const r = V(t), s = this.getDynamicVirtuals(), n = v({}, e);
807
+ e.populate && (n.populate = C(e.populate, s));
808
+ const l = yield this.model.paginate(r, n), c = yield this.populateDynamicVirtualsForDocuments(l.docs, e.populate);
809
+ return { success: !0, result: M(v({}, l), { docs: c.map((o) => {
810
+ var i, d;
811
+ return (d = (i = o == null ? void 0 : o.toObject) == null ? void 0 : i.call(o)) != null ? d : o;
812
+ }) }) };
804
813
  } catch (r) {
805
- return d(r);
814
+ return f(r);
806
815
  }
807
816
  });
808
817
  }
@@ -814,17 +823,20 @@ class we {
814
823
  * @returns A promise that resolves to a standardized response with paginated aggregation results.
815
824
  */
816
825
  findPagingAggregate(t) {
817
- return l(this, arguments, function* (e, r = {}) {
826
+ return a(this, arguments, function* (e, r = {}) {
818
827
  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(
828
+ const s = this.getDynamicVirtuals(), n = v({}, r);
829
+ r.populate && (n.populate = C(r.populate, s));
830
+ const l = yield this.model.aggregatePaginate(
822
831
  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 }) };
832
+ n
833
+ ), c = yield this.populateDynamicVirtualsForDocuments(l.docs, r.populate);
834
+ return { success: !0, result: M(v({}, l), { docs: c.map((o) => {
835
+ var i, d;
836
+ return (d = (i = o == null ? void 0 : o.toObject) == null ? void 0 : i.call(o)) != null ? d : o;
837
+ }) }) };
826
838
  } catch (s) {
827
- return d(s);
839
+ return f(s);
828
840
  }
829
841
  });
830
842
  }
@@ -835,12 +847,12 @@ class we {
835
847
  * @returns A promise that resolves to a standardized response with the document count.
836
848
  */
837
849
  count() {
838
- return l(this, arguments, function* (t = {}) {
850
+ return a(this, arguments, function* (t = {}) {
839
851
  try {
840
- const e = x(t);
852
+ const e = V(t);
841
853
  return { success: !0, result: yield this.model.countDocuments(e) };
842
854
  } catch (e) {
843
- return d(e);
855
+ return f(e);
844
856
  }
845
857
  });
846
858
  }
@@ -851,11 +863,13 @@ class we {
851
863
  * @returns A promise that resolves to a standardized response with the created document.
852
864
  */
853
865
  createOne(t) {
854
- return l(this, null, function* () {
866
+ return a(this, null, function* () {
867
+ var e, r;
855
868
  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);
869
+ const s = yield this.model.create(t);
870
+ return { success: !0, result: (r = (e = s == null ? void 0 : s.toObject) == null ? void 0 : e.call(s)) != null ? r : s };
871
+ } catch (s) {
872
+ return f(s);
859
873
  }
860
874
  });
861
875
  }
@@ -867,11 +881,14 @@ class we {
867
881
  * @returns A promise that resolves to a standardized response with the created documents.
868
882
  */
869
883
  createMany(t) {
870
- return l(this, arguments, function* (e, r = {}) {
884
+ return a(this, arguments, function* (e, r = {}) {
871
885
  try {
872
- return { success: !0, result: yield this.model.insertMany(e, r).then((c) => c.map((u) => u instanceof b ? u.toObject() : u)) };
886
+ return { success: !0, result: (yield this.model.insertMany(e, r)).map((n) => {
887
+ var l, c;
888
+ return (c = (l = n == null ? void 0 : n.toObject) == null ? void 0 : l.call(n)) != null ? c : n;
889
+ }) };
873
890
  } catch (s) {
874
- return d(s);
891
+ return f(s);
875
892
  }
876
893
  });
877
894
  }
@@ -884,18 +901,19 @@ class we {
884
901
  * @returns A promise that resolves to a standardized response with the updated document.
885
902
  */
886
903
  updateOne() {
887
- return l(this, arguments, function* (t = {}, e = {}, r = {}) {
904
+ return a(this, arguments, function* (t = {}, e = {}, r = {}) {
905
+ var s, n;
888
906
  try {
889
- const s = x(t), c = yield this.model.findOneAndUpdate(s, e, S({
907
+ const l = V(t), c = yield this.model.findOneAndUpdate(l, e, v({
890
908
  new: !0
891
- }, r)).exec().then((u) => u instanceof b ? u.toObject() : u);
892
- return c ? { success: !0, result: c } : {
909
+ }, r)).exec();
910
+ return c ? { success: !0, result: (n = (s = c == null ? void 0 : c.toObject) == null ? void 0 : s.call(c)) != null ? n : c } : {
893
911
  success: !1,
894
912
  message: `Failed to update ${this.getModelName()}.`,
895
- code: R.NOT_FOUND.CODE
913
+ code: D.NOT_FOUND.CODE
896
914
  };
897
- } catch (s) {
898
- return d(s);
915
+ } catch (l) {
916
+ return f(l);
899
917
  }
900
918
  });
901
919
  }
@@ -908,12 +926,12 @@ class we {
908
926
  * @returns A promise that resolves to a standardized response with the update result.
909
927
  */
910
928
  updateMany() {
911
- return l(this, arguments, function* (t = {}, e = {}, r = {}) {
929
+ return a(this, arguments, function* (t = {}, e = {}, r = {}) {
912
930
  try {
913
- const s = x(t);
931
+ const s = V(t);
914
932
  return { success: !0, result: yield this.model.updateMany(s, e, r).exec() };
915
933
  } catch (s) {
916
- return d(s);
934
+ return f(s);
917
935
  }
918
936
  });
919
937
  }
@@ -925,16 +943,17 @@ class we {
925
943
  * @returns A promise that resolves to a standardized response with the deleted document.
926
944
  */
927
945
  deleteOne() {
928
- return l(this, arguments, function* (t = {}, e = {}) {
946
+ return a(this, arguments, function* (t = {}, e = {}) {
947
+ var r, s;
929
948
  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 } : {
949
+ const n = V(t), l = yield this.model.findOneAndDelete(n, e).exec();
950
+ return l ? { success: !0, result: (s = (r = l == null ? void 0 : l.toObject) == null ? void 0 : r.call(l)) != null ? s : l } : {
932
951
  success: !1,
933
952
  message: `No ${this.getModelName()} found to delete.`,
934
- code: R.NOT_FOUND.CODE
953
+ code: D.NOT_FOUND.CODE
935
954
  };
936
- } catch (r) {
937
- return d(r);
955
+ } catch (n) {
956
+ return f(n);
938
957
  }
939
958
  });
940
959
  }
@@ -946,16 +965,16 @@ class we {
946
965
  * @returns A promise that resolves to a standardized response with the delete result.
947
966
  */
948
967
  deleteMany() {
949
- return l(this, arguments, function* (t = {}, e = {}) {
968
+ return a(this, arguments, function* (t = {}, e = {}) {
950
969
  try {
951
- const r = x(t), s = yield this.model.deleteMany(r, e).exec();
970
+ const r = V(t), s = yield this.model.deleteMany(r, e).exec();
952
971
  return s.deletedCount === 0 ? {
953
972
  success: !1,
954
973
  message: "No documents found to delete.",
955
- code: R.NOT_FOUND.CODE
974
+ code: D.NOT_FOUND.CODE
956
975
  } : { success: !0, result: s };
957
976
  } catch (r) {
958
- return d(r);
977
+ return f(r);
959
978
  }
960
979
  });
961
980
  }
@@ -968,23 +987,23 @@ class we {
968
987
  * @returns A promise that resolves to a standardized response with the unique short ID.
969
988
  */
970
989
  createShortId(t, e = 4) {
971
- return l(this, null, function* () {
990
+ return a(this, null, function* () {
972
991
  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 };
992
+ const s = Array.from({ length: 10 }, (c, o) => se(t, o + e)), l = (yield Promise.all(
993
+ s.map((c) => this.model.exists({ shortId: c }))
994
+ )).findIndex((c) => !c);
995
+ if (l !== -1) {
996
+ const c = s[l];
997
+ if (c)
998
+ return { success: !0, result: c };
980
999
  }
981
1000
  return {
982
1001
  success: !1,
983
1002
  message: "Failed to create a unique shortId",
984
- code: R.INTERNAL_SERVER_ERROR.CODE
1003
+ code: D.INTERNAL_SERVER_ERROR.CODE
985
1004
  };
986
1005
  } catch (r) {
987
- return d(r);
1006
+ return f(r);
988
1007
  }
989
1008
  });
990
1009
  }
@@ -1000,14 +1019,14 @@ class we {
1000
1019
  * @param options.filter - Additional filter conditions to apply to the query.
1001
1020
  * @returns A MongoDB query object for checking slug existence.
1002
1021
  */
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), {
1022
+ createSlugQuery({ slug: t, field: e, isObject: r, haveHistory: s = !1, filter: n }) {
1023
+ const l = v({}, n != null ? n : {});
1024
+ return r ? M(v({}, l), {
1006
1025
  $or: [
1007
1026
  { [`slug.${e}`]: t },
1008
1027
  ...s ? [{ slugHistory: { $elemMatch: { [`slug.${e}`]: t } } }] : []
1009
1028
  ]
1010
- }) : j(S({}, u), {
1029
+ }) : M(v({}, l), {
1011
1030
  $or: [
1012
1031
  { slug: t },
1013
1032
  ...s ? [{ slugHistory: t }] : []
@@ -1027,23 +1046,23 @@ class we {
1027
1046
  * @returns A promise that resolves to a unique slug string.
1028
1047
  */
1029
1048
  createUniqueSlug(t) {
1030
- return l(this, arguments, function* ({ slug: e, field: r, isObject: s, haveHistory: c, filter: u }) {
1049
+ return a(this, arguments, function* ({ slug: e, field: r, isObject: s, haveHistory: n, filter: l }) {
1031
1050
  if (!e || typeof e != "string")
1032
1051
  throw new Error("Invalid slug provided: must be a non-empty string");
1033
- const o = $(e);
1052
+ const c = I(e);
1034
1053
  if (!(yield this.model.exists(
1035
- this.createSlugQuery({ slug: o, field: r, isObject: s, haveHistory: c, filter: u })
1054
+ this.createSlugQuery({ slug: c, field: r, isObject: s, haveHistory: n, filter: l })
1036
1055
  )))
1037
- return o;
1038
- for (let h = 1; h <= X; h++) {
1039
- const m = `${o}-${h}`;
1056
+ return c;
1057
+ for (let h = 1; h <= J; h++) {
1058
+ const m = `${c}-${h}`;
1040
1059
  if (!(yield this.model.exists(
1041
- this.createSlugQuery({ slug: m, field: r, isObject: s, haveHistory: c, filter: u })
1060
+ this.createSlugQuery({ slug: m, field: r, isObject: s, haveHistory: n, filter: l })
1042
1061
  )))
1043
1062
  return m;
1044
1063
  }
1045
- const a = Date.now(), f = Math.random().toString(36).substring(2, 8);
1046
- return `${o}-${a}-${f}`;
1064
+ const i = Date.now(), d = Math.random().toString(36).substring(2, 8);
1065
+ return `${c}-${i}-${d}`;
1047
1066
  });
1048
1067
  }
1049
1068
  /**
@@ -1058,31 +1077,31 @@ class we {
1058
1077
  * @returns A promise that resolves to a standardized response with the created slug(s).
1059
1078
  */
1060
1079
  createSlug(t) {
1061
- return l(this, arguments, function* ({ field: e, from: r, filter: s, haveHistory: c }) {
1080
+ return a(this, arguments, function* ({ field: e, from: r, filter: s, haveHistory: n }) {
1062
1081
  try {
1063
- const u = r[e];
1064
- return G(u) ? { success: !0, result: Object.fromEntries(
1082
+ const l = r[e];
1083
+ return T(l) ? { success: !0, result: Object.fromEntries(
1065
1084
  yield Promise.all(
1066
- Object.entries(u).map((f) => l(this, [f], function* ([h, m]) {
1067
- const p = yield this.createUniqueSlug({
1085
+ Object.entries(l).map((d) => a(this, [d], function* ([h, m]) {
1086
+ const y = yield this.createUniqueSlug({
1068
1087
  slug: m,
1069
1088
  field: h,
1070
1089
  isObject: !0,
1071
- haveHistory: c,
1090
+ haveHistory: n,
1072
1091
  filter: s
1073
1092
  });
1074
- return [h, p];
1093
+ return [h, y];
1075
1094
  }))
1076
1095
  )
1077
1096
  ) } : { success: !0, result: yield this.createUniqueSlug({
1078
- slug: u,
1097
+ slug: l,
1079
1098
  field: e,
1080
1099
  isObject: !1,
1081
- haveHistory: c,
1100
+ haveHistory: n,
1082
1101
  filter: s
1083
1102
  }) };
1084
- } catch (u) {
1085
- return d(u);
1103
+ } catch (l) {
1104
+ return f(l);
1086
1105
  }
1087
1106
  });
1088
1107
  }
@@ -1099,32 +1118,32 @@ class we {
1099
1118
  * @returns A promise that resolves to a standardized response indicating whether the slug exists.
1100
1119
  */
1101
1120
  checkSlug(t) {
1102
- return l(this, arguments, function* ({ slug: e, field: r, from: s, filter: c, haveHistory: u }) {
1121
+ return a(this, arguments, function* ({ slug: e, field: r, from: s, filter: n, haveHistory: l }) {
1103
1122
  try {
1104
- const o = s[r];
1105
- if (G(o)) {
1106
- const m = Object.values(o).map((v) => $(v));
1123
+ const c = s[r];
1124
+ if (T(c)) {
1125
+ const m = Object.values(c).map((R) => I(R));
1107
1126
  return (yield Promise.all(
1108
1127
  m.map(
1109
- (v) => this.model.exists(this.createSlugQuery({
1110
- slug: v,
1128
+ (R) => this.model.exists(this.createSlugQuery({
1129
+ slug: R,
1111
1130
  field: r,
1112
1131
  isObject: !0,
1113
- haveHistory: u,
1114
- filter: c
1132
+ haveHistory: l,
1133
+ filter: n
1115
1134
  }))
1116
1135
  )
1117
- )).some((v) => v) ? { success: !0, result: !0 } : { success: !0, result: !1 };
1136
+ )).some((R) => R) ? { success: !0, result: !0 } : { success: !0, result: !1 };
1118
1137
  }
1119
- const a = $(e);
1138
+ const i = I(e);
1120
1139
  return { success: !0, result: (yield this.model.exists(this.createSlugQuery({
1121
- slug: a,
1140
+ slug: i,
1122
1141
  field: r,
1123
1142
  isObject: !1,
1124
- filter: c
1143
+ filter: n
1125
1144
  }))) !== null };
1126
- } catch (o) {
1127
- return d(o);
1145
+ } catch (c) {
1146
+ return f(c);
1128
1147
  }
1129
1148
  });
1130
1149
  }
@@ -1135,11 +1154,11 @@ class we {
1135
1154
  * @returns A promise that resolves to a standardized response with the aggregation results.
1136
1155
  */
1137
1156
  aggregate(t) {
1138
- return l(this, null, function* () {
1157
+ return a(this, null, function* () {
1139
1158
  try {
1140
1159
  return { success: !0, result: yield this.model.aggregate(t) };
1141
1160
  } catch (e) {
1142
- return d(e);
1161
+ return f(e);
1143
1162
  }
1144
1163
  });
1145
1164
  }
@@ -1152,17 +1171,17 @@ class we {
1152
1171
  * @returns A promise that resolves to a standardized response with the array of distinct values.
1153
1172
  */
1154
1173
  distinct(t) {
1155
- return l(this, arguments, function* (e, r = {}, s = {}) {
1174
+ return a(this, arguments, function* (e, r = {}, s = {}) {
1156
1175
  try {
1157
1176
  return { success: !0, result: yield this.model.distinct(e, r, s) };
1158
- } catch (c) {
1159
- return d(c);
1177
+ } catch (n) {
1178
+ return f(n);
1160
1179
  }
1161
1180
  });
1162
1181
  }
1163
1182
  }
1164
1183
  export {
1165
- xe as MongoController,
1166
- we as MongooseController,
1167
- w as mongo
1184
+ Ne as MongoController,
1185
+ Ve as MongooseController,
1186
+ x as mongo
1168
1187
  };