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