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