@cyberskill/shared 2.6.0 → 2.7.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/index.cjs +1 -1
- package/dist/node/mongo/index.js +11 -10
- package/dist/node/mongo/mongo.constant.cjs +1 -1
- package/dist/node/mongo/mongo.constant.d.ts +6 -0
- package/dist/node/mongo/mongo.constant.js +3 -2
- package/dist/node/mongo/mongo.type.d.ts +2 -0
- package/dist/node/mongo/mongo.util.cjs +5 -5
- package/dist/node/mongo/mongo.util.d.ts +4 -4
- package/dist/node/mongo/mongo.util.js +291 -282
- package/package.json +1 -1
|
@@ -1,44 +1,45 @@
|
|
|
1
|
-
import { cloneDeep as B, isObject as
|
|
2
|
-
import
|
|
1
|
+
import { cloneDeep as B, isObject as $ } from "lodash-es";
|
|
2
|
+
import Q from "migrate-mongo";
|
|
3
3
|
import { Document as W } from "mongoose";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import k from "mongoose-aggregate-paginate-v2";
|
|
5
|
+
import J from "mongoose-paginate-v2";
|
|
6
6
|
import { v4 as G } from "uuid";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
7
|
+
import { MONGO_SLUG_MAX_ATTEMPTS as X } from "./mongo.constant.js";
|
|
8
|
+
import { getNestedValue as H, setNestedValue as Y, normalizeMongoFilter as b } from "../../util/object/object.util.js";
|
|
9
|
+
import { regexSearchMapper as Z } from "../../util/common/common.util.js";
|
|
10
|
+
import { writeFileSync as q, pathExistsSync as ee, readFileSync as te, appendFileSync as re } from "../fs/fs.util.js";
|
|
11
|
+
import { PATH as w, MIGRATE_MONGO_CONFIG as L } from "../path/path.constant.js";
|
|
12
|
+
import { validate as se } from "../../util/validate/validate.util.js";
|
|
13
|
+
import { generateShortId as ne, generateSlug as I } from "../../util/string/string.util.js";
|
|
14
|
+
import { RESPONSE_STATUS as R } from "../../constant/response-status.js";
|
|
15
|
+
import { catchError as d } from "../log/log.util.js";
|
|
16
|
+
var ue = Object.defineProperty, ce = Object.defineProperties, ie = Object.getOwnPropertyDescriptors, U = Object.getOwnPropertySymbols, oe = Object.prototype.hasOwnProperty, le = Object.prototype.propertyIsEnumerable, T = (n, t, e) => t in n ? ue(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, S = (n, t) => {
|
|
16
17
|
for (var e in t || (t = {}))
|
|
17
|
-
|
|
18
|
+
oe.call(t, e) && T(n, e, t[e]);
|
|
18
19
|
if (U)
|
|
19
20
|
for (var e of U(t))
|
|
20
|
-
|
|
21
|
+
le.call(t, e) && T(n, e, t[e]);
|
|
21
22
|
return n;
|
|
22
|
-
},
|
|
23
|
-
var
|
|
23
|
+
}, F = (n, t) => ce(n, ie(t)), ae = (n, t, e) => T(n, typeof t != "symbol" ? t + "" : t, e), a = (n, t, e) => new Promise((r, s) => {
|
|
24
|
+
var u = (o) => {
|
|
24
25
|
try {
|
|
25
|
-
|
|
26
|
-
} catch (
|
|
27
|
-
s(
|
|
26
|
+
i(e.next(o));
|
|
27
|
+
} catch (l) {
|
|
28
|
+
s(l);
|
|
28
29
|
}
|
|
29
|
-
},
|
|
30
|
+
}, c = (o) => {
|
|
30
31
|
try {
|
|
31
|
-
|
|
32
|
-
} catch (
|
|
33
|
-
s(
|
|
32
|
+
i(e.throw(o));
|
|
33
|
+
} catch (l) {
|
|
34
|
+
s(l);
|
|
34
35
|
}
|
|
35
|
-
},
|
|
36
|
-
|
|
36
|
+
}, i = (o) => o.done ? r(o.value) : Promise.resolve(o.value).then(u, c);
|
|
37
|
+
i((e = e.apply(n, t)).next());
|
|
37
38
|
});
|
|
38
|
-
function
|
|
39
|
+
function de(n) {
|
|
39
40
|
return n === n.toUpperCase() ? n.charAt(0).toUpperCase() + n.slice(1).toLowerCase() : n;
|
|
40
41
|
}
|
|
41
|
-
const
|
|
42
|
+
const x = {
|
|
42
43
|
/**
|
|
43
44
|
* Creates generic fields that are commonly used across MongoDB documents.
|
|
44
45
|
* This function generates standard fields including a UUID, deletion flag, and timestamps
|
|
@@ -118,23 +119,23 @@ const b = {
|
|
|
118
119
|
toObject: { virtuals: !0 }
|
|
119
120
|
// So `console.log()` and other functions that use `toObject()` include virtuals
|
|
120
121
|
});
|
|
121
|
-
return e.forEach(({ name:
|
|
122
|
-
if (
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
name:
|
|
126
|
-
options:
|
|
122
|
+
return e.forEach(({ name: u, options: c, get: i }) => {
|
|
123
|
+
if (x.isDynamicVirtual(c)) {
|
|
124
|
+
const o = s.statics;
|
|
125
|
+
o._dynamicVirtuals || (o._dynamicVirtuals = []), o._dynamicVirtuals.push({
|
|
126
|
+
name: u,
|
|
127
|
+
options: c
|
|
127
128
|
});
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
var
|
|
131
|
-
return ((
|
|
129
|
+
const l = s.virtual(u);
|
|
130
|
+
i ? l.get(i) : l.get(function() {
|
|
131
|
+
var f;
|
|
132
|
+
return ((f = this._populated) == null ? void 0 : f[u]) || (c != null && c.count ? 0 : c != null && c.justOne ? null : []);
|
|
132
133
|
});
|
|
133
134
|
} else {
|
|
134
|
-
const
|
|
135
|
-
|
|
135
|
+
const o = s.virtual(u, c);
|
|
136
|
+
i && o.get(i);
|
|
136
137
|
}
|
|
137
|
-
}), r || s.add(
|
|
138
|
+
}), r || s.add(x.createGenericSchema(n)), s;
|
|
138
139
|
},
|
|
139
140
|
/**
|
|
140
141
|
* Creates a Mongoose model with plugins, middleware, and pagination support.
|
|
@@ -158,18 +159,18 @@ const b = {
|
|
|
158
159
|
schema: e,
|
|
159
160
|
virtuals: r = [],
|
|
160
161
|
pagination: s = !0,
|
|
161
|
-
aggregate:
|
|
162
|
-
middlewares:
|
|
162
|
+
aggregate: u = !0,
|
|
163
|
+
middlewares: c = []
|
|
163
164
|
}) {
|
|
164
165
|
if (!t)
|
|
165
166
|
throw new Error("Model name is required.");
|
|
166
167
|
if (n.models[t])
|
|
167
168
|
return n.models[t];
|
|
168
|
-
const
|
|
169
|
-
return (s ||
|
|
170
|
-
s &&
|
|
171
|
-
|
|
172
|
-
]),
|
|
169
|
+
const i = x.createSchema({ mongoose: n, schema: e, virtuals: r });
|
|
170
|
+
return (s || u) && x.applyPlugins(i, [
|
|
171
|
+
s && J,
|
|
172
|
+
u && k
|
|
173
|
+
]), x.applyMiddlewares(i, c), n.model(t, i);
|
|
173
174
|
},
|
|
174
175
|
/**
|
|
175
176
|
* Validation utilities for Mongoose schemas.
|
|
@@ -185,8 +186,8 @@ const b = {
|
|
|
185
186
|
*/
|
|
186
187
|
isRequired() {
|
|
187
188
|
return function(n) {
|
|
188
|
-
return
|
|
189
|
-
return !
|
|
189
|
+
return a(this, null, function* () {
|
|
190
|
+
return !se.isEmpty(n);
|
|
190
191
|
});
|
|
191
192
|
};
|
|
192
193
|
},
|
|
@@ -201,7 +202,7 @@ const b = {
|
|
|
201
202
|
*/
|
|
202
203
|
isUnique(n) {
|
|
203
204
|
return function(t) {
|
|
204
|
-
return
|
|
205
|
+
return a(this, null, function* () {
|
|
205
206
|
if (!Array.isArray(n) || n.length === 0)
|
|
206
207
|
throw new Error("Fields must be a non-empty array of strings.");
|
|
207
208
|
const e = { $or: n.map((s) => ({ [s]: t })) };
|
|
@@ -220,7 +221,7 @@ const b = {
|
|
|
220
221
|
*/
|
|
221
222
|
matchesRegex(n) {
|
|
222
223
|
return function(t) {
|
|
223
|
-
return
|
|
224
|
+
return a(this, null, function* () {
|
|
224
225
|
if (!Array.isArray(n) || n.some((e) => !(e instanceof RegExp)))
|
|
225
226
|
throw new Error("regexArray must be an array of valid RegExp objects.");
|
|
226
227
|
return n.every((e) => e.test(t));
|
|
@@ -232,7 +233,7 @@ const b = {
|
|
|
232
233
|
* Migration utilities for MongoDB.
|
|
233
234
|
* This object extends the migrate-mongo library with additional configuration utilities.
|
|
234
235
|
*/
|
|
235
|
-
migrate:
|
|
236
|
+
migrate: F(S({}, Q), {
|
|
236
237
|
/**
|
|
237
238
|
* Sets the migration configuration and updates .gitignore.
|
|
238
239
|
* This function creates a migration configuration file and ensures it's properly
|
|
@@ -243,12 +244,12 @@ const b = {
|
|
|
243
244
|
setConfig: (n) => {
|
|
244
245
|
const t = `// This file is automatically generated by the Cyberskill CLI.
|
|
245
246
|
module.exports = ${JSON.stringify(n, null, 4)}`;
|
|
246
|
-
q(
|
|
247
|
+
q(w.MIGRATE_MONGO_CONFIG, t);
|
|
247
248
|
const e = `
|
|
248
249
|
${L}
|
|
249
250
|
`;
|
|
250
|
-
|
|
251
|
-
`).includes(L) ||
|
|
251
|
+
ee(w.GIT_IGNORE) ? te(w.GIT_IGNORE, "utf-8").split(`
|
|
252
|
+
`).includes(L) || re(w.GIT_IGNORE, e) : q(w.GIT_IGNORE, e);
|
|
252
253
|
}
|
|
253
254
|
}),
|
|
254
255
|
/**
|
|
@@ -267,13 +268,13 @@ ${L}
|
|
|
267
268
|
if (!t || t.length === 0)
|
|
268
269
|
return e;
|
|
269
270
|
for (const r of t) {
|
|
270
|
-
const s = r.toString().split("."),
|
|
271
|
-
if (typeof
|
|
272
|
-
const
|
|
273
|
-
$regex: `.*${
|
|
271
|
+
const s = r.toString().split("."), u = H(e, s);
|
|
272
|
+
if (typeof u == "string" && u.length > 0) {
|
|
273
|
+
const c = {
|
|
274
|
+
$regex: `.*${Z(u)}.*`,
|
|
274
275
|
$options: "i"
|
|
275
276
|
};
|
|
276
|
-
e =
|
|
277
|
+
e = Y(e, s, c);
|
|
277
278
|
}
|
|
278
279
|
}
|
|
279
280
|
return e;
|
|
@@ -295,11 +296,11 @@ ${L}
|
|
|
295
296
|
* @returns Array of records that don't exist in the database
|
|
296
297
|
*/
|
|
297
298
|
getNewRecords(n, t, e) {
|
|
298
|
-
return
|
|
299
|
+
return a(this, null, function* () {
|
|
299
300
|
const r = yield n.findAll({});
|
|
300
301
|
return r.success ? t.filter(
|
|
301
|
-
(
|
|
302
|
-
(
|
|
302
|
+
(u) => !r.result.some(
|
|
303
|
+
(c) => e(c, u)
|
|
303
304
|
)
|
|
304
305
|
) : t;
|
|
305
306
|
});
|
|
@@ -312,20 +313,20 @@ ${L}
|
|
|
312
313
|
* @returns Array of existing records that match the filter criteria
|
|
313
314
|
*/
|
|
314
315
|
getExistingRecords(n, t, e) {
|
|
315
|
-
return
|
|
316
|
+
return a(this, null, function* () {
|
|
316
317
|
const r = yield n.findAll({});
|
|
317
318
|
return r.success ? r.result.filter(
|
|
318
|
-
(
|
|
319
|
-
(
|
|
319
|
+
(u) => t.some(
|
|
320
|
+
(c) => e(u, c)
|
|
320
321
|
)
|
|
321
322
|
) : [];
|
|
322
323
|
});
|
|
323
324
|
}
|
|
324
325
|
};
|
|
325
|
-
function
|
|
326
|
+
function fe(n) {
|
|
326
327
|
return n !== null && typeof n == "object" && "toObject" in n && typeof n.toObject == "function";
|
|
327
328
|
}
|
|
328
|
-
function
|
|
329
|
+
function j(n, t) {
|
|
329
330
|
if (!n || !t || t.length === 0)
|
|
330
331
|
return n;
|
|
331
332
|
const e = new Set(t.map((r) => r.name));
|
|
@@ -334,8 +335,8 @@ function I(n, t) {
|
|
|
334
335
|
if (typeof s == "string")
|
|
335
336
|
return !e.has(s);
|
|
336
337
|
if (typeof s == "object" && s !== null) {
|
|
337
|
-
const
|
|
338
|
-
return !e.has(
|
|
338
|
+
const u = s;
|
|
339
|
+
return !e.has(u.path || u.populate || "");
|
|
339
340
|
}
|
|
340
341
|
return !0;
|
|
341
342
|
});
|
|
@@ -349,130 +350,130 @@ function I(n, t) {
|
|
|
349
350
|
}
|
|
350
351
|
return n;
|
|
351
352
|
}
|
|
352
|
-
function
|
|
353
|
+
function me(n, t, e) {
|
|
353
354
|
if (!n.length || !t || !(e != null && e.ref))
|
|
354
355
|
return [];
|
|
355
356
|
const r = /* @__PURE__ */ new Map();
|
|
356
357
|
return n.forEach((s) => {
|
|
357
358
|
try {
|
|
358
|
-
const
|
|
359
|
-
if (
|
|
359
|
+
const u = e.ref(s);
|
|
360
|
+
if (u == null)
|
|
360
361
|
return;
|
|
361
|
-
const
|
|
362
|
-
if (
|
|
363
|
-
const
|
|
364
|
-
r.has(
|
|
362
|
+
const c = typeof u == "string" ? u : String(u);
|
|
363
|
+
if (c && c.trim() !== "") {
|
|
364
|
+
const i = de(c);
|
|
365
|
+
r.has(i) || r.set(i, []), r.get(i).push(s);
|
|
365
366
|
}
|
|
366
|
-
} catch (
|
|
367
|
-
|
|
367
|
+
} catch (u) {
|
|
368
|
+
d(new Error(`Dynamic ref function failed for virtual "${t}": ${u instanceof Error ? u.message : String(u)}`));
|
|
368
369
|
}
|
|
369
|
-
}), Array.from(r.entries()).map(([s,
|
|
370
|
+
}), Array.from(r.entries()).map(([s, u]) => ({ model: s, docs: u }));
|
|
370
371
|
}
|
|
371
372
|
function z(n, t, e, r, s) {
|
|
372
|
-
return
|
|
373
|
+
return a(this, null, function* () {
|
|
373
374
|
if (!t.length || !e.length || !r)
|
|
374
375
|
return t;
|
|
375
|
-
const
|
|
376
|
+
const u = e.filter((o) => {
|
|
376
377
|
if (Array.isArray(r))
|
|
377
|
-
return r.length > 0 && r.some((
|
|
378
|
+
return r.length > 0 && r.some((l) => typeof l == "string" ? l === o.name : l.path === o.name);
|
|
378
379
|
if (typeof r == "string")
|
|
379
|
-
return r ===
|
|
380
|
+
return r === o.name;
|
|
380
381
|
if (typeof r == "object" && r !== null) {
|
|
381
|
-
const
|
|
382
|
-
return
|
|
382
|
+
const l = r;
|
|
383
|
+
return l.path && l.path === o.name || l.populate && l.populate === o.name;
|
|
383
384
|
}
|
|
384
385
|
return !1;
|
|
385
386
|
});
|
|
386
|
-
if (
|
|
387
|
+
if (u.length === 0)
|
|
387
388
|
return t;
|
|
388
|
-
const
|
|
389
|
-
(
|
|
389
|
+
const c = B(t.map(
|
|
390
|
+
(o) => fe(o) ? o.toObject() : o
|
|
390
391
|
));
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
if (!(
|
|
394
|
-
const
|
|
395
|
-
|
|
392
|
+
c.forEach((o) => {
|
|
393
|
+
u.forEach(({ name: l, options: f }) => {
|
|
394
|
+
if (!(l in o)) {
|
|
395
|
+
const O = o;
|
|
396
|
+
O[l] = f.count ? 0 : f.justOne ? null : [];
|
|
396
397
|
}
|
|
397
398
|
});
|
|
398
399
|
});
|
|
399
|
-
const
|
|
400
|
-
for (const
|
|
401
|
-
const { name:
|
|
402
|
-
for (const
|
|
403
|
-
|
|
400
|
+
const i = /* @__PURE__ */ new Map();
|
|
401
|
+
for (const o of u) {
|
|
402
|
+
const { name: l, options: f } = o, O = me(c, l, f);
|
|
403
|
+
for (const m of O) {
|
|
404
|
+
i.has(m.model) || i.set(m.model, {
|
|
404
405
|
virtuals: [],
|
|
405
406
|
localValueSets: /* @__PURE__ */ new Map(),
|
|
406
407
|
docsByLocalValue: /* @__PURE__ */ new Map()
|
|
407
408
|
});
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
const A =
|
|
409
|
+
const g = i.get(m.model);
|
|
410
|
+
g.virtuals.find((V) => V.name === l) || (g.virtuals.push(o), g.localValueSets.set(l, /* @__PURE__ */ new Set()));
|
|
411
|
+
const v = g.localValueSets.get(l);
|
|
412
|
+
m.docs.forEach((V) => {
|
|
413
|
+
const A = V[f.localField];
|
|
413
414
|
if (A != null) {
|
|
414
415
|
const D = String(A);
|
|
415
|
-
|
|
416
|
+
v.add(D);
|
|
416
417
|
let _ = -1;
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
var
|
|
420
|
-
return ((
|
|
421
|
-
})), _ !== -1 && (
|
|
418
|
+
const N = V;
|
|
419
|
+
N.id !== void 0 ? _ = c.findIndex((M) => M.id === N.id) : N._id !== void 0 && (_ = c.findIndex((M) => {
|
|
420
|
+
var p, h, E, y;
|
|
421
|
+
return ((h = (p = M._id) == null ? void 0 : p.toString) == null ? void 0 : h.call(p)) === ((y = (E = N._id) == null ? void 0 : E.toString) == null ? void 0 : y.call(E));
|
|
422
|
+
})), _ !== -1 && (g.docsByLocalValue.has(D) || g.docsByLocalValue.set(D, []), g.docsByLocalValue.get(D).push(_));
|
|
422
423
|
}
|
|
423
424
|
});
|
|
424
425
|
}
|
|
425
426
|
}
|
|
426
|
-
return yield Promise.all(Array.from(
|
|
427
|
-
const
|
|
428
|
-
if (!
|
|
427
|
+
return yield Promise.all(Array.from(i.entries()).map((o) => a(null, [o], function* ([l, f]) {
|
|
428
|
+
const O = n.models[l];
|
|
429
|
+
if (!O)
|
|
429
430
|
return;
|
|
430
|
-
const
|
|
431
|
-
if (
|
|
432
|
-
D.forEach((_) =>
|
|
433
|
-
}),
|
|
431
|
+
const m = /* @__PURE__ */ new Set();
|
|
432
|
+
if (f.localValueSets.forEach((D) => {
|
|
433
|
+
D.forEach((_) => m.add(_));
|
|
434
|
+
}), m.size === 0)
|
|
434
435
|
return;
|
|
435
|
-
const
|
|
436
|
-
let
|
|
437
|
-
|
|
438
|
-
const A = yield
|
|
439
|
-
for (const D of
|
|
440
|
-
const { name: _, options:
|
|
441
|
-
const
|
|
442
|
-
return
|
|
436
|
+
const g = [...new Set(f.virtuals.map((D) => D.options.foreignField))], v = Array.from(m);
|
|
437
|
+
let V;
|
|
438
|
+
g.length === 1 ? V = { [String(g[0])]: { $in: v } } : V = { $or: g.map((D) => ({ [D]: { $in: v } })) };
|
|
439
|
+
const A = yield O.find(V, s).lean();
|
|
440
|
+
for (const D of f.virtuals) {
|
|
441
|
+
const { name: _, options: N } = D, M = A.filter((p) => {
|
|
442
|
+
const h = p[N.foreignField];
|
|
443
|
+
return h != null && m.has(String(h));
|
|
443
444
|
});
|
|
444
|
-
if (
|
|
445
|
-
const
|
|
446
|
-
|
|
445
|
+
if (N.count) {
|
|
446
|
+
const p = /* @__PURE__ */ new Map();
|
|
447
|
+
M.forEach((h) => {
|
|
447
448
|
var E;
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
}),
|
|
451
|
-
const E =
|
|
452
|
-
E.forEach((
|
|
453
|
-
const
|
|
454
|
-
|
|
449
|
+
const y = (E = h[N.foreignField]) == null ? void 0 : E.toString();
|
|
450
|
+
y && p.set(y, (p.get(y) || 0) + 1);
|
|
451
|
+
}), f.localValueSets.get(_).forEach((h) => {
|
|
452
|
+
const E = f.docsByLocalValue.get(h) || [], y = p.get(h) || 0;
|
|
453
|
+
E.forEach((P) => {
|
|
454
|
+
const C = c[P];
|
|
455
|
+
C[_] === void 0 && (C[_] = y);
|
|
455
456
|
});
|
|
456
457
|
});
|
|
457
458
|
} else {
|
|
458
|
-
const
|
|
459
|
-
|
|
459
|
+
const p = /* @__PURE__ */ new Map();
|
|
460
|
+
M.forEach((h) => {
|
|
460
461
|
var E;
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
}),
|
|
464
|
-
const E =
|
|
465
|
-
E.forEach((
|
|
466
|
-
const
|
|
467
|
-
|
|
462
|
+
const y = (E = h[N.foreignField]) == null ? void 0 : E.toString();
|
|
463
|
+
y && (p.has(y) || p.set(y, []), p.get(y).push(h));
|
|
464
|
+
}), f.localValueSets.get(_).forEach((h) => {
|
|
465
|
+
const E = f.docsByLocalValue.get(h) || [], y = p.get(h) || [], P = N.justOne ? y[0] || null : y;
|
|
466
|
+
E.forEach((C) => {
|
|
467
|
+
const K = c[C];
|
|
468
|
+
K[_] = P;
|
|
468
469
|
});
|
|
469
470
|
});
|
|
470
471
|
}
|
|
471
472
|
}
|
|
472
|
-
}))),
|
|
473
|
+
}))), c;
|
|
473
474
|
});
|
|
474
475
|
}
|
|
475
|
-
class
|
|
476
|
+
class Me {
|
|
476
477
|
/**
|
|
477
478
|
* Creates a new MongoDB controller instance.
|
|
478
479
|
*
|
|
@@ -480,7 +481,7 @@ class be {
|
|
|
480
481
|
* @param collectionName - The name of the collection to operate on.
|
|
481
482
|
*/
|
|
482
483
|
constructor(t, e) {
|
|
483
|
-
|
|
484
|
+
ae(this, "collection"), this.collection = t.collection(e);
|
|
484
485
|
}
|
|
485
486
|
/**
|
|
486
487
|
* Creates a single document in the collection.
|
|
@@ -490,9 +491,9 @@ class be {
|
|
|
490
491
|
* @returns A promise that resolves to a standardized response with the created document.
|
|
491
492
|
*/
|
|
492
493
|
createOne(t) {
|
|
493
|
-
return
|
|
494
|
+
return a(this, null, function* () {
|
|
494
495
|
try {
|
|
495
|
-
const e = S(S({},
|
|
496
|
+
const e = S(S({}, x.createGenericFields()), t);
|
|
496
497
|
return (yield this.collection.insertOne(e)).acknowledged ? {
|
|
497
498
|
success: !0,
|
|
498
499
|
message: "Document created successfully",
|
|
@@ -500,10 +501,10 @@ class be {
|
|
|
500
501
|
} : {
|
|
501
502
|
success: !1,
|
|
502
503
|
message: "Document creation failed",
|
|
503
|
-
code:
|
|
504
|
+
code: R.INTERNAL_SERVER_ERROR.CODE
|
|
504
505
|
};
|
|
505
506
|
} catch (e) {
|
|
506
|
-
return
|
|
507
|
+
return d(e);
|
|
507
508
|
}
|
|
508
509
|
});
|
|
509
510
|
}
|
|
@@ -515,20 +516,20 @@ class be {
|
|
|
515
516
|
* @returns A promise that resolves to a standardized response with the created documents.
|
|
516
517
|
*/
|
|
517
518
|
createMany(t) {
|
|
518
|
-
return
|
|
519
|
+
return a(this, null, function* () {
|
|
519
520
|
try {
|
|
520
|
-
const e = t.map((s) => S(S({},
|
|
521
|
+
const e = t.map((s) => S(S({}, x.createGenericFields()), s)), r = yield this.collection.insertMany(e);
|
|
521
522
|
return r.insertedCount === 0 ? {
|
|
522
523
|
success: !1,
|
|
523
524
|
message: "No documents were inserted",
|
|
524
|
-
code:
|
|
525
|
+
code: R.INTERNAL_SERVER_ERROR.CODE
|
|
525
526
|
} : {
|
|
526
527
|
success: !0,
|
|
527
528
|
message: `${r.insertedCount} documents created successfully`,
|
|
528
529
|
result: e
|
|
529
530
|
};
|
|
530
531
|
} catch (e) {
|
|
531
|
-
return
|
|
532
|
+
return d(e);
|
|
532
533
|
}
|
|
533
534
|
});
|
|
534
535
|
}
|
|
@@ -539,12 +540,12 @@ class be {
|
|
|
539
540
|
* @returns A promise that resolves to a standardized response with the found document.
|
|
540
541
|
*/
|
|
541
542
|
findOne(t) {
|
|
542
|
-
return
|
|
543
|
+
return a(this, null, function* () {
|
|
543
544
|
try {
|
|
544
545
|
const e = yield this.collection.findOne(t);
|
|
545
|
-
return e ? { success: !0, message: "Document found", result: e } : { success: !1, message: "Document not found", code:
|
|
546
|
+
return e ? { success: !0, message: "Document found", result: e } : { success: !1, message: "Document not found", code: R.NOT_FOUND.CODE };
|
|
546
547
|
} catch (e) {
|
|
547
|
-
return
|
|
548
|
+
return d(e);
|
|
548
549
|
}
|
|
549
550
|
});
|
|
550
551
|
}
|
|
@@ -555,7 +556,7 @@ class be {
|
|
|
555
556
|
* @returns A promise that resolves to a standardized response with the found documents.
|
|
556
557
|
*/
|
|
557
558
|
findAll() {
|
|
558
|
-
return
|
|
559
|
+
return a(this, arguments, function* (t = {}) {
|
|
559
560
|
try {
|
|
560
561
|
return {
|
|
561
562
|
success: !0,
|
|
@@ -563,7 +564,7 @@ class be {
|
|
|
563
564
|
result: yield this.collection.find(t).toArray()
|
|
564
565
|
};
|
|
565
566
|
} catch (e) {
|
|
566
|
-
return
|
|
567
|
+
return d(e);
|
|
567
568
|
}
|
|
568
569
|
});
|
|
569
570
|
}
|
|
@@ -574,7 +575,7 @@ class be {
|
|
|
574
575
|
* @returns A promise that resolves to a standardized response with the document count.
|
|
575
576
|
*/
|
|
576
577
|
count() {
|
|
577
|
-
return
|
|
578
|
+
return a(this, arguments, function* (t = {}) {
|
|
578
579
|
try {
|
|
579
580
|
const e = yield this.collection.countDocuments(t);
|
|
580
581
|
return {
|
|
@@ -583,7 +584,7 @@ class be {
|
|
|
583
584
|
result: e
|
|
584
585
|
};
|
|
585
586
|
} catch (e) {
|
|
586
|
-
return
|
|
587
|
+
return d(e);
|
|
587
588
|
}
|
|
588
589
|
});
|
|
589
590
|
}
|
|
@@ -595,7 +596,7 @@ class be {
|
|
|
595
596
|
* @returns A promise that resolves to a standardized response with the update result.
|
|
596
597
|
*/
|
|
597
598
|
updateOne(t, e) {
|
|
598
|
-
return
|
|
599
|
+
return a(this, null, function* () {
|
|
599
600
|
try {
|
|
600
601
|
const r = yield this.collection.updateOne(t, {
|
|
601
602
|
$set: e
|
|
@@ -603,14 +604,14 @@ class be {
|
|
|
603
604
|
return r.matchedCount === 0 ? {
|
|
604
605
|
success: !1,
|
|
605
606
|
message: "No documents matched the filter",
|
|
606
|
-
code:
|
|
607
|
+
code: R.INTERNAL_SERVER_ERROR.CODE
|
|
607
608
|
} : {
|
|
608
609
|
success: !0,
|
|
609
610
|
message: "Document updated successfully",
|
|
610
611
|
result: r
|
|
611
612
|
};
|
|
612
613
|
} catch (r) {
|
|
613
|
-
return
|
|
614
|
+
return d(r);
|
|
614
615
|
}
|
|
615
616
|
});
|
|
616
617
|
}
|
|
@@ -622,7 +623,7 @@ class be {
|
|
|
622
623
|
* @returns A promise that resolves to a standardized response with the update result.
|
|
623
624
|
*/
|
|
624
625
|
updateMany(t, e) {
|
|
625
|
-
return
|
|
626
|
+
return a(this, null, function* () {
|
|
626
627
|
try {
|
|
627
628
|
const r = yield this.collection.updateMany(t, {
|
|
628
629
|
$set: e
|
|
@@ -630,14 +631,14 @@ class be {
|
|
|
630
631
|
return r.matchedCount === 0 ? {
|
|
631
632
|
success: !1,
|
|
632
633
|
message: "No documents matched the filter",
|
|
633
|
-
code:
|
|
634
|
+
code: R.INTERNAL_SERVER_ERROR.CODE
|
|
634
635
|
} : {
|
|
635
636
|
success: !0,
|
|
636
637
|
message: "Documents updated successfully",
|
|
637
638
|
result: r
|
|
638
639
|
};
|
|
639
640
|
} catch (r) {
|
|
640
|
-
return
|
|
641
|
+
return d(r);
|
|
641
642
|
}
|
|
642
643
|
});
|
|
643
644
|
}
|
|
@@ -648,20 +649,20 @@ class be {
|
|
|
648
649
|
* @returns A promise that resolves to a standardized response with the delete result.
|
|
649
650
|
*/
|
|
650
651
|
deleteOne(t) {
|
|
651
|
-
return
|
|
652
|
+
return a(this, null, function* () {
|
|
652
653
|
try {
|
|
653
654
|
const e = yield this.collection.deleteOne(t);
|
|
654
655
|
return e.deletedCount === 0 ? {
|
|
655
656
|
success: !1,
|
|
656
657
|
message: "No documents matched the filter",
|
|
657
|
-
code:
|
|
658
|
+
code: R.INTERNAL_SERVER_ERROR.CODE
|
|
658
659
|
} : {
|
|
659
660
|
success: !0,
|
|
660
661
|
message: "Document deleted successfully",
|
|
661
662
|
result: e
|
|
662
663
|
};
|
|
663
664
|
} catch (e) {
|
|
664
|
-
return
|
|
665
|
+
return d(e);
|
|
665
666
|
}
|
|
666
667
|
});
|
|
667
668
|
}
|
|
@@ -672,25 +673,25 @@ class be {
|
|
|
672
673
|
* @returns A promise that resolves to a standardized response with the delete result.
|
|
673
674
|
*/
|
|
674
675
|
deleteMany(t) {
|
|
675
|
-
return
|
|
676
|
+
return a(this, null, function* () {
|
|
676
677
|
try {
|
|
677
678
|
const e = yield this.collection.deleteMany(t);
|
|
678
679
|
return e.deletedCount === 0 ? {
|
|
679
680
|
success: !1,
|
|
680
681
|
message: "No documents matched the filter",
|
|
681
|
-
code:
|
|
682
|
+
code: R.INTERNAL_SERVER_ERROR.CODE
|
|
682
683
|
} : {
|
|
683
684
|
success: !0,
|
|
684
685
|
message: "Documents deleted successfully",
|
|
685
686
|
result: e
|
|
686
687
|
};
|
|
687
688
|
} catch (e) {
|
|
688
|
-
return
|
|
689
|
+
return d(e);
|
|
689
690
|
}
|
|
690
691
|
});
|
|
691
692
|
}
|
|
692
693
|
}
|
|
693
|
-
class
|
|
694
|
+
class we {
|
|
694
695
|
/**
|
|
695
696
|
* Creates a new Mongoose controller instance.
|
|
696
697
|
*
|
|
@@ -723,7 +724,7 @@ class xe {
|
|
|
723
724
|
* @returns The document with dynamic virtuals populated.
|
|
724
725
|
*/
|
|
725
726
|
populateDynamicVirtualsForDocument(t, e) {
|
|
726
|
-
return
|
|
727
|
+
return a(this, null, function* () {
|
|
727
728
|
const r = this.getDynamicVirtuals();
|
|
728
729
|
if (r && r.length > 0) {
|
|
729
730
|
const s = yield z(this.model.base, [t], r, e);
|
|
@@ -740,7 +741,7 @@ class xe {
|
|
|
740
741
|
* @returns The documents with dynamic virtuals populated.
|
|
741
742
|
*/
|
|
742
743
|
populateDynamicVirtualsForDocuments(t, e) {
|
|
743
|
-
return
|
|
744
|
+
return a(this, null, function* () {
|
|
744
745
|
const r = this.getDynamicVirtuals();
|
|
745
746
|
return r && r.length > 0 && t.length > 0 ? yield z(this.model.base, t, r, e) : t;
|
|
746
747
|
});
|
|
@@ -756,18 +757,18 @@ class xe {
|
|
|
756
757
|
* @returns A promise that resolves to a standardized response with the found document.
|
|
757
758
|
*/
|
|
758
759
|
findOne() {
|
|
759
|
-
return
|
|
760
|
+
return a(this, arguments, function* (t = {}, e = {}, r = {}, s) {
|
|
760
761
|
try {
|
|
761
|
-
const
|
|
762
|
-
|
|
763
|
-
const
|
|
764
|
-
return
|
|
762
|
+
const u = b(t), c = this.model.findOne(u, e, r), i = this.getDynamicVirtuals(), o = j(s, i);
|
|
763
|
+
o && c.populate(o);
|
|
764
|
+
const l = yield c.exec();
|
|
765
|
+
return l ? { success: !0, result: yield this.populateDynamicVirtualsForDocument(l, s) } : {
|
|
765
766
|
success: !1,
|
|
766
767
|
message: `No ${this.getModelName()} found.`,
|
|
767
|
-
code:
|
|
768
|
+
code: R.NOT_FOUND.CODE
|
|
768
769
|
};
|
|
769
|
-
} catch (
|
|
770
|
-
return
|
|
770
|
+
} catch (u) {
|
|
771
|
+
return d(u);
|
|
771
772
|
}
|
|
772
773
|
});
|
|
773
774
|
}
|
|
@@ -782,14 +783,14 @@ class xe {
|
|
|
782
783
|
* @returns A promise that resolves to a standardized response with the found documents.
|
|
783
784
|
*/
|
|
784
785
|
findAll() {
|
|
785
|
-
return
|
|
786
|
+
return a(this, arguments, function* (t = {}, e = {}, r = {}, s) {
|
|
786
787
|
try {
|
|
787
|
-
const
|
|
788
|
-
|
|
789
|
-
const
|
|
790
|
-
return { success: !0, result: yield this.populateDynamicVirtualsForDocuments(
|
|
791
|
-
} catch (
|
|
792
|
-
return
|
|
788
|
+
const u = b(t), c = this.model.find(u, e, r), i = this.getDynamicVirtuals(), o = j(s, i);
|
|
789
|
+
o && c.populate(o);
|
|
790
|
+
const l = yield c.exec();
|
|
791
|
+
return { success: !0, result: yield this.populateDynamicVirtualsForDocuments(l, s) };
|
|
792
|
+
} catch (u) {
|
|
793
|
+
return d(u);
|
|
793
794
|
}
|
|
794
795
|
});
|
|
795
796
|
}
|
|
@@ -802,14 +803,14 @@ class xe {
|
|
|
802
803
|
* @returns A promise that resolves to a standardized response with paginated results.
|
|
803
804
|
*/
|
|
804
805
|
findPaging() {
|
|
805
|
-
return
|
|
806
|
+
return a(this, arguments, function* (t = {}, e = {}) {
|
|
806
807
|
try {
|
|
807
|
-
const r =
|
|
808
|
-
e.populate && (
|
|
809
|
-
const
|
|
810
|
-
return { success: !0, result:
|
|
808
|
+
const r = b(t), s = this.getDynamicVirtuals(), u = S({}, e);
|
|
809
|
+
e.populate && (u.populate = j(e.populate, s));
|
|
810
|
+
const c = yield this.model.paginate(r, u), i = yield this.populateDynamicVirtualsForDocuments(c.docs, e.populate);
|
|
811
|
+
return { success: !0, result: F(S({}, c), { docs: i }) };
|
|
811
812
|
} catch (r) {
|
|
812
|
-
return
|
|
813
|
+
return d(r);
|
|
813
814
|
}
|
|
814
815
|
});
|
|
815
816
|
}
|
|
@@ -821,17 +822,17 @@ class xe {
|
|
|
821
822
|
* @returns A promise that resolves to a standardized response with paginated aggregation results.
|
|
822
823
|
*/
|
|
823
824
|
findPagingAggregate(t) {
|
|
824
|
-
return
|
|
825
|
+
return a(this, arguments, function* (e, r = {}) {
|
|
825
826
|
try {
|
|
826
|
-
const s = this.getDynamicVirtuals(),
|
|
827
|
-
r.populate && (
|
|
828
|
-
const
|
|
827
|
+
const s = this.getDynamicVirtuals(), u = S({}, r);
|
|
828
|
+
r.populate && (u.populate = j(r.populate, s));
|
|
829
|
+
const c = yield this.model.aggregatePaginate(
|
|
829
830
|
this.model.aggregate(e),
|
|
830
|
-
|
|
831
|
-
),
|
|
832
|
-
return { success: !0, result:
|
|
831
|
+
u
|
|
832
|
+
), i = yield this.populateDynamicVirtualsForDocuments(c.docs, r.populate);
|
|
833
|
+
return { success: !0, result: F(S({}, c), { docs: i }) };
|
|
833
834
|
} catch (s) {
|
|
834
|
-
return
|
|
835
|
+
return d(s);
|
|
835
836
|
}
|
|
836
837
|
});
|
|
837
838
|
}
|
|
@@ -842,12 +843,12 @@ class xe {
|
|
|
842
843
|
* @returns A promise that resolves to a standardized response with the document count.
|
|
843
844
|
*/
|
|
844
845
|
count() {
|
|
845
|
-
return
|
|
846
|
+
return a(this, arguments, function* (t = {}) {
|
|
846
847
|
try {
|
|
847
|
-
const e =
|
|
848
|
+
const e = b(t);
|
|
848
849
|
return { success: !0, result: yield this.model.countDocuments(e) };
|
|
849
850
|
} catch (e) {
|
|
850
|
-
return
|
|
851
|
+
return d(e);
|
|
851
852
|
}
|
|
852
853
|
});
|
|
853
854
|
}
|
|
@@ -858,11 +859,11 @@ class xe {
|
|
|
858
859
|
* @returns A promise that resolves to a standardized response with the created document.
|
|
859
860
|
*/
|
|
860
861
|
createOne(t) {
|
|
861
|
-
return
|
|
862
|
+
return a(this, null, function* () {
|
|
862
863
|
try {
|
|
863
864
|
return { success: !0, result: yield this.model.create(t) };
|
|
864
865
|
} catch (e) {
|
|
865
|
-
return
|
|
866
|
+
return d(e);
|
|
866
867
|
}
|
|
867
868
|
});
|
|
868
869
|
}
|
|
@@ -874,11 +875,11 @@ class xe {
|
|
|
874
875
|
* @returns A promise that resolves to a standardized response with the created documents.
|
|
875
876
|
*/
|
|
876
877
|
createMany(t) {
|
|
877
|
-
return
|
|
878
|
+
return a(this, arguments, function* (e, r = {}) {
|
|
878
879
|
try {
|
|
879
|
-
return { success: !0, result: (yield this.model.insertMany(e, r)).map((
|
|
880
|
+
return { success: !0, result: (yield this.model.insertMany(e, r)).map((c) => c instanceof W ? c.toObject() : null).filter((c) => c !== null) };
|
|
880
881
|
} catch (s) {
|
|
881
|
-
return
|
|
882
|
+
return d(s);
|
|
882
883
|
}
|
|
883
884
|
});
|
|
884
885
|
}
|
|
@@ -891,18 +892,18 @@ class xe {
|
|
|
891
892
|
* @returns A promise that resolves to a standardized response with the updated document.
|
|
892
893
|
*/
|
|
893
894
|
updateOne() {
|
|
894
|
-
return
|
|
895
|
+
return a(this, arguments, function* (t = {}, e = {}, r = {}) {
|
|
895
896
|
try {
|
|
896
|
-
const s =
|
|
897
|
+
const s = b(t), u = yield this.model.findOneAndUpdate(s, e, S({
|
|
897
898
|
new: !0
|
|
898
899
|
}, r)).exec();
|
|
899
|
-
return
|
|
900
|
+
return u ? { success: !0, result: u } : {
|
|
900
901
|
success: !1,
|
|
901
902
|
message: `Failed to update ${this.getModelName()}.`,
|
|
902
|
-
code:
|
|
903
|
+
code: R.NOT_FOUND.CODE
|
|
903
904
|
};
|
|
904
905
|
} catch (s) {
|
|
905
|
-
return
|
|
906
|
+
return d(s);
|
|
906
907
|
}
|
|
907
908
|
});
|
|
908
909
|
}
|
|
@@ -915,12 +916,12 @@ class xe {
|
|
|
915
916
|
* @returns A promise that resolves to a standardized response with the update result.
|
|
916
917
|
*/
|
|
917
918
|
updateMany() {
|
|
918
|
-
return
|
|
919
|
+
return a(this, arguments, function* (t = {}, e = {}, r = {}) {
|
|
919
920
|
try {
|
|
920
|
-
const s =
|
|
921
|
+
const s = b(t);
|
|
921
922
|
return { success: !0, result: yield this.model.updateMany(s, e, r).exec() };
|
|
922
923
|
} catch (s) {
|
|
923
|
-
return
|
|
924
|
+
return d(s);
|
|
924
925
|
}
|
|
925
926
|
});
|
|
926
927
|
}
|
|
@@ -932,16 +933,16 @@ class xe {
|
|
|
932
933
|
* @returns A promise that resolves to a standardized response with the deleted document.
|
|
933
934
|
*/
|
|
934
935
|
deleteOne() {
|
|
935
|
-
return
|
|
936
|
+
return a(this, arguments, function* (t = {}, e = {}) {
|
|
936
937
|
try {
|
|
937
|
-
const r =
|
|
938
|
+
const r = b(t), s = yield this.model.findOneAndDelete(r, e).exec();
|
|
938
939
|
return s ? { success: !0, result: s } : {
|
|
939
940
|
success: !1,
|
|
940
941
|
message: `No ${this.getModelName()} found to delete.`,
|
|
941
|
-
code:
|
|
942
|
+
code: R.NOT_FOUND.CODE
|
|
942
943
|
};
|
|
943
944
|
} catch (r) {
|
|
944
|
-
return
|
|
945
|
+
return d(r);
|
|
945
946
|
}
|
|
946
947
|
});
|
|
947
948
|
}
|
|
@@ -953,16 +954,16 @@ class xe {
|
|
|
953
954
|
* @returns A promise that resolves to a standardized response with the delete result.
|
|
954
955
|
*/
|
|
955
956
|
deleteMany() {
|
|
956
|
-
return
|
|
957
|
+
return a(this, arguments, function* (t = {}, e = {}) {
|
|
957
958
|
try {
|
|
958
|
-
const r =
|
|
959
|
+
const r = b(t), s = yield this.model.deleteMany(r, e).exec();
|
|
959
960
|
return s.deletedCount === 0 ? {
|
|
960
961
|
success: !1,
|
|
961
962
|
message: "No documents found to delete.",
|
|
962
|
-
code:
|
|
963
|
+
code: R.NOT_FOUND.CODE
|
|
963
964
|
} : { success: !0, result: s };
|
|
964
965
|
} catch (r) {
|
|
965
|
-
return
|
|
966
|
+
return d(r);
|
|
966
967
|
}
|
|
967
968
|
});
|
|
968
969
|
}
|
|
@@ -975,23 +976,23 @@ class xe {
|
|
|
975
976
|
* @returns A promise that resolves to a standardized response with the unique short ID.
|
|
976
977
|
*/
|
|
977
978
|
createShortId(t, e = 4) {
|
|
978
|
-
return
|
|
979
|
+
return a(this, null, function* () {
|
|
979
980
|
try {
|
|
980
|
-
const s = Array.from({ length: 10 }, (
|
|
981
|
-
s.map((
|
|
982
|
-
)).findIndex((
|
|
983
|
-
if (
|
|
984
|
-
const
|
|
985
|
-
if (
|
|
986
|
-
return { success: !0, result:
|
|
981
|
+
const s = Array.from({ length: 10 }, (i, o) => ne(t, o + e)), c = (yield Promise.all(
|
|
982
|
+
s.map((i) => this.model.exists({ shortId: i }))
|
|
983
|
+
)).findIndex((i) => !i);
|
|
984
|
+
if (c !== -1) {
|
|
985
|
+
const i = s[c];
|
|
986
|
+
if (i)
|
|
987
|
+
return { success: !0, result: i };
|
|
987
988
|
}
|
|
988
989
|
return {
|
|
989
990
|
success: !1,
|
|
990
991
|
message: "Failed to create a unique shortId",
|
|
991
|
-
code:
|
|
992
|
+
code: R.INTERNAL_SERVER_ERROR.CODE
|
|
992
993
|
};
|
|
993
994
|
} catch (r) {
|
|
994
|
-
return
|
|
995
|
+
return d(r);
|
|
995
996
|
}
|
|
996
997
|
});
|
|
997
998
|
}
|
|
@@ -1006,17 +1007,17 @@ class xe {
|
|
|
1006
1007
|
* @param options.filter - Additional filter conditions to apply to the query.
|
|
1007
1008
|
* @returns A MongoDB query object for checking slug existence.
|
|
1008
1009
|
*/
|
|
1009
|
-
createSlugQuery({ slug: t, field: e, isObject: r,
|
|
1010
|
-
const c = S({},
|
|
1011
|
-
return r ?
|
|
1010
|
+
createSlugQuery({ slug: t, field: e, isObject: r, haveHistory: s = !1, filter: u }) {
|
|
1011
|
+
const c = S({}, u != null ? u : {});
|
|
1012
|
+
return r ? F(S({}, c), {
|
|
1012
1013
|
$or: [
|
|
1013
1014
|
{ [`slug.${e}`]: t },
|
|
1014
|
-
{ slugHistory: { $elemMatch: { [`slug.${e}`]: t } } }
|
|
1015
|
+
...s ? [{ slugHistory: { $elemMatch: { [`slug.${e}`]: t } } }] : []
|
|
1015
1016
|
]
|
|
1016
|
-
}) :
|
|
1017
|
+
}) : F(S({}, c), {
|
|
1017
1018
|
$or: [
|
|
1018
1019
|
{ slug: t },
|
|
1019
|
-
{ slugHistory: t }
|
|
1020
|
+
...s ? [{ slugHistory: t }] : []
|
|
1020
1021
|
]
|
|
1021
1022
|
});
|
|
1022
1023
|
}
|
|
@@ -1032,18 +1033,23 @@ class xe {
|
|
|
1032
1033
|
* @returns A promise that resolves to a unique slug string.
|
|
1033
1034
|
*/
|
|
1034
1035
|
createUniqueSlug(t) {
|
|
1035
|
-
return
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1036
|
+
return a(this, arguments, function* ({ slug: e, field: r, isObject: s, haveHistory: u, filter: c }) {
|
|
1037
|
+
if (!e || typeof e != "string")
|
|
1038
|
+
throw new Error("Invalid slug provided: must be a non-empty string");
|
|
1039
|
+
const i = I(e);
|
|
1040
|
+
if (!(yield this.model.exists(
|
|
1041
|
+
this.createSlugQuery({ slug: i, field: r, isObject: s, haveHistory: u, filter: c })
|
|
1042
|
+
)))
|
|
1043
|
+
return i;
|
|
1044
|
+
for (let O = 1; O <= X; O++) {
|
|
1045
|
+
const m = `${i}-${O}`;
|
|
1046
|
+
if (!(yield this.model.exists(
|
|
1047
|
+
this.createSlugQuery({ slug: m, field: r, isObject: s, haveHistory: u, filter: c })
|
|
1048
|
+
)))
|
|
1044
1049
|
return m;
|
|
1045
1050
|
}
|
|
1046
|
-
|
|
1051
|
+
const l = Date.now(), f = Math.random().toString(36).substring(2, 8);
|
|
1052
|
+
return `${i}-${l}-${f}`;
|
|
1047
1053
|
});
|
|
1048
1054
|
}
|
|
1049
1055
|
/**
|
|
@@ -1057,29 +1063,31 @@ class xe {
|
|
|
1057
1063
|
* @returns A promise that resolves to a standardized response with the created slug(s).
|
|
1058
1064
|
*/
|
|
1059
1065
|
createSlug(t) {
|
|
1060
|
-
return
|
|
1066
|
+
return a(this, arguments, function* ({ field: e, from: r, filter: s, haveHistory: u }) {
|
|
1061
1067
|
try {
|
|
1062
1068
|
const c = r[e];
|
|
1063
|
-
return
|
|
1069
|
+
return $(c) ? { success: !0, result: Object.fromEntries(
|
|
1064
1070
|
yield Promise.all(
|
|
1065
|
-
Object.entries(c).map((
|
|
1066
|
-
const
|
|
1071
|
+
Object.entries(c).map((f) => a(this, [f], function* ([O, m]) {
|
|
1072
|
+
const g = yield this.createUniqueSlug({
|
|
1067
1073
|
slug: m,
|
|
1068
|
-
field:
|
|
1074
|
+
field: O,
|
|
1069
1075
|
isObject: !0,
|
|
1076
|
+
haveHistory: u,
|
|
1070
1077
|
filter: s
|
|
1071
1078
|
});
|
|
1072
|
-
return [
|
|
1079
|
+
return [O, g];
|
|
1073
1080
|
}))
|
|
1074
1081
|
)
|
|
1075
1082
|
) } : { success: !0, result: yield this.createUniqueSlug({
|
|
1076
1083
|
slug: c,
|
|
1077
1084
|
field: e,
|
|
1078
1085
|
isObject: !1,
|
|
1086
|
+
haveHistory: u,
|
|
1079
1087
|
filter: s
|
|
1080
1088
|
}) };
|
|
1081
1089
|
} catch (c) {
|
|
1082
|
-
return
|
|
1090
|
+
return d(c);
|
|
1083
1091
|
}
|
|
1084
1092
|
});
|
|
1085
1093
|
}
|
|
@@ -1095,31 +1103,32 @@ class xe {
|
|
|
1095
1103
|
* @returns A promise that resolves to a standardized response indicating whether the slug exists.
|
|
1096
1104
|
*/
|
|
1097
1105
|
checkSlug(t) {
|
|
1098
|
-
return
|
|
1106
|
+
return a(this, arguments, function* ({ slug: e, field: r, from: s, filter: u, haveHistory: c }) {
|
|
1099
1107
|
try {
|
|
1100
|
-
const
|
|
1101
|
-
if (
|
|
1102
|
-
const m = Object.values(
|
|
1108
|
+
const i = s[r];
|
|
1109
|
+
if ($(i)) {
|
|
1110
|
+
const m = Object.values(i).map((v) => I(v));
|
|
1103
1111
|
return (yield Promise.all(
|
|
1104
1112
|
m.map(
|
|
1105
|
-
(
|
|
1106
|
-
slug:
|
|
1113
|
+
(v) => this.model.exists(this.createSlugQuery({
|
|
1114
|
+
slug: v,
|
|
1107
1115
|
field: r,
|
|
1108
1116
|
isObject: !0,
|
|
1109
|
-
|
|
1117
|
+
haveHistory: c,
|
|
1118
|
+
filter: u
|
|
1110
1119
|
}))
|
|
1111
1120
|
)
|
|
1112
|
-
)).some((
|
|
1121
|
+
)).some((v) => v) ? { success: !0, result: !0 } : { success: !0, result: !1 };
|
|
1113
1122
|
}
|
|
1114
|
-
const
|
|
1123
|
+
const l = I(e);
|
|
1115
1124
|
return { success: !0, result: (yield this.model.exists(this.createSlugQuery({
|
|
1116
|
-
slug:
|
|
1125
|
+
slug: l,
|
|
1117
1126
|
field: r,
|
|
1118
1127
|
isObject: !1,
|
|
1119
|
-
filter:
|
|
1128
|
+
filter: u
|
|
1120
1129
|
}))) !== null };
|
|
1121
|
-
} catch (
|
|
1122
|
-
return
|
|
1130
|
+
} catch (i) {
|
|
1131
|
+
return d(i);
|
|
1123
1132
|
}
|
|
1124
1133
|
});
|
|
1125
1134
|
}
|
|
@@ -1130,17 +1139,17 @@ class xe {
|
|
|
1130
1139
|
* @returns A promise that resolves to a standardized response with the aggregation results.
|
|
1131
1140
|
*/
|
|
1132
1141
|
aggregate(t) {
|
|
1133
|
-
return
|
|
1142
|
+
return a(this, null, function* () {
|
|
1134
1143
|
try {
|
|
1135
1144
|
return { success: !0, result: yield this.model.aggregate(t) };
|
|
1136
1145
|
} catch (e) {
|
|
1137
|
-
return
|
|
1146
|
+
return d(e);
|
|
1138
1147
|
}
|
|
1139
1148
|
});
|
|
1140
1149
|
}
|
|
1141
1150
|
}
|
|
1142
1151
|
export {
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1152
|
+
Me as MongoController,
|
|
1153
|
+
we as MongooseController,
|
|
1154
|
+
x as mongo
|
|
1146
1155
|
};
|