@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,233 +1,204 @@
1
- import { MONGO_SLUG_MAX_ATTEMPTS as U } from "./mongo.constant.js";
2
- import { mongo as T, applyNestedPopulate as W, convertEnumToModelName as B } from "./mongo.util.js";
3
- import { normalizeMongoFilter as M, deepClone as G } from "../../util/object/object.util.js";
4
- import { generateShortId as K, generateSlug as C } from "../../util/string/string.util.js";
5
- import { RESPONSE_STATUS as j } from "../../constant/response-status.js";
6
- import { catchError as m } from "../log/log.util.js";
7
- var Q = Object.defineProperty, k = Object.defineProperties, X = Object.getOwnPropertyDescriptors, I = Object.getOwnPropertySymbols, J = Object.prototype.hasOwnProperty, Y = Object.prototype.propertyIsEnumerable, w = (l, r, e) => r in l ? Q(l, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[r] = e, R = (l, r) => {
8
- for (var e in r || (r = {}))
9
- J.call(r, e) && w(l, e, r[e]);
10
- if (I)
11
- for (var e of I(r))
12
- Y.call(r, e) && w(l, e, r[e]);
13
- return l;
14
- }, A = (l, r) => k(l, X(r)), Z = (l, r, e) => w(l, typeof r != "symbol" ? r + "" : r, e), f = (l, r, e) => new Promise((t, s) => {
15
- var n = (a) => {
16
- try {
17
- o(e.next(a));
18
- } catch (c) {
19
- s(c);
20
- }
21
- }, u = (a) => {
22
- try {
23
- o(e.throw(a));
24
- } catch (c) {
25
- s(c);
26
- }
27
- }, o = (a) => a.done ? t(a.value) : Promise.resolve(a.value).then(n, u);
28
- o((e = e.apply(l, r)).next());
29
- });
30
- function L(l) {
31
- return l != null && typeof l == "object";
1
+ import { MONGO_SLUG_MAX_ATTEMPTS as v } from "./mongo.constant.js";
2
+ import { mongo as _, applyNestedPopulate as P, convertEnumToModelName as I } from "./mongo.util.js";
3
+ import { normalizeMongoFilter as j, deepClone as L } from "../../util/object/object.util.js";
4
+ import { generateShortId as z, generateSlug as x, generateRandomString as q } from "../../util/string/string.util.js";
5
+ import { RESPONSE_STATUS as V } from "../../constant/response-status.js";
6
+ import { catchError as d } from "../log/log.util.js";
7
+ function $(i) {
8
+ return i != null && typeof i == "object";
32
9
  }
33
- function $(l, r) {
34
- if (!l || !r || r.length === 0)
35
- return l;
36
- const e = new Set(r.map((t) => t.name));
37
- if (Array.isArray(l)) {
38
- const t = l.filter((s) => {
39
- if (typeof s == "string")
10
+ function A(i, s) {
11
+ if (!i || !s || s.length === 0)
12
+ return i;
13
+ const e = new Set(s.map((t) => t.name));
14
+ if (Array.isArray(i)) {
15
+ const t = i.filter((r) => {
16
+ if (typeof r == "string")
40
17
  return !Array.from(e).some(
41
- (n) => s === n || s.startsWith(`${n}.`)
18
+ (n) => r === n || r.startsWith(`${n}.`)
42
19
  );
43
- if (typeof s == "object" && s !== null) {
44
- const n = s, u = n.path || n.populate || "";
20
+ if (typeof r == "object" && r !== null) {
21
+ const n = r, c = n.path || n.populate || "";
45
22
  return !Array.from(e).some(
46
- (o) => u === o || u.startsWith(`${o}.`)
23
+ (a) => c === a || c.startsWith(`${a}.`)
47
24
  );
48
25
  }
49
26
  return !0;
50
27
  });
51
28
  return t.length > 0 ? t : void 0;
52
29
  }
53
- if (typeof l == "string")
30
+ if (typeof i == "string")
54
31
  return Array.from(e).some(
55
- (t) => l === t || l.startsWith(`${t}.`)
56
- ) ? void 0 : l;
57
- if (typeof l == "object" && l !== null) {
58
- const t = l, s = t.path || t.populate || "";
32
+ (t) => i === t || i.startsWith(`${t}.`)
33
+ ) ? void 0 : i;
34
+ if (typeof i == "object" && i !== null) {
35
+ const t = i, r = t.path || t.populate || "";
59
36
  return Array.from(e).some(
60
- (n) => s === n || s.startsWith(`${n}.`)
61
- ) ? void 0 : l;
37
+ (n) => r === n || r.startsWith(`${n}.`)
38
+ ) ? void 0 : i;
62
39
  }
63
- return l;
40
+ return i;
64
41
  }
65
- function H(l, r, e) {
66
- if (!l.length || !r || !(e != null && e.ref))
42
+ function U(i, s, e) {
43
+ if (!i.length || !s || !e?.ref)
67
44
  return [];
68
45
  const t = /* @__PURE__ */ new Map();
69
- return l.forEach((s) => {
46
+ return i.forEach((r) => {
70
47
  try {
71
- const n = e.ref(s);
48
+ const n = e.ref(r);
72
49
  if (n == null)
73
50
  return;
74
- const u = typeof n == "string" ? n : String(n);
75
- if (u && u.trim() !== "") {
76
- const o = B(u);
77
- t.has(o) || t.set(o, []), t.get(o).push(s);
51
+ const c = typeof n == "string" ? n : String(n);
52
+ if (c && c.trim() !== "") {
53
+ const a = I(c);
54
+ t.has(a) || t.set(a, []), t.get(a).push(r);
78
55
  }
79
56
  } catch (n) {
80
- m(new Error(`Dynamic ref function failed for virtual "${r}": ${n instanceof Error ? n.message : String(n)}`));
57
+ d(new Error(`Dynamic ref function failed for virtual "${s}": ${n instanceof Error ? n.message : String(n)}`));
81
58
  }
82
- }), Array.from(t.entries()).map(([s, n]) => ({ model: s, docs: n }));
59
+ }), Array.from(t.entries()).map(([r, n]) => ({ model: r, docs: n }));
83
60
  }
84
- function ee(l) {
85
- return l !== null && typeof l == "object" && "toObject" in l && typeof l.toObject == "function";
61
+ function W(i) {
62
+ return i !== null && typeof i == "object" && "toObject" in i && typeof i.toObject == "function";
86
63
  }
87
- function z(l, r, e, t, s, n) {
88
- return f(this, null, function* () {
89
- if (!r.length || !e.length || !t)
90
- return r;
91
- const u = e.filter((c) => {
92
- if (Array.isArray(t))
93
- return t.length > 0 && t.some((d) => {
94
- if (typeof d == "string")
95
- return d === c.name || d.startsWith(`${c.name}.`);
96
- if (d && typeof d == "object") {
97
- const i = d, p = i.path || i.populate || "";
98
- return p === c.name || p.startsWith(`${c.name}.`);
99
- }
100
- return !1;
101
- });
102
- if (typeof t == "string")
103
- return t === c.name || t.startsWith(`${c.name}.`);
104
- if (typeof t == "object" && t !== null) {
105
- const d = t, i = d.path || d.populate || "";
106
- return i === c.name || i.startsWith(`${c.name}.`);
107
- }
108
- return !1;
109
- });
110
- if (u.length === 0)
111
- return r;
112
- const o = G(r.map((c) => ee(c) ? c.toObject() : c));
113
- o.forEach((c) => {
114
- u.forEach(({ name: d, options: i }) => {
115
- d in c || (c[d] = i.count ? 0 : i.justOne ? null : []);
64
+ async function C(i, s, e, t, r, n) {
65
+ if (!s.length || !e.length || !t)
66
+ return s;
67
+ const c = e.filter((u) => {
68
+ if (Array.isArray(t))
69
+ return t.length > 0 && t.some((o) => {
70
+ if (typeof o == "string")
71
+ return o === u.name || o.startsWith(`${u.name}.`);
72
+ if (o && typeof o == "object") {
73
+ const l = o, S = l.path || l.populate || "";
74
+ return S === u.name || S.startsWith(`${u.name}.`);
75
+ }
76
+ return !1;
116
77
  });
78
+ if (typeof t == "string")
79
+ return t === u.name || t.startsWith(`${u.name}.`);
80
+ if (typeof t == "object" && t !== null) {
81
+ const o = t, l = o.path || o.populate || "";
82
+ return l === u.name || l.startsWith(`${u.name}.`);
83
+ }
84
+ return !1;
85
+ });
86
+ if (c.length === 0)
87
+ return s;
88
+ const a = L(s.map((u) => W(u) ? u.toObject() : u));
89
+ a.forEach((u) => {
90
+ c.forEach(({ name: o, options: l }) => {
91
+ o in u || (u[o] = l.count ? 0 : l.justOne ? null : []);
117
92
  });
118
- const a = /* @__PURE__ */ new Map();
119
- for (const c of u) {
120
- const { name: d, options: i } = c, p = H(o, d, i);
121
- for (const y of p) {
122
- a.has(y.model) || a.set(y.model, {
123
- virtuals: [],
124
- localValueSets: /* @__PURE__ */ new Map(),
125
- docsByLocalValue: /* @__PURE__ */ new Map()
93
+ });
94
+ const g = /* @__PURE__ */ new Map();
95
+ for (const u of c) {
96
+ const { name: o, options: l } = u, S = U(a, o, l);
97
+ for (const h of S) {
98
+ g.has(h.model) || g.set(h.model, {
99
+ virtuals: [],
100
+ localValueSets: /* @__PURE__ */ new Map(),
101
+ docsByLocalValue: /* @__PURE__ */ new Map()
102
+ });
103
+ const E = g.get(h.model);
104
+ E.virtuals.find((p) => p.name === o) || (E.virtuals.push(u), E.localValueSets.set(o, /* @__PURE__ */ new Set()));
105
+ const b = E.localValueSets.get(o);
106
+ h.docs.forEach((p) => {
107
+ const y = p[l.localField];
108
+ if (y != null) {
109
+ const f = String(y);
110
+ b.add(f);
111
+ let m = -1;
112
+ const R = p;
113
+ R.id !== void 0 ? m = a.findIndex((D) => D.id === R.id) : R._id !== void 0 && (m = a.findIndex((D) => D._id?.toString?.() === R._id?.toString?.())), m !== -1 && (E.docsByLocalValue.has(f) || E.docsByLocalValue.set(f, []), E.docsByLocalValue.get(f).push(m));
114
+ }
115
+ });
116
+ }
117
+ }
118
+ if (await Promise.all(Array.from(g.entries()).map(async ([u, o]) => {
119
+ const l = i.models[u];
120
+ if (!l)
121
+ return;
122
+ const S = /* @__PURE__ */ new Set();
123
+ if (o.localValueSets.forEach((y) => {
124
+ y.forEach((f) => S.add(f));
125
+ }), S.size === 0)
126
+ return;
127
+ const h = [...new Set(o.virtuals.map((y) => y.options.foreignField))], E = Array.from(S);
128
+ let b;
129
+ h.length === 1 ? b = { [String(h[0])]: { $in: E } } : b = { $or: h.map((y) => ({ [y]: { $in: E } })) };
130
+ const p = await l.find(b, r).lean();
131
+ for (const y of o.virtuals) {
132
+ const { name: f, options: m } = y, R = p.filter((D) => {
133
+ const O = D[m.foreignField];
134
+ return O != null && S.has(String(O));
135
+ });
136
+ if (m.count) {
137
+ const D = /* @__PURE__ */ new Map();
138
+ R.forEach((O) => {
139
+ const w = O[m.foreignField]?.toString();
140
+ w && D.set(w, (D.get(w) || 0) + 1);
141
+ }), o.localValueSets.get(f).forEach((O) => {
142
+ const w = o.docsByLocalValue.get(O) || [], N = D.get(O) || 0;
143
+ w.forEach((F) => {
144
+ const M = a[F];
145
+ M[f] === void 0 && (M[f] = N);
146
+ });
126
147
  });
127
- const O = a.get(y.model);
128
- O.virtuals.find((_) => _.name === d) || (O.virtuals.push(c), O.localValueSets.set(d, /* @__PURE__ */ new Set()));
129
- const N = O.localValueSets.get(d);
130
- y.docs.forEach((_) => {
131
- const v = _[i.localField];
132
- if (v != null) {
133
- const g = String(v);
134
- N.add(g);
135
- let h = -1;
136
- const S = _;
137
- S.id !== void 0 ? h = o.findIndex((F) => F.id === S.id) : S._id !== void 0 && (h = o.findIndex((F) => {
138
- var b, E, V, D;
139
- return ((E = (b = F._id) == null ? void 0 : b.toString) == null ? void 0 : E.call(b)) === ((D = (V = S._id) == null ? void 0 : V.toString) == null ? void 0 : D.call(V));
140
- })), h !== -1 && (O.docsByLocalValue.has(g) || O.docsByLocalValue.set(g, []), O.docsByLocalValue.get(g).push(h));
141
- }
148
+ } else {
149
+ const D = /* @__PURE__ */ new Map();
150
+ R.forEach((O) => {
151
+ const w = O[m.foreignField]?.toString();
152
+ w && (D.has(w) || D.set(w, []), D.get(w).push(O));
153
+ }), o.localValueSets.get(f).forEach((O) => {
154
+ const w = o.docsByLocalValue.get(O) || [], N = D.get(O) || [], F = m.justOne ? N[0] || null : N;
155
+ w.forEach((M) => {
156
+ const T = a[M];
157
+ T[f] = F;
158
+ });
142
159
  });
143
160
  }
144
161
  }
145
- if (yield Promise.all(Array.from(a.entries()).map((c) => f(null, [c], function* ([d, i]) {
146
- const p = l.models[d];
147
- if (!p)
148
- return;
149
- const y = /* @__PURE__ */ new Set();
150
- if (i.localValueSets.forEach((g) => {
151
- g.forEach((h) => y.add(h));
152
- }), y.size === 0)
153
- return;
154
- const O = [...new Set(i.virtuals.map((g) => g.options.foreignField))], N = Array.from(y);
155
- let _;
156
- O.length === 1 ? _ = { [String(O[0])]: { $in: N } } : _ = { $or: O.map((g) => ({ [g]: { $in: N } })) };
157
- const v = yield p.find(_, s).lean();
158
- for (const g of i.virtuals) {
159
- const { name: h, options: S } = g, F = v.filter((b) => {
160
- const E = b[S.foreignField];
161
- return E != null && y.has(String(E));
162
- });
163
- if (S.count) {
164
- const b = /* @__PURE__ */ new Map();
165
- F.forEach((E) => {
166
- var V;
167
- const D = (V = E[S.foreignField]) == null ? void 0 : V.toString();
168
- D && b.set(D, (b.get(D) || 0) + 1);
169
- }), i.localValueSets.get(h).forEach((E) => {
170
- const V = i.docsByLocalValue.get(E) || [], D = b.get(E) || 0;
171
- V.forEach((P) => {
172
- const x = o[P];
173
- x[h] === void 0 && (x[h] = D);
174
- });
175
- });
176
- } else {
177
- const b = /* @__PURE__ */ new Map();
178
- F.forEach((E) => {
179
- var V;
180
- const D = (V = E[S.foreignField]) == null ? void 0 : V.toString();
181
- D && (b.has(D) || b.set(D, []), b.get(D).push(E));
182
- }), i.localValueSets.get(h).forEach((E) => {
183
- const V = i.docsByLocalValue.get(E) || [], D = b.get(E) || [], P = S.justOne ? D[0] || null : D;
184
- V.forEach((x) => {
185
- const q = o[x];
186
- q[h] = P;
187
- });
188
- });
162
+ })), t) {
163
+ const o = ((l) => {
164
+ const S = Array.isArray(l) ? l : [l], h = /* @__PURE__ */ new Map(), E = [];
165
+ for (const p of S)
166
+ if (typeof p == "string")
167
+ if (p.includes(".")) {
168
+ const y = p.split("."), f = y[0] || "", m = y.slice(1).join(".");
169
+ f && (h.has(f) || h.set(f, []), m && h.get(f).push(m));
170
+ } else
171
+ E.push(p);
172
+ else if (p && typeof p == "object") {
173
+ const y = p;
174
+ if (y.path && y.path.includes(".")) {
175
+ const f = y.path.split("."), m = f[0] || "", R = f.slice(1).join(".");
176
+ m && (h.has(m) || h.set(m, []), R && h.get(m).push(R), y.populate && h.get(m).push(y.populate));
177
+ } else
178
+ E.push(p);
189
179
  }
190
- }
191
- }))), t) {
192
- const d = ((i) => {
193
- const p = Array.isArray(i) ? i : [i], y = /* @__PURE__ */ new Map(), O = [];
194
- for (const _ of p)
195
- if (typeof _ == "string")
196
- if (_.includes(".")) {
197
- const v = _.split("."), g = v[0] || "", h = v.slice(1).join(".");
198
- g && (y.has(g) || y.set(g, []), h && y.get(g).push(h));
199
- } else
200
- O.push(_);
201
- else if (_ && typeof _ == "object") {
202
- const v = _;
203
- if (v.path && v.path.includes(".")) {
204
- const g = v.path.split("."), h = g[0] || "", S = g.slice(1).join(".");
205
- h && (y.has(h) || y.set(h, []), S && y.get(h).push(S), v.populate && y.get(h).push(v.populate));
206
- } else
207
- O.push(_);
208
- }
209
- const N = [...O];
210
- return y.forEach((_, v) => {
211
- const g = [];
212
- for (const h of _)
213
- (typeof h == "string" || h && typeof h == "object") && g.push(h);
214
- g.length > 0 ? N.push({ path: v, populate: g }) : N.push(v);
215
- }), N;
216
- })(t);
217
- yield W(l, o, d, e, n);
218
- }
219
- return o;
220
- });
180
+ const b = [...E];
181
+ return h.forEach((p, y) => {
182
+ const f = [];
183
+ for (const m of p)
184
+ (typeof m == "string" || m && typeof m == "object") && f.push(m);
185
+ f.length > 0 ? b.push({ path: y, populate: f }) : b.push(y);
186
+ }), b;
187
+ })(t);
188
+ await P(i, a, o, e, n);
189
+ }
190
+ return a;
221
191
  }
222
- class le {
192
+ class J {
193
+ collection;
223
194
  /**
224
195
  * Creates a new MongoDB controller instance.
225
196
  *
226
197
  * @param db - The MongoDB database instance.
227
198
  * @param collectionName - The name of the collection to operate on.
228
199
  */
229
- constructor(r, e) {
230
- Z(this, "collection"), this.collection = r.collection(e);
200
+ constructor(s, e) {
201
+ this.collection = s.collection(e);
231
202
  }
232
203
  /**
233
204
  * Creates a single document in the collection.
@@ -236,23 +207,24 @@ class le {
236
207
  * @param document - The document to create, with or without generic fields.
237
208
  * @returns A promise that resolves to a standardized response with the created document.
238
209
  */
239
- createOne(r) {
240
- return f(this, null, function* () {
241
- try {
242
- const e = R(R({}, T.createGenericFields()), r);
243
- return (yield this.collection.insertOne(e)).acknowledged ? {
244
- success: !0,
245
- message: "Document created successfully",
246
- result: e
247
- } : {
248
- success: !1,
249
- message: "Document creation failed",
250
- code: j.INTERNAL_SERVER_ERROR.CODE
251
- };
252
- } catch (e) {
253
- return m(e);
254
- }
255
- });
210
+ async createOne(s) {
211
+ try {
212
+ const e = {
213
+ ..._.createGenericFields(),
214
+ ...s
215
+ };
216
+ return (await this.collection.insertOne(e)).acknowledged ? {
217
+ success: !0,
218
+ message: "Document created successfully",
219
+ result: e
220
+ } : {
221
+ success: !1,
222
+ message: "Document creation failed",
223
+ code: V.INTERNAL_SERVER_ERROR.CODE
224
+ };
225
+ } catch (e) {
226
+ return d(e);
227
+ }
256
228
  }
257
229
  /**
258
230
  * Creates multiple documents in the collection.
@@ -261,23 +233,24 @@ class le {
261
233
  * @param documents - An array of documents to create.
262
234
  * @returns A promise that resolves to a standardized response with the created documents.
263
235
  */
264
- createMany(r) {
265
- return f(this, null, function* () {
266
- try {
267
- const e = r.map((s) => R(R({}, T.createGenericFields()), s)), t = yield this.collection.insertMany(e);
268
- return t.insertedCount === 0 ? {
269
- success: !1,
270
- message: "No documents were inserted",
271
- code: j.INTERNAL_SERVER_ERROR.CODE
272
- } : {
273
- success: !0,
274
- message: `${t.insertedCount} documents created successfully`,
275
- result: e
276
- };
277
- } catch (e) {
278
- return m(e);
279
- }
280
- });
236
+ async createMany(s) {
237
+ try {
238
+ const e = s.map((r) => ({
239
+ ..._.createGenericFields(),
240
+ ...r
241
+ })), t = await this.collection.insertMany(e);
242
+ return t.insertedCount === 0 ? {
243
+ success: !1,
244
+ message: "No documents were inserted",
245
+ code: V.INTERNAL_SERVER_ERROR.CODE
246
+ } : {
247
+ success: !0,
248
+ message: `${t.insertedCount} documents created successfully`,
249
+ result: e
250
+ };
251
+ } catch (e) {
252
+ return d(e);
253
+ }
281
254
  }
282
255
  /**
283
256
  * Finds a single document by filter criteria.
@@ -285,15 +258,13 @@ class le {
285
258
  * @param filter - The filter criteria to find the document.
286
259
  * @returns A promise that resolves to a standardized response with the found document.
287
260
  */
288
- findOne(r) {
289
- return f(this, null, function* () {
290
- try {
291
- const e = yield this.collection.findOne(r);
292
- return e ? { success: !0, message: "Document found", result: e } : { success: !1, message: "Document not found", code: j.NOT_FOUND.CODE };
293
- } catch (e) {
294
- return m(e);
295
- }
296
- });
261
+ async findOne(s) {
262
+ try {
263
+ const e = await this.collection.findOne(s);
264
+ return e ? { success: !0, message: "Document found", result: e } : { success: !1, message: "Document not found", code: V.NOT_FOUND.CODE };
265
+ } catch (e) {
266
+ return d(e);
267
+ }
297
268
  }
298
269
  /**
299
270
  * Finds all documents matching the filter criteria.
@@ -301,18 +272,16 @@ class le {
301
272
  * @param filter - The filter criteria to find documents (defaults to empty object for all documents).
302
273
  * @returns A promise that resolves to a standardized response with the found documents.
303
274
  */
304
- findAll() {
305
- return f(this, arguments, function* (r = {}) {
306
- try {
307
- return {
308
- success: !0,
309
- message: "Documents retrieved successfully",
310
- result: yield this.collection.find(r).toArray()
311
- };
312
- } catch (e) {
313
- return m(e);
314
- }
315
- });
275
+ async findAll(s = {}) {
276
+ try {
277
+ return {
278
+ success: !0,
279
+ message: "Documents retrieved successfully",
280
+ result: await this.collection.find(s).toArray()
281
+ };
282
+ } catch (e) {
283
+ return d(e);
284
+ }
316
285
  }
317
286
  /**
318
287
  * Counts documents matching the filter criteria.
@@ -320,19 +289,17 @@ class le {
320
289
  * @param filter - The filter criteria to count documents (defaults to empty object for all documents).
321
290
  * @returns A promise that resolves to a standardized response with the document count.
322
291
  */
323
- count() {
324
- return f(this, arguments, function* (r = {}) {
325
- try {
326
- const e = yield this.collection.countDocuments(r);
327
- return {
328
- success: !0,
329
- message: `${e} documents counted successfully`,
330
- result: e
331
- };
332
- } catch (e) {
333
- return m(e);
334
- }
335
- });
292
+ async count(s = {}) {
293
+ try {
294
+ const e = await this.collection.countDocuments(s);
295
+ return {
296
+ success: !0,
297
+ message: `${e} documents counted successfully`,
298
+ result: e
299
+ };
300
+ } catch (e) {
301
+ return d(e);
302
+ }
336
303
  }
337
304
  /**
338
305
  * Updates a single document matching the filter criteria.
@@ -341,25 +308,23 @@ class le {
341
308
  * @param update - The update data to apply to the document.
342
309
  * @returns A promise that resolves to a standardized response with the update result.
343
310
  */
344
- updateOne(r, e) {
345
- return f(this, null, function* () {
346
- try {
347
- const t = yield this.collection.updateOne(r, {
348
- $set: e
349
- });
350
- return t.matchedCount === 0 ? {
351
- success: !1,
352
- message: "No documents matched the filter",
353
- code: j.INTERNAL_SERVER_ERROR.CODE
354
- } : {
355
- success: !0,
356
- message: "Document updated successfully",
357
- result: t
358
- };
359
- } catch (t) {
360
- return m(t);
361
- }
362
- });
311
+ async updateOne(s, e) {
312
+ try {
313
+ const t = await this.collection.updateOne(s, {
314
+ $set: e
315
+ });
316
+ return t.matchedCount === 0 ? {
317
+ success: !1,
318
+ message: "No documents matched the filter",
319
+ code: V.INTERNAL_SERVER_ERROR.CODE
320
+ } : {
321
+ success: !0,
322
+ message: "Document updated successfully",
323
+ result: t
324
+ };
325
+ } catch (t) {
326
+ return d(t);
327
+ }
363
328
  }
364
329
  /**
365
330
  * Updates multiple documents matching the filter criteria.
@@ -368,25 +333,23 @@ class le {
368
333
  * @param update - The update data to apply to the documents.
369
334
  * @returns A promise that resolves to a standardized response with the update result.
370
335
  */
371
- updateMany(r, e) {
372
- return f(this, null, function* () {
373
- try {
374
- const t = yield this.collection.updateMany(r, {
375
- $set: e
376
- });
377
- return t.matchedCount === 0 ? {
378
- success: !1,
379
- message: "No documents matched the filter",
380
- code: j.INTERNAL_SERVER_ERROR.CODE
381
- } : {
382
- success: !0,
383
- message: "Documents updated successfully",
384
- result: t
385
- };
386
- } catch (t) {
387
- return m(t);
388
- }
389
- });
336
+ async updateMany(s, e) {
337
+ try {
338
+ const t = await this.collection.updateMany(s, {
339
+ $set: e
340
+ });
341
+ return t.matchedCount === 0 ? {
342
+ success: !1,
343
+ message: "No documents matched the filter",
344
+ code: V.INTERNAL_SERVER_ERROR.CODE
345
+ } : {
346
+ success: !0,
347
+ message: "Documents updated successfully",
348
+ result: t
349
+ };
350
+ } catch (t) {
351
+ return d(t);
352
+ }
390
353
  }
391
354
  /**
392
355
  * Deletes a single document matching the filter criteria.
@@ -394,23 +357,21 @@ class le {
394
357
  * @param filter - The filter criteria to find the document to delete.
395
358
  * @returns A promise that resolves to a standardized response with the delete result.
396
359
  */
397
- deleteOne(r) {
398
- return f(this, null, function* () {
399
- try {
400
- const e = yield this.collection.deleteOne(r);
401
- return e.deletedCount === 0 ? {
402
- success: !1,
403
- message: "No documents matched the filter",
404
- code: j.INTERNAL_SERVER_ERROR.CODE
405
- } : {
406
- success: !0,
407
- message: "Document deleted successfully",
408
- result: e
409
- };
410
- } catch (e) {
411
- return m(e);
412
- }
413
- });
360
+ async deleteOne(s) {
361
+ try {
362
+ const e = await this.collection.deleteOne(s);
363
+ return e.deletedCount === 0 ? {
364
+ success: !1,
365
+ message: "No documents matched the filter",
366
+ code: V.INTERNAL_SERVER_ERROR.CODE
367
+ } : {
368
+ success: !0,
369
+ message: "Document deleted successfully",
370
+ result: e
371
+ };
372
+ } catch (e) {
373
+ return d(e);
374
+ }
414
375
  }
415
376
  /**
416
377
  * Deletes multiple documents matching the filter criteria.
@@ -418,33 +379,31 @@ class le {
418
379
  * @param filter - The filter criteria to find documents to delete.
419
380
  * @returns A promise that resolves to a standardized response with the delete result.
420
381
  */
421
- deleteMany(r) {
422
- return f(this, null, function* () {
423
- try {
424
- const e = yield this.collection.deleteMany(r);
425
- return e.deletedCount === 0 ? {
426
- success: !1,
427
- message: "No documents matched the filter",
428
- code: j.INTERNAL_SERVER_ERROR.CODE
429
- } : {
430
- success: !0,
431
- message: "Documents deleted successfully",
432
- result: e
433
- };
434
- } catch (e) {
435
- return m(e);
436
- }
437
- });
382
+ async deleteMany(s) {
383
+ try {
384
+ const e = await this.collection.deleteMany(s);
385
+ return e.deletedCount === 0 ? {
386
+ success: !1,
387
+ message: "No documents matched the filter",
388
+ code: V.INTERNAL_SERVER_ERROR.CODE
389
+ } : {
390
+ success: !0,
391
+ message: "Documents deleted successfully",
392
+ result: e
393
+ };
394
+ } catch (e) {
395
+ return d(e);
396
+ }
438
397
  }
439
398
  }
440
- class ce {
399
+ class Y {
441
400
  /**
442
401
  * Creates a new Mongoose controller instance.
443
402
  *
444
403
  * @param model - The Mongoose model to operate on.
445
404
  */
446
- constructor(r) {
447
- this.model = r;
405
+ constructor(s) {
406
+ this.model = s;
448
407
  }
449
408
  /**
450
409
  * Gets the model name for logging and error messages.
@@ -461,10 +420,7 @@ class ce {
461
420
  */
462
421
  getDynamicVirtuals() {
463
422
  if (this.model._virtualConfigs) {
464
- const t = this.model._virtualConfigs.filter((s) => {
465
- var n;
466
- return typeof ((n = s.options) == null ? void 0 : n.ref) == "function";
467
- });
423
+ const t = this.model._virtualConfigs.filter((r) => typeof r.options?.ref == "function");
468
424
  if (t.length > 0)
469
425
  return t;
470
426
  }
@@ -477,15 +433,13 @@ class ce {
477
433
  * @param populate - The populate options to determine which virtuals to populate.
478
434
  * @returns The document with dynamic virtuals populated.
479
435
  */
480
- populateDynamicVirtualsForDocument(r, e) {
481
- return f(this, null, function* () {
482
- const t = this.getDynamicVirtuals();
483
- if (t && t.length > 0) {
484
- const s = yield z(this.model.base, [r], t, e, void 0, this.model);
485
- return s && s[0] ? s[0] : r;
486
- }
487
- return r;
488
- });
436
+ async populateDynamicVirtualsForDocument(s, e) {
437
+ const t = this.getDynamicVirtuals();
438
+ if (t && t.length > 0) {
439
+ const r = await C(this.model.base, [s], t, e, void 0, this.model);
440
+ return r && r[0] ? r[0] : s;
441
+ }
442
+ return s;
489
443
  }
490
444
  /**
491
445
  * Populates dynamic virtuals for an array of documents.
@@ -494,11 +448,9 @@ class ce {
494
448
  * @param populate - The populate options to determine which virtuals to populate.
495
449
  * @returns The documents with dynamic virtuals populated.
496
450
  */
497
- populateDynamicVirtualsForDocuments(r, e) {
498
- return f(this, null, function* () {
499
- const t = this.getDynamicVirtuals();
500
- return t && t.length > 0 && r.length > 0 ? yield z(this.model.base, r, t, e, void 0, this.model) : r;
501
- });
451
+ async populateDynamicVirtualsForDocuments(s, e) {
452
+ const t = this.getDynamicVirtuals();
453
+ return t && t.length > 0 && s.length > 0 ? await C(this.model.base, s, t, e, void 0, this.model) : s;
502
454
  }
503
455
  /**
504
456
  * Finds a single document with optional population and projection.
@@ -510,25 +462,22 @@ class ce {
510
462
  * @param populate - Population configuration for related documents.
511
463
  * @returns A promise that resolves to a standardized response with the found document.
512
464
  */
513
- findOne() {
514
- return f(this, arguments, function* (r = {}, e = {}, t = {}, s) {
515
- var n, u;
516
- try {
517
- const o = M(r), a = this.model.findOne(o, e, t), c = this.getDynamicVirtuals(), d = $(s, c);
518
- d && a.populate(d);
519
- const i = yield a.exec();
520
- if (!i)
521
- return {
522
- success: !1,
523
- message: `No ${this.getModelName()} found.`,
524
- code: j.NOT_FOUND.CODE
525
- };
526
- const p = yield this.populateDynamicVirtualsForDocument(i, s);
527
- return { success: !0, result: (u = (n = p == null ? void 0 : p.toObject) == null ? void 0 : n.call(p)) != null ? u : p };
528
- } catch (o) {
529
- return m(o);
530
- }
531
- });
465
+ async findOne(s = {}, e = {}, t = {}, r) {
466
+ try {
467
+ const n = j(s), c = this.model.findOne(n, e, t), a = this.getDynamicVirtuals(), g = A(r, a);
468
+ g && c.populate(g);
469
+ const u = await c.exec();
470
+ if (!u)
471
+ return {
472
+ success: !1,
473
+ message: `No ${this.getModelName()} found.`,
474
+ code: V.NOT_FOUND.CODE
475
+ };
476
+ const o = await this.populateDynamicVirtualsForDocument(u, r);
477
+ return { success: !0, result: o?.toObject?.() ?? o };
478
+ } catch (n) {
479
+ return d(n);
480
+ }
532
481
  }
533
482
  /**
534
483
  * Finds all documents with optional population and projection.
@@ -540,20 +489,15 @@ class ce {
540
489
  * @param populate - Population configuration for related documents.
541
490
  * @returns A promise that resolves to a standardized response with the found documents.
542
491
  */
543
- findAll() {
544
- return f(this, arguments, function* (r = {}, e = {}, t = {}, s) {
545
- try {
546
- const n = M(r), u = this.model.find(n, e, t), o = this.getDynamicVirtuals(), a = $(s, o);
547
- a && u.populate(a);
548
- const c = yield u.exec();
549
- return { success: !0, result: (yield this.populateDynamicVirtualsForDocuments(c, s)).map((i) => {
550
- var p, y;
551
- return (y = (p = i == null ? void 0 : i.toObject) == null ? void 0 : p.call(i)) != null ? y : i;
552
- }) };
553
- } catch (n) {
554
- return m(n);
555
- }
556
- });
492
+ async findAll(s = {}, e = {}, t = {}, r) {
493
+ try {
494
+ const n = j(s), c = this.model.find(n, e, t), a = this.getDynamicVirtuals(), g = A(r, a);
495
+ g && c.populate(g);
496
+ const u = await c.exec();
497
+ return { success: !0, result: (await this.populateDynamicVirtualsForDocuments(u, r)).map((l) => l?.toObject?.() ?? l) };
498
+ } catch (n) {
499
+ return d(n);
500
+ }
557
501
  }
558
502
  /**
559
503
  * Finds documents with pagination support.
@@ -563,27 +507,19 @@ class ce {
563
507
  * @param options - Pagination options including page, limit, and population.
564
508
  * @returns A promise that resolves to a standardized response with paginated results.
565
509
  */
566
- findPaging() {
567
- return f(this, arguments, function* (r = {}, e = {}) {
568
- try {
569
- const t = M(r), s = this.getDynamicVirtuals(), n = R({}, e);
570
- e.populate && (n.populate = $(e.populate, s));
571
- const u = yield this.model.paginate(t, n);
572
- if (s && s.length > 0) {
573
- const o = yield this.populateDynamicVirtualsForDocuments(u.docs, e.populate);
574
- return { success: !0, result: A(R({}, u), { docs: o.map((a) => {
575
- var c, d;
576
- return (d = (c = a == null ? void 0 : a.toObject) == null ? void 0 : c.call(a)) != null ? d : a;
577
- }) }) };
578
- }
579
- return { success: !0, result: A(R({}, u), { docs: u.docs.map((o) => {
580
- var a, c;
581
- return (c = (a = o == null ? void 0 : o.toObject) == null ? void 0 : a.call(o)) != null ? c : o;
582
- }) }) };
583
- } catch (t) {
584
- return m(t);
585
- }
586
- });
510
+ async findPaging(s = {}, e = {}) {
511
+ try {
512
+ const t = j(s), r = this.getDynamicVirtuals(), n = { ...e };
513
+ e.populate && (n.populate = A(e.populate, r));
514
+ const c = await this.model.paginate(t, n);
515
+ if (r && r.length > 0) {
516
+ const a = await this.populateDynamicVirtualsForDocuments(c.docs, e.populate);
517
+ return { success: !0, result: { ...c, docs: a.map((g) => g?.toObject?.() ?? g) } };
518
+ }
519
+ return { success: !0, result: { ...c, docs: c.docs.map((a) => a?.toObject?.() ?? a) } };
520
+ } catch (t) {
521
+ return d(t);
522
+ }
587
523
  }
588
524
  /**
589
525
  * Performs aggregation with pagination support.
@@ -592,23 +528,18 @@ class ce {
592
528
  * @param options - Pagination options for the aggregation result.
593
529
  * @returns A promise that resolves to a standardized response with paginated aggregation results.
594
530
  */
595
- findPagingAggregate(r) {
596
- return f(this, arguments, function* (e, t = {}) {
597
- try {
598
- const s = this.getDynamicVirtuals(), n = R({}, t);
599
- t.populate && (n.populate = $(t.populate, s));
600
- const u = yield this.model.aggregatePaginate(
601
- this.model.aggregate(e),
602
- n
603
- ), o = yield this.populateDynamicVirtualsForDocuments(u.docs, t.populate);
604
- return { success: !0, result: A(R({}, u), { docs: o.map((a) => {
605
- var c, d;
606
- return (d = (c = a == null ? void 0 : a.toObject) == null ? void 0 : c.call(a)) != null ? d : a;
607
- }) }) };
608
- } catch (s) {
609
- return m(s);
610
- }
611
- });
531
+ async findPagingAggregate(s, e = {}) {
532
+ try {
533
+ const t = this.getDynamicVirtuals(), r = { ...e };
534
+ e.populate && (r.populate = A(e.populate, t));
535
+ const n = await this.model.aggregatePaginate(
536
+ this.model.aggregate(s),
537
+ r
538
+ ), c = await this.populateDynamicVirtualsForDocuments(n.docs, e.populate);
539
+ return { success: !0, result: { ...n, docs: c.map((a) => a?.toObject?.() ?? a) } };
540
+ } catch (t) {
541
+ return d(t);
542
+ }
612
543
  }
613
544
  /**
614
545
  * Counts documents matching the filter criteria.
@@ -616,15 +547,13 @@ class ce {
616
547
  * @param filter - The filter criteria to count documents.
617
548
  * @returns A promise that resolves to a standardized response with the document count.
618
549
  */
619
- count() {
620
- return f(this, arguments, function* (r = {}) {
621
- try {
622
- const e = M(r);
623
- return { success: !0, result: yield this.model.countDocuments(e) };
624
- } catch (e) {
625
- return m(e);
626
- }
627
- });
550
+ async count(s = {}) {
551
+ try {
552
+ const e = j(s);
553
+ return { success: !0, result: await this.model.countDocuments(e) };
554
+ } catch (e) {
555
+ return d(e);
556
+ }
628
557
  }
629
558
  /**
630
559
  * Creates a single document.
@@ -632,16 +561,13 @@ class ce {
632
561
  * @param doc - The document to create.
633
562
  * @returns A promise that resolves to a standardized response with the created document.
634
563
  */
635
- createOne(r) {
636
- return f(this, null, function* () {
637
- var e, t;
638
- try {
639
- const s = yield this.model.create(r);
640
- return { success: !0, result: (t = (e = s == null ? void 0 : s.toObject) == null ? void 0 : e.call(s)) != null ? t : s };
641
- } catch (s) {
642
- return m(s);
643
- }
644
- });
564
+ async createOne(s) {
565
+ try {
566
+ const e = await this.model.create(s);
567
+ return { success: !0, result: e?.toObject?.() ?? e };
568
+ } catch (e) {
569
+ return d(e);
570
+ }
645
571
  }
646
572
  /**
647
573
  * Creates multiple documents with bulk insertion.
@@ -650,17 +576,12 @@ class ce {
650
576
  * @param options - Options for the bulk insertion operation.
651
577
  * @returns A promise that resolves to a standardized response with the created documents.
652
578
  */
653
- createMany(r) {
654
- return f(this, arguments, function* (e, t = {}) {
655
- try {
656
- return { success: !0, result: (yield this.model.insertMany(e, t)).map((n) => {
657
- var u, o;
658
- return (o = (u = n == null ? void 0 : n.toObject) == null ? void 0 : u.call(n)) != null ? o : n;
659
- }) };
660
- } catch (s) {
661
- return m(s);
662
- }
663
- });
579
+ async createMany(s, e = {}) {
580
+ try {
581
+ return { success: !0, result: (await this.model.insertMany(s, e)).map((r) => r?.toObject?.() ?? r) };
582
+ } catch (t) {
583
+ return d(t);
584
+ }
664
585
  }
665
586
  /**
666
587
  * Updates a single document and returns the updated version.
@@ -670,22 +591,20 @@ class ce {
670
591
  * @param options - Options for the update operation.
671
592
  * @returns A promise that resolves to a standardized response with the updated document.
672
593
  */
673
- updateOne() {
674
- return f(this, arguments, function* (r = {}, e = {}, t = {}) {
675
- var s, n;
676
- try {
677
- const u = M(r), o = yield this.model.findOneAndUpdate(u, e, R({
678
- new: !0
679
- }, t)).exec();
680
- return o ? { success: !0, result: (n = (s = o == null ? void 0 : o.toObject) == null ? void 0 : s.call(o)) != null ? n : o } : {
681
- success: !1,
682
- message: `Failed to update ${this.getModelName()}.`,
683
- code: j.NOT_FOUND.CODE
684
- };
685
- } catch (u) {
686
- return m(u);
687
- }
688
- });
594
+ async updateOne(s = {}, e = {}, t = {}) {
595
+ try {
596
+ const r = j(s), n = await this.model.findOneAndUpdate(r, e, {
597
+ new: !0,
598
+ ...t
599
+ }).exec();
600
+ return n ? { success: !0, result: n?.toObject?.() ?? n } : {
601
+ success: !1,
602
+ message: `Failed to update ${this.getModelName()}.`,
603
+ code: V.NOT_FOUND.CODE
604
+ };
605
+ } catch (r) {
606
+ return d(r);
607
+ }
689
608
  }
690
609
  /**
691
610
  * Updates multiple documents matching the filter criteria.
@@ -695,15 +614,13 @@ class ce {
695
614
  * @param options - Options for the update operation.
696
615
  * @returns A promise that resolves to a standardized response with the update result.
697
616
  */
698
- updateMany() {
699
- return f(this, arguments, function* (r = {}, e = {}, t = {}) {
700
- try {
701
- const s = M(r);
702
- return { success: !0, result: yield this.model.updateMany(s, e, t).exec() };
703
- } catch (s) {
704
- return m(s);
705
- }
706
- });
617
+ async updateMany(s = {}, e = {}, t = {}) {
618
+ try {
619
+ const r = j(s);
620
+ return { success: !0, result: await this.model.updateMany(r, e, t).exec() };
621
+ } catch (r) {
622
+ return d(r);
623
+ }
707
624
  }
708
625
  /**
709
626
  * Deletes a single document and returns the deleted version.
@@ -712,20 +629,17 @@ class ce {
712
629
  * @param options - Options for the delete operation.
713
630
  * @returns A promise that resolves to a standardized response with the deleted document.
714
631
  */
715
- deleteOne() {
716
- return f(this, arguments, function* (r = {}, e = {}) {
717
- var t, s;
718
- try {
719
- const n = M(r), u = yield this.model.findOneAndDelete(n, e).exec();
720
- return u ? { success: !0, result: (s = (t = u == null ? void 0 : u.toObject) == null ? void 0 : t.call(u)) != null ? s : u } : {
721
- success: !1,
722
- message: `No ${this.getModelName()} found to delete.`,
723
- code: j.NOT_FOUND.CODE
724
- };
725
- } catch (n) {
726
- return m(n);
727
- }
728
- });
632
+ async deleteOne(s = {}, e = {}) {
633
+ try {
634
+ const t = j(s), r = await this.model.findOneAndDelete(t, e).exec();
635
+ return r ? { success: !0, result: r?.toObject?.() ?? r } : {
636
+ success: !1,
637
+ message: `No ${this.getModelName()} found to delete.`,
638
+ code: V.NOT_FOUND.CODE
639
+ };
640
+ } catch (t) {
641
+ return d(t);
642
+ }
729
643
  }
730
644
  /**
731
645
  * Deletes multiple documents matching the filter criteria.
@@ -734,19 +648,17 @@ class ce {
734
648
  * @param options - Options for the delete operation.
735
649
  * @returns A promise that resolves to a standardized response with the delete result.
736
650
  */
737
- deleteMany() {
738
- return f(this, arguments, function* (r = {}, e = {}) {
739
- try {
740
- const t = M(r), s = yield this.model.deleteMany(t, e).exec();
741
- return s.deletedCount === 0 ? {
742
- success: !1,
743
- message: "No documents found to delete.",
744
- code: j.NOT_FOUND.CODE
745
- } : { success: !0, result: s };
746
- } catch (t) {
747
- return m(t);
748
- }
749
- });
651
+ async deleteMany(s = {}, e = {}) {
652
+ try {
653
+ const t = j(s), r = await this.model.deleteMany(t, e).exec();
654
+ return r.deletedCount === 0 ? {
655
+ success: !1,
656
+ message: "No documents found to delete.",
657
+ code: V.NOT_FOUND.CODE
658
+ } : { success: !0, result: r };
659
+ } catch (t) {
660
+ return d(t);
661
+ }
750
662
  }
751
663
  /**
752
664
  * Creates a unique short ID based on a given ID.
@@ -756,26 +668,24 @@ class ce {
756
668
  * @param length - The initial length for short ID generation (default: 4).
757
669
  * @returns A promise that resolves to a standardized response with the unique short ID.
758
670
  */
759
- createShortId(r, e = 4) {
760
- return f(this, null, function* () {
761
- try {
762
- const s = Array.from({ length: 10 }, (o, a) => K(r, a + e)), u = (yield Promise.all(
763
- s.map((o) => this.model.exists({ shortId: o }))
764
- )).findIndex((o) => !o);
765
- if (u !== -1) {
766
- const o = s[u];
767
- if (o)
768
- return { success: !0, result: o };
769
- }
770
- return {
771
- success: !1,
772
- message: "Failed to create a unique shortId",
773
- code: j.INTERNAL_SERVER_ERROR.CODE
774
- };
775
- } catch (t) {
776
- return m(t);
777
- }
778
- });
671
+ async createShortId(s, e = 4) {
672
+ try {
673
+ const r = Array.from({ length: 10 }, (a, g) => z(s, g + e)), c = (await Promise.all(
674
+ r.map((a) => this.model.exists({ shortId: a }))
675
+ )).findIndex((a) => !a);
676
+ if (c !== -1) {
677
+ const a = r[c];
678
+ if (a)
679
+ return { success: !0, result: a };
680
+ }
681
+ return {
682
+ success: !1,
683
+ message: "Failed to create a unique shortId",
684
+ code: V.INTERNAL_SERVER_ERROR.CODE
685
+ };
686
+ } catch (t) {
687
+ return d(t);
688
+ }
779
689
  }
780
690
  /**
781
691
  * Creates a query for slug existence checking.
@@ -789,19 +699,21 @@ class ce {
789
699
  * @param options.filter - Additional filter conditions to apply to the query.
790
700
  * @returns A MongoDB query object for checking slug existence.
791
701
  */
792
- createSlugQuery({ slug: r, field: e, isObject: t, haveHistory: s = !1, filter: n }) {
793
- const u = R({}, n != null ? n : {});
794
- return t ? A(R({}, u), {
702
+ createSlugQuery({ slug: s, field: e, isObject: t, haveHistory: r = !1, filter: n }) {
703
+ const c = { ...n ?? {} };
704
+ return t ? {
705
+ ...c,
795
706
  $or: [
796
- { [`slug.${e}`]: r },
797
- ...s ? [{ slugHistory: { $elemMatch: { [`slug.${e}`]: r } } }] : []
707
+ { [`slug.${e}`]: s },
708
+ ...r ? [{ slugHistory: { $elemMatch: { [`slug.${e}`]: s } } }] : []
798
709
  ]
799
- }) : A(R({}, u), {
710
+ } : {
711
+ ...c,
800
712
  $or: [
801
- { slug: r },
802
- ...s ? [{ slugHistory: r }] : []
713
+ { slug: s },
714
+ ...r ? [{ slugHistory: s }] : []
803
715
  ]
804
- });
716
+ };
805
717
  }
806
718
  /**
807
719
  * Creates a unique slug based on a given string.
@@ -815,25 +727,23 @@ class ce {
815
727
  * @param options.filter - Additional filter conditions to apply when checking slug existence.
816
728
  * @returns A promise that resolves to a unique slug string.
817
729
  */
818
- createUniqueSlug(r) {
819
- return f(this, arguments, function* ({ slug: e, field: t, isObject: s, haveHistory: n, filter: u }) {
820
- if (!e || typeof e != "string")
821
- throw new Error("Invalid slug provided: must be a non-empty string");
822
- const o = C(e);
823
- if (!(yield this.model.exists(
824
- this.createSlugQuery({ slug: o, field: t, isObject: s, haveHistory: n, filter: u })
825
- )))
826
- return o;
827
- for (let i = 1; i <= U; i++) {
828
- const p = `${o}-${i}`;
829
- if (!(yield this.model.exists(
830
- this.createSlugQuery({ slug: p, field: t, isObject: s, haveHistory: n, filter: u })
831
- )))
832
- return p;
833
- }
834
- const c = Date.now(), d = Math.random().toString(36).substring(2, 8);
835
- return `${o}-${c}-${d}`;
836
- });
730
+ async createUniqueSlug({ slug: s, field: e, isObject: t, haveHistory: r, filter: n }) {
731
+ if (!s || typeof s != "string")
732
+ throw new Error("Invalid slug provided: must be a non-empty string");
733
+ const c = x(s);
734
+ if (!await this.model.exists(
735
+ this.createSlugQuery({ slug: c, field: e, isObject: t, haveHistory: r, filter: n })
736
+ ))
737
+ return c;
738
+ for (let o = 1; o <= v; o++) {
739
+ const l = `${c}-${o}`;
740
+ if (!await this.model.exists(
741
+ this.createSlugQuery({ slug: l, field: e, isObject: t, haveHistory: r, filter: n })
742
+ ))
743
+ return l;
744
+ }
745
+ const g = Date.now(), u = q(6);
746
+ return `${c}-${g}-${u}`;
837
747
  }
838
748
  /**
839
749
  * Creates a slug for a document field.
@@ -846,34 +756,32 @@ class ce {
846
756
  * @param options.filter - Additional filter conditions to apply when checking slug existence.
847
757
  * @returns A promise that resolves to a standardized response with the created slug(s).
848
758
  */
849
- createSlug(r) {
850
- return f(this, arguments, function* ({ field: e, from: t, filter: s, haveHistory: n }) {
851
- try {
852
- const u = t[e];
853
- return L(u) ? { success: !0, result: Object.fromEntries(
854
- yield Promise.all(
855
- Object.entries(u).map((d) => f(this, [d], function* ([i, p]) {
856
- const y = yield this.createUniqueSlug({
857
- slug: p,
858
- field: i,
859
- isObject: !0,
860
- haveHistory: n,
861
- filter: s
862
- });
863
- return [i, y];
864
- }))
865
- )
866
- ) } : { success: !0, result: yield this.createUniqueSlug({
867
- slug: u,
868
- field: e,
869
- isObject: !1,
870
- haveHistory: n,
871
- filter: s
872
- }) };
873
- } catch (u) {
874
- return m(u);
875
- }
876
- });
759
+ async createSlug({ field: s, from: e, filter: t, haveHistory: r }) {
760
+ try {
761
+ const n = e[s];
762
+ return $(n) ? { success: !0, result: Object.fromEntries(
763
+ await Promise.all(
764
+ Object.entries(n).map(async ([u, o]) => {
765
+ const l = await this.createUniqueSlug({
766
+ slug: o,
767
+ field: u,
768
+ isObject: !0,
769
+ haveHistory: r,
770
+ filter: t
771
+ });
772
+ return [u, l];
773
+ })
774
+ )
775
+ ) } : { success: !0, result: await this.createUniqueSlug({
776
+ slug: n,
777
+ field: s,
778
+ isObject: !1,
779
+ haveHistory: r,
780
+ filter: t
781
+ }) };
782
+ } catch (n) {
783
+ return d(n);
784
+ }
877
785
  }
878
786
  /**
879
787
  * Checks if a slug already exists in the collection.
@@ -887,35 +795,33 @@ class ce {
887
795
  * @param options.filter - Additional filter conditions to apply to the query.
888
796
  * @returns A promise that resolves to a standardized response indicating whether the slug exists.
889
797
  */
890
- checkSlug(r) {
891
- return f(this, arguments, function* ({ slug: e, field: t, from: s, filter: n, haveHistory: u }) {
892
- try {
893
- const o = s[t];
894
- if (L(o)) {
895
- const p = Object.values(o).map((O) => C(O));
896
- return (yield Promise.all(
897
- p.map(
898
- (O) => this.model.exists(this.createSlugQuery({
899
- slug: O,
900
- field: t,
901
- isObject: !0,
902
- haveHistory: u,
903
- filter: n
904
- }))
905
- )
906
- )).some((O) => O) ? { success: !0, result: !0 } : { success: !0, result: !1 };
907
- }
908
- const c = C(e);
909
- return { success: !0, result: (yield this.model.exists(this.createSlugQuery({
910
- slug: c,
911
- field: t,
912
- isObject: !1,
913
- filter: n
914
- }))) !== null };
915
- } catch (o) {
916
- return m(o);
917
- }
918
- });
798
+ async checkSlug({ slug: s, field: e, from: t, filter: r, haveHistory: n }) {
799
+ try {
800
+ const c = t[e];
801
+ if ($(c)) {
802
+ const l = Object.values(c).map((h) => x(h));
803
+ return (await Promise.all(
804
+ l.map(
805
+ (h) => this.model.exists(this.createSlugQuery({
806
+ slug: h,
807
+ field: e,
808
+ isObject: !0,
809
+ haveHistory: n,
810
+ filter: r
811
+ }))
812
+ )
813
+ )).some((h) => h) ? { success: !0, result: !0 } : { success: !0, result: !1 };
814
+ }
815
+ const g = x(s);
816
+ return { success: !0, result: await this.model.exists(this.createSlugQuery({
817
+ slug: g,
818
+ field: e,
819
+ isObject: !1,
820
+ filter: r
821
+ })) !== null };
822
+ } catch (c) {
823
+ return d(c);
824
+ }
919
825
  }
920
826
  /**
921
827
  * Performs aggregation operations on the collection.
@@ -923,14 +829,12 @@ class ce {
923
829
  * @param pipeline - The aggregation pipeline stages to execute.
924
830
  * @returns A promise that resolves to a standardized response with the aggregation results.
925
831
  */
926
- aggregate(r) {
927
- return f(this, null, function* () {
928
- try {
929
- return { success: !0, result: yield this.model.aggregate(r) };
930
- } catch (e) {
931
- return m(e);
932
- }
933
- });
832
+ async aggregate(s) {
833
+ try {
834
+ return { success: !0, result: await this.model.aggregate(s) };
835
+ } catch (e) {
836
+ return d(e);
837
+ }
934
838
  }
935
839
  /**
936
840
  * Retrieves distinct values for the specified key from the collection.
@@ -940,17 +844,15 @@ class ce {
940
844
  * @param options - Additional options for the distinct operation (optional).
941
845
  * @returns A promise that resolves to a standardized response with the array of distinct values.
942
846
  */
943
- distinct(r) {
944
- return f(this, arguments, function* (e, t = {}, s = {}) {
945
- try {
946
- return { success: !0, result: yield this.model.distinct(e, t, s) };
947
- } catch (n) {
948
- return m(n);
949
- }
950
- });
847
+ async distinct(s, e = {}, t = {}) {
848
+ try {
849
+ return { success: !0, result: await this.model.distinct(s, e, t) };
850
+ } catch (r) {
851
+ return d(r);
852
+ }
951
853
  }
952
854
  }
953
855
  export {
954
- le as MongoController,
955
- ce as MongooseController
856
+ J as MongoController,
857
+ Y as MongooseController
956
858
  };