@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.
- package/dist/config/config.util.cjs +1 -1
- package/dist/config/config.util.js +24 -33
- package/dist/config/eslint/index.cjs +1 -1
- package/dist/config/eslint/index.d.ts +4 -0
- package/dist/config/eslint/index.js +4 -12
- package/dist/config/graphql-codegen/graphql-codegen.util.cjs +1 -1
- package/dist/config/graphql-codegen/graphql-codegen.util.js +28 -33
- package/dist/config/storybook/storybook.preview.cjs +1 -1
- package/dist/config/storybook/storybook.preview.js +10 -13
- package/dist/config/vitest/vitest.e2e.cjs +1 -1
- package/dist/config/vitest/vitest.e2e.js +1 -1
- package/dist/config/vitest/vitest.unit.cjs +1 -1
- package/dist/config/vitest/vitest.unit.js +19 -8
- package/dist/constant/common.cjs +1 -1
- package/dist/constant/common.js +1 -1
- package/dist/node/apollo-server/apollo-server.util.cjs +1 -1
- package/dist/node/apollo-server/apollo-server.util.js +21 -48
- package/dist/node/cli/index.cjs +2 -2
- package/dist/node/cli/index.js +109 -165
- package/dist/node/command/command.util.cjs +2 -2
- package/dist/node/command/command.util.js +135 -170
- package/dist/node/express/express.util.cjs +1 -1
- package/dist/node/express/express.util.js +39 -72
- package/dist/node/fs/fs.util.cjs +3 -3
- package/dist/node/fs/fs.util.js +45 -60
- package/dist/node/log/log.util.cjs +1 -1
- package/dist/node/log/log.util.js +29 -30
- package/dist/node/mongo/mongo.controller.cjs +1 -1
- package/dist/node/mongo/mongo.controller.js +531 -629
- package/dist/node/mongo/mongo.util.cjs +2 -2
- package/dist/node/mongo/mongo.util.js +280 -321
- package/dist/node/package/package.util.cjs +1 -1
- package/dist/node/package/package.util.js +197 -226
- package/dist/node/path/index.cjs +1 -1
- package/dist/node/path/index.js +26 -25
- package/dist/node/path/path.constant.cjs +1 -1
- package/dist/node/path/path.constant.d.ts +2 -0
- package/dist/node/path/path.constant.js +130 -150
- package/dist/node/storage/storage.util.cjs +1 -1
- package/dist/node/storage/storage.util.js +110 -158
- package/dist/node/upload/upload.util.cjs +1 -1
- package/dist/node/upload/upload.util.js +119 -150
- package/dist/node/ws/ts.util.cjs +1 -1
- package/dist/node/ws/ts.util.js +31 -54
- package/dist/react/apollo-client/apollo-client.component.cjs +1 -1
- package/dist/react/apollo-client/apollo-client.component.js +4 -4
- package/dist/react/apollo-client/apollo-client.util.cjs +1 -1
- package/dist/react/apollo-client/apollo-client.util.js +51 -58
- package/dist/react/apollo-client/links/upload.cjs +1 -1
- package/dist/react/apollo-client/links/upload.js +71 -74
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.cjs +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.js +11 -18
- package/dist/react/apollo-error/apollo-error.component.cjs +1 -1
- package/dist/react/apollo-error/apollo-error.component.js +61 -23
- package/dist/react/apollo-error/apollo-error.module.scss.cjs +1 -1
- package/dist/react/apollo-error/apollo-error.module.scss.js +6 -6
- package/dist/react/apollo-error/apollo-error.test.unit.d.ts +1 -0
- package/dist/react/apollo-error/apollo-error.util.cjs +1 -1
- package/dist/react/apollo-error/apollo-error.util.js +6 -6
- package/dist/react/loading/loading.component.cjs +2 -2
- package/dist/react/loading/loading.component.js +30 -46
- package/dist/react/log/log.util.cjs +1 -1
- package/dist/react/log/log.util.js +4 -4
- package/dist/react/next-intl/next-intl.hoc.cjs +1 -1
- package/dist/react/next-intl/next-intl.hoc.js +13 -22
- package/dist/react/next-intl/next-intl.provider.cjs +1 -1
- package/dist/react/next-intl/next-intl.provider.js +7 -7
- package/dist/react/storage/storage.hook.cjs +1 -1
- package/dist/react/storage/storage.hook.js +43 -59
- package/dist/react/storage/storage.util.cjs +1 -1
- package/dist/react/storage/storage.util.js +28 -53
- package/dist/react/userback/userback.component.cjs +1 -1
- package/dist/react/userback/userback.component.js +18 -42
- package/dist/style.css +1 -1
- package/dist/util/common/common.util.cjs +1 -1
- package/dist/util/common/common.util.d.ts +2 -0
- package/dist/util/common/common.util.js +29 -37
- package/dist/util/index.cjs +1 -1
- package/dist/util/index.js +10 -9
- package/dist/util/object/object.util.cjs +1 -1
- package/dist/util/object/object.util.js +72 -76
- package/dist/util/string/index.cjs +1 -1
- package/dist/util/string/index.js +4 -3
- package/dist/util/string/string.util.cjs +1 -1
- package/dist/util/string/string.util.d.ts +12 -0
- package/dist/util/string/string.util.js +63 -44
- package/package.json +25 -16
- package/public/tsconfig.base.json +7 -3
- package/README.md +0 -470
- /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
- /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
|
|
2
|
-
import { mongo as
|
|
3
|
-
import { normalizeMongoFilter as
|
|
4
|
-
import { generateShortId as
|
|
5
|
-
import { RESPONSE_STATUS as
|
|
6
|
-
import { catchError as
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
34
|
-
if (!
|
|
35
|
-
return
|
|
36
|
-
const e = new Set(
|
|
37
|
-
if (Array.isArray(
|
|
38
|
-
const t =
|
|
39
|
-
if (typeof
|
|
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) =>
|
|
18
|
+
(n) => r === n || r.startsWith(`${n}.`)
|
|
42
19
|
);
|
|
43
|
-
if (typeof
|
|
44
|
-
const n =
|
|
20
|
+
if (typeof r == "object" && r !== null) {
|
|
21
|
+
const n = r, c = n.path || n.populate || "";
|
|
45
22
|
return !Array.from(e).some(
|
|
46
|
-
(
|
|
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
|
|
30
|
+
if (typeof i == "string")
|
|
54
31
|
return Array.from(e).some(
|
|
55
|
-
(t) =>
|
|
56
|
-
) ? void 0 :
|
|
57
|
-
if (typeof
|
|
58
|
-
const t =
|
|
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) =>
|
|
61
|
-
) ? void 0 :
|
|
37
|
+
(n) => r === n || r.startsWith(`${n}.`)
|
|
38
|
+
) ? void 0 : i;
|
|
62
39
|
}
|
|
63
|
-
return
|
|
40
|
+
return i;
|
|
64
41
|
}
|
|
65
|
-
function
|
|
66
|
-
if (!
|
|
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
|
|
46
|
+
return i.forEach((r) => {
|
|
70
47
|
try {
|
|
71
|
-
const n = e.ref(
|
|
48
|
+
const n = e.ref(r);
|
|
72
49
|
if (n == null)
|
|
73
50
|
return;
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
const
|
|
77
|
-
t.has(
|
|
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
|
-
|
|
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(([
|
|
59
|
+
}), Array.from(t.entries()).map(([r, n]) => ({ model: r, docs: n }));
|
|
83
60
|
}
|
|
84
|
-
function
|
|
85
|
-
return
|
|
61
|
+
function W(i) {
|
|
62
|
+
return i !== null && typeof i == "object" && "toObject" in i && typeof i.toObject == "function";
|
|
86
63
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
|
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(
|
|
230
|
-
|
|
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(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
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(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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(
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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(
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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(
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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(
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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
|
|
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(
|
|
447
|
-
this.model =
|
|
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((
|
|
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(
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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(
|
|
498
|
-
|
|
499
|
-
|
|
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
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
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(
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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(
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
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(
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
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
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
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
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
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
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
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
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
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(
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
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:
|
|
793
|
-
const
|
|
794
|
-
return t ?
|
|
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}`]:
|
|
797
|
-
...
|
|
707
|
+
{ [`slug.${e}`]: s },
|
|
708
|
+
...r ? [{ slugHistory: { $elemMatch: { [`slug.${e}`]: s } } }] : []
|
|
798
709
|
]
|
|
799
|
-
}
|
|
710
|
+
} : {
|
|
711
|
+
...c,
|
|
800
712
|
$or: [
|
|
801
|
-
{ slug:
|
|
802
|
-
...
|
|
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
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
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
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
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
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
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(
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
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(
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
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
|
-
|
|
955
|
-
|
|
856
|
+
J as MongoController,
|
|
857
|
+
Y as MongooseController
|
|
956
858
|
};
|