@cyberskill/shared 2.4.0 → 2.6.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/node/mongo/mongo.util.cjs +4 -4
- package/dist/node/mongo/mongo.util.d.ts +21 -5
- package/dist/node/mongo/mongo.util.js +299 -263
- package/dist/util/index.cjs +1 -1
- package/dist/util/index.js +16 -15
- package/dist/util/object/index.cjs +1 -1
- package/dist/util/object/index.js +6 -5
- package/dist/util/object/object.util.cjs +1 -1
- package/dist/util/object/object.util.d.ts +53 -5
- package/dist/util/object/object.util.js +76 -40
- package/package.json +11 -11
|
@@ -3,42 +3,42 @@ import K from "migrate-mongo";
|
|
|
3
3
|
import { Document as W } from "mongoose";
|
|
4
4
|
import Q from "mongoose-aggregate-paginate-v2";
|
|
5
5
|
import H from "mongoose-paginate-v2";
|
|
6
|
-
import { v4 as
|
|
7
|
-
import { getNestedValue as J, setNestedValue as
|
|
8
|
-
import { regexSearchMapper as
|
|
9
|
-
import { writeFileSync as
|
|
10
|
-
import { PATH as
|
|
11
|
-
import { validate as
|
|
12
|
-
import { generateShortId as
|
|
6
|
+
import { v4 as G } from "uuid";
|
|
7
|
+
import { getNestedValue as J, setNestedValue as X, normalizeMongoFilter as V } from "../../util/object/object.util.js";
|
|
8
|
+
import { regexSearchMapper as Y } from "../../util/common/common.util.js";
|
|
9
|
+
import { writeFileSync as q, pathExistsSync as Z, readFileSync as ee, appendFileSync as te } from "../fs/fs.util.js";
|
|
10
|
+
import { PATH as F, MIGRATE_MONGO_CONFIG as L } from "../path/path.constant.js";
|
|
11
|
+
import { validate as re } from "../../util/validate/validate.util.js";
|
|
12
|
+
import { generateShortId as se, generateSlug as j } from "../../util/string/string.util.js";
|
|
13
13
|
import { RESPONSE_STATUS as v } from "../../constant/response-status.js";
|
|
14
|
-
import { catchError as
|
|
15
|
-
var
|
|
14
|
+
import { catchError as f } from "../log/log.util.js";
|
|
15
|
+
var ne = Object.defineProperty, ce = Object.defineProperties, ue = Object.getOwnPropertyDescriptors, U = Object.getOwnPropertySymbols, ie = Object.prototype.hasOwnProperty, oe = Object.prototype.propertyIsEnumerable, $ = (n, t, e) => t in n ? ne(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, S = (n, t) => {
|
|
16
16
|
for (var e in t || (t = {}))
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
for (var e of
|
|
20
|
-
oe.call(t, e) &&
|
|
21
|
-
return
|
|
22
|
-
}, w = (
|
|
23
|
-
var
|
|
17
|
+
ie.call(t, e) && $(n, e, t[e]);
|
|
18
|
+
if (U)
|
|
19
|
+
for (var e of U(t))
|
|
20
|
+
oe.call(t, e) && $(n, e, t[e]);
|
|
21
|
+
return n;
|
|
22
|
+
}, w = (n, t) => ce(n, ue(t)), le = (n, t, e) => $(n, typeof t != "symbol" ? t + "" : t, e), l = (n, t, e) => new Promise((r, s) => {
|
|
23
|
+
var c = (i) => {
|
|
24
24
|
try {
|
|
25
|
-
|
|
25
|
+
o(e.next(i));
|
|
26
26
|
} catch (a) {
|
|
27
|
-
|
|
27
|
+
s(a);
|
|
28
28
|
}
|
|
29
|
-
},
|
|
29
|
+
}, u = (i) => {
|
|
30
30
|
try {
|
|
31
|
-
|
|
31
|
+
o(e.throw(i));
|
|
32
32
|
} catch (a) {
|
|
33
|
-
|
|
33
|
+
s(a);
|
|
34
34
|
}
|
|
35
|
-
},
|
|
36
|
-
|
|
35
|
+
}, o = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(c, u);
|
|
36
|
+
o((e = e.apply(n, t)).next());
|
|
37
37
|
});
|
|
38
|
-
function
|
|
39
|
-
return
|
|
38
|
+
function ae(n) {
|
|
39
|
+
return n === n.toUpperCase() ? n.charAt(0).toUpperCase() + n.slice(1).toLowerCase() : n;
|
|
40
40
|
}
|
|
41
|
-
const
|
|
41
|
+
const b = {
|
|
42
42
|
/**
|
|
43
43
|
* Creates generic fields that are commonly used across MongoDB documents.
|
|
44
44
|
* This function generates standard fields including a UUID, deletion flag, and timestamps
|
|
@@ -48,7 +48,7 @@ const V = {
|
|
|
48
48
|
*/
|
|
49
49
|
createGenericFields() {
|
|
50
50
|
return {
|
|
51
|
-
id:
|
|
51
|
+
id: G(),
|
|
52
52
|
isDel: !1,
|
|
53
53
|
createdAt: /* @__PURE__ */ new Date(),
|
|
54
54
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -62,8 +62,8 @@ const V = {
|
|
|
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
|
-
t.filter((e) => typeof e == "function").forEach((e) =>
|
|
65
|
+
applyPlugins(n, t) {
|
|
66
|
+
t.filter((e) => typeof e == "function").forEach((e) => n.plugin(e));
|
|
67
67
|
},
|
|
68
68
|
/**
|
|
69
69
|
* Applies middleware functions to a Mongoose schema.
|
|
@@ -72,9 +72,9 @@ const V = {
|
|
|
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
|
-
t.forEach(({ method: e, pre: r, post:
|
|
77
|
-
e && r &&
|
|
75
|
+
applyMiddlewares(n, t) {
|
|
76
|
+
t.forEach(({ method: e, pre: r, post: s }) => {
|
|
77
|
+
e && r && n.pre(e, r), e && s && n.post(e, s);
|
|
78
78
|
});
|
|
79
79
|
},
|
|
80
80
|
/**
|
|
@@ -85,10 +85,10 @@ const V = {
|
|
|
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: G, unique: !0 },
|
|
92
92
|
isDel: { type: Boolean, default: !1 }
|
|
93
93
|
},
|
|
94
94
|
{ timestamps: !0 }
|
|
@@ -107,34 +107,34 @@ const V = {
|
|
|
107
107
|
* @returns A configured Mongoose schema.
|
|
108
108
|
*/
|
|
109
109
|
createSchema({
|
|
110
|
-
mongoose:
|
|
110
|
+
mongoose: n,
|
|
111
111
|
schema: t,
|
|
112
112
|
virtuals: e = [],
|
|
113
113
|
standalone: r = !1
|
|
114
114
|
}) {
|
|
115
|
-
const
|
|
115
|
+
const s = new n.Schema(t, {
|
|
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 e.forEach(({ name:
|
|
122
|
-
if (
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
name:
|
|
126
|
-
options:
|
|
121
|
+
return e.forEach(({ name: c, options: u, get: o }) => {
|
|
122
|
+
if (b.isDynamicVirtual(u)) {
|
|
123
|
+
const i = s.statics;
|
|
124
|
+
i._dynamicVirtuals || (i._dynamicVirtuals = []), i._dynamicVirtuals.push({
|
|
125
|
+
name: c,
|
|
126
|
+
options: u
|
|
127
127
|
});
|
|
128
|
-
const a =
|
|
129
|
-
|
|
130
|
-
var
|
|
131
|
-
return ((
|
|
128
|
+
const a = s.virtual(c);
|
|
129
|
+
o ? a.get(o) : a.get(function() {
|
|
130
|
+
var d;
|
|
131
|
+
return ((d = this._populated) == null ? void 0 : d[c]) || (u != null && u.count ? 0 : u != null && u.justOne ? null : []);
|
|
132
132
|
});
|
|
133
133
|
} else {
|
|
134
|
-
const
|
|
135
|
-
|
|
134
|
+
const i = s.virtual(c, u);
|
|
135
|
+
o && i.get(o);
|
|
136
136
|
}
|
|
137
|
-
}), r ||
|
|
137
|
+
}), r || s.add(b.createGenericSchema(n)), s;
|
|
138
138
|
},
|
|
139
139
|
/**
|
|
140
140
|
* Creates a Mongoose model with plugins, middleware, and pagination support.
|
|
@@ -153,23 +153,23 @@ const V = {
|
|
|
153
153
|
* @throws {Error} When the model name is not provided.
|
|
154
154
|
*/
|
|
155
155
|
createModel({
|
|
156
|
-
mongoose:
|
|
156
|
+
mongoose: n,
|
|
157
157
|
name: t,
|
|
158
158
|
schema: e,
|
|
159
159
|
virtuals: r = [],
|
|
160
|
-
pagination:
|
|
161
|
-
aggregate:
|
|
162
|
-
middlewares:
|
|
160
|
+
pagination: s = !0,
|
|
161
|
+
aggregate: c = !0,
|
|
162
|
+
middlewares: u = []
|
|
163
163
|
}) {
|
|
164
164
|
if (!t)
|
|
165
165
|
throw new Error("Model name is required.");
|
|
166
|
-
if (
|
|
167
|
-
return
|
|
168
|
-
const
|
|
169
|
-
return (
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
]),
|
|
166
|
+
if (n.models[t])
|
|
167
|
+
return n.models[t];
|
|
168
|
+
const o = b.createSchema({ mongoose: n, schema: e, virtuals: r });
|
|
169
|
+
return (s || c) && b.applyPlugins(o, [
|
|
170
|
+
s && H,
|
|
171
|
+
c && Q
|
|
172
|
+
]), b.applyMiddlewares(o, u), n.model(t, o);
|
|
173
173
|
},
|
|
174
174
|
/**
|
|
175
175
|
* Validation utilities for Mongoose schemas.
|
|
@@ -184,9 +184,9 @@ const V = {
|
|
|
184
184
|
* @returns A validation function that returns true if the field is not empty.
|
|
185
185
|
*/
|
|
186
186
|
isRequired() {
|
|
187
|
-
return function(
|
|
187
|
+
return function(n) {
|
|
188
188
|
return l(this, null, function* () {
|
|
189
|
-
return !
|
|
189
|
+
return !re.isEmpty(n);
|
|
190
190
|
});
|
|
191
191
|
};
|
|
192
192
|
},
|
|
@@ -199,12 +199,12 @@ const V = {
|
|
|
199
199
|
* @returns A validation function that returns true if the value is unique across the specified fields.
|
|
200
200
|
* @throws {Error} When fields is not a non-empty array of strings.
|
|
201
201
|
*/
|
|
202
|
-
isUnique(
|
|
202
|
+
isUnique(n) {
|
|
203
203
|
return function(t) {
|
|
204
204
|
return l(this, null, function* () {
|
|
205
|
-
if (!Array.isArray(
|
|
205
|
+
if (!Array.isArray(n) || n.length === 0)
|
|
206
206
|
throw new Error("Fields must be a non-empty array of strings.");
|
|
207
|
-
const e = { $or:
|
|
207
|
+
const e = { $or: n.map((s) => ({ [s]: t })) };
|
|
208
208
|
return !(yield this.constructor.exists(e));
|
|
209
209
|
});
|
|
210
210
|
};
|
|
@@ -218,12 +218,12 @@ const V = {
|
|
|
218
218
|
* @returns A validation function that returns true if the value matches all regex patterns.
|
|
219
219
|
* @throws {Error} When regexArray is not an array of valid RegExp objects.
|
|
220
220
|
*/
|
|
221
|
-
matchesRegex(
|
|
221
|
+
matchesRegex(n) {
|
|
222
222
|
return function(t) {
|
|
223
223
|
return l(this, null, function* () {
|
|
224
|
-
if (!Array.isArray(
|
|
224
|
+
if (!Array.isArray(n) || n.some((e) => !(e instanceof RegExp)))
|
|
225
225
|
throw new Error("regexArray must be an array of valid RegExp objects.");
|
|
226
|
-
return
|
|
226
|
+
return n.every((e) => e.test(t));
|
|
227
227
|
});
|
|
228
228
|
};
|
|
229
229
|
}
|
|
@@ -240,15 +240,15 @@ const V = {
|
|
|
240
240
|
*
|
|
241
241
|
* @param options - Migration configuration options to write to the config file.
|
|
242
242
|
*/
|
|
243
|
-
setConfig: (
|
|
243
|
+
setConfig: (n) => {
|
|
244
244
|
const t = `// This file is automatically generated by the Cyberskill CLI.
|
|
245
|
-
module.exports = ${JSON.stringify(
|
|
246
|
-
|
|
245
|
+
module.exports = ${JSON.stringify(n, null, 4)}`;
|
|
246
|
+
q(F.MIGRATE_MONGO_CONFIG, t);
|
|
247
247
|
const e = `
|
|
248
|
-
${
|
|
248
|
+
${L}
|
|
249
249
|
`;
|
|
250
|
-
|
|
251
|
-
`).includes(
|
|
250
|
+
Z(F.GIT_IGNORE) ? ee(F.GIT_IGNORE, "utf-8").split(`
|
|
251
|
+
`).includes(L) || te(F.GIT_IGNORE, e) : q(F.GIT_IGNORE, e);
|
|
252
252
|
}
|
|
253
253
|
}),
|
|
254
254
|
/**
|
|
@@ -260,20 +260,20 @@ ${q}
|
|
|
260
260
|
* @param fields - An array of field names to convert to regex patterns.
|
|
261
261
|
* @returns A new filter object with string values converted to regex patterns.
|
|
262
262
|
*/
|
|
263
|
-
regexify(
|
|
264
|
-
if (!
|
|
263
|
+
regexify(n, t) {
|
|
264
|
+
if (!n)
|
|
265
265
|
return {};
|
|
266
|
-
let e = B(
|
|
266
|
+
let e = B(n);
|
|
267
267
|
if (!t || t.length === 0)
|
|
268
268
|
return e;
|
|
269
269
|
for (const r of t) {
|
|
270
|
-
const
|
|
271
|
-
if (typeof
|
|
272
|
-
const
|
|
273
|
-
$regex: `.*${
|
|
270
|
+
const s = r.toString().split("."), c = J(e, s);
|
|
271
|
+
if (typeof c == "string" && c.length > 0) {
|
|
272
|
+
const u = {
|
|
273
|
+
$regex: `.*${Y(c)}.*`,
|
|
274
274
|
$options: "i"
|
|
275
275
|
};
|
|
276
|
-
e =
|
|
276
|
+
e = X(e, s, u);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
return e;
|
|
@@ -284,161 +284,195 @@ ${q}
|
|
|
284
284
|
* @param options - The virtual options to check.
|
|
285
285
|
* @returns True if the options contain a dynamic ref function.
|
|
286
286
|
*/
|
|
287
|
-
isDynamicVirtual(
|
|
288
|
-
return !!(
|
|
287
|
+
isDynamicVirtual(n) {
|
|
288
|
+
return !!(n && typeof n.ref == "function");
|
|
289
|
+
},
|
|
290
|
+
/**
|
|
291
|
+
* Generic utility function to get new records from the database
|
|
292
|
+
* @param controller - MongoController instance
|
|
293
|
+
* @param recordsToCheck - Array of records to check
|
|
294
|
+
* @param filterFn - Function to determine if a record already exists
|
|
295
|
+
* @returns Array of records that don't exist in the database
|
|
296
|
+
*/
|
|
297
|
+
getNewRecords(n, t, e) {
|
|
298
|
+
return l(this, null, function* () {
|
|
299
|
+
const r = yield n.findAll({});
|
|
300
|
+
return r.success ? t.filter(
|
|
301
|
+
(c) => !r.result.some(
|
|
302
|
+
(u) => e(u, c)
|
|
303
|
+
)
|
|
304
|
+
) : t;
|
|
305
|
+
});
|
|
306
|
+
},
|
|
307
|
+
/**
|
|
308
|
+
* Generic utility function to get existing records that match the filter criteria
|
|
309
|
+
* @param controller - MongoController instance
|
|
310
|
+
* @param recordsToCheck - Array of records to check
|
|
311
|
+
* @param filterFn - Function to determine if a record exists
|
|
312
|
+
* @returns Array of existing records that match the filter criteria
|
|
313
|
+
*/
|
|
314
|
+
getExistingRecords(n, t, e) {
|
|
315
|
+
return l(this, null, function* () {
|
|
316
|
+
const r = yield n.findAll({});
|
|
317
|
+
return r.success ? r.result.filter(
|
|
318
|
+
(c) => t.some(
|
|
319
|
+
(u) => e(c, u)
|
|
320
|
+
)
|
|
321
|
+
) : [];
|
|
322
|
+
});
|
|
289
323
|
}
|
|
290
324
|
};
|
|
291
|
-
function
|
|
292
|
-
return
|
|
325
|
+
function de(n) {
|
|
326
|
+
return n !== null && typeof n == "object" && "toObject" in n && typeof n.toObject == "function";
|
|
293
327
|
}
|
|
294
|
-
function
|
|
295
|
-
if (!
|
|
296
|
-
return
|
|
328
|
+
function I(n, t) {
|
|
329
|
+
if (!n || !t || t.length === 0)
|
|
330
|
+
return n;
|
|
297
331
|
const e = new Set(t.map((r) => r.name));
|
|
298
|
-
if (Array.isArray(
|
|
299
|
-
const r =
|
|
300
|
-
if (typeof
|
|
301
|
-
return !e.has(
|
|
302
|
-
if (typeof
|
|
303
|
-
const
|
|
304
|
-
return !e.has(
|
|
332
|
+
if (Array.isArray(n)) {
|
|
333
|
+
const r = n.filter((s) => {
|
|
334
|
+
if (typeof s == "string")
|
|
335
|
+
return !e.has(s);
|
|
336
|
+
if (typeof s == "object" && s !== null) {
|
|
337
|
+
const c = s;
|
|
338
|
+
return !e.has(c.path || c.populate || "");
|
|
305
339
|
}
|
|
306
340
|
return !0;
|
|
307
341
|
});
|
|
308
342
|
return r.length > 0 ? r : void 0;
|
|
309
343
|
}
|
|
310
|
-
if (typeof
|
|
311
|
-
return e.has(
|
|
312
|
-
if (typeof
|
|
313
|
-
const r =
|
|
314
|
-
return e.has(
|
|
344
|
+
if (typeof n == "string")
|
|
345
|
+
return e.has(n) ? void 0 : n;
|
|
346
|
+
if (typeof n == "object" && n !== null) {
|
|
347
|
+
const r = n, s = r.path || r.populate || "";
|
|
348
|
+
return e.has(s) ? void 0 : n;
|
|
315
349
|
}
|
|
316
|
-
return
|
|
350
|
+
return n;
|
|
317
351
|
}
|
|
318
|
-
function
|
|
319
|
-
if (!
|
|
352
|
+
function fe(n, t, e) {
|
|
353
|
+
if (!n.length || !t || !(e != null && e.ref))
|
|
320
354
|
return [];
|
|
321
355
|
const r = /* @__PURE__ */ new Map();
|
|
322
|
-
return
|
|
356
|
+
return n.forEach((s) => {
|
|
323
357
|
try {
|
|
324
|
-
const
|
|
325
|
-
if (
|
|
358
|
+
const c = e.ref(s);
|
|
359
|
+
if (c == null)
|
|
326
360
|
return;
|
|
327
|
-
const
|
|
328
|
-
if (
|
|
329
|
-
const
|
|
330
|
-
r.has(
|
|
361
|
+
const u = typeof c == "string" ? c : String(c);
|
|
362
|
+
if (u && u.trim() !== "") {
|
|
363
|
+
const o = ae(u);
|
|
364
|
+
r.has(o) || r.set(o, []), r.get(o).push(s);
|
|
331
365
|
}
|
|
332
|
-
} catch (
|
|
333
|
-
|
|
366
|
+
} catch (c) {
|
|
367
|
+
f(new Error(`Dynamic ref function failed for virtual "${t}": ${c instanceof Error ? c.message : String(c)}`));
|
|
334
368
|
}
|
|
335
|
-
}), Array.from(r.entries()).map(([
|
|
369
|
+
}), Array.from(r.entries()).map(([s, c]) => ({ model: s, docs: c }));
|
|
336
370
|
}
|
|
337
|
-
function
|
|
371
|
+
function z(n, t, e, r, s) {
|
|
338
372
|
return l(this, null, function* () {
|
|
339
373
|
if (!t.length || !e.length || !r)
|
|
340
374
|
return t;
|
|
341
|
-
const
|
|
375
|
+
const c = e.filter((i) => {
|
|
342
376
|
if (Array.isArray(r))
|
|
343
|
-
return r.length > 0 && r.some((a) => typeof a == "string" ? a ===
|
|
377
|
+
return r.length > 0 && r.some((a) => typeof a == "string" ? a === i.name : a.path === i.name);
|
|
344
378
|
if (typeof r == "string")
|
|
345
|
-
return r ===
|
|
379
|
+
return r === i.name;
|
|
346
380
|
if (typeof r == "object" && r !== null) {
|
|
347
381
|
const a = r;
|
|
348
|
-
return a.path && a.path ===
|
|
382
|
+
return a.path && a.path === i.name || a.populate && a.populate === i.name;
|
|
349
383
|
}
|
|
350
384
|
return !1;
|
|
351
385
|
});
|
|
352
|
-
if (
|
|
386
|
+
if (c.length === 0)
|
|
353
387
|
return t;
|
|
354
|
-
const
|
|
355
|
-
(
|
|
388
|
+
const u = B(t.map(
|
|
389
|
+
(i) => de(i) ? i.toObject() : i
|
|
356
390
|
));
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (!(a in
|
|
360
|
-
const m =
|
|
361
|
-
m[a] =
|
|
391
|
+
u.forEach((i) => {
|
|
392
|
+
c.forEach(({ name: a, options: d }) => {
|
|
393
|
+
if (!(a in i)) {
|
|
394
|
+
const m = i;
|
|
395
|
+
m[a] = d.count ? 0 : d.justOne ? null : [];
|
|
362
396
|
}
|
|
363
397
|
});
|
|
364
398
|
});
|
|
365
|
-
const
|
|
366
|
-
for (const
|
|
367
|
-
const { name: a, options:
|
|
399
|
+
const o = /* @__PURE__ */ new Map();
|
|
400
|
+
for (const i of c) {
|
|
401
|
+
const { name: a, options: d } = i, m = fe(u, a, d);
|
|
368
402
|
for (const p of m) {
|
|
369
|
-
|
|
403
|
+
o.has(p.model) || o.set(p.model, {
|
|
370
404
|
virtuals: [],
|
|
371
405
|
localValueSets: /* @__PURE__ */ new Map(),
|
|
372
406
|
docsByLocalValue: /* @__PURE__ */ new Map()
|
|
373
407
|
});
|
|
374
|
-
const h =
|
|
375
|
-
h.virtuals.find((N) => N.name === a) || (h.virtuals.push(
|
|
408
|
+
const h = o.get(p.model);
|
|
409
|
+
h.virtuals.find((N) => N.name === a) || (h.virtuals.push(i), h.localValueSets.set(a, /* @__PURE__ */ new Set()));
|
|
376
410
|
const M = h.localValueSets.get(a);
|
|
377
411
|
p.docs.forEach((N) => {
|
|
378
|
-
const
|
|
379
|
-
if (
|
|
380
|
-
const D = String(
|
|
412
|
+
const A = N[d.localField];
|
|
413
|
+
if (A != null) {
|
|
414
|
+
const D = String(A);
|
|
381
415
|
M.add(D);
|
|
382
416
|
let _ = -1;
|
|
383
417
|
const R = N;
|
|
384
|
-
R.id !== void 0 ? _ =
|
|
418
|
+
R.id !== void 0 ? _ = u.findIndex((x) => x.id === R.id) : R._id !== void 0 && (_ = u.findIndex((x) => {
|
|
385
419
|
var O, y, E, g;
|
|
386
|
-
return ((y = (O =
|
|
420
|
+
return ((y = (O = x._id) == null ? void 0 : O.toString) == null ? void 0 : y.call(O)) === ((g = (E = R._id) == null ? void 0 : E.toString) == null ? void 0 : g.call(E));
|
|
387
421
|
})), _ !== -1 && (h.docsByLocalValue.has(D) || h.docsByLocalValue.set(D, []), h.docsByLocalValue.get(D).push(_));
|
|
388
422
|
}
|
|
389
423
|
});
|
|
390
424
|
}
|
|
391
425
|
}
|
|
392
|
-
return yield Promise.all(Array.from(
|
|
393
|
-
const m =
|
|
426
|
+
return yield Promise.all(Array.from(o.entries()).map((i) => l(null, [i], function* ([a, d]) {
|
|
427
|
+
const m = n.models[a];
|
|
394
428
|
if (!m)
|
|
395
429
|
return;
|
|
396
430
|
const p = /* @__PURE__ */ new Set();
|
|
397
|
-
if (
|
|
431
|
+
if (d.localValueSets.forEach((D) => {
|
|
398
432
|
D.forEach((_) => p.add(_));
|
|
399
433
|
}), p.size === 0)
|
|
400
434
|
return;
|
|
401
|
-
const h = [...new Set(
|
|
435
|
+
const h = [...new Set(d.virtuals.map((D) => D.options.foreignField))], M = Array.from(p);
|
|
402
436
|
let N;
|
|
403
437
|
h.length === 1 ? N = { [String(h[0])]: { $in: M } } : N = { $or: h.map((D) => ({ [D]: { $in: M } })) };
|
|
404
|
-
const
|
|
405
|
-
for (const D of
|
|
406
|
-
const { name: _, options: R } = D,
|
|
438
|
+
const A = yield m.find(N, s).lean();
|
|
439
|
+
for (const D of d.virtuals) {
|
|
440
|
+
const { name: _, options: R } = D, x = A.filter((O) => {
|
|
407
441
|
const y = O[R.foreignField];
|
|
408
442
|
return y != null && p.has(String(y));
|
|
409
443
|
});
|
|
410
444
|
if (R.count) {
|
|
411
445
|
const O = /* @__PURE__ */ new Map();
|
|
412
|
-
|
|
446
|
+
x.forEach((y) => {
|
|
413
447
|
var E;
|
|
414
448
|
const g = (E = y[R.foreignField]) == null ? void 0 : E.toString();
|
|
415
449
|
g && O.set(g, (O.get(g) || 0) + 1);
|
|
416
|
-
}),
|
|
417
|
-
const E =
|
|
418
|
-
E.forEach((
|
|
419
|
-
const P =
|
|
450
|
+
}), d.localValueSets.get(_).forEach((y) => {
|
|
451
|
+
const E = d.docsByLocalValue.get(y) || [], g = O.get(y) || 0;
|
|
452
|
+
E.forEach((C) => {
|
|
453
|
+
const P = u[C];
|
|
420
454
|
P[_] === void 0 && (P[_] = g);
|
|
421
455
|
});
|
|
422
456
|
});
|
|
423
457
|
} else {
|
|
424
458
|
const O = /* @__PURE__ */ new Map();
|
|
425
|
-
|
|
459
|
+
x.forEach((y) => {
|
|
426
460
|
var E;
|
|
427
461
|
const g = (E = y[R.foreignField]) == null ? void 0 : E.toString();
|
|
428
462
|
g && (O.has(g) || O.set(g, []), O.get(g).push(y));
|
|
429
|
-
}),
|
|
430
|
-
const E =
|
|
463
|
+
}), d.localValueSets.get(_).forEach((y) => {
|
|
464
|
+
const E = d.docsByLocalValue.get(y) || [], g = O.get(y) || [], C = R.justOne ? g[0] || null : g;
|
|
431
465
|
E.forEach((P) => {
|
|
432
|
-
const k =
|
|
433
|
-
k[_] =
|
|
466
|
+
const k = u[P];
|
|
467
|
+
k[_] = C;
|
|
434
468
|
});
|
|
435
469
|
});
|
|
436
470
|
}
|
|
437
471
|
}
|
|
438
|
-
}))),
|
|
472
|
+
}))), u;
|
|
439
473
|
});
|
|
440
474
|
}
|
|
441
|
-
class
|
|
475
|
+
class be {
|
|
442
476
|
/**
|
|
443
477
|
* Creates a new MongoDB controller instance.
|
|
444
478
|
*
|
|
@@ -446,7 +480,7 @@ class Ve {
|
|
|
446
480
|
* @param collectionName - The name of the collection to operate on.
|
|
447
481
|
*/
|
|
448
482
|
constructor(t, e) {
|
|
449
|
-
|
|
483
|
+
le(this, "collection"), this.collection = t.collection(e);
|
|
450
484
|
}
|
|
451
485
|
/**
|
|
452
486
|
* Creates a single document in the collection.
|
|
@@ -458,7 +492,7 @@ class Ve {
|
|
|
458
492
|
createOne(t) {
|
|
459
493
|
return l(this, null, function* () {
|
|
460
494
|
try {
|
|
461
|
-
const e = S(S({},
|
|
495
|
+
const e = S(S({}, b.createGenericFields()), t);
|
|
462
496
|
return (yield this.collection.insertOne(e)).acknowledged ? {
|
|
463
497
|
success: !0,
|
|
464
498
|
message: "Document created successfully",
|
|
@@ -469,7 +503,7 @@ class Ve {
|
|
|
469
503
|
code: v.INTERNAL_SERVER_ERROR.CODE
|
|
470
504
|
};
|
|
471
505
|
} catch (e) {
|
|
472
|
-
return
|
|
506
|
+
return f(e);
|
|
473
507
|
}
|
|
474
508
|
});
|
|
475
509
|
}
|
|
@@ -483,7 +517,7 @@ class Ve {
|
|
|
483
517
|
createMany(t) {
|
|
484
518
|
return l(this, null, function* () {
|
|
485
519
|
try {
|
|
486
|
-
const e = t.map((
|
|
520
|
+
const e = t.map((s) => S(S({}, b.createGenericFields()), s)), r = yield this.collection.insertMany(e);
|
|
487
521
|
return r.insertedCount === 0 ? {
|
|
488
522
|
success: !1,
|
|
489
523
|
message: "No documents were inserted",
|
|
@@ -494,7 +528,7 @@ class Ve {
|
|
|
494
528
|
result: e
|
|
495
529
|
};
|
|
496
530
|
} catch (e) {
|
|
497
|
-
return
|
|
531
|
+
return f(e);
|
|
498
532
|
}
|
|
499
533
|
});
|
|
500
534
|
}
|
|
@@ -510,7 +544,7 @@ class Ve {
|
|
|
510
544
|
const e = yield this.collection.findOne(t);
|
|
511
545
|
return e ? { success: !0, message: "Document found", result: e } : { success: !1, message: "Document not found", code: v.NOT_FOUND.CODE };
|
|
512
546
|
} catch (e) {
|
|
513
|
-
return
|
|
547
|
+
return f(e);
|
|
514
548
|
}
|
|
515
549
|
});
|
|
516
550
|
}
|
|
@@ -529,7 +563,7 @@ class Ve {
|
|
|
529
563
|
result: yield this.collection.find(t).toArray()
|
|
530
564
|
};
|
|
531
565
|
} catch (e) {
|
|
532
|
-
return
|
|
566
|
+
return f(e);
|
|
533
567
|
}
|
|
534
568
|
});
|
|
535
569
|
}
|
|
@@ -549,7 +583,7 @@ class Ve {
|
|
|
549
583
|
result: e
|
|
550
584
|
};
|
|
551
585
|
} catch (e) {
|
|
552
|
-
return
|
|
586
|
+
return f(e);
|
|
553
587
|
}
|
|
554
588
|
});
|
|
555
589
|
}
|
|
@@ -576,7 +610,7 @@ class Ve {
|
|
|
576
610
|
result: r
|
|
577
611
|
};
|
|
578
612
|
} catch (r) {
|
|
579
|
-
return
|
|
613
|
+
return f(r);
|
|
580
614
|
}
|
|
581
615
|
});
|
|
582
616
|
}
|
|
@@ -603,7 +637,7 @@ class Ve {
|
|
|
603
637
|
result: r
|
|
604
638
|
};
|
|
605
639
|
} catch (r) {
|
|
606
|
-
return
|
|
640
|
+
return f(r);
|
|
607
641
|
}
|
|
608
642
|
});
|
|
609
643
|
}
|
|
@@ -627,7 +661,7 @@ class Ve {
|
|
|
627
661
|
result: e
|
|
628
662
|
};
|
|
629
663
|
} catch (e) {
|
|
630
|
-
return
|
|
664
|
+
return f(e);
|
|
631
665
|
}
|
|
632
666
|
});
|
|
633
667
|
}
|
|
@@ -651,12 +685,12 @@ class Ve {
|
|
|
651
685
|
result: e
|
|
652
686
|
};
|
|
653
687
|
} catch (e) {
|
|
654
|
-
return
|
|
688
|
+
return f(e);
|
|
655
689
|
}
|
|
656
690
|
});
|
|
657
691
|
}
|
|
658
692
|
}
|
|
659
|
-
class
|
|
693
|
+
class xe {
|
|
660
694
|
/**
|
|
661
695
|
* Creates a new Mongoose controller instance.
|
|
662
696
|
*
|
|
@@ -692,8 +726,8 @@ class be {
|
|
|
692
726
|
return l(this, null, function* () {
|
|
693
727
|
const r = this.getDynamicVirtuals();
|
|
694
728
|
if (r && r.length > 0) {
|
|
695
|
-
const
|
|
696
|
-
return
|
|
729
|
+
const s = yield z(this.model.base, [t], r, e);
|
|
730
|
+
return s && s[0] ? s[0] : t;
|
|
697
731
|
}
|
|
698
732
|
return t;
|
|
699
733
|
});
|
|
@@ -708,7 +742,7 @@ class be {
|
|
|
708
742
|
populateDynamicVirtualsForDocuments(t, e) {
|
|
709
743
|
return l(this, null, function* () {
|
|
710
744
|
const r = this.getDynamicVirtuals();
|
|
711
|
-
return r && r.length > 0 && t.length > 0 ? yield
|
|
745
|
+
return r && r.length > 0 && t.length > 0 ? yield z(this.model.base, t, r, e) : t;
|
|
712
746
|
});
|
|
713
747
|
}
|
|
714
748
|
/**
|
|
@@ -722,18 +756,18 @@ class be {
|
|
|
722
756
|
* @returns A promise that resolves to a standardized response with the found document.
|
|
723
757
|
*/
|
|
724
758
|
findOne() {
|
|
725
|
-
return l(this, arguments, function* (t = {}, e = {}, r = {},
|
|
759
|
+
return l(this, arguments, function* (t = {}, e = {}, r = {}, s) {
|
|
726
760
|
try {
|
|
727
|
-
const u = this.model.findOne(
|
|
761
|
+
const c = V(t), u = this.model.findOne(c, e, r), o = this.getDynamicVirtuals(), i = I(s, o);
|
|
728
762
|
i && u.populate(i);
|
|
729
|
-
const
|
|
730
|
-
return
|
|
763
|
+
const a = yield u.exec();
|
|
764
|
+
return a ? { success: !0, result: yield this.populateDynamicVirtualsForDocument(a, s) } : {
|
|
731
765
|
success: !1,
|
|
732
766
|
message: `No ${this.getModelName()} found.`,
|
|
733
767
|
code: v.NOT_FOUND.CODE
|
|
734
768
|
};
|
|
735
|
-
} catch (
|
|
736
|
-
return
|
|
769
|
+
} catch (c) {
|
|
770
|
+
return f(c);
|
|
737
771
|
}
|
|
738
772
|
});
|
|
739
773
|
}
|
|
@@ -748,14 +782,14 @@ class be {
|
|
|
748
782
|
* @returns A promise that resolves to a standardized response with the found documents.
|
|
749
783
|
*/
|
|
750
784
|
findAll() {
|
|
751
|
-
return l(this, arguments, function* (t = {}, e = {}, r = {},
|
|
785
|
+
return l(this, arguments, function* (t = {}, e = {}, r = {}, s) {
|
|
752
786
|
try {
|
|
753
|
-
const u = this.model.find(
|
|
787
|
+
const c = V(t), u = this.model.find(c, e, r), o = this.getDynamicVirtuals(), i = I(s, o);
|
|
754
788
|
i && u.populate(i);
|
|
755
|
-
const
|
|
756
|
-
return { success: !0, result: yield this.populateDynamicVirtualsForDocuments(
|
|
757
|
-
} catch (
|
|
758
|
-
return
|
|
789
|
+
const a = yield u.exec();
|
|
790
|
+
return { success: !0, result: yield this.populateDynamicVirtualsForDocuments(a, s) };
|
|
791
|
+
} catch (c) {
|
|
792
|
+
return f(c);
|
|
759
793
|
}
|
|
760
794
|
});
|
|
761
795
|
}
|
|
@@ -770,12 +804,12 @@ class be {
|
|
|
770
804
|
findPaging() {
|
|
771
805
|
return l(this, arguments, function* (t = {}, e = {}) {
|
|
772
806
|
try {
|
|
773
|
-
const r = this.getDynamicVirtuals(),
|
|
774
|
-
e.populate && (
|
|
775
|
-
const u = yield this.model.paginate(
|
|
776
|
-
return { success: !0, result: w(S({}, u), { docs:
|
|
807
|
+
const r = V(t), s = this.getDynamicVirtuals(), c = S({}, e);
|
|
808
|
+
e.populate && (c.populate = I(e.populate, s));
|
|
809
|
+
const u = yield this.model.paginate(r, c), o = yield this.populateDynamicVirtualsForDocuments(u.docs, e.populate);
|
|
810
|
+
return { success: !0, result: w(S({}, u), { docs: o }) };
|
|
777
811
|
} catch (r) {
|
|
778
|
-
return
|
|
812
|
+
return f(r);
|
|
779
813
|
}
|
|
780
814
|
});
|
|
781
815
|
}
|
|
@@ -789,15 +823,15 @@ class be {
|
|
|
789
823
|
findPagingAggregate(t) {
|
|
790
824
|
return l(this, arguments, function* (e, r = {}) {
|
|
791
825
|
try {
|
|
792
|
-
const
|
|
793
|
-
r.populate && (
|
|
794
|
-
const
|
|
826
|
+
const s = this.getDynamicVirtuals(), c = S({}, r);
|
|
827
|
+
r.populate && (c.populate = I(r.populate, s));
|
|
828
|
+
const u = yield this.model.aggregatePaginate(
|
|
795
829
|
this.model.aggregate(e),
|
|
796
|
-
|
|
797
|
-
),
|
|
798
|
-
return { success: !0, result: w(S({},
|
|
799
|
-
} catch (
|
|
800
|
-
return
|
|
830
|
+
c
|
|
831
|
+
), o = yield this.populateDynamicVirtualsForDocuments(u.docs, r.populate);
|
|
832
|
+
return { success: !0, result: w(S({}, u), { docs: o }) };
|
|
833
|
+
} catch (s) {
|
|
834
|
+
return f(s);
|
|
801
835
|
}
|
|
802
836
|
});
|
|
803
837
|
}
|
|
@@ -810,9 +844,10 @@ class be {
|
|
|
810
844
|
count() {
|
|
811
845
|
return l(this, arguments, function* (t = {}) {
|
|
812
846
|
try {
|
|
813
|
-
|
|
847
|
+
const e = V(t);
|
|
848
|
+
return { success: !0, result: yield this.model.countDocuments(e) };
|
|
814
849
|
} catch (e) {
|
|
815
|
-
return
|
|
850
|
+
return f(e);
|
|
816
851
|
}
|
|
817
852
|
});
|
|
818
853
|
}
|
|
@@ -827,7 +862,7 @@ class be {
|
|
|
827
862
|
try {
|
|
828
863
|
return { success: !0, result: yield this.model.create(t) };
|
|
829
864
|
} catch (e) {
|
|
830
|
-
return
|
|
865
|
+
return f(e);
|
|
831
866
|
}
|
|
832
867
|
});
|
|
833
868
|
}
|
|
@@ -841,9 +876,9 @@ class be {
|
|
|
841
876
|
createMany(t) {
|
|
842
877
|
return l(this, arguments, function* (e, r = {}) {
|
|
843
878
|
try {
|
|
844
|
-
return { success: !0, result: (yield this.model.insertMany(e, r)).map((
|
|
845
|
-
} catch (
|
|
846
|
-
return
|
|
879
|
+
return { success: !0, result: (yield this.model.insertMany(e, r)).map((u) => u instanceof W ? u.toObject() : null).filter((u) => u !== null) };
|
|
880
|
+
} catch (s) {
|
|
881
|
+
return f(s);
|
|
847
882
|
}
|
|
848
883
|
});
|
|
849
884
|
}
|
|
@@ -858,16 +893,16 @@ class be {
|
|
|
858
893
|
updateOne() {
|
|
859
894
|
return l(this, arguments, function* (t = {}, e = {}, r = {}) {
|
|
860
895
|
try {
|
|
861
|
-
const
|
|
896
|
+
const s = V(t), c = yield this.model.findOneAndUpdate(s, e, S({
|
|
862
897
|
new: !0
|
|
863
898
|
}, r)).exec();
|
|
864
|
-
return
|
|
899
|
+
return c ? { success: !0, result: c } : {
|
|
865
900
|
success: !1,
|
|
866
901
|
message: `Failed to update ${this.getModelName()}.`,
|
|
867
902
|
code: v.NOT_FOUND.CODE
|
|
868
903
|
};
|
|
869
|
-
} catch (
|
|
870
|
-
return
|
|
904
|
+
} catch (s) {
|
|
905
|
+
return f(s);
|
|
871
906
|
}
|
|
872
907
|
});
|
|
873
908
|
}
|
|
@@ -882,9 +917,10 @@ class be {
|
|
|
882
917
|
updateMany() {
|
|
883
918
|
return l(this, arguments, function* (t = {}, e = {}, r = {}) {
|
|
884
919
|
try {
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
920
|
+
const s = V(t);
|
|
921
|
+
return { success: !0, result: yield this.model.updateMany(s, e, r).exec() };
|
|
922
|
+
} catch (s) {
|
|
923
|
+
return f(s);
|
|
888
924
|
}
|
|
889
925
|
});
|
|
890
926
|
}
|
|
@@ -898,14 +934,14 @@ class be {
|
|
|
898
934
|
deleteOne() {
|
|
899
935
|
return l(this, arguments, function* (t = {}, e = {}) {
|
|
900
936
|
try {
|
|
901
|
-
const r = yield this.model.findOneAndDelete(
|
|
902
|
-
return
|
|
937
|
+
const r = V(t), s = yield this.model.findOneAndDelete(r, e).exec();
|
|
938
|
+
return s ? { success: !0, result: s } : {
|
|
903
939
|
success: !1,
|
|
904
940
|
message: `No ${this.getModelName()} found to delete.`,
|
|
905
941
|
code: v.NOT_FOUND.CODE
|
|
906
942
|
};
|
|
907
943
|
} catch (r) {
|
|
908
|
-
return
|
|
944
|
+
return f(r);
|
|
909
945
|
}
|
|
910
946
|
});
|
|
911
947
|
}
|
|
@@ -919,14 +955,14 @@ class be {
|
|
|
919
955
|
deleteMany() {
|
|
920
956
|
return l(this, arguments, function* (t = {}, e = {}) {
|
|
921
957
|
try {
|
|
922
|
-
const r = yield this.model.deleteMany(
|
|
923
|
-
return
|
|
958
|
+
const r = V(t), s = yield this.model.deleteMany(r, e).exec();
|
|
959
|
+
return s.deletedCount === 0 ? {
|
|
924
960
|
success: !1,
|
|
925
961
|
message: "No documents found to delete.",
|
|
926
962
|
code: v.NOT_FOUND.CODE
|
|
927
|
-
} : { success: !0, result:
|
|
963
|
+
} : { success: !0, result: s };
|
|
928
964
|
} catch (r) {
|
|
929
|
-
return
|
|
965
|
+
return f(r);
|
|
930
966
|
}
|
|
931
967
|
});
|
|
932
968
|
}
|
|
@@ -941,13 +977,13 @@ class be {
|
|
|
941
977
|
createShortId(t, e = 4) {
|
|
942
978
|
return l(this, null, function* () {
|
|
943
979
|
try {
|
|
944
|
-
const
|
|
945
|
-
|
|
946
|
-
)).findIndex((
|
|
947
|
-
if (
|
|
948
|
-
const
|
|
949
|
-
if (
|
|
950
|
-
return { success: !0, result:
|
|
980
|
+
const s = Array.from({ length: 10 }, (o, i) => se(t, i + e)), u = (yield Promise.all(
|
|
981
|
+
s.map((o) => this.model.exists({ shortId: o }))
|
|
982
|
+
)).findIndex((o) => !o);
|
|
983
|
+
if (u !== -1) {
|
|
984
|
+
const o = s[u];
|
|
985
|
+
if (o)
|
|
986
|
+
return { success: !0, result: o };
|
|
951
987
|
}
|
|
952
988
|
return {
|
|
953
989
|
success: !1,
|
|
@@ -955,7 +991,7 @@ class be {
|
|
|
955
991
|
code: v.INTERNAL_SERVER_ERROR.CODE
|
|
956
992
|
};
|
|
957
993
|
} catch (r) {
|
|
958
|
-
return
|
|
994
|
+
return f(r);
|
|
959
995
|
}
|
|
960
996
|
});
|
|
961
997
|
}
|
|
@@ -970,14 +1006,14 @@ class be {
|
|
|
970
1006
|
* @param options.filter - Additional filter conditions to apply to the query.
|
|
971
1007
|
* @returns A MongoDB query object for checking slug existence.
|
|
972
1008
|
*/
|
|
973
|
-
createSlugQuery({ slug: t, field: e, isObject: r, filter:
|
|
974
|
-
const
|
|
975
|
-
return r ? w(S({},
|
|
1009
|
+
createSlugQuery({ slug: t, field: e, isObject: r, filter: s }) {
|
|
1010
|
+
const c = S({}, s != null ? s : {});
|
|
1011
|
+
return r ? w(S({}, c), {
|
|
976
1012
|
$or: [
|
|
977
1013
|
{ [`slug.${e}`]: t },
|
|
978
1014
|
{ slugHistory: { $elemMatch: { [`slug.${e}`]: t } } }
|
|
979
1015
|
]
|
|
980
|
-
}) : w(S({},
|
|
1016
|
+
}) : w(S({}, c), {
|
|
981
1017
|
$or: [
|
|
982
1018
|
{ slug: t },
|
|
983
1019
|
{ slugHistory: t }
|
|
@@ -996,18 +1032,18 @@ class be {
|
|
|
996
1032
|
* @returns A promise that resolves to a unique slug string.
|
|
997
1033
|
*/
|
|
998
1034
|
createUniqueSlug(t) {
|
|
999
|
-
return l(this, arguments, function* ({ slug: e, field: r, isObject:
|
|
1000
|
-
const
|
|
1001
|
-
|
|
1002
|
-
(m) => this.model.exists(this.createSlugQuery({ slug: m, field: r, isObject:
|
|
1035
|
+
return l(this, arguments, function* ({ slug: e, field: r, isObject: s, filter: c }) {
|
|
1036
|
+
const u = j(e), i = Array.from({ length: 100 }, (m, p) => p === 0 ? u : `${u}-${p}`), d = (yield Promise.all(
|
|
1037
|
+
i.map(
|
|
1038
|
+
(m) => this.model.exists(this.createSlugQuery({ slug: m, field: r, isObject: s, filter: c }))
|
|
1003
1039
|
)
|
|
1004
1040
|
)).findIndex((m) => !m);
|
|
1005
|
-
if (
|
|
1006
|
-
const m =
|
|
1041
|
+
if (d !== -1) {
|
|
1042
|
+
const m = i[d];
|
|
1007
1043
|
if (m)
|
|
1008
1044
|
return m;
|
|
1009
1045
|
}
|
|
1010
|
-
return `${
|
|
1046
|
+
return `${u}-${Date.now()}`;
|
|
1011
1047
|
});
|
|
1012
1048
|
}
|
|
1013
1049
|
/**
|
|
@@ -1021,29 +1057,29 @@ class be {
|
|
|
1021
1057
|
* @returns A promise that resolves to a standardized response with the created slug(s).
|
|
1022
1058
|
*/
|
|
1023
1059
|
createSlug(t) {
|
|
1024
|
-
return l(this, arguments, function* ({ field: e, from: r, filter:
|
|
1060
|
+
return l(this, arguments, function* ({ field: e, from: r, filter: s }) {
|
|
1025
1061
|
try {
|
|
1026
|
-
const
|
|
1027
|
-
return T(
|
|
1062
|
+
const c = r[e];
|
|
1063
|
+
return T(c) ? { success: !0, result: Object.fromEntries(
|
|
1028
1064
|
yield Promise.all(
|
|
1029
|
-
Object.entries(
|
|
1065
|
+
Object.entries(c).map((a) => l(this, [a], function* ([d, m]) {
|
|
1030
1066
|
const p = yield this.createUniqueSlug({
|
|
1031
1067
|
slug: m,
|
|
1032
|
-
field:
|
|
1068
|
+
field: d,
|
|
1033
1069
|
isObject: !0,
|
|
1034
|
-
filter:
|
|
1070
|
+
filter: s
|
|
1035
1071
|
});
|
|
1036
|
-
return [
|
|
1072
|
+
return [d, p];
|
|
1037
1073
|
}))
|
|
1038
1074
|
)
|
|
1039
1075
|
) } : { success: !0, result: yield this.createUniqueSlug({
|
|
1040
|
-
slug:
|
|
1076
|
+
slug: c,
|
|
1041
1077
|
field: e,
|
|
1042
1078
|
isObject: !1,
|
|
1043
|
-
filter:
|
|
1079
|
+
filter: s
|
|
1044
1080
|
}) };
|
|
1045
|
-
} catch (
|
|
1046
|
-
return
|
|
1081
|
+
} catch (c) {
|
|
1082
|
+
return f(c);
|
|
1047
1083
|
}
|
|
1048
1084
|
});
|
|
1049
1085
|
}
|
|
@@ -1059,31 +1095,31 @@ class be {
|
|
|
1059
1095
|
* @returns A promise that resolves to a standardized response indicating whether the slug exists.
|
|
1060
1096
|
*/
|
|
1061
1097
|
checkSlug(t) {
|
|
1062
|
-
return l(this, arguments, function* ({ slug: e, field: r, from:
|
|
1098
|
+
return l(this, arguments, function* ({ slug: e, field: r, from: s, filter: c }) {
|
|
1063
1099
|
try {
|
|
1064
|
-
const
|
|
1065
|
-
if (T(
|
|
1066
|
-
const m = Object.values(
|
|
1100
|
+
const u = s[r];
|
|
1101
|
+
if (T(u)) {
|
|
1102
|
+
const m = Object.values(u).map((h) => j(h));
|
|
1067
1103
|
return (yield Promise.all(
|
|
1068
1104
|
m.map(
|
|
1069
1105
|
(h) => this.model.exists(this.createSlugQuery({
|
|
1070
1106
|
slug: h,
|
|
1071
1107
|
field: r,
|
|
1072
1108
|
isObject: !0,
|
|
1073
|
-
filter:
|
|
1109
|
+
filter: c
|
|
1074
1110
|
}))
|
|
1075
1111
|
)
|
|
1076
1112
|
)).some((h) => h) ? { success: !0, result: !0 } : { success: !0, result: !1 };
|
|
1077
1113
|
}
|
|
1078
|
-
const
|
|
1114
|
+
const i = j(e);
|
|
1079
1115
|
return { success: !0, result: (yield this.model.exists(this.createSlugQuery({
|
|
1080
|
-
slug:
|
|
1116
|
+
slug: i,
|
|
1081
1117
|
field: r,
|
|
1082
1118
|
isObject: !1,
|
|
1083
|
-
filter:
|
|
1119
|
+
filter: c
|
|
1084
1120
|
}))) !== null };
|
|
1085
|
-
} catch (
|
|
1086
|
-
return
|
|
1121
|
+
} catch (u) {
|
|
1122
|
+
return f(u);
|
|
1087
1123
|
}
|
|
1088
1124
|
});
|
|
1089
1125
|
}
|
|
@@ -1098,13 +1134,13 @@ class be {
|
|
|
1098
1134
|
try {
|
|
1099
1135
|
return { success: !0, result: yield this.model.aggregate(t) };
|
|
1100
1136
|
} catch (e) {
|
|
1101
|
-
return
|
|
1137
|
+
return f(e);
|
|
1102
1138
|
}
|
|
1103
1139
|
});
|
|
1104
1140
|
}
|
|
1105
1141
|
}
|
|
1106
1142
|
export {
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1143
|
+
be as MongoController,
|
|
1144
|
+
xe as MongooseController,
|
|
1145
|
+
b as mongo
|
|
1110
1146
|
};
|