@cyberskill/shared 2.28.0 → 3.0.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 (91) hide show
  1. package/dist/config/config.util.cjs +1 -1
  2. package/dist/config/config.util.js +24 -33
  3. package/dist/config/eslint/index.cjs +1 -1
  4. package/dist/config/eslint/index.d.ts +4 -0
  5. package/dist/config/eslint/index.js +4 -12
  6. package/dist/config/graphql-codegen/graphql-codegen.util.cjs +1 -1
  7. package/dist/config/graphql-codegen/graphql-codegen.util.js +28 -33
  8. package/dist/config/storybook/storybook.preview.cjs +1 -1
  9. package/dist/config/storybook/storybook.preview.js +10 -13
  10. package/dist/config/vitest/vitest.e2e.cjs +1 -1
  11. package/dist/config/vitest/vitest.e2e.js +1 -1
  12. package/dist/config/vitest/vitest.unit.cjs +1 -1
  13. package/dist/config/vitest/vitest.unit.js +19 -8
  14. package/dist/constant/common.cjs +1 -1
  15. package/dist/constant/common.js +1 -1
  16. package/dist/node/apollo-server/apollo-server.util.cjs +1 -1
  17. package/dist/node/apollo-server/apollo-server.util.js +21 -48
  18. package/dist/node/cli/index.cjs +2 -2
  19. package/dist/node/cli/index.js +109 -165
  20. package/dist/node/command/command.util.cjs +2 -2
  21. package/dist/node/command/command.util.js +135 -170
  22. package/dist/node/express/express.util.cjs +1 -1
  23. package/dist/node/express/express.util.js +39 -72
  24. package/dist/node/fs/fs.util.cjs +3 -3
  25. package/dist/node/fs/fs.util.js +45 -60
  26. package/dist/node/log/log.util.cjs +1 -1
  27. package/dist/node/log/log.util.js +29 -30
  28. package/dist/node/mongo/mongo.controller.cjs +1 -1
  29. package/dist/node/mongo/mongo.controller.js +531 -629
  30. package/dist/node/mongo/mongo.util.cjs +2 -2
  31. package/dist/node/mongo/mongo.util.js +280 -321
  32. package/dist/node/package/package.util.cjs +1 -1
  33. package/dist/node/package/package.util.js +197 -226
  34. package/dist/node/path/index.cjs +1 -1
  35. package/dist/node/path/index.js +26 -25
  36. package/dist/node/path/path.constant.cjs +1 -1
  37. package/dist/node/path/path.constant.d.ts +2 -0
  38. package/dist/node/path/path.constant.js +130 -150
  39. package/dist/node/storage/storage.util.cjs +1 -1
  40. package/dist/node/storage/storage.util.js +110 -158
  41. package/dist/node/upload/upload.util.cjs +1 -1
  42. package/dist/node/upload/upload.util.js +119 -150
  43. package/dist/node/ws/ts.util.cjs +1 -1
  44. package/dist/node/ws/ts.util.js +31 -54
  45. package/dist/react/apollo-client/apollo-client.component.cjs +1 -1
  46. package/dist/react/apollo-client/apollo-client.component.js +4 -4
  47. package/dist/react/apollo-client/apollo-client.util.cjs +1 -1
  48. package/dist/react/apollo-client/apollo-client.util.js +51 -58
  49. package/dist/react/apollo-client/links/upload.cjs +1 -1
  50. package/dist/react/apollo-client/links/upload.js +71 -74
  51. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.cjs +1 -1
  52. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.js +11 -18
  53. package/dist/react/apollo-error/apollo-error.component.cjs +1 -1
  54. package/dist/react/apollo-error/apollo-error.component.js +61 -23
  55. package/dist/react/apollo-error/apollo-error.module.scss.cjs +1 -1
  56. package/dist/react/apollo-error/apollo-error.module.scss.js +6 -6
  57. package/dist/react/apollo-error/apollo-error.test.unit.d.ts +1 -0
  58. package/dist/react/apollo-error/apollo-error.util.cjs +1 -1
  59. package/dist/react/apollo-error/apollo-error.util.js +6 -6
  60. package/dist/react/loading/loading.component.cjs +2 -2
  61. package/dist/react/loading/loading.component.js +30 -46
  62. package/dist/react/log/log.util.cjs +1 -1
  63. package/dist/react/log/log.util.js +4 -4
  64. package/dist/react/next-intl/next-intl.hoc.cjs +1 -1
  65. package/dist/react/next-intl/next-intl.hoc.js +13 -22
  66. package/dist/react/next-intl/next-intl.provider.cjs +1 -1
  67. package/dist/react/next-intl/next-intl.provider.js +7 -7
  68. package/dist/react/storage/storage.hook.cjs +1 -1
  69. package/dist/react/storage/storage.hook.js +43 -59
  70. package/dist/react/storage/storage.util.cjs +1 -1
  71. package/dist/react/storage/storage.util.js +28 -53
  72. package/dist/react/userback/userback.component.cjs +1 -1
  73. package/dist/react/userback/userback.component.js +18 -42
  74. package/dist/style.css +1 -1
  75. package/dist/util/common/common.util.cjs +1 -1
  76. package/dist/util/common/common.util.d.ts +2 -0
  77. package/dist/util/common/common.util.js +29 -37
  78. package/dist/util/index.cjs +1 -1
  79. package/dist/util/index.js +10 -9
  80. package/dist/util/object/object.util.cjs +1 -1
  81. package/dist/util/object/object.util.js +72 -76
  82. package/dist/util/string/index.cjs +1 -1
  83. package/dist/util/string/index.js +4 -3
  84. package/dist/util/string/string.util.cjs +1 -1
  85. package/dist/util/string/string.util.d.ts +12 -0
  86. package/dist/util/string/string.util.js +63 -44
  87. package/package.json +25 -16
  88. package/public/tsconfig.base.json +7 -3
  89. package/README.md +0 -470
  90. /package/dist/node_modules/.pnpm/{vitest@4.0.18_@types_node@25.3.0_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2 → vitest@4.0.18_@types_node@25.3.3_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2}/node_modules/vitest/dist/config.cjs +0 -0
  91. /package/dist/node_modules/.pnpm/{vitest@4.0.18_@types_node@25.3.0_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2 → vitest@4.0.18_@types_node@25.3.3_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2}/node_modules/vitest/dist/config.js +0 -0
@@ -1,39 +1,16 @@
1
- import C from "migrate-mongo";
2
- import k from "mongoose-aggregate-paginate-v2";
3
- import U from "mongoose-paginate-v2";
4
- import { randomUUID as I } from "node:crypto";
5
- import { deepClone as q, getNestedValue as B, setNestedValue as J } from "../../util/object/object.util.js";
6
- import { regexSearchMapper as K } from "../../util/common/common.util.js";
7
- import { writeFileSync as L, addGitIgnoreEntry as H } from "../fs/fs.util.js";
8
- import { PATH as V, MIGRATE_MONGO_CONFIG as z } from "../path/path.constant.js";
9
- import { validate as Q } from "../../util/validate/validate.util.js";
10
- var W = Object.defineProperty, X = Object.defineProperties, Y = Object.getOwnPropertyDescriptors, x = Object.getOwnPropertySymbols, Z = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable, $ = (t, e, i) => e in t ? W(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i, M = (t, e) => {
11
- for (var i in e || (e = {}))
12
- Z.call(e, i) && $(t, i, e[i]);
13
- if (x)
14
- for (var i of x(e))
15
- T.call(e, i) && $(t, i, e[i]);
16
- return t;
17
- }, tt = (t, e) => X(t, Y(e)), w = (t, e, i) => new Promise((n, r) => {
18
- var o = (s) => {
19
- try {
20
- y(i.next(s));
21
- } catch (h) {
22
- r(h);
23
- }
24
- }, l = (s) => {
25
- try {
26
- y(i.throw(s));
27
- } catch (h) {
28
- r(h);
29
- }
30
- }, y = (s) => s.done ? n(s.value) : Promise.resolve(s.value).then(o, l);
31
- y((i = i.apply(t, e)).next());
32
- });
33
- function P(t) {
1
+ import I from "migrate-mongo";
2
+ import $ from "mongoose-aggregate-paginate-v2";
3
+ import G from "mongoose-paginate-v2";
4
+ import { randomUUID as x } from "node:crypto";
5
+ import { deepClone as D, getNestedValue as k, setNestedValue as C } from "../../util/object/object.util.js";
6
+ import { regexSearchMapper as U } from "../../util/common/common.util.js";
7
+ import { writeFileSync as q, addGitIgnoreEntry as B } from "../fs/fs.util.js";
8
+ import { PATH as V, MIGRATE_MONGO_CONFIG as P } from "../path/path.constant.js";
9
+ import { validate as J } from "../../util/validate/validate.util.js";
10
+ function A(t) {
34
11
  return t === t.toUpperCase() ? t.charAt(0).toUpperCase() + t.slice(1).toLowerCase() : t;
35
12
  }
36
- const A = {
13
+ const R = {
37
14
  /**
38
15
  * Creates generic fields that are commonly used across MongoDB documents.
39
16
  * This function generates standard fields including a UUID, deletion flag, and timestamps
@@ -43,7 +20,7 @@ const A = {
43
20
  */
44
21
  createGenericFields() {
45
22
  return {
46
- id: I(),
23
+ id: x(),
47
24
  isDel: !1,
48
25
  createdAt: /* @__PURE__ */ new Date(),
49
26
  updatedAt: /* @__PURE__ */ new Date()
@@ -68,8 +45,8 @@ const A = {
68
45
  * @param middlewares - An array of middleware configurations with method, pre, and post functions.
69
46
  */
70
47
  applyMiddlewares(t, e) {
71
- e.forEach(({ method: i, pre: n, post: r }) => {
72
- i && n && t.pre(i, n), i && r && t.post(i, r);
48
+ e.forEach(({ method: i, pre: a, post: r }) => {
49
+ i && a && t.pre(i, a), i && r && t.post(i, r);
73
50
  });
74
51
  },
75
52
  /**
@@ -83,7 +60,7 @@ const A = {
83
60
  createGenericSchema(t) {
84
61
  return new t.Schema(
85
62
  {
86
- id: { type: String, default: () => I(), unique: !0 },
63
+ id: { type: String, default: () => x(), unique: !0 },
87
64
  isDel: { type: Boolean, default: !1 }
88
65
  },
89
66
  { timestamps: !0 }
@@ -105,7 +82,7 @@ const A = {
105
82
  mongoose: t,
106
83
  schema: e,
107
84
  virtuals: i = [],
108
- standalone: n = !1
85
+ standalone: a = !1
109
86
  }) {
110
87
  const r = new t.Schema(e, {
111
88
  toJSON: { virtuals: !0 },
@@ -113,23 +90,22 @@ const A = {
113
90
  toObject: { virtuals: !0 }
114
91
  // So `console.log()` and other functions that use `toObject()` include virtuals
115
92
  });
116
- return i.forEach(({ name: o, options: l, get: y }) => {
117
- if (A.isDynamicVirtual(l)) {
118
- const s = r.statics;
119
- s._dynamicVirtuals || (s._dynamicVirtuals = []), s._dynamicVirtuals.push({
93
+ return i.forEach(({ name: o, options: s, get: u }) => {
94
+ if (R.isDynamicVirtual(s)) {
95
+ const p = r.statics;
96
+ p._dynamicVirtuals || (p._dynamicVirtuals = []), p._dynamicVirtuals.push({
120
97
  name: o,
121
- options: l
98
+ options: s
122
99
  });
123
- const h = r.virtual(o);
124
- y ? h.get(y) : h.get(function() {
125
- var u;
126
- return ((u = this._populated) == null ? void 0 : u[o]) || (l != null && l.count ? 0 : l != null && l.justOne ? null : []);
100
+ const y = r.virtual(o);
101
+ u ? y.get(u) : y.get(function() {
102
+ return this._populated?.[o] || (s?.count ? 0 : s?.justOne ? null : []);
127
103
  });
128
104
  } else {
129
- const s = r.virtual(o, l);
130
- y && s.get(y);
105
+ const p = r.virtual(o, s);
106
+ u && p.get(u);
131
107
  }
132
- }), n || r.add(A.createGenericSchema(t)), r;
108
+ }), a || r.add(R.createGenericSchema(t)), r;
133
109
  },
134
110
  /**
135
111
  * Creates a Mongoose model with plugins, middleware, and pagination support.
@@ -151,22 +127,22 @@ const A = {
151
127
  mongoose: t,
152
128
  name: e,
153
129
  schema: i,
154
- virtuals: n = [],
130
+ virtuals: a = [],
155
131
  pagination: r = !0,
156
132
  aggregate: o = !0,
157
- middlewares: l = []
133
+ middlewares: s = []
158
134
  }) {
159
135
  if (!e)
160
136
  throw new Error("Model name is required.");
161
137
  if (t.models[e])
162
138
  return t.models[e];
163
- const y = A.createSchema({ mongoose: t, schema: i, virtuals: n });
164
- (r || o) && A.applyPlugins(y, [
165
- r && U,
166
- o && k
167
- ]), A.applyMiddlewares(y, l);
168
- const s = t.model(e, y);
169
- return n.length > 0 && (s._virtualConfigs = n), s;
139
+ const u = R.createSchema({ mongoose: t, schema: i, virtuals: a });
140
+ (r || o) && R.applyPlugins(u, [
141
+ r && G,
142
+ o && $
143
+ ]), R.applyMiddlewares(u, s);
144
+ const p = t.model(e, u);
145
+ return a.length > 0 && (p._virtualConfigs = a), p;
170
146
  },
171
147
  /**
172
148
  * Validation utilities for Mongoose schemas.
@@ -181,10 +157,8 @@ const A = {
181
157
  * @returns A validation function that returns true if the field is not empty.
182
158
  */
183
159
  isRequired() {
184
- return function(t) {
185
- return w(this, null, function* () {
186
- return !Q.isEmpty(t);
187
- });
160
+ return async function(t) {
161
+ return !J.isEmpty(t);
188
162
  };
189
163
  },
190
164
  /**
@@ -197,13 +171,11 @@ const A = {
197
171
  * @throws {Error} When fields is not a non-empty array of strings.
198
172
  */
199
173
  isUnique(t) {
200
- return function(e) {
201
- return w(this, null, function* () {
202
- if (!Array.isArray(t) || t.length === 0)
203
- throw new Error("Fields must be a non-empty array of strings.");
204
- const i = { $or: t.map((r) => ({ [r]: e })) };
205
- return !(yield this.constructor.exists(i));
206
- });
174
+ return async function(e) {
175
+ if (!Array.isArray(t) || t.length === 0)
176
+ throw new Error("Fields must be a non-empty array of strings.");
177
+ const i = { $or: t.map((r) => ({ [r]: e })) };
178
+ return !await this.constructor.exists(i);
207
179
  };
208
180
  },
209
181
  /**
@@ -216,18 +188,19 @@ const A = {
216
188
  * @throws {Error} When regexArray is not an array of valid RegExp objects.
217
189
  */
218
190
  matchesRegex(t) {
219
- return (e) => w(null, null, function* () {
191
+ return async (e) => {
220
192
  if (!Array.isArray(t) || t.some((i) => !(i instanceof RegExp)))
221
193
  throw new Error("regexArray must be an array of valid RegExp objects.");
222
194
  return t.every((i) => i.test(e));
223
- });
195
+ };
224
196
  }
225
197
  },
226
198
  /**
227
199
  * Migration utilities for MongoDB.
228
200
  * This object extends the migrate-mongo library with additional configuration utilities.
229
201
  */
230
- migrate: tt(M({}, C), {
202
+ migrate: {
203
+ ...I,
231
204
  /**
232
205
  * Sets the migration configuration and updates .gitignore.
233
206
  * This function creates a migration configuration file and ensures it's properly
@@ -238,9 +211,9 @@ const A = {
238
211
  setConfig: (t) => {
239
212
  const e = `// This file is automatically generated by the Cyberskill CLI.
240
213
  module.exports = ${JSON.stringify(t, null, 4)}`;
241
- L(V.MIGRATE_MONGO_CONFIG, e), H(V.GIT_IGNORE, z);
214
+ q(V.MIGRATE_MONGO_CONFIG, e), B(V.GIT_IGNORE, P);
242
215
  }
243
- }),
216
+ },
244
217
  /**
245
218
  * Converts string values in a filter to regex patterns for case-insensitive search.
246
219
  * This function recursively processes a filter object and converts string values in specified fields
@@ -253,17 +226,17 @@ module.exports = ${JSON.stringify(t, null, 4)}`;
253
226
  regexify(t, e) {
254
227
  if (!t)
255
228
  return {};
256
- let i = q(t);
229
+ let i = D(t);
257
230
  if (!e || e.length === 0)
258
231
  return i;
259
- for (const n of e) {
260
- const r = n.toString().split("."), o = B(i, r);
232
+ for (const a of e) {
233
+ const r = a.toString().split("."), o = k(i, r);
261
234
  if (typeof o == "string" && o.length > 0) {
262
- const l = {
263
- $regex: `.*${K(o)}.*`,
235
+ const s = {
236
+ $regex: `.*${U(o)}.*`,
264
237
  $options: "i"
265
238
  };
266
- i = J(i, r, l);
239
+ i = C(i, r, s);
267
240
  }
268
241
  }
269
242
  return i;
@@ -284,15 +257,13 @@ module.exports = ${JSON.stringify(t, null, 4)}`;
284
257
  * @param filterFn - Function to determine if a record already exists
285
258
  * @returns Array of records that don't exist in the database
286
259
  */
287
- getNewRecords(t, e, i) {
288
- return w(this, null, function* () {
289
- const n = yield t.findAll({});
290
- return n.success ? e.filter(
291
- (o) => !n.result.some(
292
- (l) => i(l, o)
293
- )
294
- ) : e;
295
- });
260
+ async getNewRecords(t, e, i) {
261
+ const a = await t.findAll({});
262
+ return a.success ? e.filter(
263
+ (o) => !a.result.some(
264
+ (s) => i(s, o)
265
+ )
266
+ ) : e;
296
267
  },
297
268
  /**
298
269
  * Generic utility function to get existing records that match the filter criteria
@@ -301,293 +272,281 @@ module.exports = ${JSON.stringify(t, null, 4)}`;
301
272
  * @param filterFn - Function to determine if a record exists
302
273
  * @returns Array of existing records that match the filter criteria
303
274
  */
304
- getExistingRecords(t, e, i) {
305
- return w(this, null, function* () {
306
- const n = yield t.findAll({});
307
- return n.success ? n.result.filter(
308
- (o) => e.some(
309
- (l) => i(o, l)
310
- )
311
- ) : [];
312
- });
275
+ async getExistingRecords(t, e, i) {
276
+ const a = await t.findAll({});
277
+ return a.success ? a.result.filter(
278
+ (o) => e.some(
279
+ (s) => i(o, s)
280
+ )
281
+ ) : [];
313
282
  }
314
283
  };
315
- function D(t, e, i, n, r) {
316
- return w(this, null, function* () {
317
- if (!e.length || !i)
318
- return e;
319
- const o = Array.isArray(i) ? i : [i];
320
- for (const l of o)
321
- typeof l == "string" ? yield G(t, e, l, n, r) : l && typeof l == "object" && (yield et(t, e, l, n, r));
284
+ async function _(t, e, i, a, r) {
285
+ if (!e.length || !i)
322
286
  return e;
323
- });
287
+ const o = Array.isArray(i) ? i : [i];
288
+ for (const s of o)
289
+ typeof s == "string" ? await E(t, e, s, a, r) : s && typeof s == "object" && await K(t, e, s, a, r);
290
+ return e;
324
291
  }
325
- function G(t, e, i, n, r) {
326
- return w(this, null, function* () {
327
- var o, l, y, s;
328
- const h = i.split(".");
329
- if (h.length < 2) {
330
- for (const m of e)
331
- yield F(t, m, i, n, void 0, r);
332
- return;
333
- }
334
- const u = h[0];
335
- if (!u || u.trim() === "")
336
- return;
337
- const R = h.slice(1).join(".");
338
- for (const m of e) {
339
- const j = m, O = j[u];
340
- if (O && typeof O == "object") {
341
- let c = r;
342
- const a = c;
343
- if (r && r.schema && r.schema.virtuals) {
344
- const f = r.schema.virtuals[u];
345
- if (f && f.options && f.options.ref) {
346
- let b;
347
- if (typeof f.options.ref == "function" ? b = f.options.ref(j) : typeof f.options.ref == "string" && (b = f.options.ref), b) {
348
- const p = P(b);
349
- t.models[p] && (c = t.models[p]);
350
- }
292
+ async function E(t, e, i, a, r) {
293
+ const o = i.split(".");
294
+ if (o.length < 2) {
295
+ for (const p of e)
296
+ await F(t, p, i, a, void 0, r);
297
+ return;
298
+ }
299
+ const s = o[0];
300
+ if (!s || s.trim() === "")
301
+ return;
302
+ const u = o.slice(1).join(".");
303
+ for (const p of e) {
304
+ const y = p, l = y[s];
305
+ if (l && typeof l == "object") {
306
+ let b = r;
307
+ const d = b;
308
+ if (r && r.schema && r.schema.virtuals) {
309
+ const f = r.schema.virtuals[s];
310
+ if (f && f.options && f.options.ref) {
311
+ let c;
312
+ if (typeof f.options.ref == "function" ? c = f.options.ref(y) : typeof f.options.ref == "string" && (c = f.options.ref), c) {
313
+ const n = A(c);
314
+ t.models[n] && (b = t.models[n]);
351
315
  }
352
316
  }
353
- if (!c) {
354
- const f = (l = (o = r == null ? void 0 : r.schema) == null ? void 0 : o.statics) != null ? l : {}, p = ((r == null ? void 0 : r._virtualConfigs) || f._dynamicVirtuals || []).find((d) => d.name === u);
355
- if (p && p.options && p.options.ref) {
356
- let d;
357
- if (typeof p.options.ref == "function" ? d = p.options.ref(j) : typeof p.options.ref == "string" && (d = p.options.ref), d) {
358
- const g = P(d);
359
- t.models[g] && (c = t.models[g]);
360
- }
317
+ }
318
+ if (!b) {
319
+ const f = r?.schema?.statics ?? {}, n = (r?._virtualConfigs || f._dynamicVirtuals || []).find((m) => m.name === s);
320
+ if (n && n.options && n.options.ref) {
321
+ let m;
322
+ if (typeof n.options.ref == "function" ? m = n.options.ref(y) : typeof n.options.ref == "string" && (m = n.options.ref), m) {
323
+ const v = A(m);
324
+ t.models[v] && (b = t.models[v]);
361
325
  }
362
326
  }
363
- if (c === a) {
364
- 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);
365
- if (p && p.options && p.options.ref) {
366
- let d;
367
- if (typeof p.options.ref == "function" ? d = p.options.ref(j) : typeof p.options.ref == "string" && (d = p.options.ref), d) {
368
- const g = P(d);
369
- t.models[g] && (c = t.models[g]);
370
- }
327
+ }
328
+ if (b === d) {
329
+ const f = r?.schema?.statics ?? {}, n = (r?._virtualConfigs || f._dynamicVirtuals || []).find((m) => m.name === s);
330
+ if (n && n.options && n.options.ref) {
331
+ let m;
332
+ if (typeof n.options.ref == "function" ? m = n.options.ref(y) : typeof n.options.ref == "string" && (m = n.options.ref), m) {
333
+ const v = A(m);
334
+ t.models[v] && (b = t.models[v]);
371
335
  }
372
336
  }
373
- if (Array.isArray(O))
374
- for (const f of O)
375
- f && typeof f == "object" && (yield F(t, f, R, n, u, c));
376
- else O && typeof O == "object" && (yield F(t, O, R, n, u, c));
377
337
  }
338
+ if (Array.isArray(l))
339
+ for (const f of l)
340
+ f && typeof f == "object" && await F(t, f, u, a, s, b);
341
+ else l && typeof l == "object" && await F(t, l, u, a, s, b);
378
342
  }
379
- });
343
+ }
380
344
  }
381
- function et(t, e, i, n, r) {
382
- return w(this, null, function* () {
383
- const { path: o, populate: l } = i;
384
- if (!o)
385
- return;
386
- if (!l) {
387
- yield G(t, e, o, n, r);
388
- return;
389
- }
390
- const y = o;
391
- for (const s of e) {
392
- const h = s, u = h[y];
393
- let R = r;
394
- if (r && r.schema && r.schema.virtuals) {
395
- const m = r.schema.virtuals[y];
396
- if (m && m.options && m.options.ref) {
397
- let j;
398
- if (typeof m.options.ref == "function" ? j = m.options.ref(h) : typeof m.options.ref == "string" && (j = m.options.ref), j) {
399
- const O = P(j);
400
- t.models[O] && (R = t.models[O]);
401
- }
345
+ async function K(t, e, i, a, r) {
346
+ const { path: o, populate: s } = i;
347
+ if (!o)
348
+ return;
349
+ if (!s) {
350
+ await E(t, e, o, a, r);
351
+ return;
352
+ }
353
+ const u = o;
354
+ for (const p of e) {
355
+ const y = p, l = y[u];
356
+ let b = r;
357
+ if (r && r.schema && r.schema.virtuals) {
358
+ const d = r.schema.virtuals[u];
359
+ if (d && d.options && d.options.ref) {
360
+ let f;
361
+ if (typeof d.options.ref == "function" ? f = d.options.ref(y) : typeof d.options.ref == "string" && (f = d.options.ref), f) {
362
+ const c = A(f);
363
+ t.models[c] && (b = t.models[c]);
402
364
  }
403
365
  }
404
- if (!R && typeof u == "object" && u && "entityType" in u) {
405
- const m = P(String(u.entityType));
406
- t.models[m] && (R = t.models[m]);
407
- }
408
- if (u && typeof u == "object")
409
- if (Array.isArray(u))
410
- for (const m of u)
411
- m && typeof m == "object" && (yield D(t, [m], l, n, R));
412
- else u && typeof u == "object" && (yield D(t, [u], l, n, R));
413
366
  }
414
- });
367
+ if (!b && typeof l == "object" && l && "entityType" in l) {
368
+ const d = A(String(l.entityType));
369
+ t.models[d] && (b = t.models[d]);
370
+ }
371
+ if (l && typeof l == "object")
372
+ if (Array.isArray(l))
373
+ for (const d of l)
374
+ d && typeof d == "object" && await _(t, [d], s, a, b);
375
+ else l && typeof l == "object" && await _(t, [l], s, a, b);
376
+ }
415
377
  }
416
- function E(t, e, i, n) {
378
+ function S(t, e, i, a) {
417
379
  if (!i || !e || !e.schema)
418
380
  return;
419
381
  const r = i.split(".");
420
382
  let o = e.schema;
421
- for (let l = 0; l < r.length; l++) {
422
- const y = r[l];
423
- if (o && o.virtuals && y) {
424
- const s = o.virtuals[y];
425
- if (s && s.options && s.options.ref) {
426
- let h;
427
- if (typeof s.options.ref == "function" ? h = s.options.ref(n) : typeof s.options.ref == "string" && (h = s.options.ref), h && typeof h == "string") {
428
- if (l === r.length - 1)
429
- return h;
430
- const u = t.models[h];
431
- if (u && u.schema) {
432
- o = u.schema;
383
+ for (let s = 0; s < r.length; s++) {
384
+ const u = r[s];
385
+ if (o && o.virtuals && u) {
386
+ const p = o.virtuals[u];
387
+ if (p && p.options && p.options.ref) {
388
+ let y;
389
+ if (typeof p.options.ref == "function" ? y = p.options.ref(a) : typeof p.options.ref == "string" && (y = p.options.ref), y && typeof y == "string") {
390
+ if (s === r.length - 1)
391
+ return y;
392
+ const l = t.models[y];
393
+ if (l && l.schema) {
394
+ o = l.schema;
433
395
  continue;
434
396
  }
435
397
  }
436
398
  }
437
399
  }
438
- if (o && o.paths && y) {
439
- const s = o.paths[y];
440
- if (s && s.schema) {
441
- o = s.schema;
400
+ if (o && o.paths && u) {
401
+ const p = o.paths[u];
402
+ if (p && p.schema) {
403
+ o = p.schema;
442
404
  continue;
443
405
  }
444
406
  }
445
407
  return;
446
408
  }
447
409
  }
448
- function it(t, e) {
410
+ function L(t, e) {
449
411
  if (e)
450
412
  for (const i of Object.keys(t.models)) {
451
- const n = t.models[i], r = n == null ? void 0 : n.schema;
413
+ const a = t.models[i], r = a?.schema;
452
414
  if (r && (r.paths && r.paths[e] || r.virtuals && r.virtuals[e]))
453
- return n;
415
+ return a;
454
416
  }
455
417
  }
456
- function rt(t, e) {
418
+ function H(t, e) {
457
419
  const i = (e || "").split(".")[0] || "";
458
420
  if (i)
459
- for (const n of Object.keys(t.models)) {
460
- const r = t.models[n], o = r == null ? void 0 : r.schema;
421
+ for (const a of Object.keys(t.models)) {
422
+ const r = t.models[a], o = r?.schema;
461
423
  if (o && (o.paths && o.paths[i] || o.virtuals && o.virtuals[i]))
462
424
  return r;
463
425
  }
464
426
  }
465
- function F(t, e, i, n, r, o) {
466
- return w(this, null, function* () {
467
- var l, y;
468
- let s = e.__t;
469
- if (!s) {
470
- if (o) {
471
- const c = r ? `${r}.${i}` : i, a = (c || "").split(".")[0] || "";
472
- let f = o;
473
- 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])) {
474
- const d = rt(t, c);
475
- d && (f = d);
476
- }
477
- const p = E(t, f, c, e);
478
- if (p)
479
- s = p;
480
- else {
481
- const d = (c.includes(".") ? c.split(".").pop() : c) || "";
482
- if (d) {
483
- const g = it(t, d);
484
- if (g) {
485
- const N = E(t, g, c, e);
486
- N && (s = N);
487
- }
427
+ async function F(t, e, i, a, r, o) {
428
+ let s = e.__t;
429
+ if (!s) {
430
+ if (o) {
431
+ const f = r ? `${r}.${i}` : i, c = (f || "").split(".")[0] || "";
432
+ let n = o;
433
+ if (!!!(n?.schema?.paths && n.schema.paths[c] || n?.schema?.virtuals && n.schema.virtuals[c])) {
434
+ const w = H(t, f);
435
+ w && (n = w);
436
+ }
437
+ const v = S(t, n, f, e);
438
+ if (v)
439
+ s = v;
440
+ else {
441
+ const w = (f.includes(".") ? f.split(".").pop() : f) || "";
442
+ if (w) {
443
+ const O = L(t, w);
444
+ if (O) {
445
+ const N = S(t, O, f, e);
446
+ N && (s = N);
488
447
  }
489
448
  }
490
449
  }
491
- if (n && n.length > 0) {
492
- const c = i.split(".").pop() || "", a = n.find((f) => f.name === c);
493
- if (a && a.options.ref) {
494
- let f;
495
- typeof a.options.ref == "function" ? f = a.options.ref(e) : typeof a.options.ref == "string" && (f = a.options.ref), f && typeof f == "string" && (s = f);
496
- }
450
+ }
451
+ if (a && a.length > 0) {
452
+ const f = i.split(".").pop() || "", c = a.find((n) => n.name === f);
453
+ if (c && c.options.ref) {
454
+ let n;
455
+ typeof c.options.ref == "function" ? n = c.options.ref(e) : typeof c.options.ref == "string" && (n = c.options.ref), n && typeof n == "string" && (s = n);
497
456
  }
498
- if (!s) {
499
- for (const [c, a] of Object.entries(e))
500
- if (c === "entityType" && typeof a == "string") {
501
- s = a;
502
- break;
503
- }
504
- if (s && t.models[s]) {
505
- const c = t.models[s];
506
- if (c && c.schema) {
507
- const a = c.schema, f = i.split(".").pop() || "", b = (d, g = "root") => {
508
- if (!d || !d.virtuals)
509
- return;
510
- const N = d.virtuals;
511
- for (const _ of Object.keys(N))
512
- if (_ === f) {
513
- const v = N[_];
514
- if (v && v.options && v.options.ref) {
515
- let S;
516
- if (typeof v.options.ref == "function" ? S = v.options.ref(e) : typeof v.options.ref == "string" && (S = v.options.ref), S && typeof S == "string")
517
- return S;
518
- }
519
- }
520
- if (d.paths)
521
- for (const _ of Object.keys(d.paths)) {
522
- const v = d.paths[_];
523
- if (v && v.schema) {
524
- const S = b(v.schema, `${g}.${_}`);
525
- if (S)
526
- return S;
527
- }
528
- }
529
- }, p = b(a);
530
- p && (s = p);
531
- }
457
+ }
458
+ if (!s) {
459
+ for (const [f, c] of Object.entries(e))
460
+ if (f === "entityType" && typeof c == "string") {
461
+ s = c;
462
+ break;
532
463
  }
533
- }
534
- if (!s) {
535
- const c = i.split(".").pop() || "";
536
- if (o && o.schema) {
537
- const a = o.schema, f = (p, d = "root") => {
538
- if (!p || !p.virtuals)
464
+ if (s && t.models[s]) {
465
+ const f = t.models[s];
466
+ if (f && f.schema) {
467
+ const c = f.schema, n = i.split(".").pop() || "", m = (w, O = "root") => {
468
+ if (!w || !w.virtuals)
539
469
  return;
540
- const g = p.virtuals;
541
- for (const N of Object.keys(g))
542
- if (N === c) {
543
- const _ = g[N];
544
- if (_ && _.options && _.options.ref) {
545
- let v;
546
- if (typeof _.options.ref == "function" ? v = _.options.ref(e) : typeof _.options.ref == "string" && (v = _.options.ref), v && typeof v == "string")
547
- return v;
470
+ const N = w.virtuals;
471
+ for (const g of Object.keys(N))
472
+ if (g === n) {
473
+ const h = N[g];
474
+ if (h && h.options && h.options.ref) {
475
+ let j;
476
+ if (typeof h.options.ref == "function" ? j = h.options.ref(e) : typeof h.options.ref == "string" && (j = h.options.ref), j && typeof j == "string")
477
+ return j;
548
478
  }
549
479
  }
550
- if (p.paths)
551
- for (const N of Object.keys(p.paths)) {
552
- const _ = p.paths[N];
553
- if (_ && _.schema) {
554
- const v = f(_.schema, `${d}.${N}`);
555
- if (v)
556
- return v;
480
+ if (w.paths)
481
+ for (const g of Object.keys(w.paths)) {
482
+ const h = w.paths[g];
483
+ if (h && h.schema) {
484
+ const j = m(h.schema, `${O}.${g}`);
485
+ if (j)
486
+ return j;
557
487
  }
558
488
  }
559
- }, b = f(a);
560
- b && (s = b);
561
- }
562
- if (!s && o) {
563
- const a = E(t, o, i, e);
564
- a && (s = a);
565
- }
566
- if (!s && n && n.length > 0) {
567
- const a = n.find((f) => f.name === c);
568
- if (a && a.options.ref) {
569
- let f;
570
- typeof a.options.ref == "function" ? f = a.options.ref(e) : typeof a.options.ref == "string" && (f = a.options.ref), f && typeof f == "string" && (s = f);
571
- }
489
+ }, v = m(c);
490
+ v && (s = v);
572
491
  }
573
492
  }
574
- if (!s) {
575
- const c = i.split(".").pop() || "", a = c ? c.charAt(0).toUpperCase() + c.slice(1) : "";
576
- a && t.models[a] && (s = a);
493
+ }
494
+ if (!s) {
495
+ const f = i.split(".").pop() || "";
496
+ if (o && o.schema) {
497
+ const c = o.schema, n = (v, w = "root") => {
498
+ if (!v || !v.virtuals)
499
+ return;
500
+ const O = v.virtuals;
501
+ for (const N of Object.keys(O))
502
+ if (N === f) {
503
+ const g = O[N];
504
+ if (g && g.options && g.options.ref) {
505
+ let h;
506
+ if (typeof g.options.ref == "function" ? h = g.options.ref(e) : typeof g.options.ref == "string" && (h = g.options.ref), h && typeof h == "string")
507
+ return h;
508
+ }
509
+ }
510
+ if (v.paths)
511
+ for (const N of Object.keys(v.paths)) {
512
+ const g = v.paths[N];
513
+ if (g && g.schema) {
514
+ const h = n(g.schema, `${w}.${N}`);
515
+ if (h)
516
+ return h;
517
+ }
518
+ }
519
+ }, m = n(c);
520
+ m && (s = m);
521
+ }
522
+ if (!s && o) {
523
+ const c = S(t, o, i, e);
524
+ c && (s = c);
577
525
  }
526
+ if (!s && a && a.length > 0) {
527
+ const c = a.find((n) => n.name === f);
528
+ if (c && c.options.ref) {
529
+ let n;
530
+ typeof c.options.ref == "function" ? n = c.options.ref(e) : typeof c.options.ref == "string" && (n = c.options.ref), n && typeof n == "string" && (s = n);
531
+ }
532
+ }
533
+ }
534
+ if (!s) {
535
+ const f = i.split(".").pop() || "", c = f ? f.charAt(0).toUpperCase() + f.slice(1) : "";
536
+ c && t.models[c] && (s = c);
578
537
  }
579
- const h = t.models[s];
580
- if (!h)
581
- return;
582
- const u = `${i}Id`, R = `${i}Ids`, m = e[u] || e[R] || e[i];
583
- if (!m)
584
- return;
585
- const j = Array.isArray(m) ? m : [m], O = yield h.find({ id: { $in: j } }).lean();
586
- O.length > 0 && (Array.isArray(m) ? e[i] = O : e[i] = O[0]);
587
- });
538
+ }
539
+ const u = t.models[s];
540
+ if (!u)
541
+ return;
542
+ const p = `${i}Id`, y = `${i}Ids`, l = e[p] || e[y] || e[i];
543
+ if (!l)
544
+ return;
545
+ const b = Array.isArray(l) ? l : [l], d = await u.find({ id: { $in: b } }).lean();
546
+ d.length > 0 && (Array.isArray(l) ? e[i] = d : e[i] = d[0]);
588
547
  }
589
548
  export {
590
- D as applyNestedPopulate,
591
- P as convertEnumToModelName,
592
- A as mongo
549
+ _ as applyNestedPopulate,
550
+ A as convertEnumToModelName,
551
+ R as mongo
593
552
  };