@cyberskill/shared 2.21.0 → 2.26.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.
Files changed (41) hide show
  1. package/dist/config/eslint/index.cjs +1 -1
  2. package/dist/config/eslint/index.d.ts +2 -7
  3. package/dist/config/eslint/index.js +1 -1
  4. package/dist/config/vitest/vitest.e2e.cjs +1 -1
  5. package/dist/config/vitest/vitest.e2e.js +1 -1
  6. package/dist/config/vitest/vitest.unit.cjs +1 -1
  7. package/dist/config/vitest/vitest.unit.js +1 -1
  8. package/dist/config/vitest/vitest.unit.setup.d.ts +0 -1
  9. package/dist/node/cli/index.cjs +4 -4
  10. package/dist/node/cli/index.js +56 -51
  11. package/dist/node/command/command.util.cjs +2 -2
  12. package/dist/node/command/command.util.d.ts +4 -1
  13. package/dist/node/command/command.util.js +125 -112
  14. package/dist/node/express/express.type.d.ts +2 -0
  15. package/dist/node/express/express.util.cjs +1 -1
  16. package/dist/node/express/express.util.js +53 -47
  17. package/dist/node/mongo/index.cjs +1 -1
  18. package/dist/node/mongo/index.d.ts +1 -0
  19. package/dist/node/mongo/index.js +15 -12
  20. package/dist/node/mongo/mongo.controller.cjs +1 -0
  21. package/dist/node/mongo/mongo.controller.d.ts +317 -0
  22. package/dist/node/mongo/mongo.controller.js +956 -0
  23. package/dist/node/mongo/mongo.type.d.ts +9 -10
  24. package/dist/node/mongo/mongo.util.cjs +5 -5
  25. package/dist/node/mongo/mongo.util.d.ts +26 -315
  26. package/dist/node/mongo/mongo.util.js +314 -1241
  27. package/dist/node/path/path.constant.cjs +1 -1
  28. package/dist/node/path/path.constant.d.ts +2 -2
  29. package/dist/node/path/path.constant.js +43 -43
  30. package/dist/util/common/common.util.cjs +1 -1
  31. package/dist/util/common/common.util.d.ts +3 -0
  32. package/dist/util/common/common.util.js +36 -35
  33. package/dist/util/object/object.util.cjs +1 -1
  34. package/dist/util/object/object.util.js +49 -45
  35. package/dist/util/validate/validate.util.cjs +1 -1
  36. package/dist/util/validate/validate.util.js +1 -1
  37. package/package.json +25 -24
  38. /package/dist/node/mongo/{mongo-controller.test.unit.d.ts → mongo.controller.test.unit.d.ts} +0 -0
  39. /package/dist/node/mongo/{mongo.test.unit.d.ts → mongo.util.test.unit.d.ts} +0 -0
  40. /package/dist/node_modules/.pnpm/{vitest@4.0.16_@types_node@25.0.3_jiti@2.6.1_jsdom@27.3.0_sass@1.97.0_tsx@4.21.0_yaml@2.8.2 → vitest@4.0.16_@types_node@25.0.3_jiti@2.6.1_jsdom@27.4.0_sass@1.97.2_tsx@4.21.0_yaml@2.8.2}/node_modules/vitest/dist/config.cjs +0 -0
  41. /package/dist/node_modules/.pnpm/{vitest@4.0.16_@types_node@25.0.3_jiti@2.6.1_jsdom@27.3.0_sass@1.97.0_tsx@4.21.0_yaml@2.8.2 → vitest@4.0.16_@types_node@25.0.3_jiti@2.6.1_jsdom@27.4.0_sass@1.97.2_tsx@4.21.0_yaml@2.8.2}/node_modules/vitest/dist/config.js +0 -0
@@ -1,46 +1,39 @@
1
- import { randomUUID as z } from "node:crypto";
2
- import Y from "migrate-mongo";
3
- import Z from "mongoose-aggregate-paginate-v2";
4
- import tt from "mongoose-paginate-v2";
5
- import { MONGO_SLUG_MAX_ATTEMPTS as et } from "./mongo.constant.js";
6
- import { deepClone as J, getNestedValue as rt, setNestedValue as st, normalizeMongoFilter as F } from "../../util/object/object.util.js";
7
- import { regexSearchMapper as nt } from "../../util/common/common.util.js";
8
- import { writeFileSync as W, pathExistsSync as it, readFileSync as ot, appendFileSync as lt } from "../fs/fs.util.js";
9
- import { PATH as I, MIGRATE_MONGO_CONFIG as k } from "../path/path.constant.js";
10
- import { validate as ct } from "../../util/validate/validate.util.js";
11
- import { generateShortId as ut, generateSlug as G } from "../../util/string/string.util.js";
12
- import { RESPONSE_STATUS as A } from "../../constant/response-status.js";
13
- import { catchError as D } from "../log/log.util.js";
14
- var at = Object.defineProperty, ft = Object.defineProperties, dt = Object.getOwnPropertyDescriptors, B = Object.getOwnPropertySymbols, pt = Object.prototype.hasOwnProperty, mt = Object.prototype.propertyIsEnumerable, q = (n, e, t) => e in n ? at(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, N = (n, e) => {
15
- for (var t in e || (e = {}))
16
- pt.call(e, t) && q(n, t, e[t]);
17
- if (B)
18
- for (var t of B(e))
19
- mt.call(e, t) && q(n, t, e[t]);
20
- return n;
21
- }, $ = (n, e) => ft(n, dt(e)), ht = (n, e, t) => q(n, typeof e != "symbol" ? e + "" : e, t), v = (n, e, t) => new Promise((r, s) => {
22
- var i = (c) => {
1
+ import U from "migrate-mongo";
2
+ import q from "mongoose-aggregate-paginate-v2";
3
+ import B from "mongoose-paginate-v2";
4
+ import { randomUUID as x } from "node:crypto";
5
+ import { deepClone as J, getNestedValue as K, setNestedValue as L } from "../../util/object/object.util.js";
6
+ import { regexSearchMapper as H } from "../../util/common/common.util.js";
7
+ import { writeFileSync as G, pathExistsSync as T, readFileSync as z, appendFileSync as Q } from "../fs/fs.util.js";
8
+ import { PATH as A, MIGRATE_MONGO_CONFIG as V } from "../path/path.constant.js";
9
+ import { validate as W } from "../../util/validate/validate.util.js";
10
+ var X = Object.defineProperty, Y = Object.defineProperties, Z = Object.getOwnPropertyDescriptors, $ = Object.getOwnPropertySymbols, M = Object.prototype.hasOwnProperty, tt = Object.prototype.propertyIsEnumerable, D = (t, i, e) => i in t ? X(t, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[i] = e, et = (t, i) => {
11
+ for (var e in i || (i = {}))
12
+ M.call(i, e) && D(t, e, i[e]);
13
+ if ($)
14
+ for (var e of $(i))
15
+ tt.call(i, e) && D(t, e, i[e]);
16
+ return t;
17
+ }, it = (t, i) => Y(t, Z(i)), S = (t, i, e) => new Promise((o, r) => {
18
+ var n = (s) => {
23
19
  try {
24
- l(t.next(c));
25
- } catch (a) {
26
- s(a);
20
+ y(e.next(s));
21
+ } catch (h) {
22
+ r(h);
27
23
  }
28
- }, o = (c) => {
24
+ }, l = (s) => {
29
25
  try {
30
- l(t.throw(c));
31
- } catch (a) {
32
- s(a);
26
+ y(e.throw(s));
27
+ } catch (h) {
28
+ r(h);
33
29
  }
34
- }, l = (c) => c.done ? r(c.value) : Promise.resolve(c.value).then(i, o);
35
- l((t = t.apply(n, e)).next());
30
+ }, y = (s) => s.done ? o(s.value) : Promise.resolve(s.value).then(n, l);
31
+ y((e = e.apply(t, i)).next());
36
32
  });
37
- function K(n) {
38
- return n != null && typeof n == "object";
33
+ function E(t) {
34
+ return t === t.toUpperCase() ? t.charAt(0).toUpperCase() + t.slice(1).toLowerCase() : t;
39
35
  }
40
- function w(n) {
41
- return n === n.toUpperCase() ? n.charAt(0).toUpperCase() + n.slice(1).toLowerCase() : n;
42
- }
43
- const x = {
36
+ const I = {
44
37
  /**
45
38
  * Creates generic fields that are commonly used across MongoDB documents.
46
39
  * This function generates standard fields including a UUID, deletion flag, and timestamps
@@ -50,7 +43,7 @@ const x = {
50
43
  */
51
44
  createGenericFields() {
52
45
  return {
53
- id: z(),
46
+ id: x(),
54
47
  isDel: !1,
55
48
  createdAt: /* @__PURE__ */ new Date(),
56
49
  updatedAt: /* @__PURE__ */ new Date()
@@ -64,8 +57,8 @@ const x = {
64
57
  * @param schema - The Mongoose schema to apply plugins to.
65
58
  * @param plugins - An array of plugin functions or false values to filter and apply.
66
59
  */
67
- applyPlugins(n, e) {
68
- e.filter((t) => typeof t == "function").forEach((t) => n.plugin(t));
60
+ applyPlugins(t, i) {
61
+ i.filter((e) => typeof e == "function").forEach((e) => t.plugin(e));
69
62
  },
70
63
  /**
71
64
  * Applies middleware functions to a Mongoose schema.
@@ -74,9 +67,9 @@ const x = {
74
67
  * @param schema - The Mongoose schema to apply middleware to.
75
68
  * @param middlewares - An array of middleware configurations with method, pre, and post functions.
76
69
  */
77
- applyMiddlewares(n, e) {
78
- e.forEach(({ method: t, pre: r, post: s }) => {
79
- t && r && n.pre(t, r), t && s && n.post(t, s);
70
+ applyMiddlewares(t, i) {
71
+ i.forEach(({ method: e, pre: o, post: r }) => {
72
+ e && o && t.pre(e, o), e && r && t.post(e, r);
80
73
  });
81
74
  },
82
75
  /**
@@ -87,10 +80,10 @@ const x = {
87
80
  * @param mongoose - The Mongoose instance to create the schema with.
88
81
  * @returns A Mongoose schema with generic document fields.
89
82
  */
90
- createGenericSchema(n) {
91
- return new n.Schema(
83
+ createGenericSchema(t) {
84
+ return new t.Schema(
92
85
  {
93
- id: { type: String, default: () => z(), unique: !0 },
86
+ id: { type: String, default: () => x(), unique: !0 },
94
87
  isDel: { type: Boolean, default: !1 }
95
88
  },
96
89
  { timestamps: !0 }
@@ -109,34 +102,34 @@ const x = {
109
102
  * @returns A configured Mongoose schema.
110
103
  */
111
104
  createSchema({
112
- mongoose: n,
113
- schema: e,
114
- virtuals: t = [],
115
- standalone: r = !1
105
+ mongoose: t,
106
+ schema: i,
107
+ virtuals: e = [],
108
+ standalone: o = !1
116
109
  }) {
117
- const s = new n.Schema(e, {
110
+ const r = new t.Schema(i, {
118
111
  toJSON: { virtuals: !0 },
119
112
  // So `res.json()` and other `JSON.stringify()` functions include virtuals
120
113
  toObject: { virtuals: !0 }
121
114
  // So `console.log()` and other functions that use `toObject()` include virtuals
122
115
  });
123
- return t.forEach(({ name: i, options: o, get: l }) => {
124
- if (x.isDynamicVirtual(o)) {
125
- const c = s.statics;
126
- c._dynamicVirtuals || (c._dynamicVirtuals = []), c._dynamicVirtuals.push({
127
- name: i,
128
- options: o
116
+ return e.forEach(({ name: n, options: l, get: y }) => {
117
+ if (I.isDynamicVirtual(l)) {
118
+ const s = r.statics;
119
+ s._dynamicVirtuals || (s._dynamicVirtuals = []), s._dynamicVirtuals.push({
120
+ name: n,
121
+ options: l
129
122
  });
130
- const a = s.virtual(i);
131
- l ? a.get(l) : a.get(function() {
123
+ const h = r.virtual(n);
124
+ y ? h.get(y) : h.get(function() {
132
125
  var u;
133
- return ((u = this._populated) == null ? void 0 : u[i]) || (o != null && o.count ? 0 : o != null && o.justOne ? null : []);
126
+ return ((u = this._populated) == null ? void 0 : u[n]) || (l != null && l.count ? 0 : l != null && l.justOne ? null : []);
134
127
  });
135
128
  } else {
136
- const c = s.virtual(i, o);
137
- l && c.get(l);
129
+ const s = r.virtual(n, l);
130
+ y && s.get(y);
138
131
  }
139
- }), r || s.add(x.createGenericSchema(n)), s;
132
+ }), o || r.add(I.createGenericSchema(t)), r;
140
133
  },
141
134
  /**
142
135
  * Creates a Mongoose model with plugins, middleware, and pagination support.
@@ -155,25 +148,25 @@ const x = {
155
148
  * @throws {Error} When the model name is not provided.
156
149
  */
157
150
  createModel({
158
- mongoose: n,
159
- name: e,
160
- schema: t,
161
- virtuals: r = [],
162
- pagination: s = !0,
163
- aggregate: i = !0,
164
- middlewares: o = []
151
+ mongoose: t,
152
+ name: i,
153
+ schema: e,
154
+ virtuals: o = [],
155
+ pagination: r = !0,
156
+ aggregate: n = !0,
157
+ middlewares: l = []
165
158
  }) {
166
- if (!e)
159
+ if (!i)
167
160
  throw new Error("Model name is required.");
168
- if (n.models[e])
169
- return n.models[e];
170
- const l = x.createSchema({ mongoose: n, schema: t, virtuals: r });
171
- (s || i) && x.applyPlugins(l, [
172
- s && tt,
173
- i && Z
174
- ]), x.applyMiddlewares(l, o);
175
- const c = n.model(e, l);
176
- return r.length > 0 && (c._virtualConfigs = r), c;
161
+ if (t.models[i])
162
+ return t.models[i];
163
+ const y = I.createSchema({ mongoose: t, schema: e, virtuals: o });
164
+ (r || n) && I.applyPlugins(y, [
165
+ r && B,
166
+ n && q
167
+ ]), I.applyMiddlewares(y, l);
168
+ const s = t.model(i, y);
169
+ return o.length > 0 && (s._virtualConfigs = o), s;
177
170
  },
178
171
  /**
179
172
  * Validation utilities for Mongoose schemas.
@@ -188,9 +181,9 @@ const x = {
188
181
  * @returns A validation function that returns true if the field is not empty.
189
182
  */
190
183
  isRequired() {
191
- return function(n) {
192
- return v(this, null, function* () {
193
- return !ct.isEmpty(n);
184
+ return function(t) {
185
+ return S(this, null, function* () {
186
+ return !W.isEmpty(t);
194
187
  });
195
188
  };
196
189
  },
@@ -203,13 +196,13 @@ const x = {
203
196
  * @returns A validation function that returns true if the value is unique across the specified fields.
204
197
  * @throws {Error} When fields is not a non-empty array of strings.
205
198
  */
206
- isUnique(n) {
207
- return function(e) {
208
- return v(this, null, function* () {
209
- if (!Array.isArray(n) || n.length === 0)
199
+ isUnique(t) {
200
+ return function(i) {
201
+ return S(this, null, function* () {
202
+ if (!Array.isArray(t) || t.length === 0)
210
203
  throw new Error("Fields must be a non-empty array of strings.");
211
- const t = { $or: n.map((s) => ({ [s]: e })) };
212
- return !(yield this.constructor.exists(t));
204
+ const e = { $or: t.map((r) => ({ [r]: i })) };
205
+ return !(yield this.constructor.exists(e));
213
206
  });
214
207
  };
215
208
  },
@@ -222,11 +215,11 @@ const x = {
222
215
  * @returns A validation function that returns true if the value matches all regex patterns.
223
216
  * @throws {Error} When regexArray is not an array of valid RegExp objects.
224
217
  */
225
- matchesRegex(n) {
226
- return (e) => v(null, null, function* () {
227
- if (!Array.isArray(n) || n.some((t) => !(t instanceof RegExp)))
218
+ matchesRegex(t) {
219
+ return (i) => S(null, null, function* () {
220
+ if (!Array.isArray(t) || t.some((e) => !(e instanceof RegExp)))
228
221
  throw new Error("regexArray must be an array of valid RegExp objects.");
229
- return n.every((t) => t.test(e));
222
+ return t.every((e) => e.test(i));
230
223
  });
231
224
  }
232
225
  },
@@ -234,7 +227,7 @@ const x = {
234
227
  * Migration utilities for MongoDB.
235
228
  * This object extends the migrate-mongo library with additional configuration utilities.
236
229
  */
237
- migrate: $(N({}, Y), {
230
+ migrate: it(et({}, U), {
238
231
  /**
239
232
  * Sets the migration configuration and updates .gitignore.
240
233
  * This function creates a migration configuration file and ensures it's properly
@@ -242,15 +235,15 @@ const x = {
242
235
  *
243
236
  * @param options - Migration configuration options to write to the config file.
244
237
  */
245
- setConfig: (n) => {
246
- const e = `// This file is automatically generated by the Cyberskill CLI.
247
- module.exports = ${JSON.stringify(n, null, 4)}`;
248
- W(I.MIGRATE_MONGO_CONFIG, e);
249
- const t = `
250
- ${k}
238
+ setConfig: (t) => {
239
+ const i = `// This file is automatically generated by the Cyberskill CLI.
240
+ module.exports = ${JSON.stringify(t, null, 4)}`;
241
+ G(A.MIGRATE_MONGO_CONFIG, i);
242
+ const e = `
243
+ ${V}
251
244
  `;
252
- it(I.GIT_IGNORE) ? ot(I.GIT_IGNORE, "utf-8").split(`
253
- `).includes(k) || lt(I.GIT_IGNORE, t) : W(I.GIT_IGNORE, t);
245
+ T(A.GIT_IGNORE) ? z(A.GIT_IGNORE, "utf-8").split(`
246
+ `).includes(V) || Q(A.GIT_IGNORE, e) : G(A.GIT_IGNORE, e);
254
247
  }
255
248
  }),
256
249
  /**
@@ -262,23 +255,23 @@ ${k}
262
255
  * @param fields - An array of field names to convert to regex patterns.
263
256
  * @returns A new filter object with string values converted to regex patterns.
264
257
  */
265
- regexify(n, e) {
266
- if (!n)
258
+ regexify(t, i) {
259
+ if (!t)
267
260
  return {};
268
- let t = J(n);
269
- if (!e || e.length === 0)
270
- return t;
271
- for (const r of e) {
272
- const s = r.toString().split("."), i = rt(t, s);
273
- if (typeof i == "string" && i.length > 0) {
274
- const o = {
275
- $regex: `.*${nt(i)}.*`,
261
+ let e = J(t);
262
+ if (!i || i.length === 0)
263
+ return e;
264
+ for (const o of i) {
265
+ const r = o.toString().split("."), n = K(e, r);
266
+ if (typeof n == "string" && n.length > 0) {
267
+ const l = {
268
+ $regex: `.*${H(n)}.*`,
276
269
  $options: "i"
277
270
  };
278
- t = st(t, s, o);
271
+ e = L(e, r, l);
279
272
  }
280
273
  }
281
- return t;
274
+ return e;
282
275
  },
283
276
  /**
284
277
  * Checks if a virtual options object has a dynamic ref function.
@@ -286,8 +279,8 @@ ${k}
286
279
  * @param options - The virtual options to check.
287
280
  * @returns True if the options contain a dynamic ref function.
288
281
  */
289
- isDynamicVirtual(n) {
290
- return !!(n && typeof n.ref == "function");
282
+ isDynamicVirtual(t) {
283
+ return !!(t && typeof t.ref == "function");
291
284
  },
292
285
  /**
293
286
  * Generic utility function to get new records from the database
@@ -296,14 +289,14 @@ ${k}
296
289
  * @param filterFn - Function to determine if a record already exists
297
290
  * @returns Array of records that don't exist in the database
298
291
  */
299
- getNewRecords(n, e, t) {
300
- return v(this, null, function* () {
301
- const r = yield n.findAll({});
302
- return r.success ? e.filter(
303
- (i) => !r.result.some(
304
- (o) => t(o, i)
292
+ getNewRecords(t, i, e) {
293
+ return S(this, null, function* () {
294
+ const o = yield t.findAll({});
295
+ return o.success ? i.filter(
296
+ (n) => !o.result.some(
297
+ (l) => e(l, n)
305
298
  )
306
- ) : e;
299
+ ) : i;
307
300
  });
308
301
  },
309
302
  /**
@@ -313,1213 +306,293 @@ ${k}
313
306
  * @param filterFn - Function to determine if a record exists
314
307
  * @returns Array of existing records that match the filter criteria
315
308
  */
316
- getExistingRecords(n, e, t) {
317
- return v(this, null, function* () {
318
- const r = yield n.findAll({});
319
- return r.success ? r.result.filter(
320
- (i) => e.some(
321
- (o) => t(i, o)
309
+ getExistingRecords(t, i, e) {
310
+ return S(this, null, function* () {
311
+ const o = yield t.findAll({});
312
+ return o.success ? o.result.filter(
313
+ (n) => i.some(
314
+ (l) => e(n, l)
322
315
  )
323
316
  ) : [];
324
317
  });
325
318
  }
326
319
  };
327
- function M(n, e) {
328
- if (!n || !e || e.length === 0)
329
- return n;
330
- const t = new Set(e.map((r) => r.name));
331
- if (Array.isArray(n)) {
332
- const r = n.filter((s) => {
333
- if (typeof s == "string")
334
- return !Array.from(t).some(
335
- (i) => s === i || s.startsWith(`${i}.`)
336
- );
337
- if (typeof s == "object" && s !== null) {
338
- const i = s, o = i.path || i.populate || "";
339
- return !Array.from(t).some(
340
- (l) => o === l || o.startsWith(`${l}.`)
341
- );
342
- }
343
- return !0;
344
- });
345
- return r.length > 0 ? r : void 0;
346
- }
347
- if (typeof n == "string")
348
- return Array.from(t).some(
349
- (r) => n === r || n.startsWith(`${r}.`)
350
- ) ? void 0 : n;
351
- if (typeof n == "object" && n !== null) {
352
- const r = n, s = r.path || r.populate || "";
353
- return Array.from(t).some(
354
- (i) => s === i || s.startsWith(`${i}.`)
355
- ) ? void 0 : n;
356
- }
357
- return n;
358
- }
359
- function yt(n, e, t) {
360
- if (!n.length || !e || !(t != null && t.ref))
361
- return [];
362
- const r = /* @__PURE__ */ new Map();
363
- return n.forEach((s) => {
364
- try {
365
- const i = t.ref(s);
366
- if (i == null)
367
- return;
368
- const o = typeof i == "string" ? i : String(i);
369
- if (o && o.trim() !== "") {
370
- const l = w(o);
371
- r.has(l) || r.set(l, []), r.get(l).push(s);
372
- }
373
- } catch (i) {
374
- D(new Error(`Dynamic ref function failed for virtual "${e}": ${i instanceof Error ? i.message : String(i)}`));
375
- }
376
- }), Array.from(r.entries()).map(([s, i]) => ({ model: s, docs: i }));
377
- }
378
- function gt(n) {
379
- return n !== null && typeof n == "object" && "toObject" in n && typeof n.toObject == "function";
380
- }
381
- function L(n, e, t, r, s) {
382
- return v(this, null, function* () {
383
- if (!e.length || !t)
384
- return e;
385
- const i = Array.isArray(t) ? t : [t];
386
- for (const o of i)
387
- typeof o == "string" ? yield X(n, e, o, r, s) : o && typeof o == "object" && (yield vt(n, e, o, r, s));
388
- return e;
320
+ function C(t, i, e, o, r) {
321
+ return S(this, null, function* () {
322
+ if (!i.length || !e)
323
+ return i;
324
+ const n = Array.isArray(e) ? e : [e];
325
+ for (const l of n)
326
+ typeof l == "string" ? yield k(t, i, l, o, r) : l && typeof l == "object" && (yield rt(t, i, l, o, r));
327
+ return i;
389
328
  });
390
329
  }
391
- function X(n, e, t, r, s) {
392
- return v(this, null, function* () {
393
- var i, o, l, c;
394
- const a = t.split(".");
395
- if (a.length < 2) {
396
- for (const h of e)
397
- yield U(n, h, t, r, void 0, s);
330
+ function k(t, i, e, o, r) {
331
+ return S(this, null, function* () {
332
+ var n, l, y, s;
333
+ const h = e.split(".");
334
+ if (h.length < 2) {
335
+ for (const m of i)
336
+ yield P(t, m, e, o, void 0, r);
398
337
  return;
399
338
  }
400
- const u = a[0];
339
+ const u = h[0];
401
340
  if (!u || u.trim() === "")
402
341
  return;
403
- const m = a.slice(1).join(".");
404
- for (const h of e) {
405
- const _ = h, b = _[u];
406
- if (b && typeof b == "object") {
407
- let g = s;
408
- const p = g;
409
- if (s && s.schema && s.schema.virtuals) {
410
- const f = s.schema.virtuals[u];
342
+ const R = h.slice(1).join(".");
343
+ for (const m of i) {
344
+ const N = m, O = N[u];
345
+ if (O && typeof O == "object") {
346
+ let c = r;
347
+ const a = c;
348
+ if (r && r.schema && r.schema.virtuals) {
349
+ const f = r.schema.virtuals[u];
411
350
  if (f && f.options && f.options.ref) {
412
- let O;
413
- if (typeof f.options.ref == "function" ? O = f.options.ref(_) : typeof f.options.ref == "string" && (O = f.options.ref), O) {
414
- const d = w(O);
415
- n.models[d] && (g = n.models[d]);
351
+ let g;
352
+ if (typeof f.options.ref == "function" ? g = f.options.ref(N) : typeof f.options.ref == "string" && (g = f.options.ref), g) {
353
+ const p = E(g);
354
+ t.models[p] && (c = t.models[p]);
416
355
  }
417
356
  }
418
357
  }
419
- if (!g) {
420
- const f = (o = (i = s == null ? void 0 : s.schema) == null ? void 0 : i.statics) != null ? o : {}, d = ((s == null ? void 0 : s._virtualConfigs) || f._dynamicVirtuals || []).find((y) => y.name === u);
421
- if (d && d.options && d.options.ref) {
422
- let y;
423
- if (typeof d.options.ref == "function" ? y = d.options.ref(_) : typeof d.options.ref == "string" && (y = d.options.ref), y) {
424
- const V = w(y);
425
- n.models[V] && (g = n.models[V]);
358
+ if (!c) {
359
+ const f = (l = (n = r == null ? void 0 : r.schema) == null ? void 0 : n.statics) != null ? l : {}, p = ((r == null ? void 0 : r._virtualConfigs) || f._dynamicVirtuals || []).find((d) => d.name === u);
360
+ if (p && p.options && p.options.ref) {
361
+ let d;
362
+ if (typeof p.options.ref == "function" ? d = p.options.ref(N) : typeof p.options.ref == "string" && (d = p.options.ref), d) {
363
+ const b = E(d);
364
+ t.models[b] && (c = t.models[b]);
426
365
  }
427
366
  }
428
367
  }
429
- if (g === p) {
430
- const f = (c = (l = s == null ? void 0 : s.schema) == null ? void 0 : l.statics) != null ? c : {}, d = ((s == null ? void 0 : s._virtualConfigs) || f._dynamicVirtuals || []).find((y) => y.name === u);
431
- if (d && d.options && d.options.ref) {
432
- let y;
433
- if (typeof d.options.ref == "function" ? y = d.options.ref(_) : typeof d.options.ref == "string" && (y = d.options.ref), y) {
434
- const V = w(y);
435
- n.models[V] && (g = n.models[V]);
368
+ if (c === a) {
369
+ const f = (s = (y = r == null ? void 0 : r.schema) == null ? void 0 : y.statics) != null ? s : {}, p = ((r == null ? void 0 : r._virtualConfigs) || f._dynamicVirtuals || []).find((d) => d.name === u);
370
+ if (p && p.options && p.options.ref) {
371
+ let d;
372
+ if (typeof p.options.ref == "function" ? d = p.options.ref(N) : typeof p.options.ref == "string" && (d = p.options.ref), d) {
373
+ const b = E(d);
374
+ t.models[b] && (c = t.models[b]);
436
375
  }
437
376
  }
438
377
  }
439
- if (Array.isArray(b))
440
- for (const f of b)
441
- f && typeof f == "object" && (yield U(n, f, m, r, u, g));
442
- else b && typeof b == "object" && (yield U(n, b, m, r, u, g));
378
+ if (Array.isArray(O))
379
+ for (const f of O)
380
+ f && typeof f == "object" && (yield P(t, f, R, o, u, c));
381
+ else O && typeof O == "object" && (yield P(t, O, R, o, u, c));
443
382
  }
444
383
  }
445
384
  });
446
385
  }
447
- function vt(n, e, t, r, s) {
448
- return v(this, null, function* () {
449
- const { path: i, populate: o } = t;
450
- if (!i)
386
+ function rt(t, i, e, o, r) {
387
+ return S(this, null, function* () {
388
+ const { path: n, populate: l } = e;
389
+ if (!n)
451
390
  return;
452
- if (!o) {
453
- yield X(n, e, i, r, s);
391
+ if (!l) {
392
+ yield k(t, i, n, o, r);
454
393
  return;
455
394
  }
456
- const l = i;
457
- for (const c of e) {
458
- const a = c, u = a[l];
459
- let m = s;
460
- if (s && s.schema && s.schema.virtuals) {
461
- const h = s.schema.virtuals[l];
462
- if (h && h.options && h.options.ref) {
463
- let _;
464
- if (typeof h.options.ref == "function" ? _ = h.options.ref(a) : typeof h.options.ref == "string" && (_ = h.options.ref), _) {
465
- const b = w(_);
466
- n.models[b] && (m = n.models[b]);
395
+ const y = n;
396
+ for (const s of i) {
397
+ const h = s, u = h[y];
398
+ let R = r;
399
+ if (r && r.schema && r.schema.virtuals) {
400
+ const m = r.schema.virtuals[y];
401
+ if (m && m.options && m.options.ref) {
402
+ let N;
403
+ if (typeof m.options.ref == "function" ? N = m.options.ref(h) : typeof m.options.ref == "string" && (N = m.options.ref), N) {
404
+ const O = E(N);
405
+ t.models[O] && (R = t.models[O]);
467
406
  }
468
407
  }
469
408
  }
470
- if (!m && typeof u == "object" && u && "entityType" in u) {
471
- const h = w(String(u.entityType));
472
- n.models[h] && (m = n.models[h]);
409
+ if (!R && typeof u == "object" && u && "entityType" in u) {
410
+ const m = E(String(u.entityType));
411
+ t.models[m] && (R = t.models[m]);
473
412
  }
474
413
  if (u && typeof u == "object")
475
414
  if (Array.isArray(u))
476
- for (const h of u)
477
- h && typeof h == "object" && (yield L(n, [h], o, r, m));
478
- else u && typeof u == "object" && (yield L(n, [u], o, r, m));
415
+ for (const m of u)
416
+ m && typeof m == "object" && (yield C(t, [m], l, o, R));
417
+ else u && typeof u == "object" && (yield C(t, [u], l, o, R));
479
418
  }
480
419
  });
481
420
  }
482
- function T(n, e, t, r) {
483
- if (!t || !e || !e.schema)
421
+ function F(t, i, e, o) {
422
+ if (!e || !i || !i.schema)
484
423
  return;
485
- const s = t.split(".");
486
- let i = e.schema;
487
- for (let o = 0; o < s.length; o++) {
488
- const l = s[o];
489
- if (i && i.virtuals && l) {
490
- const c = i.virtuals[l];
491
- if (c && c.options && c.options.ref) {
492
- let a;
493
- if (typeof c.options.ref == "function" ? a = c.options.ref(r) : typeof c.options.ref == "string" && (a = c.options.ref), a && typeof a == "string") {
494
- if (o === s.length - 1)
495
- return a;
496
- const u = n.models[a];
424
+ const r = e.split(".");
425
+ let n = i.schema;
426
+ for (let l = 0; l < r.length; l++) {
427
+ const y = r[l];
428
+ if (n && n.virtuals && y) {
429
+ const s = n.virtuals[y];
430
+ if (s && s.options && s.options.ref) {
431
+ let h;
432
+ if (typeof s.options.ref == "function" ? h = s.options.ref(o) : typeof s.options.ref == "string" && (h = s.options.ref), h && typeof h == "string") {
433
+ if (l === r.length - 1)
434
+ return h;
435
+ const u = t.models[h];
497
436
  if (u && u.schema) {
498
- i = u.schema;
437
+ n = u.schema;
499
438
  continue;
500
439
  }
501
440
  }
502
441
  }
503
442
  }
504
- if (i && i.paths && l) {
505
- const c = i.paths[l];
506
- if (c && c.schema) {
507
- i = c.schema;
443
+ if (n && n.paths && y) {
444
+ const s = n.paths[y];
445
+ if (s && s.schema) {
446
+ n = s.schema;
508
447
  continue;
509
448
  }
510
449
  }
511
450
  return;
512
451
  }
513
452
  }
514
- function Ot(n, e) {
515
- if (e)
516
- for (const t of Object.keys(n.models)) {
517
- const r = n.models[t], s = r == null ? void 0 : r.schema;
518
- if (s && (s.paths && s.paths[e] || s.virtuals && s.virtuals[e]))
519
- return r;
453
+ function st(t, i) {
454
+ if (i)
455
+ for (const e of Object.keys(t.models)) {
456
+ const o = t.models[e], r = o == null ? void 0 : o.schema;
457
+ if (r && (r.paths && r.paths[i] || r.virtuals && r.virtuals[i]))
458
+ return o;
520
459
  }
521
460
  }
522
- function _t(n, e) {
523
- const t = (e || "").split(".")[0] || "";
524
- if (t)
525
- for (const r of Object.keys(n.models)) {
526
- const s = n.models[r], i = s == null ? void 0 : s.schema;
527
- if (i && (i.paths && i.paths[t] || i.virtuals && i.virtuals[t]))
528
- return s;
461
+ function nt(t, i) {
462
+ const e = (i || "").split(".")[0] || "";
463
+ if (e)
464
+ for (const o of Object.keys(t.models)) {
465
+ const r = t.models[o], n = r == null ? void 0 : r.schema;
466
+ if (n && (n.paths && n.paths[e] || n.virtuals && n.virtuals[e]))
467
+ return r;
529
468
  }
530
469
  }
531
- function U(n, e, t, r, s, i) {
532
- return v(this, null, function* () {
533
- var o, l;
534
- let c = e.__t;
535
- if (!c) {
536
- if (i) {
537
- const g = s ? `${s}.${t}` : t, p = (g || "").split(".")[0] || "";
538
- let f = i;
539
- if (!!!((o = f == null ? void 0 : f.schema) != null && o.paths && f.schema.paths[p] || (l = f == null ? void 0 : f.schema) != null && l.virtuals && f.schema.virtuals[p])) {
540
- const y = _t(n, g);
541
- y && (f = y);
470
+ function P(t, i, e, o, r, n) {
471
+ return S(this, null, function* () {
472
+ var l, y;
473
+ let s = i.__t;
474
+ if (!s) {
475
+ if (n) {
476
+ const c = r ? `${r}.${e}` : e, a = (c || "").split(".")[0] || "";
477
+ let f = n;
478
+ if (!!!((l = f == null ? void 0 : f.schema) != null && l.paths && f.schema.paths[a] || (y = f == null ? void 0 : f.schema) != null && y.virtuals && f.schema.virtuals[a])) {
479
+ const d = nt(t, c);
480
+ d && (f = d);
542
481
  }
543
- const d = T(n, f, g, e);
544
- if (d)
545
- c = d;
482
+ const p = F(t, f, c, i);
483
+ if (p)
484
+ s = p;
546
485
  else {
547
- const y = (g.includes(".") ? g.split(".").pop() : g) || "";
548
- if (y) {
549
- const V = Ot(n, y);
550
- if (V) {
551
- const R = T(n, V, g, e);
552
- R && (c = R);
486
+ const d = (c.includes(".") ? c.split(".").pop() : c) || "";
487
+ if (d) {
488
+ const b = st(t, d);
489
+ if (b) {
490
+ const j = F(t, b, c, i);
491
+ j && (s = j);
553
492
  }
554
493
  }
555
494
  }
556
495
  }
557
- if (r && r.length > 0) {
558
- const g = t.split(".").pop() || "", p = r.find((f) => f.name === g);
559
- if (p && p.options.ref) {
496
+ if (o && o.length > 0) {
497
+ const c = e.split(".").pop() || "", a = o.find((f) => f.name === c);
498
+ if (a && a.options.ref) {
560
499
  let f;
561
- typeof p.options.ref == "function" ? f = p.options.ref(e) : typeof p.options.ref == "string" && (f = p.options.ref), f && typeof f == "string" && (c = f);
500
+ typeof a.options.ref == "function" ? f = a.options.ref(i) : typeof a.options.ref == "string" && (f = a.options.ref), f && typeof f == "string" && (s = f);
562
501
  }
563
502
  }
564
- if (!c) {
565
- for (const [g, p] of Object.entries(e))
566
- if (g === "entityType" && typeof p == "string") {
567
- c = p;
503
+ if (!s) {
504
+ for (const [c, a] of Object.entries(i))
505
+ if (c === "entityType" && typeof a == "string") {
506
+ s = a;
568
507
  break;
569
508
  }
570
- if (c && n.models[c]) {
571
- const g = n.models[c];
572
- if (g && g.schema) {
573
- const p = g.schema, f = t.split(".").pop() || "", O = (y, V = "root") => {
574
- if (!y || !y.virtuals)
509
+ if (s && t.models[s]) {
510
+ const c = t.models[s];
511
+ if (c && c.schema) {
512
+ const a = c.schema, f = e.split(".").pop() || "", g = (d, b = "root") => {
513
+ if (!d || !d.virtuals)
575
514
  return;
576
- const R = y.virtuals;
577
- for (const S of Object.keys(R))
578
- if (S === f) {
579
- const E = R[S];
580
- if (E && E.options && E.options.ref) {
581
- let j;
582
- if (typeof E.options.ref == "function" ? j = E.options.ref(e) : typeof E.options.ref == "string" && (j = E.options.ref), j && typeof j == "string")
583
- return j;
515
+ const j = d.virtuals;
516
+ for (const _ of Object.keys(j))
517
+ if (_ === f) {
518
+ const v = j[_];
519
+ if (v && v.options && v.options.ref) {
520
+ let w;
521
+ if (typeof v.options.ref == "function" ? w = v.options.ref(i) : typeof v.options.ref == "string" && (w = v.options.ref), w && typeof w == "string")
522
+ return w;
584
523
  }
585
524
  }
586
- if (y.paths)
587
- for (const S of Object.keys(y.paths)) {
588
- const E = y.paths[S];
589
- if (E && E.schema) {
590
- const j = O(E.schema, `${V}.${S}`);
591
- if (j)
592
- return j;
525
+ if (d.paths)
526
+ for (const _ of Object.keys(d.paths)) {
527
+ const v = d.paths[_];
528
+ if (v && v.schema) {
529
+ const w = g(v.schema, `${b}.${_}`);
530
+ if (w)
531
+ return w;
593
532
  }
594
533
  }
595
- }, d = O(p);
596
- d && (c = d);
534
+ }, p = g(a);
535
+ p && (s = p);
597
536
  }
598
537
  }
599
538
  }
600
- if (!c) {
601
- const g = t.split(".").pop() || "";
602
- if (i && i.schema) {
603
- const p = i.schema, f = (d, y = "root") => {
604
- if (!d || !d.virtuals)
539
+ if (!s) {
540
+ const c = e.split(".").pop() || "";
541
+ if (n && n.schema) {
542
+ const a = n.schema, f = (p, d = "root") => {
543
+ if (!p || !p.virtuals)
605
544
  return;
606
- const V = d.virtuals;
607
- for (const R of Object.keys(V))
608
- if (R === g) {
609
- const S = V[R];
610
- if (S && S.options && S.options.ref) {
611
- let E;
612
- if (typeof S.options.ref == "function" ? E = S.options.ref(e) : typeof S.options.ref == "string" && (E = S.options.ref), E && typeof E == "string")
613
- return E;
545
+ const b = p.virtuals;
546
+ for (const j of Object.keys(b))
547
+ if (j === c) {
548
+ const _ = b[j];
549
+ if (_ && _.options && _.options.ref) {
550
+ let v;
551
+ if (typeof _.options.ref == "function" ? v = _.options.ref(i) : typeof _.options.ref == "string" && (v = _.options.ref), v && typeof v == "string")
552
+ return v;
614
553
  }
615
554
  }
616
- if (d.paths)
617
- for (const R of Object.keys(d.paths)) {
618
- const S = d.paths[R];
619
- if (S && S.schema) {
620
- const E = f(S.schema, `${y}.${R}`);
621
- if (E)
622
- return E;
555
+ if (p.paths)
556
+ for (const j of Object.keys(p.paths)) {
557
+ const _ = p.paths[j];
558
+ if (_ && _.schema) {
559
+ const v = f(_.schema, `${d}.${j}`);
560
+ if (v)
561
+ return v;
623
562
  }
624
563
  }
625
- }, O = f(p);
626
- O && (c = O);
564
+ }, g = f(a);
565
+ g && (s = g);
627
566
  }
628
- if (!c && i) {
629
- const p = T(n, i, t, e);
630
- p && (c = p);
567
+ if (!s && n) {
568
+ const a = F(t, n, e, i);
569
+ a && (s = a);
631
570
  }
632
- if (!c && r && r.length > 0) {
633
- const p = r.find((f) => f.name === g);
634
- if (p && p.options.ref) {
571
+ if (!s && o && o.length > 0) {
572
+ const a = o.find((f) => f.name === c);
573
+ if (a && a.options.ref) {
635
574
  let f;
636
- typeof p.options.ref == "function" ? f = p.options.ref(e) : typeof p.options.ref == "string" && (f = p.options.ref), f && typeof f == "string" && (c = f);
575
+ typeof a.options.ref == "function" ? f = a.options.ref(i) : typeof a.options.ref == "string" && (f = a.options.ref), f && typeof f == "string" && (s = f);
637
576
  }
638
577
  }
639
578
  }
640
- if (!c) {
641
- const g = t.split(".").pop() || "", p = g ? g.charAt(0).toUpperCase() + g.slice(1) : "";
642
- p && n.models[p] && (c = p);
579
+ if (!s) {
580
+ const c = e.split(".").pop() || "", a = c ? c.charAt(0).toUpperCase() + c.slice(1) : "";
581
+ a && t.models[a] && (s = a);
643
582
  }
644
583
  }
645
- const a = n.models[c];
646
- if (!a)
647
- return;
648
- const u = `${t}Id`, m = `${t}Ids`, h = e[u] || e[m] || e[t];
584
+ const h = t.models[s];
649
585
  if (!h)
650
586
  return;
651
- const _ = Array.isArray(h) ? h : [h], b = yield a.find({ id: { $in: _ } }).lean();
652
- b.length > 0 && (Array.isArray(h) ? e[t] = b : e[t] = b[0]);
653
- });
654
- }
655
- function Q(n, e, t, r, s, i) {
656
- return v(this, null, function* () {
657
- if (!e.length || !t.length || !r)
658
- return e;
659
- const o = t.filter((a) => {
660
- if (Array.isArray(r))
661
- return r.length > 0 && r.some((u) => {
662
- if (typeof u == "string")
663
- return u === a.name || u.startsWith(`${a.name}.`);
664
- if (u && typeof u == "object") {
665
- const m = u, h = m.path || m.populate || "";
666
- return h === a.name || h.startsWith(`${a.name}.`);
667
- }
668
- return !1;
669
- });
670
- if (typeof r == "string")
671
- return r === a.name || r.startsWith(`${a.name}.`);
672
- if (typeof r == "object" && r !== null) {
673
- const u = r, m = u.path || u.populate || "";
674
- return m === a.name || m.startsWith(`${a.name}.`);
675
- }
676
- return !1;
677
- });
678
- if (o.length === 0)
679
- return e;
680
- const l = J(e.map((a) => gt(a) ? a.toObject() : a));
681
- l.forEach((a) => {
682
- o.forEach(({ name: u, options: m }) => {
683
- u in a || (a[u] = m.count ? 0 : m.justOne ? null : []);
684
- });
685
- });
686
- const c = /* @__PURE__ */ new Map();
687
- for (const a of o) {
688
- const { name: u, options: m } = a, h = yt(l, u, m);
689
- for (const _ of h) {
690
- c.has(_.model) || c.set(_.model, {
691
- virtuals: [],
692
- localValueSets: /* @__PURE__ */ new Map(),
693
- docsByLocalValue: /* @__PURE__ */ new Map()
694
- });
695
- const b = c.get(_.model);
696
- b.virtuals.find((p) => p.name === u) || (b.virtuals.push(a), b.localValueSets.set(u, /* @__PURE__ */ new Set()));
697
- const g = b.localValueSets.get(u);
698
- _.docs.forEach((p) => {
699
- const f = p[m.localField];
700
- if (f != null) {
701
- const O = String(f);
702
- g.add(O);
703
- let d = -1;
704
- const y = p;
705
- y.id !== void 0 ? d = l.findIndex((V) => V.id === y.id) : y._id !== void 0 && (d = l.findIndex((V) => {
706
- var R, S, E, j;
707
- return ((S = (R = V._id) == null ? void 0 : R.toString) == null ? void 0 : S.call(R)) === ((j = (E = y._id) == null ? void 0 : E.toString) == null ? void 0 : j.call(E));
708
- })), d !== -1 && (b.docsByLocalValue.has(O) || b.docsByLocalValue.set(O, []), b.docsByLocalValue.get(O).push(d));
709
- }
710
- });
711
- }
712
- }
713
- if (yield Promise.all(Array.from(c.entries()).map((a) => v(null, [a], function* ([u, m]) {
714
- const h = n.models[u];
715
- if (!h)
716
- return;
717
- const _ = /* @__PURE__ */ new Set();
718
- if (m.localValueSets.forEach((O) => {
719
- O.forEach((d) => _.add(d));
720
- }), _.size === 0)
721
- return;
722
- const b = [...new Set(m.virtuals.map((O) => O.options.foreignField))], g = Array.from(_);
723
- let p;
724
- b.length === 1 ? p = { [String(b[0])]: { $in: g } } : p = { $or: b.map((O) => ({ [O]: { $in: g } })) };
725
- const f = yield h.find(p, s).lean();
726
- for (const O of m.virtuals) {
727
- const { name: d, options: y } = O, V = f.filter((R) => {
728
- const S = R[y.foreignField];
729
- return S != null && _.has(String(S));
730
- });
731
- if (y.count) {
732
- const R = /* @__PURE__ */ new Map();
733
- V.forEach((S) => {
734
- var E;
735
- const j = (E = S[y.foreignField]) == null ? void 0 : E.toString();
736
- j && R.set(j, (R.get(j) || 0) + 1);
737
- }), m.localValueSets.get(d).forEach((S) => {
738
- const E = m.docsByLocalValue.get(S) || [], j = R.get(S) || 0;
739
- E.forEach((P) => {
740
- const C = l[P];
741
- C[d] === void 0 && (C[d] = j);
742
- });
743
- });
744
- } else {
745
- const R = /* @__PURE__ */ new Map();
746
- V.forEach((S) => {
747
- var E;
748
- const j = (E = S[y.foreignField]) == null ? void 0 : E.toString();
749
- j && (R.has(j) || R.set(j, []), R.get(j).push(S));
750
- }), m.localValueSets.get(d).forEach((S) => {
751
- const E = m.docsByLocalValue.get(S) || [], j = R.get(S) || [], P = y.justOne ? j[0] || null : j;
752
- E.forEach((C) => {
753
- const H = l[C];
754
- H[d] = P;
755
- });
756
- });
757
- }
758
- }
759
- }))), r) {
760
- const u = ((m) => {
761
- const h = Array.isArray(m) ? m : [m], _ = /* @__PURE__ */ new Map(), b = [];
762
- for (const p of h)
763
- if (typeof p == "string")
764
- if (p.includes(".")) {
765
- const f = p.split("."), O = f[0] || "", d = f.slice(1).join(".");
766
- O && (_.has(O) || _.set(O, []), d && _.get(O).push(d));
767
- } else
768
- b.push(p);
769
- else if (p && typeof p == "object") {
770
- const f = p;
771
- if (f.path && f.path.includes(".")) {
772
- const O = f.path.split("."), d = O[0] || "", y = O.slice(1).join(".");
773
- d && (_.has(d) || _.set(d, []), y && _.get(d).push(y), f.populate && _.get(d).push(f.populate));
774
- } else
775
- b.push(p);
776
- }
777
- const g = [...b];
778
- return _.forEach((p, f) => {
779
- const O = [];
780
- for (const d of p)
781
- (typeof d == "string" || d && typeof d == "object") && O.push(d);
782
- O.length > 0 ? g.push({ path: f, populate: O }) : g.push(f);
783
- }), g;
784
- })(r);
785
- yield L(n, l, u, t, i);
786
- }
787
- return l;
587
+ const u = `${e}Id`, R = `${e}Ids`, m = i[u] || i[R] || i[e];
588
+ if (!m)
589
+ return;
590
+ const N = Array.isArray(m) ? m : [m], O = yield h.find({ id: { $in: N } }).lean();
591
+ O.length > 0 && (Array.isArray(m) ? i[e] = O : i[e] = O[0]);
788
592
  });
789
593
  }
790
- class It {
791
- /**
792
- * Creates a new MongoDB controller instance.
793
- *
794
- * @param db - The MongoDB database instance.
795
- * @param collectionName - The name of the collection to operate on.
796
- */
797
- constructor(e, t) {
798
- ht(this, "collection"), this.collection = e.collection(t);
799
- }
800
- /**
801
- * Creates a single document in the collection.
802
- * This method adds generic fields (id, isDel, timestamps) to the document before insertion.
803
- *
804
- * @param document - The document to create, with or without generic fields.
805
- * @returns A promise that resolves to a standardized response with the created document.
806
- */
807
- createOne(e) {
808
- return v(this, null, function* () {
809
- try {
810
- const t = N(N({}, x.createGenericFields()), e);
811
- return (yield this.collection.insertOne(t)).acknowledged ? {
812
- success: !0,
813
- message: "Document created successfully",
814
- result: t
815
- } : {
816
- success: !1,
817
- message: "Document creation failed",
818
- code: A.INTERNAL_SERVER_ERROR.CODE
819
- };
820
- } catch (t) {
821
- return D(t);
822
- }
823
- });
824
- }
825
- /**
826
- * Creates multiple documents in the collection.
827
- * This method adds generic fields to each document before bulk insertion.
828
- *
829
- * @param documents - An array of documents to create.
830
- * @returns A promise that resolves to a standardized response with the created documents.
831
- */
832
- createMany(e) {
833
- return v(this, null, function* () {
834
- try {
835
- const t = e.map((s) => N(N({}, x.createGenericFields()), s)), r = yield this.collection.insertMany(t);
836
- return r.insertedCount === 0 ? {
837
- success: !1,
838
- message: "No documents were inserted",
839
- code: A.INTERNAL_SERVER_ERROR.CODE
840
- } : {
841
- success: !0,
842
- message: `${r.insertedCount} documents created successfully`,
843
- result: t
844
- };
845
- } catch (t) {
846
- return D(t);
847
- }
848
- });
849
- }
850
- /**
851
- * Finds a single document by filter criteria.
852
- *
853
- * @param filter - The filter criteria to find the document.
854
- * @returns A promise that resolves to a standardized response with the found document.
855
- */
856
- findOne(e) {
857
- return v(this, null, function* () {
858
- try {
859
- const t = yield this.collection.findOne(e);
860
- return t ? { success: !0, message: "Document found", result: t } : { success: !1, message: "Document not found", code: A.NOT_FOUND.CODE };
861
- } catch (t) {
862
- return D(t);
863
- }
864
- });
865
- }
866
- /**
867
- * Finds all documents matching the filter criteria.
868
- *
869
- * @param filter - The filter criteria to find documents (defaults to empty object for all documents).
870
- * @returns A promise that resolves to a standardized response with the found documents.
871
- */
872
- findAll() {
873
- return v(this, arguments, function* (e = {}) {
874
- try {
875
- return {
876
- success: !0,
877
- message: "Documents retrieved successfully",
878
- result: yield this.collection.find(e).toArray()
879
- };
880
- } catch (t) {
881
- return D(t);
882
- }
883
- });
884
- }
885
- /**
886
- * Counts documents matching the filter criteria.
887
- *
888
- * @param filter - The filter criteria to count documents (defaults to empty object for all documents).
889
- * @returns A promise that resolves to a standardized response with the document count.
890
- */
891
- count() {
892
- return v(this, arguments, function* (e = {}) {
893
- try {
894
- const t = yield this.collection.countDocuments(e);
895
- return {
896
- success: !0,
897
- message: `${t} documents counted successfully`,
898
- result: t
899
- };
900
- } catch (t) {
901
- return D(t);
902
- }
903
- });
904
- }
905
- /**
906
- * Updates a single document matching the filter criteria.
907
- *
908
- * @param filter - The filter criteria to find the document to update.
909
- * @param update - The update data to apply to the document.
910
- * @returns A promise that resolves to a standardized response with the update result.
911
- */
912
- updateOne(e, t) {
913
- return v(this, null, function* () {
914
- try {
915
- const r = yield this.collection.updateOne(e, {
916
- $set: t
917
- });
918
- return r.matchedCount === 0 ? {
919
- success: !1,
920
- message: "No documents matched the filter",
921
- code: A.INTERNAL_SERVER_ERROR.CODE
922
- } : {
923
- success: !0,
924
- message: "Document updated successfully",
925
- result: r
926
- };
927
- } catch (r) {
928
- return D(r);
929
- }
930
- });
931
- }
932
- /**
933
- * Updates multiple documents matching the filter criteria.
934
- *
935
- * @param filter - The filter criteria to find documents to update.
936
- * @param update - The update data to apply to the documents.
937
- * @returns A promise that resolves to a standardized response with the update result.
938
- */
939
- updateMany(e, t) {
940
- return v(this, null, function* () {
941
- try {
942
- const r = yield this.collection.updateMany(e, {
943
- $set: t
944
- });
945
- return r.matchedCount === 0 ? {
946
- success: !1,
947
- message: "No documents matched the filter",
948
- code: A.INTERNAL_SERVER_ERROR.CODE
949
- } : {
950
- success: !0,
951
- message: "Documents updated successfully",
952
- result: r
953
- };
954
- } catch (r) {
955
- return D(r);
956
- }
957
- });
958
- }
959
- /**
960
- * Deletes a single document matching the filter criteria.
961
- *
962
- * @param filter - The filter criteria to find the document to delete.
963
- * @returns A promise that resolves to a standardized response with the delete result.
964
- */
965
- deleteOne(e) {
966
- return v(this, null, function* () {
967
- try {
968
- const t = yield this.collection.deleteOne(e);
969
- return t.deletedCount === 0 ? {
970
- success: !1,
971
- message: "No documents matched the filter",
972
- code: A.INTERNAL_SERVER_ERROR.CODE
973
- } : {
974
- success: !0,
975
- message: "Document deleted successfully",
976
- result: t
977
- };
978
- } catch (t) {
979
- return D(t);
980
- }
981
- });
982
- }
983
- /**
984
- * Deletes multiple documents matching the filter criteria.
985
- *
986
- * @param filter - The filter criteria to find documents to delete.
987
- * @returns A promise that resolves to a standardized response with the delete result.
988
- */
989
- deleteMany(e) {
990
- return v(this, null, function* () {
991
- try {
992
- const t = yield this.collection.deleteMany(e);
993
- return t.deletedCount === 0 ? {
994
- success: !1,
995
- message: "No documents matched the filter",
996
- code: A.INTERNAL_SERVER_ERROR.CODE
997
- } : {
998
- success: !0,
999
- message: "Documents deleted successfully",
1000
- result: t
1001
- };
1002
- } catch (t) {
1003
- return D(t);
1004
- }
1005
- });
1006
- }
1007
- }
1008
- class Pt {
1009
- /**
1010
- * Creates a new Mongoose controller instance.
1011
- *
1012
- * @param model - The Mongoose model to operate on.
1013
- */
1014
- constructor(e) {
1015
- this.model = e;
1016
- }
1017
- /**
1018
- * Gets the model name for logging and error messages.
1019
- *
1020
- * @returns The name of the model.
1021
- */
1022
- getModelName() {
1023
- return this.model.modelName;
1024
- }
1025
- /**
1026
- * Gets the dynamic virtuals configuration from the model instance.
1027
- *
1028
- * @returns Array of dynamic virtual configurations or undefined if none exist.
1029
- */
1030
- getDynamicVirtuals() {
1031
- if (this.model._virtualConfigs) {
1032
- const r = this.model._virtualConfigs.filter((s) => {
1033
- var i;
1034
- return typeof ((i = s.options) == null ? void 0 : i.ref) == "function";
1035
- });
1036
- if (r.length > 0)
1037
- return r;
1038
- }
1039
- return this.model.schema.statics._dynamicVirtuals;
1040
- }
1041
- /**
1042
- * Populates dynamic virtuals for a single document.
1043
- *
1044
- * @param result - The document to populate dynamic virtuals for.
1045
- * @param populate - The populate options to determine which virtuals to populate.
1046
- * @returns The document with dynamic virtuals populated.
1047
- */
1048
- populateDynamicVirtualsForDocument(e, t) {
1049
- return v(this, null, function* () {
1050
- const r = this.getDynamicVirtuals();
1051
- if (r && r.length > 0) {
1052
- const s = yield Q(this.model.base, [e], r, t, void 0, this.model);
1053
- return s && s[0] ? s[0] : e;
1054
- }
1055
- return e;
1056
- });
1057
- }
1058
- /**
1059
- * Populates dynamic virtuals for an array of documents.
1060
- *
1061
- * @param results - The documents to populate dynamic virtuals for.
1062
- * @param populate - The populate options to determine which virtuals to populate.
1063
- * @returns The documents with dynamic virtuals populated.
1064
- */
1065
- populateDynamicVirtualsForDocuments(e, t) {
1066
- return v(this, null, function* () {
1067
- const r = this.getDynamicVirtuals();
1068
- return r && r.length > 0 && e.length > 0 ? yield Q(this.model.base, e, r, t, void 0, this.model) : e;
1069
- });
1070
- }
1071
- /**
1072
- * Finds a single document with optional population and projection.
1073
- * Automatically handles dynamic virtual population if configured.
1074
- *
1075
- * @param filter - The filter criteria to find the document.
1076
- * @param projection - The fields to include/exclude in the result.
1077
- * @param options - Query options for the operation.
1078
- * @param populate - Population configuration for related documents.
1079
- * @returns A promise that resolves to a standardized response with the found document.
1080
- */
1081
- findOne() {
1082
- return v(this, arguments, function* (e = {}, t = {}, r = {}, s) {
1083
- var i, o;
1084
- try {
1085
- const l = F(e), c = this.model.findOne(l, t, r), a = this.getDynamicVirtuals(), u = M(s, a);
1086
- u && c.populate(u);
1087
- const m = yield c.exec();
1088
- if (!m)
1089
- return {
1090
- success: !1,
1091
- message: `No ${this.getModelName()} found.`,
1092
- code: A.NOT_FOUND.CODE
1093
- };
1094
- const h = yield this.populateDynamicVirtualsForDocument(m, s);
1095
- return { success: !0, result: (o = (i = h == null ? void 0 : h.toObject) == null ? void 0 : i.call(h)) != null ? o : h };
1096
- } catch (l) {
1097
- return D(l);
1098
- }
1099
- });
1100
- }
1101
- /**
1102
- * Finds all documents with optional population and projection.
1103
- * Automatically handles dynamic virtual population if configured.
1104
- *
1105
- * @param filter - The filter criteria to find documents.
1106
- * @param projection - The fields to include/exclude in the result.
1107
- * @param options - Query options for the operation.
1108
- * @param populate - Population configuration for related documents.
1109
- * @returns A promise that resolves to a standardized response with the found documents.
1110
- */
1111
- findAll() {
1112
- return v(this, arguments, function* (e = {}, t = {}, r = {}, s) {
1113
- try {
1114
- const i = F(e), o = this.model.find(i, t, r), l = this.getDynamicVirtuals(), c = M(s, l);
1115
- c && o.populate(c);
1116
- const a = yield o.exec();
1117
- return { success: !0, result: (yield this.populateDynamicVirtualsForDocuments(a, s)).map((m) => {
1118
- var h, _;
1119
- return (_ = (h = m == null ? void 0 : m.toObject) == null ? void 0 : h.call(m)) != null ? _ : m;
1120
- }) };
1121
- } catch (i) {
1122
- return D(i);
1123
- }
1124
- });
1125
- }
1126
- /**
1127
- * Finds documents with pagination support.
1128
- * Automatically handles dynamic virtual population if configured.
1129
- *
1130
- * @param filter - The filter criteria to find documents.
1131
- * @param options - Pagination options including page, limit, and population.
1132
- * @returns A promise that resolves to a standardized response with paginated results.
1133
- */
1134
- findPaging() {
1135
- return v(this, arguments, function* (e = {}, t = {}) {
1136
- try {
1137
- const r = F(e), s = this.getDynamicVirtuals(), i = N({}, t);
1138
- t.populate && (i.populate = M(t.populate, s));
1139
- const o = yield this.model.paginate(r, i);
1140
- if (s && s.length > 0) {
1141
- const l = yield this.populateDynamicVirtualsForDocuments(o.docs, t.populate);
1142
- return { success: !0, result: $(N({}, o), { docs: l.map((c) => {
1143
- var a, u;
1144
- return (u = (a = c == null ? void 0 : c.toObject) == null ? void 0 : a.call(c)) != null ? u : c;
1145
- }) }) };
1146
- }
1147
- return { success: !0, result: $(N({}, o), { docs: o.docs.map((l) => {
1148
- var c, a;
1149
- return (a = (c = l == null ? void 0 : l.toObject) == null ? void 0 : c.call(l)) != null ? a : l;
1150
- }) }) };
1151
- } catch (r) {
1152
- return D(r);
1153
- }
1154
- });
1155
- }
1156
- /**
1157
- * Performs aggregation with pagination support.
1158
- *
1159
- * @param pipeline - The aggregation pipeline stages.
1160
- * @param options - Pagination options for the aggregation result.
1161
- * @returns A promise that resolves to a standardized response with paginated aggregation results.
1162
- */
1163
- findPagingAggregate(e) {
1164
- return v(this, arguments, function* (t, r = {}) {
1165
- try {
1166
- const s = this.getDynamicVirtuals(), i = N({}, r);
1167
- r.populate && (i.populate = M(r.populate, s));
1168
- const o = yield this.model.aggregatePaginate(
1169
- this.model.aggregate(t),
1170
- i
1171
- ), l = yield this.populateDynamicVirtualsForDocuments(o.docs, r.populate);
1172
- return { success: !0, result: $(N({}, o), { docs: l.map((c) => {
1173
- var a, u;
1174
- return (u = (a = c == null ? void 0 : c.toObject) == null ? void 0 : a.call(c)) != null ? u : c;
1175
- }) }) };
1176
- } catch (s) {
1177
- return D(s);
1178
- }
1179
- });
1180
- }
1181
- /**
1182
- * Counts documents matching the filter criteria.
1183
- *
1184
- * @param filter - The filter criteria to count documents.
1185
- * @returns A promise that resolves to a standardized response with the document count.
1186
- */
1187
- count() {
1188
- return v(this, arguments, function* (e = {}) {
1189
- try {
1190
- const t = F(e);
1191
- return { success: !0, result: yield this.model.countDocuments(t) };
1192
- } catch (t) {
1193
- return D(t);
1194
- }
1195
- });
1196
- }
1197
- /**
1198
- * Creates a single document.
1199
- *
1200
- * @param doc - The document to create.
1201
- * @returns A promise that resolves to a standardized response with the created document.
1202
- */
1203
- createOne(e) {
1204
- return v(this, null, function* () {
1205
- var t, r;
1206
- try {
1207
- const s = yield this.model.create(e);
1208
- return { success: !0, result: (r = (t = s == null ? void 0 : s.toObject) == null ? void 0 : t.call(s)) != null ? r : s };
1209
- } catch (s) {
1210
- return D(s);
1211
- }
1212
- });
1213
- }
1214
- /**
1215
- * Creates multiple documents with bulk insertion.
1216
- *
1217
- * @param docs - An array of documents to create.
1218
- * @param options - Options for the bulk insertion operation.
1219
- * @returns A promise that resolves to a standardized response with the created documents.
1220
- */
1221
- createMany(e) {
1222
- return v(this, arguments, function* (t, r = {}) {
1223
- try {
1224
- return { success: !0, result: (yield this.model.insertMany(t, r)).map((i) => {
1225
- var o, l;
1226
- return (l = (o = i == null ? void 0 : i.toObject) == null ? void 0 : o.call(i)) != null ? l : i;
1227
- }) };
1228
- } catch (s) {
1229
- return D(s);
1230
- }
1231
- });
1232
- }
1233
- /**
1234
- * Updates a single document and returns the updated version.
1235
- *
1236
- * @param filter - The filter criteria to find the document to update.
1237
- * @param update - The update data to apply.
1238
- * @param options - Options for the update operation.
1239
- * @returns A promise that resolves to a standardized response with the updated document.
1240
- */
1241
- updateOne() {
1242
- return v(this, arguments, function* (e = {}, t = {}, r = {}) {
1243
- var s, i;
1244
- try {
1245
- const o = F(e), l = yield this.model.findOneAndUpdate(o, t, N({
1246
- new: !0
1247
- }, r)).exec();
1248
- return l ? { success: !0, result: (i = (s = l == null ? void 0 : l.toObject) == null ? void 0 : s.call(l)) != null ? i : l } : {
1249
- success: !1,
1250
- message: `Failed to update ${this.getModelName()}.`,
1251
- code: A.NOT_FOUND.CODE
1252
- };
1253
- } catch (o) {
1254
- return D(o);
1255
- }
1256
- });
1257
- }
1258
- /**
1259
- * Updates multiple documents matching the filter criteria.
1260
- *
1261
- * @param filter - The filter criteria to find documents to update.
1262
- * @param update - The update data to apply.
1263
- * @param options - Options for the update operation.
1264
- * @returns A promise that resolves to a standardized response with the update result.
1265
- */
1266
- updateMany() {
1267
- return v(this, arguments, function* (e = {}, t = {}, r = {}) {
1268
- try {
1269
- const s = F(e);
1270
- return { success: !0, result: yield this.model.updateMany(s, t, r).exec() };
1271
- } catch (s) {
1272
- return D(s);
1273
- }
1274
- });
1275
- }
1276
- /**
1277
- * Deletes a single document and returns the deleted version.
1278
- *
1279
- * @param filter - The filter criteria to find the document to delete.
1280
- * @param options - Options for the delete operation.
1281
- * @returns A promise that resolves to a standardized response with the deleted document.
1282
- */
1283
- deleteOne() {
1284
- return v(this, arguments, function* (e = {}, t = {}) {
1285
- var r, s;
1286
- try {
1287
- const i = F(e), o = yield this.model.findOneAndDelete(i, t).exec();
1288
- return o ? { success: !0, result: (s = (r = o == null ? void 0 : o.toObject) == null ? void 0 : r.call(o)) != null ? s : o } : {
1289
- success: !1,
1290
- message: `No ${this.getModelName()} found to delete.`,
1291
- code: A.NOT_FOUND.CODE
1292
- };
1293
- } catch (i) {
1294
- return D(i);
1295
- }
1296
- });
1297
- }
1298
- /**
1299
- * Deletes multiple documents matching the filter criteria.
1300
- *
1301
- * @param filter - The filter criteria to find documents to delete.
1302
- * @param options - Options for the delete operation.
1303
- * @returns A promise that resolves to a standardized response with the delete result.
1304
- */
1305
- deleteMany() {
1306
- return v(this, arguments, function* (e = {}, t = {}) {
1307
- try {
1308
- const r = F(e), s = yield this.model.deleteMany(r, t).exec();
1309
- return s.deletedCount === 0 ? {
1310
- success: !1,
1311
- message: "No documents found to delete.",
1312
- code: A.NOT_FOUND.CODE
1313
- } : { success: !0, result: s };
1314
- } catch (r) {
1315
- return D(r);
1316
- }
1317
- });
1318
- }
1319
- /**
1320
- * Creates a unique short ID based on a given ID.
1321
- * This method generates multiple short IDs with increasing lengths and finds the first available one.
1322
- *
1323
- * @param id - The base ID to generate short IDs from.
1324
- * @param length - The initial length for short ID generation (default: 4).
1325
- * @returns A promise that resolves to a standardized response with the unique short ID.
1326
- */
1327
- createShortId(e, t = 4) {
1328
- return v(this, null, function* () {
1329
- try {
1330
- const s = Array.from({ length: 10 }, (l, c) => ut(e, c + t)), o = (yield Promise.all(
1331
- s.map((l) => this.model.exists({ shortId: l }))
1332
- )).findIndex((l) => !l);
1333
- if (o !== -1) {
1334
- const l = s[o];
1335
- if (l)
1336
- return { success: !0, result: l };
1337
- }
1338
- return {
1339
- success: !1,
1340
- message: "Failed to create a unique shortId",
1341
- code: A.INTERNAL_SERVER_ERROR.CODE
1342
- };
1343
- } catch (r) {
1344
- return D(r);
1345
- }
1346
- });
1347
- }
1348
- /**
1349
- * Creates a query for slug existence checking.
1350
- * This method generates a query that checks for slug existence in both current and historical slug fields.
1351
- *
1352
- * @param options - Configuration for slug query generation including slug, field, and filter.
1353
- * @param options.slug - The slug string to check for existence.
1354
- * @param options.field - The field name for object-based slug checking.
1355
- * @param options.isObject - Whether the slug is stored as an object with nested fields.
1356
- * @param options.haveHistory - Whether to check historical slug fields for existence.
1357
- * @param options.filter - Additional filter conditions to apply to the query.
1358
- * @returns A MongoDB query object for checking slug existence.
1359
- */
1360
- createSlugQuery({ slug: e, field: t, isObject: r, haveHistory: s = !1, filter: i }) {
1361
- const o = N({}, i != null ? i : {});
1362
- return r ? $(N({}, o), {
1363
- $or: [
1364
- { [`slug.${t}`]: e },
1365
- ...s ? [{ slugHistory: { $elemMatch: { [`slug.${t}`]: e } } }] : []
1366
- ]
1367
- }) : $(N({}, o), {
1368
- $or: [
1369
- { slug: e },
1370
- ...s ? [{ slugHistory: e }] : []
1371
- ]
1372
- });
1373
- }
1374
- /**
1375
- * Creates a unique slug based on a given string.
1376
- * This method generates multiple slug variations and finds the first available one.
1377
- *
1378
- * @param options - Configuration for slug generation including slug, field, and filter.
1379
- * @param options.slug - The base slug string to make unique.
1380
- * @param options.field - The field name for object-based slug checking.
1381
- * @param options.isObject - Whether the slug is stored as an object with nested fields.
1382
- * @param options.haveHistory - Whether to check historical slug fields for uniqueness.
1383
- * @param options.filter - Additional filter conditions to apply when checking slug existence.
1384
- * @returns A promise that resolves to a unique slug string.
1385
- */
1386
- createUniqueSlug(e) {
1387
- return v(this, arguments, function* ({ slug: t, field: r, isObject: s, haveHistory: i, filter: o }) {
1388
- if (!t || typeof t != "string")
1389
- throw new Error("Invalid slug provided: must be a non-empty string");
1390
- const l = G(t);
1391
- if (!(yield this.model.exists(
1392
- this.createSlugQuery({ slug: l, field: r, isObject: s, haveHistory: i, filter: o })
1393
- )))
1394
- return l;
1395
- for (let m = 1; m <= et; m++) {
1396
- const h = `${l}-${m}`;
1397
- if (!(yield this.model.exists(
1398
- this.createSlugQuery({ slug: h, field: r, isObject: s, haveHistory: i, filter: o })
1399
- )))
1400
- return h;
1401
- }
1402
- const a = Date.now(), u = Math.random().toString(36).substring(2, 8);
1403
- return `${l}-${a}-${u}`;
1404
- });
1405
- }
1406
- /**
1407
- * Creates a slug for a document field.
1408
- * This method handles both simple string fields and object fields with nested slug generation.
1409
- *
1410
- * @param options - Configuration for slug creation including field, source document, and filter.
1411
- * @param options.field - The field name to create a slug for.
1412
- * @param options.from - The source document containing the field value.
1413
- * @param options.haveHistory - Whether to check historical slug fields for uniqueness.
1414
- * @param options.filter - Additional filter conditions to apply when checking slug existence.
1415
- * @returns A promise that resolves to a standardized response with the created slug(s).
1416
- */
1417
- createSlug(e) {
1418
- return v(this, arguments, function* ({ field: t, from: r, filter: s, haveHistory: i }) {
1419
- try {
1420
- const o = r[t];
1421
- return K(o) ? { success: !0, result: Object.fromEntries(
1422
- yield Promise.all(
1423
- Object.entries(o).map((u) => v(this, [u], function* ([m, h]) {
1424
- const _ = yield this.createUniqueSlug({
1425
- slug: h,
1426
- field: m,
1427
- isObject: !0,
1428
- haveHistory: i,
1429
- filter: s
1430
- });
1431
- return [m, _];
1432
- }))
1433
- )
1434
- ) } : { success: !0, result: yield this.createUniqueSlug({
1435
- slug: o,
1436
- field: t,
1437
- isObject: !1,
1438
- haveHistory: i,
1439
- filter: s
1440
- }) };
1441
- } catch (o) {
1442
- return D(o);
1443
- }
1444
- });
1445
- }
1446
- /**
1447
- * Checks if a slug already exists in the collection.
1448
- * This method verifies slug existence in both current and historical slug fields.
1449
- *
1450
- * @param options - Configuration for slug checking including slug, field, source document, and filter.
1451
- * @param options.slug - The slug string to check for existence.
1452
- * @param options.field - The field name for object-based slug checking.
1453
- * @param options.from - The source document containing the field value.
1454
- * @param options.haveHistory - Whether to check historical slug fields for existence.
1455
- * @param options.filter - Additional filter conditions to apply to the query.
1456
- * @returns A promise that resolves to a standardized response indicating whether the slug exists.
1457
- */
1458
- checkSlug(e) {
1459
- return v(this, arguments, function* ({ slug: t, field: r, from: s, filter: i, haveHistory: o }) {
1460
- try {
1461
- const l = s[r];
1462
- if (K(l)) {
1463
- const h = Object.values(l).map((b) => G(b));
1464
- return (yield Promise.all(
1465
- h.map(
1466
- (b) => this.model.exists(this.createSlugQuery({
1467
- slug: b,
1468
- field: r,
1469
- isObject: !0,
1470
- haveHistory: o,
1471
- filter: i
1472
- }))
1473
- )
1474
- )).some((b) => b) ? { success: !0, result: !0 } : { success: !0, result: !1 };
1475
- }
1476
- const a = G(t);
1477
- return { success: !0, result: (yield this.model.exists(this.createSlugQuery({
1478
- slug: a,
1479
- field: r,
1480
- isObject: !1,
1481
- filter: i
1482
- }))) !== null };
1483
- } catch (l) {
1484
- return D(l);
1485
- }
1486
- });
1487
- }
1488
- /**
1489
- * Performs aggregation operations on the collection.
1490
- *
1491
- * @param pipeline - The aggregation pipeline stages to execute.
1492
- * @returns A promise that resolves to a standardized response with the aggregation results.
1493
- */
1494
- aggregate(e) {
1495
- return v(this, null, function* () {
1496
- try {
1497
- return { success: !0, result: yield this.model.aggregate(e) };
1498
- } catch (t) {
1499
- return D(t);
1500
- }
1501
- });
1502
- }
1503
- /**
1504
- * Retrieves distinct values for the specified key from the collection.
1505
- *
1506
- * @param key - The field for which to return distinct values.
1507
- * @param filter - The filter query to apply (optional).
1508
- * @param options - Additional options for the distinct operation (optional).
1509
- * @returns A promise that resolves to a standardized response with the array of distinct values.
1510
- */
1511
- distinct(e) {
1512
- return v(this, arguments, function* (t, r = {}, s = {}) {
1513
- try {
1514
- return { success: !0, result: yield this.model.distinct(t, r, s) };
1515
- } catch (i) {
1516
- return D(i);
1517
- }
1518
- });
1519
- }
1520
- }
1521
594
  export {
1522
- It as MongoController,
1523
- Pt as MongooseController,
1524
- x as mongo
595
+ C as applyNestedPopulate,
596
+ E as convertEnumToModelName,
597
+ I as mongo
1525
598
  };