@cyberskill/shared 2.26.0 → 2.28.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/README.md +1 -1
- package/dist/config/config.util.cjs +1 -1
- package/dist/config/config.util.js +14 -19
- package/dist/config/eslint/index.cjs +1 -1
- package/dist/config/eslint/index.d.ts +2 -0
- package/dist/config/eslint/index.js +1 -1
- 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/cli/index.cjs +2 -5
- package/dist/node/cli/index.js +108 -103
- package/dist/node/command/command.util.js +1 -1
- package/dist/node/fs/fs.util.cjs +4 -1
- package/dist/node/fs/fs.util.d.ts +8 -0
- package/dist/node/fs/fs.util.js +58 -50
- package/dist/node/fs/index.cjs +1 -1
- package/dist/node/fs/index.js +13 -12
- package/dist/node/mongo/mongo.type.js +3 -3
- package/dist/node/mongo/mongo.util.cjs +2 -5
- package/dist/node/mongo/mongo.util.js +206 -211
- package/dist/node/path/index.cjs +1 -1
- package/dist/node/path/index.js +53 -51
- package/dist/node/path/path.constant.cjs +1 -1
- package/dist/node/path/path.constant.d.ts +3 -0
- package/dist/node/path/path.constant.js +63 -60
- package/dist/node/storage/storage.util.cjs +1 -1
- package/dist/node/storage/storage.util.js +1 -1
- package/dist/node/upload/upload.util.js +3 -3
- package/dist/react/apollo-client/apollo-client.component.cjs +1 -1
- package/dist/react/apollo-client/apollo-client.component.d.ts +1 -1
- package/dist/react/apollo-client/apollo-client.component.js +4 -3
- package/dist/react/apollo-client/apollo-client.context.cjs +1 -1
- package/dist/react/apollo-client/apollo-client.context.d.ts +1 -1
- package/dist/react/apollo-client/apollo-client.context.js +9 -8
- package/dist/react/apollo-client/apollo-client.util.cjs +1 -1
- package/dist/react/apollo-client/apollo-client.util.js +3 -3
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.cjs +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.d.ts +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js +9 -8
- package/dist/react/apollo-error/apollo-error.component.cjs +1 -1
- package/dist/react/apollo-error/apollo-error.component.d.ts +1 -1
- package/dist/react/apollo-error/apollo-error.component.js +2 -1
- package/dist/react/apollo-error/apollo-error.provider.cjs +1 -1
- package/dist/react/apollo-error/apollo-error.provider.d.ts +1 -1
- package/dist/react/apollo-error/apollo-error.provider.js +4 -3
- package/dist/react/loading/loading.component.cjs +2 -2
- package/dist/react/loading/loading.component.d.ts +1 -1
- package/dist/react/loading/loading.component.js +7 -6
- package/dist/react/loading/loading.provider.cjs +1 -1
- package/dist/react/loading/loading.provider.d.ts +1 -1
- package/dist/react/loading/loading.provider.js +8 -7
- package/dist/react/next-intl/next-intl.hoc.cjs +1 -1
- package/dist/react/next-intl/next-intl.hoc.d.ts +2 -1
- package/dist/react/next-intl/next-intl.hoc.js +12 -12
- package/dist/react/next-intl/next-intl.provider.cjs +1 -1
- package/dist/react/next-intl/next-intl.provider.d.ts +1 -1
- package/dist/react/next-intl/next-intl.provider.js +5 -4
- package/dist/util/common/common.util.cjs +1 -1
- package/dist/util/common/common.util.d.ts +9 -0
- package/dist/util/common/common.util.js +33 -29
- package/dist/util/common/index.cjs +1 -1
- package/dist/util/common/index.js +6 -5
- package/dist/util/index.cjs +1 -1
- package/dist/util/index.js +23 -22
- package/dist/util/object/object.util.cjs +1 -1
- package/dist/util/object/object.util.js +40 -36
- package/package.json +45 -44
- package/dist/node/mongo/mongo.util.d.ts +0 -1040
- /package/dist/node_modules/.pnpm/{vitest@4.0.16_@types_node@25.0.3_jiti@2.6.1_jsdom@27.4.0_sass@1.97.2_tsx@4.21.0_yaml@2.8.2 → vitest@4.0.18_@types_node@25.3.0_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2}/node_modules/vitest/dist/config.cjs +0 -0
- /package/dist/node_modules/.pnpm/{vitest@4.0.16_@types_node@25.0.3_jiti@2.6.1_jsdom@27.4.0_sass@1.97.2_tsx@4.21.0_yaml@2.8.2 → vitest@4.0.18_@types_node@25.3.0_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2}/node_modules/vitest/dist/config.js +0 -0
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { randomUUID as
|
|
5
|
-
import { deepClone as
|
|
6
|
-
import { regexSearchMapper as
|
|
7
|
-
import { writeFileSync as
|
|
8
|
-
import { PATH as
|
|
9
|
-
import { validate as
|
|
10
|
-
var
|
|
11
|
-
for (var
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
for (var
|
|
15
|
-
|
|
1
|
+
import C from "migrate-mongo";
|
|
2
|
+
import k from "mongoose-aggregate-paginate-v2";
|
|
3
|
+
import U from "mongoose-paginate-v2";
|
|
4
|
+
import { randomUUID as I } from "node:crypto";
|
|
5
|
+
import { deepClone as q, getNestedValue as B, setNestedValue as J } from "../../util/object/object.util.js";
|
|
6
|
+
import { regexSearchMapper as K } from "../../util/common/common.util.js";
|
|
7
|
+
import { writeFileSync as L, addGitIgnoreEntry as H } from "../fs/fs.util.js";
|
|
8
|
+
import { PATH as V, MIGRATE_MONGO_CONFIG as z } from "../path/path.constant.js";
|
|
9
|
+
import { validate as Q } from "../../util/validate/validate.util.js";
|
|
10
|
+
var W = Object.defineProperty, X = Object.defineProperties, Y = Object.getOwnPropertyDescriptors, x = Object.getOwnPropertySymbols, Z = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable, $ = (t, e, i) => e in t ? W(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i, M = (t, e) => {
|
|
11
|
+
for (var i in e || (e = {}))
|
|
12
|
+
Z.call(e, i) && $(t, i, e[i]);
|
|
13
|
+
if (x)
|
|
14
|
+
for (var i of x(e))
|
|
15
|
+
T.call(e, i) && $(t, i, e[i]);
|
|
16
16
|
return t;
|
|
17
|
-
},
|
|
18
|
-
var
|
|
17
|
+
}, tt = (t, e) => X(t, Y(e)), w = (t, e, i) => new Promise((n, r) => {
|
|
18
|
+
var o = (s) => {
|
|
19
19
|
try {
|
|
20
|
-
y(
|
|
20
|
+
y(i.next(s));
|
|
21
21
|
} catch (h) {
|
|
22
22
|
r(h);
|
|
23
23
|
}
|
|
24
24
|
}, l = (s) => {
|
|
25
25
|
try {
|
|
26
|
-
y(
|
|
26
|
+
y(i.throw(s));
|
|
27
27
|
} catch (h) {
|
|
28
28
|
r(h);
|
|
29
29
|
}
|
|
30
|
-
}, y = (s) => s.done ?
|
|
31
|
-
y((
|
|
30
|
+
}, y = (s) => s.done ? n(s.value) : Promise.resolve(s.value).then(o, l);
|
|
31
|
+
y((i = i.apply(t, e)).next());
|
|
32
32
|
});
|
|
33
|
-
function
|
|
33
|
+
function P(t) {
|
|
34
34
|
return t === t.toUpperCase() ? t.charAt(0).toUpperCase() + t.slice(1).toLowerCase() : t;
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const A = {
|
|
37
37
|
/**
|
|
38
38
|
* Creates generic fields that are commonly used across MongoDB documents.
|
|
39
39
|
* This function generates standard fields including a UUID, deletion flag, and timestamps
|
|
@@ -43,7 +43,7 @@ const I = {
|
|
|
43
43
|
*/
|
|
44
44
|
createGenericFields() {
|
|
45
45
|
return {
|
|
46
|
-
id:
|
|
46
|
+
id: I(),
|
|
47
47
|
isDel: !1,
|
|
48
48
|
createdAt: /* @__PURE__ */ new Date(),
|
|
49
49
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -57,8 +57,8 @@ const I = {
|
|
|
57
57
|
* @param schema - The Mongoose schema to apply plugins to.
|
|
58
58
|
* @param plugins - An array of plugin functions or false values to filter and apply.
|
|
59
59
|
*/
|
|
60
|
-
applyPlugins(t,
|
|
61
|
-
|
|
60
|
+
applyPlugins(t, e) {
|
|
61
|
+
e.filter((i) => typeof i == "function").forEach((i) => t.plugin(i));
|
|
62
62
|
},
|
|
63
63
|
/**
|
|
64
64
|
* Applies middleware functions to a Mongoose schema.
|
|
@@ -67,9 +67,9 @@ const I = {
|
|
|
67
67
|
* @param schema - The Mongoose schema to apply middleware to.
|
|
68
68
|
* @param middlewares - An array of middleware configurations with method, pre, and post functions.
|
|
69
69
|
*/
|
|
70
|
-
applyMiddlewares(t,
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
applyMiddlewares(t, e) {
|
|
71
|
+
e.forEach(({ method: i, pre: n, post: r }) => {
|
|
72
|
+
i && n && t.pre(i, n), i && r && t.post(i, r);
|
|
73
73
|
});
|
|
74
74
|
},
|
|
75
75
|
/**
|
|
@@ -83,7 +83,7 @@ const I = {
|
|
|
83
83
|
createGenericSchema(t) {
|
|
84
84
|
return new t.Schema(
|
|
85
85
|
{
|
|
86
|
-
id: { type: String, default: () =>
|
|
86
|
+
id: { type: String, default: () => I(), unique: !0 },
|
|
87
87
|
isDel: { type: Boolean, default: !1 }
|
|
88
88
|
},
|
|
89
89
|
{ timestamps: !0 }
|
|
@@ -103,33 +103,33 @@ const I = {
|
|
|
103
103
|
*/
|
|
104
104
|
createSchema({
|
|
105
105
|
mongoose: t,
|
|
106
|
-
schema:
|
|
107
|
-
virtuals:
|
|
108
|
-
standalone:
|
|
106
|
+
schema: e,
|
|
107
|
+
virtuals: i = [],
|
|
108
|
+
standalone: n = !1
|
|
109
109
|
}) {
|
|
110
|
-
const r = new t.Schema(
|
|
110
|
+
const r = new t.Schema(e, {
|
|
111
111
|
toJSON: { virtuals: !0 },
|
|
112
112
|
// So `res.json()` and other `JSON.stringify()` functions include virtuals
|
|
113
113
|
toObject: { virtuals: !0 }
|
|
114
114
|
// So `console.log()` and other functions that use `toObject()` include virtuals
|
|
115
115
|
});
|
|
116
|
-
return
|
|
117
|
-
if (
|
|
116
|
+
return i.forEach(({ name: o, options: l, get: y }) => {
|
|
117
|
+
if (A.isDynamicVirtual(l)) {
|
|
118
118
|
const s = r.statics;
|
|
119
119
|
s._dynamicVirtuals || (s._dynamicVirtuals = []), s._dynamicVirtuals.push({
|
|
120
|
-
name:
|
|
120
|
+
name: o,
|
|
121
121
|
options: l
|
|
122
122
|
});
|
|
123
|
-
const h = r.virtual(
|
|
123
|
+
const h = r.virtual(o);
|
|
124
124
|
y ? h.get(y) : h.get(function() {
|
|
125
125
|
var u;
|
|
126
|
-
return ((u = this._populated) == null ? void 0 : u[
|
|
126
|
+
return ((u = this._populated) == null ? void 0 : u[o]) || (l != null && l.count ? 0 : l != null && l.justOne ? null : []);
|
|
127
127
|
});
|
|
128
128
|
} else {
|
|
129
|
-
const s = r.virtual(
|
|
129
|
+
const s = r.virtual(o, l);
|
|
130
130
|
y && s.get(y);
|
|
131
131
|
}
|
|
132
|
-
}),
|
|
132
|
+
}), n || r.add(A.createGenericSchema(t)), r;
|
|
133
133
|
},
|
|
134
134
|
/**
|
|
135
135
|
* Creates a Mongoose model with plugins, middleware, and pagination support.
|
|
@@ -149,24 +149,24 @@ const I = {
|
|
|
149
149
|
*/
|
|
150
150
|
createModel({
|
|
151
151
|
mongoose: t,
|
|
152
|
-
name:
|
|
153
|
-
schema:
|
|
154
|
-
virtuals:
|
|
152
|
+
name: e,
|
|
153
|
+
schema: i,
|
|
154
|
+
virtuals: n = [],
|
|
155
155
|
pagination: r = !0,
|
|
156
|
-
aggregate:
|
|
156
|
+
aggregate: o = !0,
|
|
157
157
|
middlewares: l = []
|
|
158
158
|
}) {
|
|
159
|
-
if (!
|
|
159
|
+
if (!e)
|
|
160
160
|
throw new Error("Model name is required.");
|
|
161
|
-
if (t.models[
|
|
162
|
-
return t.models[
|
|
163
|
-
const y =
|
|
164
|
-
(r ||
|
|
165
|
-
r &&
|
|
166
|
-
|
|
167
|
-
]),
|
|
168
|
-
const s = t.model(
|
|
169
|
-
return
|
|
161
|
+
if (t.models[e])
|
|
162
|
+
return t.models[e];
|
|
163
|
+
const y = A.createSchema({ mongoose: t, schema: i, virtuals: n });
|
|
164
|
+
(r || o) && A.applyPlugins(y, [
|
|
165
|
+
r && U,
|
|
166
|
+
o && k
|
|
167
|
+
]), A.applyMiddlewares(y, l);
|
|
168
|
+
const s = t.model(e, y);
|
|
169
|
+
return n.length > 0 && (s._virtualConfigs = n), s;
|
|
170
170
|
},
|
|
171
171
|
/**
|
|
172
172
|
* Validation utilities for Mongoose schemas.
|
|
@@ -182,8 +182,8 @@ const I = {
|
|
|
182
182
|
*/
|
|
183
183
|
isRequired() {
|
|
184
184
|
return function(t) {
|
|
185
|
-
return
|
|
186
|
-
return !
|
|
185
|
+
return w(this, null, function* () {
|
|
186
|
+
return !Q.isEmpty(t);
|
|
187
187
|
});
|
|
188
188
|
};
|
|
189
189
|
},
|
|
@@ -197,12 +197,12 @@ const I = {
|
|
|
197
197
|
* @throws {Error} When fields is not a non-empty array of strings.
|
|
198
198
|
*/
|
|
199
199
|
isUnique(t) {
|
|
200
|
-
return function(
|
|
201
|
-
return
|
|
200
|
+
return function(e) {
|
|
201
|
+
return w(this, null, function* () {
|
|
202
202
|
if (!Array.isArray(t) || t.length === 0)
|
|
203
203
|
throw new Error("Fields must be a non-empty array of strings.");
|
|
204
|
-
const
|
|
205
|
-
return !(yield this.constructor.exists(
|
|
204
|
+
const i = { $or: t.map((r) => ({ [r]: e })) };
|
|
205
|
+
return !(yield this.constructor.exists(i));
|
|
206
206
|
});
|
|
207
207
|
};
|
|
208
208
|
},
|
|
@@ -216,10 +216,10 @@ const I = {
|
|
|
216
216
|
* @throws {Error} When regexArray is not an array of valid RegExp objects.
|
|
217
217
|
*/
|
|
218
218
|
matchesRegex(t) {
|
|
219
|
-
return (
|
|
220
|
-
if (!Array.isArray(t) || t.some((
|
|
219
|
+
return (e) => w(null, null, function* () {
|
|
220
|
+
if (!Array.isArray(t) || t.some((i) => !(i instanceof RegExp)))
|
|
221
221
|
throw new Error("regexArray must be an array of valid RegExp objects.");
|
|
222
|
-
return t.every((
|
|
222
|
+
return t.every((i) => i.test(e));
|
|
223
223
|
});
|
|
224
224
|
}
|
|
225
225
|
},
|
|
@@ -227,7 +227,7 @@ const I = {
|
|
|
227
227
|
* Migration utilities for MongoDB.
|
|
228
228
|
* This object extends the migrate-mongo library with additional configuration utilities.
|
|
229
229
|
*/
|
|
230
|
-
migrate:
|
|
230
|
+
migrate: tt(M({}, C), {
|
|
231
231
|
/**
|
|
232
232
|
* Sets the migration configuration and updates .gitignore.
|
|
233
233
|
* This function creates a migration configuration file and ensures it's properly
|
|
@@ -236,14 +236,9 @@ const I = {
|
|
|
236
236
|
* @param options - Migration configuration options to write to the config file.
|
|
237
237
|
*/
|
|
238
238
|
setConfig: (t) => {
|
|
239
|
-
const
|
|
239
|
+
const e = `// This file is automatically generated by the Cyberskill CLI.
|
|
240
240
|
module.exports = ${JSON.stringify(t, null, 4)}`;
|
|
241
|
-
|
|
242
|
-
const e = `
|
|
243
|
-
${V}
|
|
244
|
-
`;
|
|
245
|
-
T(A.GIT_IGNORE) ? z(A.GIT_IGNORE, "utf-8").split(`
|
|
246
|
-
`).includes(V) || Q(A.GIT_IGNORE, e) : G(A.GIT_IGNORE, e);
|
|
241
|
+
L(V.MIGRATE_MONGO_CONFIG, e), H(V.GIT_IGNORE, z);
|
|
247
242
|
}
|
|
248
243
|
}),
|
|
249
244
|
/**
|
|
@@ -255,23 +250,23 @@ ${V}
|
|
|
255
250
|
* @param fields - An array of field names to convert to regex patterns.
|
|
256
251
|
* @returns A new filter object with string values converted to regex patterns.
|
|
257
252
|
*/
|
|
258
|
-
regexify(t,
|
|
253
|
+
regexify(t, e) {
|
|
259
254
|
if (!t)
|
|
260
255
|
return {};
|
|
261
|
-
let
|
|
262
|
-
if (!
|
|
263
|
-
return
|
|
264
|
-
for (const
|
|
265
|
-
const r =
|
|
266
|
-
if (typeof
|
|
256
|
+
let i = q(t);
|
|
257
|
+
if (!e || e.length === 0)
|
|
258
|
+
return i;
|
|
259
|
+
for (const n of e) {
|
|
260
|
+
const r = n.toString().split("."), o = B(i, r);
|
|
261
|
+
if (typeof o == "string" && o.length > 0) {
|
|
267
262
|
const l = {
|
|
268
|
-
$regex: `.*${
|
|
263
|
+
$regex: `.*${K(o)}.*`,
|
|
269
264
|
$options: "i"
|
|
270
265
|
};
|
|
271
|
-
|
|
266
|
+
i = J(i, r, l);
|
|
272
267
|
}
|
|
273
268
|
}
|
|
274
|
-
return
|
|
269
|
+
return i;
|
|
275
270
|
},
|
|
276
271
|
/**
|
|
277
272
|
* Checks if a virtual options object has a dynamic ref function.
|
|
@@ -289,14 +284,14 @@ ${V}
|
|
|
289
284
|
* @param filterFn - Function to determine if a record already exists
|
|
290
285
|
* @returns Array of records that don't exist in the database
|
|
291
286
|
*/
|
|
292
|
-
getNewRecords(t,
|
|
293
|
-
return
|
|
294
|
-
const
|
|
295
|
-
return
|
|
296
|
-
(
|
|
297
|
-
(l) =>
|
|
287
|
+
getNewRecords(t, e, i) {
|
|
288
|
+
return w(this, null, function* () {
|
|
289
|
+
const n = yield t.findAll({});
|
|
290
|
+
return n.success ? e.filter(
|
|
291
|
+
(o) => !n.result.some(
|
|
292
|
+
(l) => i(l, o)
|
|
298
293
|
)
|
|
299
|
-
) :
|
|
294
|
+
) : e;
|
|
300
295
|
});
|
|
301
296
|
},
|
|
302
297
|
/**
|
|
@@ -306,62 +301,62 @@ ${V}
|
|
|
306
301
|
* @param filterFn - Function to determine if a record exists
|
|
307
302
|
* @returns Array of existing records that match the filter criteria
|
|
308
303
|
*/
|
|
309
|
-
getExistingRecords(t,
|
|
310
|
-
return
|
|
311
|
-
const
|
|
312
|
-
return
|
|
313
|
-
(
|
|
314
|
-
(l) =>
|
|
304
|
+
getExistingRecords(t, e, i) {
|
|
305
|
+
return w(this, null, function* () {
|
|
306
|
+
const n = yield t.findAll({});
|
|
307
|
+
return n.success ? n.result.filter(
|
|
308
|
+
(o) => e.some(
|
|
309
|
+
(l) => i(o, l)
|
|
315
310
|
)
|
|
316
311
|
) : [];
|
|
317
312
|
});
|
|
318
313
|
}
|
|
319
314
|
};
|
|
320
|
-
function
|
|
321
|
-
return
|
|
322
|
-
if (!
|
|
323
|
-
return
|
|
324
|
-
const
|
|
325
|
-
for (const l of
|
|
326
|
-
typeof l == "string" ? yield
|
|
327
|
-
return
|
|
315
|
+
function D(t, e, i, n, r) {
|
|
316
|
+
return w(this, null, function* () {
|
|
317
|
+
if (!e.length || !i)
|
|
318
|
+
return e;
|
|
319
|
+
const o = Array.isArray(i) ? i : [i];
|
|
320
|
+
for (const l of o)
|
|
321
|
+
typeof l == "string" ? yield G(t, e, l, n, r) : l && typeof l == "object" && (yield et(t, e, l, n, r));
|
|
322
|
+
return e;
|
|
328
323
|
});
|
|
329
324
|
}
|
|
330
|
-
function
|
|
331
|
-
return
|
|
332
|
-
var
|
|
333
|
-
const h =
|
|
325
|
+
function G(t, e, i, n, r) {
|
|
326
|
+
return w(this, null, function* () {
|
|
327
|
+
var o, l, y, s;
|
|
328
|
+
const h = i.split(".");
|
|
334
329
|
if (h.length < 2) {
|
|
335
|
-
for (const m of
|
|
336
|
-
yield
|
|
330
|
+
for (const m of e)
|
|
331
|
+
yield F(t, m, i, n, void 0, r);
|
|
337
332
|
return;
|
|
338
333
|
}
|
|
339
334
|
const u = h[0];
|
|
340
335
|
if (!u || u.trim() === "")
|
|
341
336
|
return;
|
|
342
337
|
const R = h.slice(1).join(".");
|
|
343
|
-
for (const m of
|
|
344
|
-
const
|
|
338
|
+
for (const m of e) {
|
|
339
|
+
const j = m, O = j[u];
|
|
345
340
|
if (O && typeof O == "object") {
|
|
346
341
|
let c = r;
|
|
347
342
|
const a = c;
|
|
348
343
|
if (r && r.schema && r.schema.virtuals) {
|
|
349
344
|
const f = r.schema.virtuals[u];
|
|
350
345
|
if (f && f.options && f.options.ref) {
|
|
351
|
-
let
|
|
352
|
-
if (typeof f.options.ref == "function" ?
|
|
353
|
-
const p =
|
|
346
|
+
let b;
|
|
347
|
+
if (typeof f.options.ref == "function" ? b = f.options.ref(j) : typeof f.options.ref == "string" && (b = f.options.ref), b) {
|
|
348
|
+
const p = P(b);
|
|
354
349
|
t.models[p] && (c = t.models[p]);
|
|
355
350
|
}
|
|
356
351
|
}
|
|
357
352
|
}
|
|
358
353
|
if (!c) {
|
|
359
|
-
const f = (l = (
|
|
354
|
+
const f = (l = (o = r == null ? void 0 : r.schema) == null ? void 0 : o.statics) != null ? l : {}, p = ((r == null ? void 0 : r._virtualConfigs) || f._dynamicVirtuals || []).find((d) => d.name === u);
|
|
360
355
|
if (p && p.options && p.options.ref) {
|
|
361
356
|
let d;
|
|
362
|
-
if (typeof p.options.ref == "function" ? d = p.options.ref(
|
|
363
|
-
const
|
|
364
|
-
t.models[
|
|
357
|
+
if (typeof p.options.ref == "function" ? d = p.options.ref(j) : typeof p.options.ref == "string" && (d = p.options.ref), d) {
|
|
358
|
+
const g = P(d);
|
|
359
|
+
t.models[g] && (c = t.models[g]);
|
|
365
360
|
}
|
|
366
361
|
}
|
|
367
362
|
}
|
|
@@ -369,139 +364,139 @@ function k(t, i, e, o, r) {
|
|
|
369
364
|
const f = (s = (y = r == null ? void 0 : r.schema) == null ? void 0 : y.statics) != null ? s : {}, p = ((r == null ? void 0 : r._virtualConfigs) || f._dynamicVirtuals || []).find((d) => d.name === u);
|
|
370
365
|
if (p && p.options && p.options.ref) {
|
|
371
366
|
let d;
|
|
372
|
-
if (typeof p.options.ref == "function" ? d = p.options.ref(
|
|
373
|
-
const
|
|
374
|
-
t.models[
|
|
367
|
+
if (typeof p.options.ref == "function" ? d = p.options.ref(j) : typeof p.options.ref == "string" && (d = p.options.ref), d) {
|
|
368
|
+
const g = P(d);
|
|
369
|
+
t.models[g] && (c = t.models[g]);
|
|
375
370
|
}
|
|
376
371
|
}
|
|
377
372
|
}
|
|
378
373
|
if (Array.isArray(O))
|
|
379
374
|
for (const f of O)
|
|
380
|
-
f && typeof f == "object" && (yield
|
|
381
|
-
else O && typeof O == "object" && (yield
|
|
375
|
+
f && typeof f == "object" && (yield F(t, f, R, n, u, c));
|
|
376
|
+
else O && typeof O == "object" && (yield F(t, O, R, n, u, c));
|
|
382
377
|
}
|
|
383
378
|
}
|
|
384
379
|
});
|
|
385
380
|
}
|
|
386
|
-
function
|
|
387
|
-
return
|
|
388
|
-
const { path:
|
|
389
|
-
if (!
|
|
381
|
+
function et(t, e, i, n, r) {
|
|
382
|
+
return w(this, null, function* () {
|
|
383
|
+
const { path: o, populate: l } = i;
|
|
384
|
+
if (!o)
|
|
390
385
|
return;
|
|
391
386
|
if (!l) {
|
|
392
|
-
yield
|
|
387
|
+
yield G(t, e, o, n, r);
|
|
393
388
|
return;
|
|
394
389
|
}
|
|
395
|
-
const y =
|
|
396
|
-
for (const s of
|
|
390
|
+
const y = o;
|
|
391
|
+
for (const s of e) {
|
|
397
392
|
const h = s, u = h[y];
|
|
398
393
|
let R = r;
|
|
399
394
|
if (r && r.schema && r.schema.virtuals) {
|
|
400
395
|
const m = r.schema.virtuals[y];
|
|
401
396
|
if (m && m.options && m.options.ref) {
|
|
402
|
-
let
|
|
403
|
-
if (typeof m.options.ref == "function" ?
|
|
404
|
-
const O =
|
|
397
|
+
let j;
|
|
398
|
+
if (typeof m.options.ref == "function" ? j = m.options.ref(h) : typeof m.options.ref == "string" && (j = m.options.ref), j) {
|
|
399
|
+
const O = P(j);
|
|
405
400
|
t.models[O] && (R = t.models[O]);
|
|
406
401
|
}
|
|
407
402
|
}
|
|
408
403
|
}
|
|
409
404
|
if (!R && typeof u == "object" && u && "entityType" in u) {
|
|
410
|
-
const m =
|
|
405
|
+
const m = P(String(u.entityType));
|
|
411
406
|
t.models[m] && (R = t.models[m]);
|
|
412
407
|
}
|
|
413
408
|
if (u && typeof u == "object")
|
|
414
409
|
if (Array.isArray(u))
|
|
415
410
|
for (const m of u)
|
|
416
|
-
m && typeof m == "object" && (yield
|
|
417
|
-
else u && typeof u == "object" && (yield
|
|
411
|
+
m && typeof m == "object" && (yield D(t, [m], l, n, R));
|
|
412
|
+
else u && typeof u == "object" && (yield D(t, [u], l, n, R));
|
|
418
413
|
}
|
|
419
414
|
});
|
|
420
415
|
}
|
|
421
|
-
function
|
|
422
|
-
if (!
|
|
416
|
+
function E(t, e, i, n) {
|
|
417
|
+
if (!i || !e || !e.schema)
|
|
423
418
|
return;
|
|
424
|
-
const r =
|
|
425
|
-
let
|
|
419
|
+
const r = i.split(".");
|
|
420
|
+
let o = e.schema;
|
|
426
421
|
for (let l = 0; l < r.length; l++) {
|
|
427
422
|
const y = r[l];
|
|
428
|
-
if (
|
|
429
|
-
const s =
|
|
423
|
+
if (o && o.virtuals && y) {
|
|
424
|
+
const s = o.virtuals[y];
|
|
430
425
|
if (s && s.options && s.options.ref) {
|
|
431
426
|
let h;
|
|
432
|
-
if (typeof s.options.ref == "function" ? h = s.options.ref(
|
|
427
|
+
if (typeof s.options.ref == "function" ? h = s.options.ref(n) : typeof s.options.ref == "string" && (h = s.options.ref), h && typeof h == "string") {
|
|
433
428
|
if (l === r.length - 1)
|
|
434
429
|
return h;
|
|
435
430
|
const u = t.models[h];
|
|
436
431
|
if (u && u.schema) {
|
|
437
|
-
|
|
432
|
+
o = u.schema;
|
|
438
433
|
continue;
|
|
439
434
|
}
|
|
440
435
|
}
|
|
441
436
|
}
|
|
442
437
|
}
|
|
443
|
-
if (
|
|
444
|
-
const s =
|
|
438
|
+
if (o && o.paths && y) {
|
|
439
|
+
const s = o.paths[y];
|
|
445
440
|
if (s && s.schema) {
|
|
446
|
-
|
|
441
|
+
o = s.schema;
|
|
447
442
|
continue;
|
|
448
443
|
}
|
|
449
444
|
}
|
|
450
445
|
return;
|
|
451
446
|
}
|
|
452
447
|
}
|
|
453
|
-
function
|
|
454
|
-
if (
|
|
455
|
-
for (const
|
|
456
|
-
const
|
|
457
|
-
if (r && (r.paths && r.paths[
|
|
458
|
-
return
|
|
448
|
+
function it(t, e) {
|
|
449
|
+
if (e)
|
|
450
|
+
for (const i of Object.keys(t.models)) {
|
|
451
|
+
const n = t.models[i], r = n == null ? void 0 : n.schema;
|
|
452
|
+
if (r && (r.paths && r.paths[e] || r.virtuals && r.virtuals[e]))
|
|
453
|
+
return n;
|
|
459
454
|
}
|
|
460
455
|
}
|
|
461
|
-
function
|
|
462
|
-
const
|
|
463
|
-
if (
|
|
464
|
-
for (const
|
|
465
|
-
const r = t.models[
|
|
466
|
-
if (
|
|
456
|
+
function rt(t, e) {
|
|
457
|
+
const i = (e || "").split(".")[0] || "";
|
|
458
|
+
if (i)
|
|
459
|
+
for (const n of Object.keys(t.models)) {
|
|
460
|
+
const r = t.models[n], o = r == null ? void 0 : r.schema;
|
|
461
|
+
if (o && (o.paths && o.paths[i] || o.virtuals && o.virtuals[i]))
|
|
467
462
|
return r;
|
|
468
463
|
}
|
|
469
464
|
}
|
|
470
|
-
function
|
|
471
|
-
return
|
|
465
|
+
function F(t, e, i, n, r, o) {
|
|
466
|
+
return w(this, null, function* () {
|
|
472
467
|
var l, y;
|
|
473
|
-
let s =
|
|
468
|
+
let s = e.__t;
|
|
474
469
|
if (!s) {
|
|
475
|
-
if (
|
|
476
|
-
const c = r ? `${r}.${
|
|
477
|
-
let f =
|
|
470
|
+
if (o) {
|
|
471
|
+
const c = r ? `${r}.${i}` : i, a = (c || "").split(".")[0] || "";
|
|
472
|
+
let f = o;
|
|
478
473
|
if (!!!((l = f == null ? void 0 : f.schema) != null && l.paths && f.schema.paths[a] || (y = f == null ? void 0 : f.schema) != null && y.virtuals && f.schema.virtuals[a])) {
|
|
479
|
-
const d =
|
|
474
|
+
const d = rt(t, c);
|
|
480
475
|
d && (f = d);
|
|
481
476
|
}
|
|
482
|
-
const p =
|
|
477
|
+
const p = E(t, f, c, e);
|
|
483
478
|
if (p)
|
|
484
479
|
s = p;
|
|
485
480
|
else {
|
|
486
481
|
const d = (c.includes(".") ? c.split(".").pop() : c) || "";
|
|
487
482
|
if (d) {
|
|
488
|
-
const
|
|
489
|
-
if (
|
|
490
|
-
const
|
|
491
|
-
|
|
483
|
+
const g = it(t, d);
|
|
484
|
+
if (g) {
|
|
485
|
+
const N = E(t, g, c, e);
|
|
486
|
+
N && (s = N);
|
|
492
487
|
}
|
|
493
488
|
}
|
|
494
489
|
}
|
|
495
490
|
}
|
|
496
|
-
if (
|
|
497
|
-
const c =
|
|
491
|
+
if (n && n.length > 0) {
|
|
492
|
+
const c = i.split(".").pop() || "", a = n.find((f) => f.name === c);
|
|
498
493
|
if (a && a.options.ref) {
|
|
499
494
|
let f;
|
|
500
|
-
typeof a.options.ref == "function" ? f = a.options.ref(
|
|
495
|
+
typeof a.options.ref == "function" ? f = a.options.ref(e) : typeof a.options.ref == "string" && (f = a.options.ref), f && typeof f == "string" && (s = f);
|
|
501
496
|
}
|
|
502
497
|
}
|
|
503
498
|
if (!s) {
|
|
504
|
-
for (const [c, a] of Object.entries(
|
|
499
|
+
for (const [c, a] of Object.entries(e))
|
|
505
500
|
if (c === "entityType" && typeof a == "string") {
|
|
506
501
|
s = a;
|
|
507
502
|
break;
|
|
@@ -509,90 +504,90 @@ function P(t, i, e, o, r, n) {
|
|
|
509
504
|
if (s && t.models[s]) {
|
|
510
505
|
const c = t.models[s];
|
|
511
506
|
if (c && c.schema) {
|
|
512
|
-
const a = c.schema, f =
|
|
507
|
+
const a = c.schema, f = i.split(".").pop() || "", b = (d, g = "root") => {
|
|
513
508
|
if (!d || !d.virtuals)
|
|
514
509
|
return;
|
|
515
|
-
const
|
|
516
|
-
for (const _ of Object.keys(
|
|
510
|
+
const N = d.virtuals;
|
|
511
|
+
for (const _ of Object.keys(N))
|
|
517
512
|
if (_ === f) {
|
|
518
|
-
const v =
|
|
513
|
+
const v = N[_];
|
|
519
514
|
if (v && v.options && v.options.ref) {
|
|
520
|
-
let
|
|
521
|
-
if (typeof v.options.ref == "function" ?
|
|
522
|
-
return
|
|
515
|
+
let S;
|
|
516
|
+
if (typeof v.options.ref == "function" ? S = v.options.ref(e) : typeof v.options.ref == "string" && (S = v.options.ref), S && typeof S == "string")
|
|
517
|
+
return S;
|
|
523
518
|
}
|
|
524
519
|
}
|
|
525
520
|
if (d.paths)
|
|
526
521
|
for (const _ of Object.keys(d.paths)) {
|
|
527
522
|
const v = d.paths[_];
|
|
528
523
|
if (v && v.schema) {
|
|
529
|
-
const
|
|
530
|
-
if (
|
|
531
|
-
return
|
|
524
|
+
const S = b(v.schema, `${g}.${_}`);
|
|
525
|
+
if (S)
|
|
526
|
+
return S;
|
|
532
527
|
}
|
|
533
528
|
}
|
|
534
|
-
}, p =
|
|
529
|
+
}, p = b(a);
|
|
535
530
|
p && (s = p);
|
|
536
531
|
}
|
|
537
532
|
}
|
|
538
533
|
}
|
|
539
534
|
if (!s) {
|
|
540
|
-
const c =
|
|
541
|
-
if (
|
|
542
|
-
const a =
|
|
535
|
+
const c = i.split(".").pop() || "";
|
|
536
|
+
if (o && o.schema) {
|
|
537
|
+
const a = o.schema, f = (p, d = "root") => {
|
|
543
538
|
if (!p || !p.virtuals)
|
|
544
539
|
return;
|
|
545
|
-
const
|
|
546
|
-
for (const
|
|
547
|
-
if (
|
|
548
|
-
const _ =
|
|
540
|
+
const g = p.virtuals;
|
|
541
|
+
for (const N of Object.keys(g))
|
|
542
|
+
if (N === c) {
|
|
543
|
+
const _ = g[N];
|
|
549
544
|
if (_ && _.options && _.options.ref) {
|
|
550
545
|
let v;
|
|
551
|
-
if (typeof _.options.ref == "function" ? v = _.options.ref(
|
|
546
|
+
if (typeof _.options.ref == "function" ? v = _.options.ref(e) : typeof _.options.ref == "string" && (v = _.options.ref), v && typeof v == "string")
|
|
552
547
|
return v;
|
|
553
548
|
}
|
|
554
549
|
}
|
|
555
550
|
if (p.paths)
|
|
556
|
-
for (const
|
|
557
|
-
const _ = p.paths[
|
|
551
|
+
for (const N of Object.keys(p.paths)) {
|
|
552
|
+
const _ = p.paths[N];
|
|
558
553
|
if (_ && _.schema) {
|
|
559
|
-
const v = f(_.schema, `${d}.${
|
|
554
|
+
const v = f(_.schema, `${d}.${N}`);
|
|
560
555
|
if (v)
|
|
561
556
|
return v;
|
|
562
557
|
}
|
|
563
558
|
}
|
|
564
|
-
},
|
|
565
|
-
|
|
559
|
+
}, b = f(a);
|
|
560
|
+
b && (s = b);
|
|
566
561
|
}
|
|
567
|
-
if (!s &&
|
|
568
|
-
const a =
|
|
562
|
+
if (!s && o) {
|
|
563
|
+
const a = E(t, o, i, e);
|
|
569
564
|
a && (s = a);
|
|
570
565
|
}
|
|
571
|
-
if (!s &&
|
|
572
|
-
const a =
|
|
566
|
+
if (!s && n && n.length > 0) {
|
|
567
|
+
const a = n.find((f) => f.name === c);
|
|
573
568
|
if (a && a.options.ref) {
|
|
574
569
|
let f;
|
|
575
|
-
typeof a.options.ref == "function" ? f = a.options.ref(
|
|
570
|
+
typeof a.options.ref == "function" ? f = a.options.ref(e) : typeof a.options.ref == "string" && (f = a.options.ref), f && typeof f == "string" && (s = f);
|
|
576
571
|
}
|
|
577
572
|
}
|
|
578
573
|
}
|
|
579
574
|
if (!s) {
|
|
580
|
-
const c =
|
|
575
|
+
const c = i.split(".").pop() || "", a = c ? c.charAt(0).toUpperCase() + c.slice(1) : "";
|
|
581
576
|
a && t.models[a] && (s = a);
|
|
582
577
|
}
|
|
583
578
|
}
|
|
584
579
|
const h = t.models[s];
|
|
585
580
|
if (!h)
|
|
586
581
|
return;
|
|
587
|
-
const u = `${
|
|
582
|
+
const u = `${i}Id`, R = `${i}Ids`, m = e[u] || e[R] || e[i];
|
|
588
583
|
if (!m)
|
|
589
584
|
return;
|
|
590
|
-
const
|
|
591
|
-
O.length > 0 && (Array.isArray(m) ? i
|
|
585
|
+
const j = Array.isArray(m) ? m : [m], O = yield h.find({ id: { $in: j } }).lean();
|
|
586
|
+
O.length > 0 && (Array.isArray(m) ? e[i] = O : e[i] = O[0]);
|
|
592
587
|
});
|
|
593
588
|
}
|
|
594
589
|
export {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
590
|
+
D as applyNestedPopulate,
|
|
591
|
+
P as convertEnumToModelName,
|
|
592
|
+
A as mongo
|
|
598
593
|
};
|