@cyberskill/shared 2.27.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 (98) 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 +6 -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 -5
  19. package/dist/node/cli/index.js +109 -170
  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 +4 -1
  25. package/dist/node/fs/fs.util.d.ts +8 -0
  26. package/dist/node/fs/fs.util.js +46 -53
  27. package/dist/node/fs/index.cjs +1 -1
  28. package/dist/node/fs/index.js +13 -12
  29. package/dist/node/log/log.util.cjs +1 -1
  30. package/dist/node/log/log.util.js +29 -30
  31. package/dist/node/mongo/mongo.controller.cjs +1 -1
  32. package/dist/node/mongo/mongo.controller.js +531 -629
  33. package/dist/node/mongo/mongo.type.js +3 -3
  34. package/dist/node/mongo/mongo.util.cjs +2 -5
  35. package/dist/node/mongo/mongo.util.js +308 -354
  36. package/dist/node/package/package.util.cjs +1 -1
  37. package/dist/node/package/package.util.js +197 -226
  38. package/dist/node/path/index.cjs +1 -1
  39. package/dist/node/path/index.js +26 -25
  40. package/dist/node/path/path.constant.cjs +1 -1
  41. package/dist/node/path/path.constant.d.ts +2 -0
  42. package/dist/node/path/path.constant.js +130 -150
  43. package/dist/node/storage/storage.util.cjs +1 -1
  44. package/dist/node/storage/storage.util.js +110 -158
  45. package/dist/node/upload/upload.util.cjs +1 -1
  46. package/dist/node/upload/upload.util.js +119 -150
  47. package/dist/node/ws/ts.util.cjs +1 -1
  48. package/dist/node/ws/ts.util.js +31 -54
  49. package/dist/react/apollo-client/apollo-client.component.cjs +1 -1
  50. package/dist/react/apollo-client/apollo-client.component.js +4 -4
  51. package/dist/react/apollo-client/apollo-client.util.cjs +1 -1
  52. package/dist/react/apollo-client/apollo-client.util.js +51 -58
  53. package/dist/react/apollo-client/links/upload.cjs +1 -1
  54. package/dist/react/apollo-client/links/upload.js +71 -74
  55. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.cjs +1 -1
  56. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.js +11 -18
  57. package/dist/react/apollo-error/apollo-error.component.cjs +1 -1
  58. package/dist/react/apollo-error/apollo-error.component.js +61 -23
  59. package/dist/react/apollo-error/apollo-error.module.scss.cjs +1 -1
  60. package/dist/react/apollo-error/apollo-error.module.scss.js +6 -6
  61. package/dist/react/apollo-error/apollo-error.test.unit.d.ts +1 -0
  62. package/dist/react/apollo-error/apollo-error.util.cjs +1 -1
  63. package/dist/react/apollo-error/apollo-error.util.js +6 -6
  64. package/dist/react/loading/loading.component.cjs +2 -2
  65. package/dist/react/loading/loading.component.js +30 -46
  66. package/dist/react/log/log.util.cjs +1 -1
  67. package/dist/react/log/log.util.js +4 -4
  68. package/dist/react/next-intl/next-intl.hoc.cjs +1 -1
  69. package/dist/react/next-intl/next-intl.hoc.js +13 -22
  70. package/dist/react/next-intl/next-intl.provider.cjs +1 -1
  71. package/dist/react/next-intl/next-intl.provider.js +7 -7
  72. package/dist/react/storage/storage.hook.cjs +1 -1
  73. package/dist/react/storage/storage.hook.js +43 -59
  74. package/dist/react/storage/storage.util.cjs +1 -1
  75. package/dist/react/storage/storage.util.js +28 -53
  76. package/dist/react/userback/userback.component.cjs +1 -1
  77. package/dist/react/userback/userback.component.js +18 -42
  78. package/dist/style.css +1 -1
  79. package/dist/util/common/common.util.cjs +1 -1
  80. package/dist/util/common/common.util.d.ts +11 -0
  81. package/dist/util/common/common.util.js +33 -37
  82. package/dist/util/common/index.cjs +1 -1
  83. package/dist/util/common/index.js +6 -5
  84. package/dist/util/index.cjs +1 -1
  85. package/dist/util/index.js +22 -20
  86. package/dist/util/object/object.util.cjs +1 -1
  87. package/dist/util/object/object.util.js +70 -70
  88. package/dist/util/string/index.cjs +1 -1
  89. package/dist/util/string/index.js +4 -3
  90. package/dist/util/string/string.util.cjs +1 -1
  91. package/dist/util/string/string.util.d.ts +12 -0
  92. package/dist/util/string/string.util.js +63 -44
  93. package/package.json +53 -44
  94. package/public/tsconfig.base.json +7 -3
  95. package/README.md +0 -470
  96. package/dist/node/mongo/mongo.util.d.ts +0 -1040
  97. /package/dist/node_modules/.pnpm/{vitest@4.0.17_@types_node@25.0.9_jiti@2.6.1_jsdom@27.4.0_@noble_hashes@1.8.0__sass@1.97.2_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
  98. /package/dist/node_modules/.pnpm/{vitest@4.0.17_@types_node@25.0.9_jiti@2.6.1_jsdom@27.4.0_@noble_hashes@1.8.0__sass@1.97.2_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 U from "migrate-mongo";
2
- import q from "mongoose-aggregate-paginate-v2";
3
- import B from "mongoose-paginate-v2";
1
+ import I from "migrate-mongo";
2
+ import $ from "mongoose-aggregate-paginate-v2";
3
+ import G from "mongoose-paginate-v2";
4
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) => {
19
- try {
20
- y(e.next(s));
21
- } catch (h) {
22
- r(h);
23
- }
24
- }, l = (s) => {
25
- try {
26
- y(e.throw(s));
27
- } catch (h) {
28
- r(h);
29
- }
30
- }, y = (s) => s.done ? o(s.value) : Promise.resolve(s.value).then(n, l);
31
- y((e = e.apply(t, i)).next());
32
- });
33
- function E(t) {
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 I = {
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
@@ -57,8 +34,8 @@ const I = {
57
34
  * @param schema - The Mongoose schema to apply plugins to.
58
35
  * @param plugins - An array of plugin functions or false values to filter and apply.
59
36
  */
60
- applyPlugins(t, i) {
61
- i.filter((e) => typeof e == "function").forEach((e) => t.plugin(e));
37
+ applyPlugins(t, e) {
38
+ e.filter((i) => typeof i == "function").forEach((i) => t.plugin(i));
62
39
  },
63
40
  /**
64
41
  * Applies middleware functions to a Mongoose schema.
@@ -67,9 +44,9 @@ const I = {
67
44
  * @param schema - The Mongoose schema to apply middleware to.
68
45
  * @param middlewares - An array of middleware configurations with method, pre, and post functions.
69
46
  */
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);
47
+ applyMiddlewares(t, e) {
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
  /**
@@ -103,33 +80,32 @@ const I = {
103
80
  */
104
81
  createSchema({
105
82
  mongoose: t,
106
- schema: i,
107
- virtuals: e = [],
108
- standalone: o = !1
83
+ schema: e,
84
+ virtuals: i = [],
85
+ standalone: a = !1
109
86
  }) {
110
- const r = new t.Schema(i, {
87
+ const r = new t.Schema(e, {
111
88
  toJSON: { virtuals: !0 },
112
89
  // So `res.json()` and other `JSON.stringify()` functions include virtuals
113
90
  toObject: { virtuals: !0 }
114
91
  // So `console.log()` and other functions that use `toObject()` include virtuals
115
92
  });
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
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({
97
+ name: o,
98
+ options: s
122
99
  });
123
- const h = r.virtual(n);
124
- y ? h.get(y) : h.get(function() {
125
- var u;
126
- return ((u = this._populated) == null ? void 0 : u[n]) || (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(n, l);
130
- y && s.get(y);
105
+ const p = r.virtual(o, s);
106
+ u && p.get(u);
131
107
  }
132
- }), o || r.add(I.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.
@@ -149,24 +125,24 @@ const I = {
149
125
  */
150
126
  createModel({
151
127
  mongoose: t,
152
- name: i,
153
- schema: e,
154
- virtuals: o = [],
128
+ name: e,
129
+ schema: i,
130
+ virtuals: a = [],
155
131
  pagination: r = !0,
156
- aggregate: n = !0,
157
- middlewares: l = []
132
+ aggregate: o = !0,
133
+ middlewares: s = []
158
134
  }) {
159
- if (!i)
135
+ if (!e)
160
136
  throw new Error("Model name is required.");
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;
137
+ if (t.models[e])
138
+ return t.models[e];
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 I = {
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 S(this, null, function* () {
186
- return !W.isEmpty(t);
187
- });
160
+ return async function(t) {
161
+ return !J.isEmpty(t);
188
162
  };
189
163
  },
190
164
  /**
@@ -197,13 +171,11 @@ const I = {
197
171
  * @throws {Error} When fields is not a non-empty array of strings.
198
172
  */
199
173
  isUnique(t) {
200
- return function(i) {
201
- return S(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 e = { $or: t.map((r) => ({ [r]: i })) };
205
- return !(yield this.constructor.exists(e));
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 I = {
216
188
  * @throws {Error} When regexArray is not an array of valid RegExp objects.
217
189
  */
218
190
  matchesRegex(t) {
219
- return (i) => S(null, null, function* () {
220
- if (!Array.isArray(t) || t.some((e) => !(e instanceof RegExp)))
191
+ return async (e) => {
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
- return t.every((e) => e.test(i));
223
- });
194
+ return t.every((i) => i.test(e));
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: it(et({}, U), {
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
@@ -236,16 +209,11 @@ const I = {
236
209
  * @param options - Migration configuration options to write to the config file.
237
210
  */
238
211
  setConfig: (t) => {
239
- const i = `// This file is automatically generated by the Cyberskill CLI.
212
+ const e = `// This file is automatically generated by the Cyberskill CLI.
240
213
  module.exports = ${JSON.stringify(t, null, 4)}`;
241
- G(A.MIGRATE_MONGO_CONFIG, i);
242
- const e = `
243
- ${V}
244
- `;
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);
214
+ q(V.MIGRATE_MONGO_CONFIG, e), B(V.GIT_IGNORE, P);
247
215
  }
248
- }),
216
+ },
249
217
  /**
250
218
  * Converts string values in a filter to regex patterns for case-insensitive search.
251
219
  * This function recursively processes a filter object and converts string values in specified fields
@@ -255,23 +223,23 @@ ${V}
255
223
  * @param fields - An array of field names to convert to regex patterns.
256
224
  * @returns A new filter object with string values converted to regex patterns.
257
225
  */
258
- regexify(t, i) {
226
+ regexify(t, e) {
259
227
  if (!t)
260
228
  return {};
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)}.*`,
229
+ let i = D(t);
230
+ if (!e || e.length === 0)
231
+ return i;
232
+ for (const a of e) {
233
+ const r = a.toString().split("."), o = k(i, r);
234
+ if (typeof o == "string" && o.length > 0) {
235
+ const s = {
236
+ $regex: `.*${U(o)}.*`,
269
237
  $options: "i"
270
238
  };
271
- e = L(e, r, l);
239
+ i = C(i, r, s);
272
240
  }
273
241
  }
274
- return e;
242
+ return i;
275
243
  },
276
244
  /**
277
245
  * Checks if a virtual options object has a dynamic ref function.
@@ -289,15 +257,13 @@ ${V}
289
257
  * @param filterFn - Function to determine if a record already exists
290
258
  * @returns Array of records that don't exist in the database
291
259
  */
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)
298
- )
299
- ) : i;
300
- });
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;
301
267
  },
302
268
  /**
303
269
  * Generic utility function to get existing records that match the filter criteria
@@ -306,293 +272,281 @@ ${V}
306
272
  * @param filterFn - Function to determine if a record exists
307
273
  * @returns Array of existing records that match the filter criteria
308
274
  */
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)
315
- )
316
- ) : [];
317
- });
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
+ ) : [];
318
282
  }
319
283
  };
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;
328
- });
284
+ async function _(t, e, i, a, r) {
285
+ if (!e.length || !i)
286
+ return e;
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;
329
291
  }
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);
337
- return;
338
- }
339
- const u = h[0];
340
- if (!u || u.trim() === "")
341
- return;
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];
350
- if (f && f.options && f.options.ref) {
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]);
355
- }
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]);
356
315
  }
357
316
  }
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]);
365
- }
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]);
366
325
  }
367
326
  }
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]);
375
- }
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]);
376
335
  }
377
336
  }
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));
382
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);
383
342
  }
384
- });
343
+ }
385
344
  }
386
- function rt(t, i, e, o, r) {
387
- return S(this, null, function* () {
388
- const { path: n, populate: l } = e;
389
- if (!n)
390
- return;
391
- if (!l) {
392
- yield k(t, i, n, o, r);
393
- return;
394
- }
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]);
406
- }
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]);
407
364
  }
408
365
  }
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]);
412
- }
413
- if (u && typeof u == "object")
414
- if (Array.isArray(u))
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));
418
366
  }
419
- });
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
+ }
420
377
  }
421
- function F(t, i, e, o) {
422
- if (!e || !i || !i.schema)
378
+ function S(t, e, i, a) {
379
+ if (!i || !e || !e.schema)
423
380
  return;
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];
436
- if (u && u.schema) {
437
- n = u.schema;
381
+ const r = i.split(".");
382
+ let o = e.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;
438
395
  continue;
439
396
  }
440
397
  }
441
398
  }
442
399
  }
443
- if (n && n.paths && y) {
444
- const s = n.paths[y];
445
- if (s && s.schema) {
446
- n = s.schema;
400
+ if (o && o.paths && u) {
401
+ const p = o.paths[u];
402
+ if (p && p.schema) {
403
+ o = p.schema;
447
404
  continue;
448
405
  }
449
406
  }
450
407
  return;
451
408
  }
452
409
  }
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;
410
+ function L(t, e) {
411
+ if (e)
412
+ for (const i of Object.keys(t.models)) {
413
+ const a = t.models[i], r = a?.schema;
414
+ if (r && (r.paths && r.paths[e] || r.virtuals && r.virtuals[e]))
415
+ return a;
459
416
  }
460
417
  }
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]))
418
+ function H(t, e) {
419
+ const i = (e || "").split(".")[0] || "";
420
+ if (i)
421
+ for (const a of Object.keys(t.models)) {
422
+ const r = t.models[a], o = r?.schema;
423
+ if (o && (o.paths && o.paths[i] || o.virtuals && o.virtuals[i]))
467
424
  return r;
468
425
  }
469
426
  }
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);
481
- }
482
- const p = F(t, f, c, i);
483
- if (p)
484
- s = p;
485
- else {
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);
492
- }
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);
493
447
  }
494
448
  }
495
449
  }
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) {
499
- let 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);
501
- }
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);
502
456
  }
503
- if (!s) {
504
- for (const [c, a] of Object.entries(i))
505
- if (c === "entityType" && typeof a == "string") {
506
- s = a;
507
- break;
508
- }
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)
514
- return;
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;
523
- }
524
- }
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;
532
- }
533
- }
534
- }, p = g(a);
535
- p && (s = p);
536
- }
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;
537
463
  }
538
- }
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)
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)
544
469
  return;
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;
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;
553
478
  }
554
479
  }
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;
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;
562
487
  }
563
488
  }
564
- }, g = f(a);
565
- g && (s = g);
566
- }
567
- if (!s && n) {
568
- const a = F(t, n, e, i);
569
- a && (s = a);
570
- }
571
- if (!s && o && o.length > 0) {
572
- const a = o.find((f) => f.name === c);
573
- if (a && a.options.ref) {
574
- let 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);
576
- }
489
+ }, v = m(c);
490
+ v && (s = v);
577
491
  }
578
492
  }
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);
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);
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
+ }
582
532
  }
583
533
  }
584
- const h = t.models[s];
585
- if (!h)
586
- return;
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]);
592
- });
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);
537
+ }
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]);
593
547
  }
594
548
  export {
595
- C as applyNestedPopulate,
596
- E as convertEnumToModelName,
597
- I as mongo
549
+ _ as applyNestedPopulate,
550
+ A as convertEnumToModelName,
551
+ R as mongo
598
552
  };