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