@cyberskill/shared 2.5.0 → 2.6.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,44 @@
1
- import { cloneDeep as B, isObject as $ } from "lodash-es";
1
+ import { cloneDeep as B, isObject as T } from "lodash-es";
2
2
  import K from "migrate-mongo";
3
3
  import { Document as W } from "mongoose";
4
4
  import Q from "mongoose-aggregate-paginate-v2";
5
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";
6
+ import { v4 as G } from "uuid";
7
+ import { getNestedValue as J, setNestedValue as X, normalizeMongoFilter as V } from "../../util/object/object.util.js";
8
+ import { regexSearchMapper as Y } from "../../util/common/common.util.js";
9
+ import { writeFileSync as q, pathExistsSync as Z, readFileSync as ee, appendFileSync as te } from "../fs/fs.util.js";
10
+ import { PATH as F, MIGRATE_MONGO_CONFIG as L } from "../path/path.constant.js";
11
+ import { validate as re } from "../../util/validate/validate.util.js";
12
+ import { generateShortId as se, generateSlug as j } from "../../util/string/string.util.js";
13
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, 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) => {
14
+ import { catchError as f } from "../log/log.util.js";
15
+ var ne = Object.defineProperty, ce = Object.defineProperties, ue = Object.getOwnPropertyDescriptors, U = Object.getOwnPropertySymbols, ie = Object.prototype.hasOwnProperty, oe = Object.prototype.propertyIsEnumerable, $ = (n, t, e) => t in n ? ne(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, S = (n, t) => {
16
16
  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) => {
17
+ ie.call(t, e) && $(n, e, t[e]);
18
+ if (U)
19
+ for (var e of U(t))
20
+ oe.call(t, e) && $(n, e, t[e]);
21
+ return n;
22
+ }, w = (n, t) => ce(n, ue(t)), le = (n, t, e) => $(n, typeof t != "symbol" ? t + "" : t, e), l = (n, t, e) => new Promise((r, s) => {
23
+ var c = (i) => {
24
24
  try {
25
25
  o(e.next(i));
26
26
  } catch (a) {
27
- n(a);
27
+ s(a);
28
28
  }
29
- }, c = (i) => {
29
+ }, u = (i) => {
30
30
  try {
31
31
  o(e.throw(i));
32
32
  } catch (a) {
33
- n(a);
33
+ s(a);
34
34
  }
35
- }, o = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(u, c);
36
- o((e = e.apply(s, t)).next());
35
+ }, o = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(c, u);
36
+ o((e = e.apply(n, t)).next());
37
37
  });
38
- function le(s) {
39
- return s === s.toUpperCase() ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : s;
38
+ function ae(n) {
39
+ return n === n.toUpperCase() ? n.charAt(0).toUpperCase() + n.slice(1).toLowerCase() : n;
40
40
  }
41
- const V = {
41
+ const b = {
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 V = {
48
48
  */
49
49
  createGenericFields() {
50
50
  return {
51
- id: T(),
51
+ id: G(),
52
52
  isDel: !1,
53
53
  createdAt: /* @__PURE__ */ new Date(),
54
54
  updatedAt: /* @__PURE__ */ new Date()
@@ -62,8 +62,8 @@ const V = {
62
62
  * @param schema - The Mongoose schema to apply plugins to.
63
63
  * @param plugins - An array of plugin functions or false values to filter and apply.
64
64
  */
65
- applyPlugins(s, t) {
66
- t.filter((e) => typeof e == "function").forEach((e) => s.plugin(e));
65
+ applyPlugins(n, t) {
66
+ t.filter((e) => typeof e == "function").forEach((e) => n.plugin(e));
67
67
  },
68
68
  /**
69
69
  * Applies middleware functions to a Mongoose schema.
@@ -72,9 +72,9 @@ const V = {
72
72
  * @param schema - The Mongoose schema to apply middleware to.
73
73
  * @param middlewares - An array of middleware configurations with method, pre, and post functions.
74
74
  */
75
- applyMiddlewares(s, t) {
76
- t.forEach(({ method: e, pre: r, post: n }) => {
77
- e && r && s.pre(e, r), e && n && s.post(e, n);
75
+ applyMiddlewares(n, t) {
76
+ t.forEach(({ method: e, pre: r, post: s }) => {
77
+ e && r && n.pre(e, r), e && s && n.post(e, s);
78
78
  });
79
79
  },
80
80
  /**
@@ -85,10 +85,10 @@ const V = {
85
85
  * @param mongoose - The Mongoose instance to create the schema with.
86
86
  * @returns A Mongoose schema with generic document fields.
87
87
  */
88
- createGenericSchema(s) {
89
- return new s.Schema(
88
+ createGenericSchema(n) {
89
+ return new n.Schema(
90
90
  {
91
- id: { type: String, default: T, unique: !0 },
91
+ id: { type: String, default: G, unique: !0 },
92
92
  isDel: { type: Boolean, default: !1 }
93
93
  },
94
94
  { timestamps: !0 }
@@ -107,34 +107,34 @@ const V = {
107
107
  * @returns A configured Mongoose schema.
108
108
  */
109
109
  createSchema({
110
- mongoose: s,
110
+ mongoose: n,
111
111
  schema: t,
112
112
  virtuals: e = [],
113
113
  standalone: r = !1
114
114
  }) {
115
- const n = new s.Schema(t, {
115
+ const s = new n.Schema(t, {
116
116
  toJSON: { virtuals: !0 },
117
117
  // So `res.json()` and other `JSON.stringify()` functions include virtuals
118
118
  toObject: { virtuals: !0 }
119
119
  // So `console.log()` and other functions that use `toObject()` include virtuals
120
120
  });
121
- return e.forEach(({ name: u, options: c, get: o }) => {
122
- if (V.isDynamicVirtual(c)) {
123
- const i = n.statics;
121
+ return e.forEach(({ name: c, options: u, get: o }) => {
122
+ if (b.isDynamicVirtual(u)) {
123
+ const i = s.statics;
124
124
  i._dynamicVirtuals || (i._dynamicVirtuals = []), i._dynamicVirtuals.push({
125
- name: u,
126
- options: c
125
+ name: c,
126
+ options: u
127
127
  });
128
- const a = n.virtual(u);
128
+ const a = s.virtual(c);
129
129
  o ? a.get(o) : 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 : []);
130
+ var d;
131
+ return ((d = this._populated) == null ? void 0 : d[c]) || (u != null && u.count ? 0 : u != null && u.justOne ? null : []);
132
132
  });
133
133
  } else {
134
- const i = n.virtual(u, c);
134
+ const i = s.virtual(c, u);
135
135
  o && i.get(o);
136
136
  }
137
- }), r || n.add(V.createGenericSchema(s)), n;
137
+ }), r || s.add(b.createGenericSchema(n)), s;
138
138
  },
139
139
  /**
140
140
  * Creates a Mongoose model with plugins, middleware, and pagination support.
@@ -153,23 +153,23 @@ const V = {
153
153
  * @throws {Error} When the model name is not provided.
154
154
  */
155
155
  createModel({
156
- mongoose: s,
156
+ mongoose: n,
157
157
  name: t,
158
158
  schema: e,
159
159
  virtuals: r = [],
160
- pagination: n = !0,
161
- aggregate: u = !0,
162
- middlewares: c = []
160
+ pagination: s = !0,
161
+ aggregate: c = !0,
162
+ middlewares: u = []
163
163
  }) {
164
164
  if (!t)
165
165
  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);
166
+ if (n.models[t])
167
+ return n.models[t];
168
+ const o = b.createSchema({ mongoose: n, schema: e, virtuals: r });
169
+ return (s || c) && b.applyPlugins(o, [
170
+ s && H,
171
+ c && Q
172
+ ]), b.applyMiddlewares(o, u), n.model(t, o);
173
173
  },
174
174
  /**
175
175
  * Validation utilities for Mongoose schemas.
@@ -184,9 +184,9 @@ const V = {
184
184
  * @returns A validation function that returns true if the field is not empty.
185
185
  */
186
186
  isRequired() {
187
- return function(s) {
187
+ return function(n) {
188
188
  return l(this, null, function* () {
189
- return !te.isEmpty(s);
189
+ return !re.isEmpty(n);
190
190
  });
191
191
  };
192
192
  },
@@ -199,12 +199,12 @@ const V = {
199
199
  * @returns A validation function that returns true if the value is unique across the specified fields.
200
200
  * @throws {Error} When fields is not a non-empty array of strings.
201
201
  */
202
- isUnique(s) {
202
+ isUnique(n) {
203
203
  return function(t) {
204
204
  return l(this, null, function* () {
205
- if (!Array.isArray(s) || s.length === 0)
205
+ if (!Array.isArray(n) || n.length === 0)
206
206
  throw new Error("Fields must be a non-empty array of strings.");
207
- const e = { $or: s.map((n) => ({ [n]: t })) };
207
+ const e = { $or: n.map((s) => ({ [s]: t })) };
208
208
  return !(yield this.constructor.exists(e));
209
209
  });
210
210
  };
@@ -218,12 +218,12 @@ const V = {
218
218
  * @returns A validation function that returns true if the value matches all regex patterns.
219
219
  * @throws {Error} When regexArray is not an array of valid RegExp objects.
220
220
  */
221
- matchesRegex(s) {
221
+ matchesRegex(n) {
222
222
  return function(t) {
223
223
  return l(this, null, function* () {
224
- if (!Array.isArray(s) || s.some((e) => !(e instanceof RegExp)))
224
+ if (!Array.isArray(n) || n.some((e) => !(e instanceof RegExp)))
225
225
  throw new Error("regexArray must be an array of valid RegExp objects.");
226
- return s.every((e) => e.test(t));
226
+ return n.every((e) => e.test(t));
227
227
  });
228
228
  };
229
229
  }
@@ -240,15 +240,15 @@ const V = {
240
240
  *
241
241
  * @param options - Migration configuration options to write to the config file.
242
242
  */
243
- setConfig: (s) => {
243
+ setConfig: (n) => {
244
244
  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);
245
+ module.exports = ${JSON.stringify(n, null, 4)}`;
246
+ q(F.MIGRATE_MONGO_CONFIG, t);
247
247
  const e = `
248
- ${q}
248
+ ${L}
249
249
  `;
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);
250
+ Z(F.GIT_IGNORE) ? ee(F.GIT_IGNORE, "utf-8").split(`
251
+ `).includes(L) || te(F.GIT_IGNORE, e) : q(F.GIT_IGNORE, e);
252
252
  }
253
253
  }),
254
254
  /**
@@ -260,20 +260,20 @@ ${q}
260
260
  * @param fields - An array of field names to convert to regex patterns.
261
261
  * @returns A new filter object with string values converted to regex patterns.
262
262
  */
263
- regexify(s, t) {
264
- if (!s)
263
+ regexify(n, t) {
264
+ if (!n)
265
265
  return {};
266
- let e = B(s);
266
+ let e = B(n);
267
267
  if (!t || t.length === 0)
268
268
  return e;
269
269
  for (const r of t) {
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)}.*`,
270
+ const s = r.toString().split("."), c = J(e, s);
271
+ if (typeof c == "string" && c.length > 0) {
272
+ const u = {
273
+ $regex: `.*${Y(c)}.*`,
274
274
  $options: "i"
275
275
  };
276
- e = z(e, n, c);
276
+ e = X(e, s, u);
277
277
  }
278
278
  }
279
279
  return e;
@@ -284,8 +284,8 @@ ${q}
284
284
  * @param options - The virtual options to check.
285
285
  * @returns True if the options contain a dynamic ref function.
286
286
  */
287
- isDynamicVirtual(s) {
288
- return !!(s && typeof s.ref == "function");
287
+ isDynamicVirtual(n) {
288
+ return !!(n && typeof n.ref == "function");
289
289
  },
290
290
  /**
291
291
  * Generic utility function to get new records from the database
@@ -294,12 +294,12 @@ ${q}
294
294
  * @param filterFn - Function to determine if a record already exists
295
295
  * @returns Array of records that don't exist in the database
296
296
  */
297
- getNewRecords(s, t, e) {
297
+ getNewRecords(n, t, e) {
298
298
  return l(this, null, function* () {
299
- const r = yield s.findAll({});
299
+ const r = yield n.findAll({});
300
300
  return r.success ? t.filter(
301
- (u) => !r.result.some(
302
- (c) => e(c, u)
301
+ (c) => !r.result.some(
302
+ (u) => e(u, c)
303
303
  )
304
304
  ) : t;
305
305
  });
@@ -311,68 +311,68 @@ ${q}
311
311
  * @param filterFn - Function to determine if a record exists
312
312
  * @returns Array of existing records that match the filter criteria
313
313
  */
314
- getExistingRecords(s, t, e) {
314
+ getExistingRecords(n, t, e) {
315
315
  return l(this, null, function* () {
316
- const r = yield s.findAll({});
316
+ const r = yield n.findAll({});
317
317
  return r.success ? r.result.filter(
318
- (u) => t.some(
319
- (c) => e(u, c)
318
+ (c) => t.some(
319
+ (u) => e(c, u)
320
320
  )
321
321
  ) : [];
322
322
  });
323
323
  }
324
324
  };
325
- function ae(s) {
326
- return s !== null && typeof s == "object" && "toObject" in s && typeof s.toObject == "function";
325
+ function de(n) {
326
+ return n !== null && typeof n == "object" && "toObject" in n && typeof n.toObject == "function";
327
327
  }
328
- function F(s, t) {
329
- if (!s || !t || t.length === 0)
330
- return s;
328
+ function I(n, t) {
329
+ if (!n || !t || t.length === 0)
330
+ return n;
331
331
  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;
338
- return !e.has(u.path || u.populate || "");
332
+ if (Array.isArray(n)) {
333
+ const r = n.filter((s) => {
334
+ if (typeof s == "string")
335
+ return !e.has(s);
336
+ if (typeof s == "object" && s !== null) {
337
+ const c = s;
338
+ return !e.has(c.path || c.populate || "");
339
339
  }
340
340
  return !0;
341
341
  });
342
342
  return r.length > 0 ? r : void 0;
343
343
  }
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;
344
+ if (typeof n == "string")
345
+ return e.has(n) ? void 0 : n;
346
+ if (typeof n == "object" && n !== null) {
347
+ const r = n, s = r.path || r.populate || "";
348
+ return e.has(s) ? void 0 : n;
349
349
  }
350
- return s;
350
+ return n;
351
351
  }
352
- function de(s, t, e) {
353
- if (!s.length || !t || !(e != null && e.ref))
352
+ function fe(n, t, e) {
353
+ if (!n.length || !t || !(e != null && e.ref))
354
354
  return [];
355
355
  const r = /* @__PURE__ */ new Map();
356
- return s.forEach((n) => {
356
+ return n.forEach((s) => {
357
357
  try {
358
- const u = e.ref(n);
359
- if (u == null)
358
+ const c = e.ref(s);
359
+ if (c == null)
360
360
  return;
361
- const c = typeof u == "string" ? u : String(u);
362
- if (c && c.trim() !== "") {
363
- const o = le(c);
364
- r.has(o) || r.set(o, []), r.get(o).push(n);
361
+ const u = typeof c == "string" ? c : String(c);
362
+ if (u && u.trim() !== "") {
363
+ const o = ae(u);
364
+ r.has(o) || r.set(o, []), r.get(o).push(s);
365
365
  }
366
- } catch (u) {
367
- d(new Error(`Dynamic ref function failed for virtual "${t}": ${u instanceof Error ? u.message : String(u)}`));
366
+ } catch (c) {
367
+ f(new Error(`Dynamic ref function failed for virtual "${t}": ${c instanceof Error ? c.message : String(c)}`));
368
368
  }
369
- }), Array.from(r.entries()).map(([n, u]) => ({ model: n, docs: u }));
369
+ }), Array.from(r.entries()).map(([s, c]) => ({ model: s, docs: c }));
370
370
  }
371
- function U(s, t, e, r, n) {
371
+ function z(n, t, e, r, s) {
372
372
  return l(this, null, function* () {
373
373
  if (!t.length || !e.length || !r)
374
374
  return t;
375
- const u = e.filter((i) => {
375
+ const c = e.filter((i) => {
376
376
  if (Array.isArray(r))
377
377
  return r.length > 0 && r.some((a) => typeof a == "string" ? a === i.name : a.path === i.name);
378
378
  if (typeof r == "string")
@@ -383,22 +383,22 @@ function U(s, t, e, r, n) {
383
383
  }
384
384
  return !1;
385
385
  });
386
- if (u.length === 0)
386
+ if (c.length === 0)
387
387
  return t;
388
- const c = B(t.map(
389
- (i) => ae(i) ? i.toObject() : i
388
+ const u = B(t.map(
389
+ (i) => de(i) ? i.toObject() : i
390
390
  ));
391
- c.forEach((i) => {
392
- u.forEach(({ name: a, options: f }) => {
391
+ u.forEach((i) => {
392
+ c.forEach(({ name: a, options: d }) => {
393
393
  if (!(a in i)) {
394
394
  const m = i;
395
- m[a] = f.count ? 0 : f.justOne ? null : [];
395
+ m[a] = d.count ? 0 : d.justOne ? null : [];
396
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);
400
+ for (const i of c) {
401
+ const { name: a, options: d } = i, m = fe(u, a, d);
402
402
  for (const p of m) {
403
403
  o.has(p.model) || o.set(p.model, {
404
404
  virtuals: [],
@@ -407,72 +407,72 @@ function U(s, t, e, r, n) {
407
407
  });
408
408
  const h = o.get(p.model);
409
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);
410
+ const M = h.localValueSets.get(a);
411
411
  p.docs.forEach((N) => {
412
- const M = N[f.localField];
413
- if (M != null) {
414
- const D = String(M);
415
- A.add(D);
412
+ const A = N[d.localField];
413
+ if (A != null) {
414
+ const D = String(A);
415
+ M.add(D);
416
416
  let _ = -1;
417
417
  const R = N;
418
- R.id !== void 0 ? _ = c.findIndex((b) => b.id === R.id) : R._id !== void 0 && (_ = c.findIndex((b) => {
418
+ R.id !== void 0 ? _ = u.findIndex((x) => x.id === R.id) : R._id !== void 0 && (_ = u.findIndex((x) => {
419
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));
420
+ return ((y = (O = x._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
421
  })), _ !== -1 && (h.docsByLocalValue.has(D) || h.docsByLocalValue.set(D, []), h.docsByLocalValue.get(D).push(_));
422
422
  }
423
423
  });
424
424
  }
425
425
  }
426
- return yield Promise.all(Array.from(o.entries()).map((i) => l(null, [i], function* ([a, f]) {
427
- const m = s.models[a];
426
+ return yield Promise.all(Array.from(o.entries()).map((i) => l(null, [i], function* ([a, d]) {
427
+ const m = n.models[a];
428
428
  if (!m)
429
429
  return;
430
430
  const p = /* @__PURE__ */ new Set();
431
- if (f.localValueSets.forEach((D) => {
431
+ if (d.localValueSets.forEach((D) => {
432
432
  D.forEach((_) => p.add(_));
433
433
  }), p.size === 0)
434
434
  return;
435
- const h = [...new Set(f.virtuals.map((D) => D.options.foreignField))], A = Array.from(p);
435
+ const h = [...new Set(d.virtuals.map((D) => D.options.foreignField))], M = Array.from(p);
436
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();
439
- for (const D of f.virtuals) {
440
- const { name: _, options: R } = D, b = M.filter((O) => {
437
+ h.length === 1 ? N = { [String(h[0])]: { $in: M } } : N = { $or: h.map((D) => ({ [D]: { $in: M } })) };
438
+ const A = yield m.find(N, s).lean();
439
+ for (const D of d.virtuals) {
440
+ const { name: _, options: R } = D, x = A.filter((O) => {
441
441
  const y = O[R.foreignField];
442
442
  return y != null && p.has(String(y));
443
443
  });
444
444
  if (R.count) {
445
445
  const O = /* @__PURE__ */ new Map();
446
- b.forEach((y) => {
446
+ x.forEach((y) => {
447
447
  var E;
448
448
  const g = (E = y[R.foreignField]) == null ? void 0 : E.toString();
449
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;
450
+ }), d.localValueSets.get(_).forEach((y) => {
451
+ const E = d.docsByLocalValue.get(y) || [], g = O.get(y) || 0;
452
452
  E.forEach((C) => {
453
- const P = c[C];
453
+ const P = u[C];
454
454
  P[_] === void 0 && (P[_] = g);
455
455
  });
456
456
  });
457
457
  } else {
458
458
  const O = /* @__PURE__ */ new Map();
459
- b.forEach((y) => {
459
+ x.forEach((y) => {
460
460
  var E;
461
461
  const g = (E = y[R.foreignField]) == null ? void 0 : E.toString();
462
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;
463
+ }), d.localValueSets.get(_).forEach((y) => {
464
+ const E = d.docsByLocalValue.get(y) || [], g = O.get(y) || [], C = R.justOne ? g[0] || null : g;
465
465
  E.forEach((P) => {
466
- const k = c[P];
466
+ const k = u[P];
467
467
  k[_] = C;
468
468
  });
469
469
  });
470
470
  }
471
471
  }
472
- }))), c;
472
+ }))), u;
473
473
  });
474
474
  }
475
- class Ve {
475
+ class be {
476
476
  /**
477
477
  * Creates a new MongoDB controller instance.
478
478
  *
@@ -480,7 +480,7 @@ class Ve {
480
480
  * @param collectionName - The name of the collection to operate on.
481
481
  */
482
482
  constructor(t, e) {
483
- oe(this, "collection"), this.collection = t.collection(e);
483
+ le(this, "collection"), this.collection = t.collection(e);
484
484
  }
485
485
  /**
486
486
  * Creates a single document in the collection.
@@ -492,7 +492,7 @@ class Ve {
492
492
  createOne(t) {
493
493
  return l(this, null, function* () {
494
494
  try {
495
- const e = S(S({}, V.createGenericFields()), t);
495
+ const e = S(S({}, b.createGenericFields()), t);
496
496
  return (yield this.collection.insertOne(e)).acknowledged ? {
497
497
  success: !0,
498
498
  message: "Document created successfully",
@@ -503,7 +503,7 @@ class Ve {
503
503
  code: v.INTERNAL_SERVER_ERROR.CODE
504
504
  };
505
505
  } catch (e) {
506
- return d(e);
506
+ return f(e);
507
507
  }
508
508
  });
509
509
  }
@@ -517,7 +517,7 @@ class Ve {
517
517
  createMany(t) {
518
518
  return l(this, null, function* () {
519
519
  try {
520
- const e = t.map((n) => S(S({}, V.createGenericFields()), n)), r = yield this.collection.insertMany(e);
520
+ const e = t.map((s) => S(S({}, b.createGenericFields()), s)), r = yield this.collection.insertMany(e);
521
521
  return r.insertedCount === 0 ? {
522
522
  success: !1,
523
523
  message: "No documents were inserted",
@@ -528,7 +528,7 @@ class Ve {
528
528
  result: e
529
529
  };
530
530
  } catch (e) {
531
- return d(e);
531
+ return f(e);
532
532
  }
533
533
  });
534
534
  }
@@ -544,7 +544,7 @@ class Ve {
544
544
  const e = yield this.collection.findOne(t);
545
545
  return e ? { success: !0, message: "Document found", result: e } : { success: !1, message: "Document not found", code: v.NOT_FOUND.CODE };
546
546
  } catch (e) {
547
- return d(e);
547
+ return f(e);
548
548
  }
549
549
  });
550
550
  }
@@ -563,7 +563,7 @@ class Ve {
563
563
  result: yield this.collection.find(t).toArray()
564
564
  };
565
565
  } catch (e) {
566
- return d(e);
566
+ return f(e);
567
567
  }
568
568
  });
569
569
  }
@@ -583,7 +583,7 @@ class Ve {
583
583
  result: e
584
584
  };
585
585
  } catch (e) {
586
- return d(e);
586
+ return f(e);
587
587
  }
588
588
  });
589
589
  }
@@ -610,7 +610,7 @@ class Ve {
610
610
  result: r
611
611
  };
612
612
  } catch (r) {
613
- return d(r);
613
+ return f(r);
614
614
  }
615
615
  });
616
616
  }
@@ -637,7 +637,7 @@ class Ve {
637
637
  result: r
638
638
  };
639
639
  } catch (r) {
640
- return d(r);
640
+ return f(r);
641
641
  }
642
642
  });
643
643
  }
@@ -661,7 +661,7 @@ class Ve {
661
661
  result: e
662
662
  };
663
663
  } catch (e) {
664
- return d(e);
664
+ return f(e);
665
665
  }
666
666
  });
667
667
  }
@@ -685,12 +685,12 @@ class Ve {
685
685
  result: e
686
686
  };
687
687
  } catch (e) {
688
- return d(e);
688
+ return f(e);
689
689
  }
690
690
  });
691
691
  }
692
692
  }
693
- class be {
693
+ class xe {
694
694
  /**
695
695
  * Creates a new Mongoose controller instance.
696
696
  *
@@ -726,8 +726,8 @@ class be {
726
726
  return l(this, null, function* () {
727
727
  const r = this.getDynamicVirtuals();
728
728
  if (r && r.length > 0) {
729
- const n = yield U(this.model.base, [t], r, e);
730
- return n && n[0] ? n[0] : t;
729
+ const s = yield z(this.model.base, [t], r, e);
730
+ return s && s[0] ? s[0] : t;
731
731
  }
732
732
  return t;
733
733
  });
@@ -742,7 +742,7 @@ class be {
742
742
  populateDynamicVirtualsForDocuments(t, e) {
743
743
  return l(this, null, function* () {
744
744
  const r = this.getDynamicVirtuals();
745
- return r && r.length > 0 && t.length > 0 ? yield U(this.model.base, t, r, e) : t;
745
+ return r && r.length > 0 && t.length > 0 ? yield z(this.model.base, t, r, e) : t;
746
746
  });
747
747
  }
748
748
  /**
@@ -756,18 +756,18 @@ class be {
756
756
  * @returns A promise that resolves to a standardized response with the found document.
757
757
  */
758
758
  findOne() {
759
- return l(this, arguments, function* (t = {}, e = {}, r = {}, n) {
759
+ return l(this, arguments, function* (t = {}, e = {}, r = {}, s) {
760
760
  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) } : {
761
+ const c = V(t), u = this.model.findOne(c, e, r), o = this.getDynamicVirtuals(), i = I(s, o);
762
+ i && u.populate(i);
763
+ const a = yield u.exec();
764
+ return a ? { success: !0, result: yield this.populateDynamicVirtualsForDocument(a, s) } : {
765
765
  success: !1,
766
766
  message: `No ${this.getModelName()} found.`,
767
767
  code: v.NOT_FOUND.CODE
768
768
  };
769
- } catch (u) {
770
- return d(u);
769
+ } catch (c) {
770
+ return f(c);
771
771
  }
772
772
  });
773
773
  }
@@ -782,14 +782,14 @@ class be {
782
782
  * @returns A promise that resolves to a standardized response with the found documents.
783
783
  */
784
784
  findAll() {
785
- return l(this, arguments, function* (t = {}, e = {}, r = {}, n) {
785
+ return l(this, arguments, function* (t = {}, e = {}, r = {}, s) {
786
786
  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) };
791
- } catch (u) {
792
- return d(u);
787
+ const c = V(t), u = this.model.find(c, e, r), o = this.getDynamicVirtuals(), i = I(s, o);
788
+ i && u.populate(i);
789
+ const a = yield u.exec();
790
+ return { success: !0, result: yield this.populateDynamicVirtualsForDocuments(a, s) };
791
+ } catch (c) {
792
+ return f(c);
793
793
  }
794
794
  });
795
795
  }
@@ -804,12 +804,12 @@ class be {
804
804
  findPaging() {
805
805
  return l(this, arguments, function* (t = {}, e = {}) {
806
806
  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 }) };
807
+ const r = V(t), s = this.getDynamicVirtuals(), c = S({}, e);
808
+ e.populate && (c.populate = I(e.populate, s));
809
+ const u = yield this.model.paginate(r, c), o = yield this.populateDynamicVirtualsForDocuments(u.docs, e.populate);
810
+ return { success: !0, result: w(S({}, u), { docs: o }) };
811
811
  } catch (r) {
812
- return d(r);
812
+ return f(r);
813
813
  }
814
814
  });
815
815
  }
@@ -823,15 +823,15 @@ class be {
823
823
  findPagingAggregate(t) {
824
824
  return l(this, arguments, function* (e, r = {}) {
825
825
  try {
826
- const n = this.getDynamicVirtuals(), u = S({}, r);
827
- r.populate && (u.populate = F(r.populate, n));
828
- const c = yield this.model.aggregatePaginate(
826
+ const s = this.getDynamicVirtuals(), c = S({}, r);
827
+ r.populate && (c.populate = I(r.populate, s));
828
+ const u = yield this.model.aggregatePaginate(
829
829
  this.model.aggregate(e),
830
- 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);
830
+ c
831
+ ), o = yield this.populateDynamicVirtualsForDocuments(u.docs, r.populate);
832
+ return { success: !0, result: w(S({}, u), { docs: o }) };
833
+ } catch (s) {
834
+ return f(s);
835
835
  }
836
836
  });
837
837
  }
@@ -844,9 +844,10 @@ class be {
844
844
  count() {
845
845
  return l(this, arguments, function* (t = {}) {
846
846
  try {
847
- return { success: !0, result: yield this.model.countDocuments(t) };
847
+ const e = V(t);
848
+ return { success: !0, result: yield this.model.countDocuments(e) };
848
849
  } catch (e) {
849
- return d(e);
850
+ return f(e);
850
851
  }
851
852
  });
852
853
  }
@@ -861,7 +862,7 @@ class be {
861
862
  try {
862
863
  return { success: !0, result: yield this.model.create(t) };
863
864
  } catch (e) {
864
- return d(e);
865
+ return f(e);
865
866
  }
866
867
  });
867
868
  }
@@ -875,9 +876,9 @@ class be {
875
876
  createMany(t) {
876
877
  return l(this, arguments, function* (e, r = {}) {
877
878
  try {
878
- 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);
879
+ return { success: !0, result: (yield this.model.insertMany(e, r)).map((u) => u instanceof W ? u.toObject() : null).filter((u) => u !== null) };
880
+ } catch (s) {
881
+ return f(s);
881
882
  }
882
883
  });
883
884
  }
@@ -892,16 +893,16 @@ class be {
892
893
  updateOne() {
893
894
  return l(this, arguments, function* (t = {}, e = {}, r = {}) {
894
895
  try {
895
- const n = yield this.model.findOneAndUpdate(t, e, S({
896
+ const s = V(t), c = yield this.model.findOneAndUpdate(s, e, S({
896
897
  new: !0
897
898
  }, r)).exec();
898
- return n ? { success: !0, result: n } : {
899
+ return c ? { success: !0, result: c } : {
899
900
  success: !1,
900
901
  message: `Failed to update ${this.getModelName()}.`,
901
902
  code: v.NOT_FOUND.CODE
902
903
  };
903
- } catch (n) {
904
- return d(n);
904
+ } catch (s) {
905
+ return f(s);
905
906
  }
906
907
  });
907
908
  }
@@ -916,9 +917,10 @@ class be {
916
917
  updateMany() {
917
918
  return l(this, arguments, function* (t = {}, e = {}, r = {}) {
918
919
  try {
919
- return { success: !0, result: yield this.model.updateMany(t, e, r).exec() };
920
- } catch (n) {
921
- return d(n);
920
+ const s = V(t);
921
+ return { success: !0, result: yield this.model.updateMany(s, e, r).exec() };
922
+ } catch (s) {
923
+ return f(s);
922
924
  }
923
925
  });
924
926
  }
@@ -932,14 +934,14 @@ class be {
932
934
  deleteOne() {
933
935
  return l(this, arguments, function* (t = {}, e = {}) {
934
936
  try {
935
- const r = yield this.model.findOneAndDelete(t, e).exec();
936
- return r ? { success: !0, result: r } : {
937
+ const r = V(t), s = yield this.model.findOneAndDelete(r, e).exec();
938
+ return s ? { success: !0, result: s } : {
937
939
  success: !1,
938
940
  message: `No ${this.getModelName()} found to delete.`,
939
941
  code: v.NOT_FOUND.CODE
940
942
  };
941
943
  } catch (r) {
942
- return d(r);
944
+ return f(r);
943
945
  }
944
946
  });
945
947
  }
@@ -953,14 +955,14 @@ class be {
953
955
  deleteMany() {
954
956
  return l(this, arguments, function* (t = {}, e = {}) {
955
957
  try {
956
- const r = yield this.model.deleteMany(t, e).exec();
957
- return r.deletedCount === 0 ? {
958
+ const r = V(t), s = yield this.model.deleteMany(r, e).exec();
959
+ return s.deletedCount === 0 ? {
958
960
  success: !1,
959
961
  message: "No documents found to delete.",
960
962
  code: v.NOT_FOUND.CODE
961
- } : { success: !0, result: r };
963
+ } : { success: !0, result: s };
962
964
  } catch (r) {
963
- return d(r);
965
+ return f(r);
964
966
  }
965
967
  });
966
968
  }
@@ -975,11 +977,11 @@ class be {
975
977
  createShortId(t, e = 4) {
976
978
  return l(this, null, function* () {
977
979
  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
+ const s = Array.from({ length: 10 }, (o, i) => se(t, i + e)), u = (yield Promise.all(
981
+ s.map((o) => this.model.exists({ shortId: o }))
980
982
  )).findIndex((o) => !o);
981
- if (c !== -1) {
982
- const o = n[c];
983
+ if (u !== -1) {
984
+ const o = s[u];
983
985
  if (o)
984
986
  return { success: !0, result: o };
985
987
  }
@@ -989,7 +991,7 @@ class be {
989
991
  code: v.INTERNAL_SERVER_ERROR.CODE
990
992
  };
991
993
  } catch (r) {
992
- return d(r);
994
+ return f(r);
993
995
  }
994
996
  });
995
997
  }
@@ -1004,14 +1006,14 @@ class be {
1004
1006
  * @param options.filter - Additional filter conditions to apply to the query.
1005
1007
  * @returns A MongoDB query object for checking slug existence.
1006
1008
  */
1007
- createSlugQuery({ slug: t, field: e, isObject: r, filter: n }) {
1008
- const u = S({}, n != null ? n : {});
1009
- return r ? w(S({}, u), {
1009
+ createSlugQuery({ slug: t, field: e, isObject: r, filter: s }) {
1010
+ const c = S({}, s != null ? s : {});
1011
+ return r ? w(S({}, c), {
1010
1012
  $or: [
1011
1013
  { [`slug.${e}`]: t },
1012
1014
  { slugHistory: { $elemMatch: { [`slug.${e}`]: t } } }
1013
1015
  ]
1014
- }) : w(S({}, u), {
1016
+ }) : w(S({}, c), {
1015
1017
  $or: [
1016
1018
  { slug: t },
1017
1019
  { slugHistory: t }
@@ -1030,18 +1032,18 @@ class be {
1030
1032
  * @returns A promise that resolves to a unique slug string.
1031
1033
  */
1032
1034
  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
+ return l(this, arguments, function* ({ slug: e, field: r, isObject: s, filter: c }) {
1036
+ const u = j(e), i = Array.from({ length: 100 }, (m, p) => p === 0 ? u : `${u}-${p}`), d = (yield Promise.all(
1035
1037
  i.map(
1036
- (m) => this.model.exists(this.createSlugQuery({ slug: m, field: r, isObject: n, filter: u }))
1038
+ (m) => this.model.exists(this.createSlugQuery({ slug: m, field: r, isObject: s, filter: c }))
1037
1039
  )
1038
1040
  )).findIndex((m) => !m);
1039
- if (f !== -1) {
1040
- const m = i[f];
1041
+ if (d !== -1) {
1042
+ const m = i[d];
1041
1043
  if (m)
1042
1044
  return m;
1043
1045
  }
1044
- return `${c}-${Date.now()}`;
1046
+ return `${u}-${Date.now()}`;
1045
1047
  });
1046
1048
  }
1047
1049
  /**
@@ -1055,29 +1057,29 @@ class be {
1055
1057
  * @returns A promise that resolves to a standardized response with the created slug(s).
1056
1058
  */
1057
1059
  createSlug(t) {
1058
- return l(this, arguments, function* ({ field: e, from: r, filter: n }) {
1060
+ return l(this, arguments, function* ({ field: e, from: r, filter: s }) {
1059
1061
  try {
1060
- const u = r[e];
1061
- return $(u) ? { success: !0, result: Object.fromEntries(
1062
+ const c = r[e];
1063
+ return T(c) ? { success: !0, result: Object.fromEntries(
1062
1064
  yield Promise.all(
1063
- Object.entries(u).map((a) => l(this, [a], function* ([f, m]) {
1065
+ Object.entries(c).map((a) => l(this, [a], function* ([d, m]) {
1064
1066
  const p = yield this.createUniqueSlug({
1065
1067
  slug: m,
1066
- field: f,
1068
+ field: d,
1067
1069
  isObject: !0,
1068
- filter: n
1070
+ filter: s
1069
1071
  });
1070
- return [f, p];
1072
+ return [d, p];
1071
1073
  }))
1072
1074
  )
1073
1075
  ) } : { success: !0, result: yield this.createUniqueSlug({
1074
- slug: u,
1076
+ slug: c,
1075
1077
  field: e,
1076
1078
  isObject: !1,
1077
- filter: n
1079
+ filter: s
1078
1080
  }) };
1079
- } catch (u) {
1080
- return d(u);
1081
+ } catch (c) {
1082
+ return f(c);
1081
1083
  }
1082
1084
  });
1083
1085
  }
@@ -1093,31 +1095,31 @@ class be {
1093
1095
  * @returns A promise that resolves to a standardized response indicating whether the slug exists.
1094
1096
  */
1095
1097
  checkSlug(t) {
1096
- return l(this, arguments, function* ({ slug: e, field: r, from: n, filter: u }) {
1098
+ return l(this, arguments, function* ({ slug: e, field: r, from: s, filter: c }) {
1097
1099
  try {
1098
- const c = n[r];
1099
- if ($(c)) {
1100
- const m = Object.values(c).map((h) => I(h));
1100
+ const u = s[r];
1101
+ if (T(u)) {
1102
+ const m = Object.values(u).map((h) => j(h));
1101
1103
  return (yield Promise.all(
1102
1104
  m.map(
1103
1105
  (h) => this.model.exists(this.createSlugQuery({
1104
1106
  slug: h,
1105
1107
  field: r,
1106
1108
  isObject: !0,
1107
- filter: u
1109
+ filter: c
1108
1110
  }))
1109
1111
  )
1110
1112
  )).some((h) => h) ? { success: !0, result: !0 } : { success: !0, result: !1 };
1111
1113
  }
1112
- const i = I(e);
1114
+ const i = j(e);
1113
1115
  return { success: !0, result: (yield this.model.exists(this.createSlugQuery({
1114
1116
  slug: i,
1115
1117
  field: r,
1116
1118
  isObject: !1,
1117
- filter: u
1119
+ filter: c
1118
1120
  }))) !== null };
1119
- } catch (c) {
1120
- return d(c);
1121
+ } catch (u) {
1122
+ return f(u);
1121
1123
  }
1122
1124
  });
1123
1125
  }
@@ -1132,13 +1134,13 @@ class be {
1132
1134
  try {
1133
1135
  return { success: !0, result: yield this.model.aggregate(t) };
1134
1136
  } catch (e) {
1135
- return d(e);
1137
+ return f(e);
1136
1138
  }
1137
1139
  });
1138
1140
  }
1139
1141
  }
1140
1142
  export {
1141
- Ve as MongoController,
1142
- be as MongooseController,
1143
- V as mongo
1143
+ be as MongoController,
1144
+ xe as MongooseController,
1145
+ b as mongo
1144
1146
  };