@cyberskill/shared 2.10.0 → 2.12.0

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