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