@cyberskill/shared 2.2.0 → 2.3.1

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