@cyberskill/shared 2.13.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 +4 -4
- package/dist/node/mongo/mongo.util.d.ts +1 -1
- package/dist/node/mongo/mongo.util.js +793 -458
- 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 +24 -24
- /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
|
-
|
|
25
|
+
l(t.next(c));
|
|
26
|
+
} catch (a) {
|
|
27
|
+
s(a);
|
|
28
28
|
}
|
|
29
|
-
},
|
|
29
|
+
}, o = (c) => {
|
|
30
30
|
try {
|
|
31
|
-
|
|
32
|
-
} catch (
|
|
33
|
-
|
|
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
|
|
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 ||
|
|
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
|
-
pagination:
|
|
161
|
-
aggregate:
|
|
162
|
-
middlewares:
|
|
160
|
+
pagination: s = !0,
|
|
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
|
-
|
|
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
|
|
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,171 +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 =
|
|
331
|
-
if (typeof
|
|
332
|
-
return !
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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) => {
|
|
333
|
+
if (typeof s == "string")
|
|
334
|
+
return !Array.from(t).some(
|
|
335
|
+
(i) => s === i || s.startsWith(`${i}.`)
|
|
336
|
+
);
|
|
337
|
+
if (typeof s == "object" && s !== null) {
|
|
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(([
|
|
376
|
+
}), Array.from(r.entries()).map(([s, i]) => ({ model: s, docs: i }));
|
|
367
377
|
}
|
|
368
|
-
function
|
|
369
|
-
return
|
|
378
|
+
function gt(n) {
|
|
379
|
+
return n !== null && typeof n == "object" && "toObject" in n && typeof n.toObject == "function";
|
|
370
380
|
}
|
|
371
|
-
function
|
|
372
|
-
return
|
|
373
|
-
if (!
|
|
374
|
-
return
|
|
375
|
-
const
|
|
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) => {
|
|
376
660
|
if (Array.isArray(r))
|
|
377
|
-
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
|
+
});
|
|
378
670
|
if (typeof r == "string")
|
|
379
|
-
return r ===
|
|
671
|
+
return r === a.name || r.startsWith(`${a.name}.`);
|
|
380
672
|
if (typeof r == "object" && r !== null) {
|
|
381
|
-
const
|
|
382
|
-
return
|
|
673
|
+
const u = r, m = u.path || u.populate || "";
|
|
674
|
+
return m === a.name || m.startsWith(`${a.name}.`);
|
|
383
675
|
}
|
|
384
676
|
return !1;
|
|
385
677
|
});
|
|
386
|
-
if (
|
|
387
|
-
return
|
|
388
|
-
const l =
|
|
389
|
-
l.forEach((
|
|
390
|
-
|
|
391
|
-
|
|
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 : []);
|
|
392
684
|
});
|
|
393
685
|
});
|
|
394
686
|
const c = /* @__PURE__ */ new Map();
|
|
395
|
-
for (const
|
|
396
|
-
const { name:
|
|
397
|
-
for (const
|
|
398
|
-
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, {
|
|
399
691
|
virtuals: [],
|
|
400
692
|
localValueSets: /* @__PURE__ */ new Map(),
|
|
401
693
|
docsByLocalValue: /* @__PURE__ */ new Map()
|
|
402
694
|
});
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
const
|
|
408
|
-
if (
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
let
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
var
|
|
415
|
-
return ((
|
|
416
|
-
})),
|
|
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));
|
|
417
709
|
}
|
|
418
710
|
});
|
|
419
711
|
}
|
|
420
712
|
}
|
|
421
|
-
|
|
422
|
-
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];
|
|
423
715
|
if (!h)
|
|
424
716
|
return;
|
|
425
|
-
const
|
|
426
|
-
if (
|
|
427
|
-
|
|
428
|
-
}),
|
|
717
|
+
const _ = /* @__PURE__ */ new Set();
|
|
718
|
+
if (m.localValueSets.forEach((O) => {
|
|
719
|
+
O.forEach((d) => _.add(d));
|
|
720
|
+
}), _.size === 0)
|
|
429
721
|
return;
|
|
430
|
-
const
|
|
431
|
-
let
|
|
432
|
-
|
|
433
|
-
const
|
|
434
|
-
for (const
|
|
435
|
-
const { name:
|
|
436
|
-
const
|
|
437
|
-
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));
|
|
438
730
|
});
|
|
439
|
-
if (
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
var
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
}),
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
const
|
|
449
|
-
|
|
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);
|
|
450
742
|
});
|
|
451
743
|
});
|
|
452
744
|
} else {
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
var
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
}),
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
const
|
|
462
|
-
|
|
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;
|
|
463
755
|
});
|
|
464
756
|
});
|
|
465
757
|
}
|
|
466
758
|
}
|
|
467
|
-
}))),
|
|
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;
|
|
468
788
|
});
|
|
469
789
|
}
|
|
470
|
-
class
|
|
790
|
+
class Pt {
|
|
471
791
|
/**
|
|
472
792
|
* Creates a new MongoDB controller instance.
|
|
473
793
|
*
|
|
474
794
|
* @param db - The MongoDB database instance.
|
|
475
795
|
* @param collectionName - The name of the collection to operate on.
|
|
476
796
|
*/
|
|
477
|
-
constructor(
|
|
478
|
-
|
|
797
|
+
constructor(e, t) {
|
|
798
|
+
ht(this, "collection"), this.collection = e.collection(t);
|
|
479
799
|
}
|
|
480
800
|
/**
|
|
481
801
|
* Creates a single document in the collection.
|
|
@@ -484,21 +804,21 @@ class Ve {
|
|
|
484
804
|
* @param document - The document to create, with or without generic fields.
|
|
485
805
|
* @returns A promise that resolves to a standardized response with the created document.
|
|
486
806
|
*/
|
|
487
|
-
createOne(
|
|
488
|
-
return
|
|
807
|
+
createOne(e) {
|
|
808
|
+
return v(this, null, function* () {
|
|
489
809
|
try {
|
|
490
|
-
const
|
|
491
|
-
return (yield this.collection.insertOne(
|
|
810
|
+
const t = N(N({}, x.createGenericFields()), e);
|
|
811
|
+
return (yield this.collection.insertOne(t)).acknowledged ? {
|
|
492
812
|
success: !0,
|
|
493
813
|
message: "Document created successfully",
|
|
494
|
-
result:
|
|
814
|
+
result: t
|
|
495
815
|
} : {
|
|
496
816
|
success: !1,
|
|
497
817
|
message: "Document creation failed",
|
|
498
|
-
code:
|
|
818
|
+
code: A.INTERNAL_SERVER_ERROR.CODE
|
|
499
819
|
};
|
|
500
|
-
} catch (
|
|
501
|
-
return
|
|
820
|
+
} catch (t) {
|
|
821
|
+
return D(t);
|
|
502
822
|
}
|
|
503
823
|
});
|
|
504
824
|
}
|
|
@@ -509,21 +829,21 @@ class Ve {
|
|
|
509
829
|
* @param documents - An array of documents to create.
|
|
510
830
|
* @returns A promise that resolves to a standardized response with the created documents.
|
|
511
831
|
*/
|
|
512
|
-
createMany(
|
|
513
|
-
return
|
|
832
|
+
createMany(e) {
|
|
833
|
+
return v(this, null, function* () {
|
|
514
834
|
try {
|
|
515
|
-
const
|
|
835
|
+
const t = e.map((s) => N(N({}, x.createGenericFields()), s)), r = yield this.collection.insertMany(t);
|
|
516
836
|
return r.insertedCount === 0 ? {
|
|
517
837
|
success: !1,
|
|
518
838
|
message: "No documents were inserted",
|
|
519
|
-
code:
|
|
839
|
+
code: A.INTERNAL_SERVER_ERROR.CODE
|
|
520
840
|
} : {
|
|
521
841
|
success: !0,
|
|
522
842
|
message: `${r.insertedCount} documents created successfully`,
|
|
523
|
-
result:
|
|
843
|
+
result: t
|
|
524
844
|
};
|
|
525
|
-
} catch (
|
|
526
|
-
return
|
|
845
|
+
} catch (t) {
|
|
846
|
+
return D(t);
|
|
527
847
|
}
|
|
528
848
|
});
|
|
529
849
|
}
|
|
@@ -533,13 +853,13 @@ class Ve {
|
|
|
533
853
|
* @param filter - The filter criteria to find the document.
|
|
534
854
|
* @returns A promise that resolves to a standardized response with the found document.
|
|
535
855
|
*/
|
|
536
|
-
findOne(
|
|
537
|
-
return
|
|
856
|
+
findOne(e) {
|
|
857
|
+
return v(this, null, function* () {
|
|
538
858
|
try {
|
|
539
|
-
const
|
|
540
|
-
return
|
|
541
|
-
} catch (
|
|
542
|
-
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);
|
|
543
863
|
}
|
|
544
864
|
});
|
|
545
865
|
}
|
|
@@ -550,15 +870,15 @@ class Ve {
|
|
|
550
870
|
* @returns A promise that resolves to a standardized response with the found documents.
|
|
551
871
|
*/
|
|
552
872
|
findAll() {
|
|
553
|
-
return
|
|
873
|
+
return v(this, arguments, function* (e = {}) {
|
|
554
874
|
try {
|
|
555
875
|
return {
|
|
556
876
|
success: !0,
|
|
557
877
|
message: "Documents retrieved successfully",
|
|
558
|
-
result: yield this.collection.find(
|
|
878
|
+
result: yield this.collection.find(e).toArray()
|
|
559
879
|
};
|
|
560
|
-
} catch (
|
|
561
|
-
return
|
|
880
|
+
} catch (t) {
|
|
881
|
+
return D(t);
|
|
562
882
|
}
|
|
563
883
|
});
|
|
564
884
|
}
|
|
@@ -569,16 +889,16 @@ class Ve {
|
|
|
569
889
|
* @returns A promise that resolves to a standardized response with the document count.
|
|
570
890
|
*/
|
|
571
891
|
count() {
|
|
572
|
-
return
|
|
892
|
+
return v(this, arguments, function* (e = {}) {
|
|
573
893
|
try {
|
|
574
|
-
const
|
|
894
|
+
const t = yield this.collection.countDocuments(e);
|
|
575
895
|
return {
|
|
576
896
|
success: !0,
|
|
577
|
-
message: `${
|
|
578
|
-
result:
|
|
897
|
+
message: `${t} documents counted successfully`,
|
|
898
|
+
result: t
|
|
579
899
|
};
|
|
580
|
-
} catch (
|
|
581
|
-
return
|
|
900
|
+
} catch (t) {
|
|
901
|
+
return D(t);
|
|
582
902
|
}
|
|
583
903
|
});
|
|
584
904
|
}
|
|
@@ -589,23 +909,23 @@ class Ve {
|
|
|
589
909
|
* @param update - The update data to apply to the document.
|
|
590
910
|
* @returns A promise that resolves to a standardized response with the update result.
|
|
591
911
|
*/
|
|
592
|
-
updateOne(
|
|
593
|
-
return
|
|
912
|
+
updateOne(e, t) {
|
|
913
|
+
return v(this, null, function* () {
|
|
594
914
|
try {
|
|
595
|
-
const r = yield this.collection.updateOne(
|
|
596
|
-
$set:
|
|
915
|
+
const r = yield this.collection.updateOne(e, {
|
|
916
|
+
$set: t
|
|
597
917
|
});
|
|
598
918
|
return r.matchedCount === 0 ? {
|
|
599
919
|
success: !1,
|
|
600
920
|
message: "No documents matched the filter",
|
|
601
|
-
code:
|
|
921
|
+
code: A.INTERNAL_SERVER_ERROR.CODE
|
|
602
922
|
} : {
|
|
603
923
|
success: !0,
|
|
604
924
|
message: "Document updated successfully",
|
|
605
925
|
result: r
|
|
606
926
|
};
|
|
607
927
|
} catch (r) {
|
|
608
|
-
return
|
|
928
|
+
return D(r);
|
|
609
929
|
}
|
|
610
930
|
});
|
|
611
931
|
}
|
|
@@ -616,23 +936,23 @@ class Ve {
|
|
|
616
936
|
* @param update - The update data to apply to the documents.
|
|
617
937
|
* @returns A promise that resolves to a standardized response with the update result.
|
|
618
938
|
*/
|
|
619
|
-
updateMany(
|
|
620
|
-
return
|
|
939
|
+
updateMany(e, t) {
|
|
940
|
+
return v(this, null, function* () {
|
|
621
941
|
try {
|
|
622
|
-
const r = yield this.collection.updateMany(
|
|
623
|
-
$set:
|
|
942
|
+
const r = yield this.collection.updateMany(e, {
|
|
943
|
+
$set: t
|
|
624
944
|
});
|
|
625
945
|
return r.matchedCount === 0 ? {
|
|
626
946
|
success: !1,
|
|
627
947
|
message: "No documents matched the filter",
|
|
628
|
-
code:
|
|
948
|
+
code: A.INTERNAL_SERVER_ERROR.CODE
|
|
629
949
|
} : {
|
|
630
950
|
success: !0,
|
|
631
951
|
message: "Documents updated successfully",
|
|
632
952
|
result: r
|
|
633
953
|
};
|
|
634
954
|
} catch (r) {
|
|
635
|
-
return
|
|
955
|
+
return D(r);
|
|
636
956
|
}
|
|
637
957
|
});
|
|
638
958
|
}
|
|
@@ -642,21 +962,21 @@ class Ve {
|
|
|
642
962
|
* @param filter - The filter criteria to find the document to delete.
|
|
643
963
|
* @returns A promise that resolves to a standardized response with the delete result.
|
|
644
964
|
*/
|
|
645
|
-
deleteOne(
|
|
646
|
-
return
|
|
965
|
+
deleteOne(e) {
|
|
966
|
+
return v(this, null, function* () {
|
|
647
967
|
try {
|
|
648
|
-
const
|
|
649
|
-
return
|
|
968
|
+
const t = yield this.collection.deleteOne(e);
|
|
969
|
+
return t.deletedCount === 0 ? {
|
|
650
970
|
success: !1,
|
|
651
971
|
message: "No documents matched the filter",
|
|
652
|
-
code:
|
|
972
|
+
code: A.INTERNAL_SERVER_ERROR.CODE
|
|
653
973
|
} : {
|
|
654
974
|
success: !0,
|
|
655
975
|
message: "Document deleted successfully",
|
|
656
|
-
result:
|
|
976
|
+
result: t
|
|
657
977
|
};
|
|
658
|
-
} catch (
|
|
659
|
-
return
|
|
978
|
+
} catch (t) {
|
|
979
|
+
return D(t);
|
|
660
980
|
}
|
|
661
981
|
});
|
|
662
982
|
}
|
|
@@ -666,33 +986,33 @@ class Ve {
|
|
|
666
986
|
* @param filter - The filter criteria to find documents to delete.
|
|
667
987
|
* @returns A promise that resolves to a standardized response with the delete result.
|
|
668
988
|
*/
|
|
669
|
-
deleteMany(
|
|
670
|
-
return
|
|
989
|
+
deleteMany(e) {
|
|
990
|
+
return v(this, null, function* () {
|
|
671
991
|
try {
|
|
672
|
-
const
|
|
673
|
-
return
|
|
992
|
+
const t = yield this.collection.deleteMany(e);
|
|
993
|
+
return t.deletedCount === 0 ? {
|
|
674
994
|
success: !1,
|
|
675
995
|
message: "No documents matched the filter",
|
|
676
|
-
code:
|
|
996
|
+
code: A.INTERNAL_SERVER_ERROR.CODE
|
|
677
997
|
} : {
|
|
678
998
|
success: !0,
|
|
679
999
|
message: "Documents deleted successfully",
|
|
680
|
-
result:
|
|
1000
|
+
result: t
|
|
681
1001
|
};
|
|
682
|
-
} catch (
|
|
683
|
-
return
|
|
1002
|
+
} catch (t) {
|
|
1003
|
+
return D(t);
|
|
684
1004
|
}
|
|
685
1005
|
});
|
|
686
1006
|
}
|
|
687
1007
|
}
|
|
688
|
-
class
|
|
1008
|
+
class Mt {
|
|
689
1009
|
/**
|
|
690
1010
|
* Creates a new Mongoose controller instance.
|
|
691
1011
|
*
|
|
692
1012
|
* @param model - The Mongoose model to operate on.
|
|
693
1013
|
*/
|
|
694
|
-
constructor(
|
|
695
|
-
this.model =
|
|
1014
|
+
constructor(e) {
|
|
1015
|
+
this.model = e;
|
|
696
1016
|
}
|
|
697
1017
|
/**
|
|
698
1018
|
* Gets the model name for logging and error messages.
|
|
@@ -703,11 +1023,19 @@ class xe {
|
|
|
703
1023
|
return this.model.modelName;
|
|
704
1024
|
}
|
|
705
1025
|
/**
|
|
706
|
-
* Gets the dynamic virtuals configuration from the model
|
|
1026
|
+
* Gets the dynamic virtuals configuration from the model instance.
|
|
707
1027
|
*
|
|
708
1028
|
* @returns Array of dynamic virtual configurations or undefined if none exist.
|
|
709
1029
|
*/
|
|
710
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
|
+
}
|
|
711
1039
|
return this.model.schema.statics._dynamicVirtuals;
|
|
712
1040
|
}
|
|
713
1041
|
/**
|
|
@@ -717,14 +1045,14 @@ class xe {
|
|
|
717
1045
|
* @param populate - The populate options to determine which virtuals to populate.
|
|
718
1046
|
* @returns The document with dynamic virtuals populated.
|
|
719
1047
|
*/
|
|
720
|
-
populateDynamicVirtualsForDocument(
|
|
721
|
-
return
|
|
1048
|
+
populateDynamicVirtualsForDocument(e, t) {
|
|
1049
|
+
return v(this, null, function* () {
|
|
722
1050
|
const r = this.getDynamicVirtuals();
|
|
723
1051
|
if (r && r.length > 0) {
|
|
724
|
-
const
|
|
725
|
-
return
|
|
1052
|
+
const s = yield Q(this.model.base, [e], r, t, void 0, this.model);
|
|
1053
|
+
return s && s[0] ? s[0] : e;
|
|
726
1054
|
}
|
|
727
|
-
return
|
|
1055
|
+
return e;
|
|
728
1056
|
});
|
|
729
1057
|
}
|
|
730
1058
|
/**
|
|
@@ -734,10 +1062,10 @@ class xe {
|
|
|
734
1062
|
* @param populate - The populate options to determine which virtuals to populate.
|
|
735
1063
|
* @returns The documents with dynamic virtuals populated.
|
|
736
1064
|
*/
|
|
737
|
-
populateDynamicVirtualsForDocuments(
|
|
738
|
-
return
|
|
1065
|
+
populateDynamicVirtualsForDocuments(e, t) {
|
|
1066
|
+
return v(this, null, function* () {
|
|
739
1067
|
const r = this.getDynamicVirtuals();
|
|
740
|
-
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;
|
|
741
1069
|
});
|
|
742
1070
|
}
|
|
743
1071
|
/**
|
|
@@ -751,22 +1079,22 @@ class xe {
|
|
|
751
1079
|
* @returns A promise that resolves to a standardized response with the found document.
|
|
752
1080
|
*/
|
|
753
1081
|
findOne() {
|
|
754
|
-
return
|
|
755
|
-
var
|
|
1082
|
+
return v(this, arguments, function* (e = {}, t = {}, r = {}, s) {
|
|
1083
|
+
var i, o;
|
|
756
1084
|
try {
|
|
757
|
-
const
|
|
758
|
-
|
|
759
|
-
const
|
|
760
|
-
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)
|
|
761
1089
|
return {
|
|
762
1090
|
success: !1,
|
|
763
1091
|
message: `No ${this.getModelName()} found.`,
|
|
764
|
-
code:
|
|
1092
|
+
code: A.NOT_FOUND.CODE
|
|
765
1093
|
};
|
|
766
|
-
const
|
|
767
|
-
return { success: !0, result: (
|
|
768
|
-
} catch (
|
|
769
|
-
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);
|
|
770
1098
|
}
|
|
771
1099
|
});
|
|
772
1100
|
}
|
|
@@ -781,17 +1109,17 @@ class xe {
|
|
|
781
1109
|
* @returns A promise that resolves to a standardized response with the found documents.
|
|
782
1110
|
*/
|
|
783
1111
|
findAll() {
|
|
784
|
-
return
|
|
1112
|
+
return v(this, arguments, function* (e = {}, t = {}, r = {}, s) {
|
|
785
1113
|
try {
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
const
|
|
789
|
-
return { success: !0, result: (yield this.populateDynamicVirtualsForDocuments(
|
|
790
|
-
var
|
|
791
|
-
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;
|
|
792
1120
|
}) };
|
|
793
|
-
} catch (
|
|
794
|
-
return
|
|
1121
|
+
} catch (i) {
|
|
1122
|
+
return D(i);
|
|
795
1123
|
}
|
|
796
1124
|
});
|
|
797
1125
|
}
|
|
@@ -804,17 +1132,24 @@ class xe {
|
|
|
804
1132
|
* @returns A promise that resolves to a standardized response with paginated results.
|
|
805
1133
|
*/
|
|
806
1134
|
findPaging() {
|
|
807
|
-
return
|
|
1135
|
+
return v(this, arguments, function* (e = {}, t = {}) {
|
|
808
1136
|
try {
|
|
809
|
-
const r =
|
|
810
|
-
|
|
811
|
-
const
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
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;
|
|
815
1150
|
}) }) };
|
|
816
1151
|
} catch (r) {
|
|
817
|
-
return
|
|
1152
|
+
return D(r);
|
|
818
1153
|
}
|
|
819
1154
|
});
|
|
820
1155
|
}
|
|
@@ -825,21 +1160,21 @@ class xe {
|
|
|
825
1160
|
* @param options - Pagination options for the aggregation result.
|
|
826
1161
|
* @returns A promise that resolves to a standardized response with paginated aggregation results.
|
|
827
1162
|
*/
|
|
828
|
-
findPagingAggregate(
|
|
829
|
-
return
|
|
1163
|
+
findPagingAggregate(e) {
|
|
1164
|
+
return v(this, arguments, function* (t, r = {}) {
|
|
830
1165
|
try {
|
|
831
|
-
const
|
|
832
|
-
r.populate && (
|
|
833
|
-
const
|
|
834
|
-
this.model.aggregate(
|
|
835
|
-
|
|
836
|
-
),
|
|
837
|
-
return { success: !0, result:
|
|
838
|
-
var
|
|
839
|
-
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;
|
|
840
1175
|
}) }) };
|
|
841
|
-
} catch (
|
|
842
|
-
return
|
|
1176
|
+
} catch (s) {
|
|
1177
|
+
return D(s);
|
|
843
1178
|
}
|
|
844
1179
|
});
|
|
845
1180
|
}
|
|
@@ -850,12 +1185,12 @@ class xe {
|
|
|
850
1185
|
* @returns A promise that resolves to a standardized response with the document count.
|
|
851
1186
|
*/
|
|
852
1187
|
count() {
|
|
853
|
-
return
|
|
1188
|
+
return v(this, arguments, function* (e = {}) {
|
|
854
1189
|
try {
|
|
855
|
-
const
|
|
856
|
-
return { success: !0, result: yield this.model.countDocuments(
|
|
857
|
-
} catch (
|
|
858
|
-
return
|
|
1190
|
+
const t = F(e);
|
|
1191
|
+
return { success: !0, result: yield this.model.countDocuments(t) };
|
|
1192
|
+
} catch (t) {
|
|
1193
|
+
return D(t);
|
|
859
1194
|
}
|
|
860
1195
|
});
|
|
861
1196
|
}
|
|
@@ -865,14 +1200,14 @@ class xe {
|
|
|
865
1200
|
* @param doc - The document to create.
|
|
866
1201
|
* @returns A promise that resolves to a standardized response with the created document.
|
|
867
1202
|
*/
|
|
868
|
-
createOne(
|
|
869
|
-
return
|
|
870
|
-
var
|
|
1203
|
+
createOne(e) {
|
|
1204
|
+
return v(this, null, function* () {
|
|
1205
|
+
var t, r;
|
|
871
1206
|
try {
|
|
872
|
-
const
|
|
873
|
-
return { success: !0, result: (r = (
|
|
874
|
-
} catch (
|
|
875
|
-
return
|
|
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 };
|
|
1209
|
+
} catch (s) {
|
|
1210
|
+
return D(s);
|
|
876
1211
|
}
|
|
877
1212
|
});
|
|
878
1213
|
}
|
|
@@ -883,15 +1218,15 @@ class xe {
|
|
|
883
1218
|
* @param options - Options for the bulk insertion operation.
|
|
884
1219
|
* @returns A promise that resolves to a standardized response with the created documents.
|
|
885
1220
|
*/
|
|
886
|
-
createMany(
|
|
887
|
-
return
|
|
1221
|
+
createMany(e) {
|
|
1222
|
+
return v(this, arguments, function* (t, r = {}) {
|
|
888
1223
|
try {
|
|
889
|
-
return { success: !0, result: (yield this.model.insertMany(
|
|
890
|
-
var
|
|
891
|
-
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;
|
|
892
1227
|
}) };
|
|
893
|
-
} catch (
|
|
894
|
-
return
|
|
1228
|
+
} catch (s) {
|
|
1229
|
+
return D(s);
|
|
895
1230
|
}
|
|
896
1231
|
});
|
|
897
1232
|
}
|
|
@@ -904,19 +1239,19 @@ class xe {
|
|
|
904
1239
|
* @returns A promise that resolves to a standardized response with the updated document.
|
|
905
1240
|
*/
|
|
906
1241
|
updateOne() {
|
|
907
|
-
return
|
|
908
|
-
var
|
|
1242
|
+
return v(this, arguments, function* (e = {}, t = {}, r = {}) {
|
|
1243
|
+
var s, i;
|
|
909
1244
|
try {
|
|
910
|
-
const
|
|
1245
|
+
const o = F(e), l = yield this.model.findOneAndUpdate(o, t, N({
|
|
911
1246
|
new: !0
|
|
912
1247
|
}, r)).exec();
|
|
913
|
-
return
|
|
1248
|
+
return l ? { success: !0, result: (i = (s = l == null ? void 0 : l.toObject) == null ? void 0 : s.call(l)) != null ? i : l } : {
|
|
914
1249
|
success: !1,
|
|
915
1250
|
message: `Failed to update ${this.getModelName()}.`,
|
|
916
|
-
code:
|
|
1251
|
+
code: A.NOT_FOUND.CODE
|
|
917
1252
|
};
|
|
918
|
-
} catch (
|
|
919
|
-
return
|
|
1253
|
+
} catch (o) {
|
|
1254
|
+
return D(o);
|
|
920
1255
|
}
|
|
921
1256
|
});
|
|
922
1257
|
}
|
|
@@ -929,12 +1264,12 @@ class xe {
|
|
|
929
1264
|
* @returns A promise that resolves to a standardized response with the update result.
|
|
930
1265
|
*/
|
|
931
1266
|
updateMany() {
|
|
932
|
-
return
|
|
1267
|
+
return v(this, arguments, function* (e = {}, t = {}, r = {}) {
|
|
933
1268
|
try {
|
|
934
|
-
const
|
|
935
|
-
return { success: !0, result: yield this.model.updateMany(
|
|
936
|
-
} catch (
|
|
937
|
-
return
|
|
1269
|
+
const s = F(e);
|
|
1270
|
+
return { success: !0, result: yield this.model.updateMany(s, t, r).exec() };
|
|
1271
|
+
} catch (s) {
|
|
1272
|
+
return D(s);
|
|
938
1273
|
}
|
|
939
1274
|
});
|
|
940
1275
|
}
|
|
@@ -946,17 +1281,17 @@ class xe {
|
|
|
946
1281
|
* @returns A promise that resolves to a standardized response with the deleted document.
|
|
947
1282
|
*/
|
|
948
1283
|
deleteOne() {
|
|
949
|
-
return
|
|
950
|
-
var r,
|
|
1284
|
+
return v(this, arguments, function* (e = {}, t = {}) {
|
|
1285
|
+
var r, s;
|
|
951
1286
|
try {
|
|
952
|
-
const
|
|
953
|
-
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 } : {
|
|
954
1289
|
success: !1,
|
|
955
1290
|
message: `No ${this.getModelName()} found to delete.`,
|
|
956
|
-
code:
|
|
1291
|
+
code: A.NOT_FOUND.CODE
|
|
957
1292
|
};
|
|
958
|
-
} catch (
|
|
959
|
-
return
|
|
1293
|
+
} catch (i) {
|
|
1294
|
+
return D(i);
|
|
960
1295
|
}
|
|
961
1296
|
});
|
|
962
1297
|
}
|
|
@@ -968,16 +1303,16 @@ class xe {
|
|
|
968
1303
|
* @returns A promise that resolves to a standardized response with the delete result.
|
|
969
1304
|
*/
|
|
970
1305
|
deleteMany() {
|
|
971
|
-
return
|
|
1306
|
+
return v(this, arguments, function* (e = {}, t = {}) {
|
|
972
1307
|
try {
|
|
973
|
-
const r =
|
|
974
|
-
return
|
|
1308
|
+
const r = F(e), s = yield this.model.deleteMany(r, t).exec();
|
|
1309
|
+
return s.deletedCount === 0 ? {
|
|
975
1310
|
success: !1,
|
|
976
1311
|
message: "No documents found to delete.",
|
|
977
|
-
code:
|
|
978
|
-
} : { success: !0, result:
|
|
1312
|
+
code: A.NOT_FOUND.CODE
|
|
1313
|
+
} : { success: !0, result: s };
|
|
979
1314
|
} catch (r) {
|
|
980
|
-
return
|
|
1315
|
+
return D(r);
|
|
981
1316
|
}
|
|
982
1317
|
});
|
|
983
1318
|
}
|
|
@@ -989,24 +1324,24 @@ class xe {
|
|
|
989
1324
|
* @param length - The initial length for short ID generation (default: 4).
|
|
990
1325
|
* @returns A promise that resolves to a standardized response with the unique short ID.
|
|
991
1326
|
*/
|
|
992
|
-
createShortId(
|
|
993
|
-
return
|
|
1327
|
+
createShortId(e, t = 4) {
|
|
1328
|
+
return v(this, null, function* () {
|
|
994
1329
|
try {
|
|
995
|
-
const
|
|
996
|
-
|
|
997
|
-
)).findIndex((
|
|
998
|
-
if (
|
|
999
|
-
const
|
|
1000
|
-
if (
|
|
1001
|
-
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 };
|
|
1002
1337
|
}
|
|
1003
1338
|
return {
|
|
1004
1339
|
success: !1,
|
|
1005
1340
|
message: "Failed to create a unique shortId",
|
|
1006
|
-
code:
|
|
1341
|
+
code: A.INTERNAL_SERVER_ERROR.CODE
|
|
1007
1342
|
};
|
|
1008
1343
|
} catch (r) {
|
|
1009
|
-
return
|
|
1344
|
+
return D(r);
|
|
1010
1345
|
}
|
|
1011
1346
|
});
|
|
1012
1347
|
}
|
|
@@ -1022,17 +1357,17 @@ class xe {
|
|
|
1022
1357
|
* @param options.filter - Additional filter conditions to apply to the query.
|
|
1023
1358
|
* @returns A MongoDB query object for checking slug existence.
|
|
1024
1359
|
*/
|
|
1025
|
-
createSlugQuery({ slug:
|
|
1026
|
-
const
|
|
1027
|
-
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), {
|
|
1028
1363
|
$or: [
|
|
1029
|
-
{ [`slug.${
|
|
1030
|
-
...
|
|
1364
|
+
{ [`slug.${t}`]: e },
|
|
1365
|
+
...s ? [{ slugHistory: { $elemMatch: { [`slug.${t}`]: e } } }] : []
|
|
1031
1366
|
]
|
|
1032
|
-
}) :
|
|
1367
|
+
}) : $(N({}, o), {
|
|
1033
1368
|
$or: [
|
|
1034
|
-
{ slug:
|
|
1035
|
-
...
|
|
1369
|
+
{ slug: e },
|
|
1370
|
+
...s ? [{ slugHistory: e }] : []
|
|
1036
1371
|
]
|
|
1037
1372
|
});
|
|
1038
1373
|
}
|
|
@@ -1048,24 +1383,24 @@ class xe {
|
|
|
1048
1383
|
* @param options.filter - Additional filter conditions to apply when checking slug existence.
|
|
1049
1384
|
* @returns A promise that resolves to a unique slug string.
|
|
1050
1385
|
*/
|
|
1051
|
-
createUniqueSlug(
|
|
1052
|
-
return
|
|
1053
|
-
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")
|
|
1054
1389
|
throw new Error("Invalid slug provided: must be a non-empty string");
|
|
1055
|
-
const
|
|
1390
|
+
const l = G(t);
|
|
1056
1391
|
if (!(yield this.model.exists(
|
|
1057
|
-
this.createSlugQuery({ slug:
|
|
1392
|
+
this.createSlugQuery({ slug: l, field: r, isObject: s, haveHistory: i, filter: o })
|
|
1058
1393
|
)))
|
|
1059
|
-
return
|
|
1060
|
-
for (let
|
|
1061
|
-
const
|
|
1394
|
+
return l;
|
|
1395
|
+
for (let m = 1; m <= et; m++) {
|
|
1396
|
+
const h = `${l}-${m}`;
|
|
1062
1397
|
if (!(yield this.model.exists(
|
|
1063
|
-
this.createSlugQuery({ slug:
|
|
1398
|
+
this.createSlugQuery({ slug: h, field: r, isObject: s, haveHistory: i, filter: o })
|
|
1064
1399
|
)))
|
|
1065
|
-
return
|
|
1400
|
+
return h;
|
|
1066
1401
|
}
|
|
1067
|
-
const
|
|
1068
|
-
return `${
|
|
1402
|
+
const a = Date.now(), u = Math.random().toString(36).substring(2, 8);
|
|
1403
|
+
return `${l}-${a}-${u}`;
|
|
1069
1404
|
});
|
|
1070
1405
|
}
|
|
1071
1406
|
/**
|
|
@@ -1079,32 +1414,32 @@ class xe {
|
|
|
1079
1414
|
* @param options.filter - Additional filter conditions to apply when checking slug existence.
|
|
1080
1415
|
* @returns A promise that resolves to a standardized response with the created slug(s).
|
|
1081
1416
|
*/
|
|
1082
|
-
createSlug(
|
|
1083
|
-
return
|
|
1417
|
+
createSlug(e) {
|
|
1418
|
+
return v(this, arguments, function* ({ field: t, from: r, filter: s, haveHistory: i }) {
|
|
1084
1419
|
try {
|
|
1085
|
-
const
|
|
1086
|
-
return
|
|
1420
|
+
const o = r[t];
|
|
1421
|
+
return z(o) ? { success: !0, result: Object.fromEntries(
|
|
1087
1422
|
yield Promise.all(
|
|
1088
|
-
Object.entries(
|
|
1089
|
-
const
|
|
1090
|
-
slug:
|
|
1091
|
-
field:
|
|
1423
|
+
Object.entries(o).map((u) => v(this, [u], function* ([m, h]) {
|
|
1424
|
+
const _ = yield this.createUniqueSlug({
|
|
1425
|
+
slug: h,
|
|
1426
|
+
field: m,
|
|
1092
1427
|
isObject: !0,
|
|
1093
|
-
haveHistory:
|
|
1094
|
-
filter:
|
|
1428
|
+
haveHistory: i,
|
|
1429
|
+
filter: s
|
|
1095
1430
|
});
|
|
1096
|
-
return [
|
|
1431
|
+
return [m, _];
|
|
1097
1432
|
}))
|
|
1098
1433
|
)
|
|
1099
1434
|
) } : { success: !0, result: yield this.createUniqueSlug({
|
|
1100
|
-
slug:
|
|
1101
|
-
field:
|
|
1435
|
+
slug: o,
|
|
1436
|
+
field: t,
|
|
1102
1437
|
isObject: !1,
|
|
1103
|
-
haveHistory:
|
|
1104
|
-
filter:
|
|
1438
|
+
haveHistory: i,
|
|
1439
|
+
filter: s
|
|
1105
1440
|
}) };
|
|
1106
|
-
} catch (
|
|
1107
|
-
return
|
|
1441
|
+
} catch (o) {
|
|
1442
|
+
return D(o);
|
|
1108
1443
|
}
|
|
1109
1444
|
});
|
|
1110
1445
|
}
|
|
@@ -1120,33 +1455,33 @@ class xe {
|
|
|
1120
1455
|
* @param options.filter - Additional filter conditions to apply to the query.
|
|
1121
1456
|
* @returns A promise that resolves to a standardized response indicating whether the slug exists.
|
|
1122
1457
|
*/
|
|
1123
|
-
checkSlug(
|
|
1124
|
-
return
|
|
1458
|
+
checkSlug(e) {
|
|
1459
|
+
return v(this, arguments, function* ({ slug: t, field: r, from: s, filter: i, haveHistory: o }) {
|
|
1125
1460
|
try {
|
|
1126
|
-
const
|
|
1127
|
-
if (
|
|
1128
|
-
const
|
|
1461
|
+
const l = s[r];
|
|
1462
|
+
if (z(l)) {
|
|
1463
|
+
const h = Object.values(l).map((b) => G(b));
|
|
1129
1464
|
return (yield Promise.all(
|
|
1130
|
-
|
|
1131
|
-
(
|
|
1132
|
-
slug:
|
|
1465
|
+
h.map(
|
|
1466
|
+
(b) => this.model.exists(this.createSlugQuery({
|
|
1467
|
+
slug: b,
|
|
1133
1468
|
field: r,
|
|
1134
1469
|
isObject: !0,
|
|
1135
|
-
haveHistory:
|
|
1136
|
-
filter:
|
|
1470
|
+
haveHistory: o,
|
|
1471
|
+
filter: i
|
|
1137
1472
|
}))
|
|
1138
1473
|
)
|
|
1139
|
-
)).some((
|
|
1474
|
+
)).some((b) => b) ? { success: !0, result: !0 } : { success: !0, result: !1 };
|
|
1140
1475
|
}
|
|
1141
|
-
const
|
|
1476
|
+
const a = G(t);
|
|
1142
1477
|
return { success: !0, result: (yield this.model.exists(this.createSlugQuery({
|
|
1143
|
-
slug:
|
|
1478
|
+
slug: a,
|
|
1144
1479
|
field: r,
|
|
1145
1480
|
isObject: !1,
|
|
1146
|
-
filter:
|
|
1481
|
+
filter: i
|
|
1147
1482
|
}))) !== null };
|
|
1148
|
-
} catch (
|
|
1149
|
-
return
|
|
1483
|
+
} catch (l) {
|
|
1484
|
+
return D(l);
|
|
1150
1485
|
}
|
|
1151
1486
|
});
|
|
1152
1487
|
}
|
|
@@ -1156,12 +1491,12 @@ class xe {
|
|
|
1156
1491
|
* @param pipeline - The aggregation pipeline stages to execute.
|
|
1157
1492
|
* @returns A promise that resolves to a standardized response with the aggregation results.
|
|
1158
1493
|
*/
|
|
1159
|
-
aggregate(
|
|
1160
|
-
return
|
|
1494
|
+
aggregate(e) {
|
|
1495
|
+
return v(this, null, function* () {
|
|
1161
1496
|
try {
|
|
1162
|
-
return { success: !0, result: yield this.model.aggregate(
|
|
1163
|
-
} catch (
|
|
1164
|
-
return
|
|
1497
|
+
return { success: !0, result: yield this.model.aggregate(e) };
|
|
1498
|
+
} catch (t) {
|
|
1499
|
+
return D(t);
|
|
1165
1500
|
}
|
|
1166
1501
|
});
|
|
1167
1502
|
}
|
|
@@ -1173,18 +1508,18 @@ class xe {
|
|
|
1173
1508
|
* @param options - Additional options for the distinct operation (optional).
|
|
1174
1509
|
* @returns A promise that resolves to a standardized response with the array of distinct values.
|
|
1175
1510
|
*/
|
|
1176
|
-
distinct(
|
|
1177
|
-
return
|
|
1511
|
+
distinct(e) {
|
|
1512
|
+
return v(this, arguments, function* (t, r = {}, s = {}) {
|
|
1178
1513
|
try {
|
|
1179
|
-
return { success: !0, result: yield this.model.distinct(
|
|
1180
|
-
} catch (
|
|
1181
|
-
return
|
|
1514
|
+
return { success: !0, result: yield this.model.distinct(t, r, s) };
|
|
1515
|
+
} catch (i) {
|
|
1516
|
+
return D(i);
|
|
1182
1517
|
}
|
|
1183
1518
|
});
|
|
1184
1519
|
}
|
|
1185
1520
|
}
|
|
1186
1521
|
export {
|
|
1187
|
-
|
|
1188
|
-
|
|
1522
|
+
Pt as MongoController,
|
|
1523
|
+
Mt as MongooseController,
|
|
1189
1524
|
x as mongo
|
|
1190
1525
|
};
|