@cyberskill/shared 2.27.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 +6 -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 -5
- package/dist/node/cli/index.js +109 -170
- 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 +4 -1
- package/dist/node/fs/fs.util.d.ts +8 -0
- package/dist/node/fs/fs.util.js +46 -53
- package/dist/node/fs/index.cjs +1 -1
- package/dist/node/fs/index.js +13 -12
- 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.type.js +3 -3
- package/dist/node/mongo/mongo.util.cjs +2 -5
- package/dist/node/mongo/mongo.util.js +308 -354
- 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 +11 -0
- package/dist/util/common/common.util.js +33 -37
- 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 +22 -20
- package/dist/util/object/object.util.cjs +1 -1
- package/dist/util/object/object.util.js +70 -70
- 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 +53 -44
- package/public/tsconfig.base.json +7 -3
- package/README.md +0 -470
- package/dist/node/mongo/mongo.util.d.ts +0 -1040
- /package/dist/node_modules/.pnpm/{vitest@4.0.17_@types_node@25.0.9_jiti@2.6.1_jsdom@27.4.0_@noble_hashes@1.8.0__sass@1.97.2_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.17_@types_node@25.0.9_jiti@2.6.1_jsdom@27.4.0_@noble_hashes@1.8.0__sass@1.97.2_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
|
|
1
|
+
import I from "migrate-mongo";
|
|
2
|
+
import $ from "mongoose-aggregate-paginate-v2";
|
|
3
|
+
import G from "mongoose-paginate-v2";
|
|
4
4
|
import { randomUUID as x } from "node:crypto";
|
|
5
|
-
import { deepClone as
|
|
6
|
-
import { regexSearchMapper as
|
|
7
|
-
import { writeFileSync as
|
|
8
|
-
import { PATH as
|
|
9
|
-
import { validate as
|
|
10
|
-
|
|
11
|
-
for (var e in i || (i = {}))
|
|
12
|
-
M.call(i, e) && D(t, e, i[e]);
|
|
13
|
-
if ($)
|
|
14
|
-
for (var e of $(i))
|
|
15
|
-
tt.call(i, e) && D(t, e, i[e]);
|
|
16
|
-
return t;
|
|
17
|
-
}, it = (t, i) => Y(t, Z(i)), S = (t, i, e) => new Promise((o, r) => {
|
|
18
|
-
var n = (s) => {
|
|
19
|
-
try {
|
|
20
|
-
y(e.next(s));
|
|
21
|
-
} catch (h) {
|
|
22
|
-
r(h);
|
|
23
|
-
}
|
|
24
|
-
}, l = (s) => {
|
|
25
|
-
try {
|
|
26
|
-
y(e.throw(s));
|
|
27
|
-
} catch (h) {
|
|
28
|
-
r(h);
|
|
29
|
-
}
|
|
30
|
-
}, y = (s) => s.done ? o(s.value) : Promise.resolve(s.value).then(n, l);
|
|
31
|
-
y((e = e.apply(t, i)).next());
|
|
32
|
-
});
|
|
33
|
-
function E(t) {
|
|
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
|
|
@@ -57,8 +34,8 @@ const I = {
|
|
|
57
34
|
* @param schema - The Mongoose schema to apply plugins to.
|
|
58
35
|
* @param plugins - An array of plugin functions or false values to filter and apply.
|
|
59
36
|
*/
|
|
60
|
-
applyPlugins(t,
|
|
61
|
-
|
|
37
|
+
applyPlugins(t, e) {
|
|
38
|
+
e.filter((i) => typeof i == "function").forEach((i) => t.plugin(i));
|
|
62
39
|
},
|
|
63
40
|
/**
|
|
64
41
|
* Applies middleware functions to a Mongoose schema.
|
|
@@ -67,9 +44,9 @@ const I = {
|
|
|
67
44
|
* @param schema - The Mongoose schema to apply middleware to.
|
|
68
45
|
* @param middlewares - An array of middleware configurations with method, pre, and post functions.
|
|
69
46
|
*/
|
|
70
|
-
applyMiddlewares(t,
|
|
71
|
-
|
|
72
|
-
|
|
47
|
+
applyMiddlewares(t, e) {
|
|
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
|
/**
|
|
@@ -103,33 +80,32 @@ const I = {
|
|
|
103
80
|
*/
|
|
104
81
|
createSchema({
|
|
105
82
|
mongoose: t,
|
|
106
|
-
schema:
|
|
107
|
-
virtuals:
|
|
108
|
-
standalone:
|
|
83
|
+
schema: e,
|
|
84
|
+
virtuals: i = [],
|
|
85
|
+
standalone: a = !1
|
|
109
86
|
}) {
|
|
110
|
-
const r = new t.Schema(
|
|
87
|
+
const r = new t.Schema(e, {
|
|
111
88
|
toJSON: { virtuals: !0 },
|
|
112
89
|
// So `res.json()` and other `JSON.stringify()` functions include virtuals
|
|
113
90
|
toObject: { virtuals: !0 }
|
|
114
91
|
// So `console.log()` and other functions that use `toObject()` include virtuals
|
|
115
92
|
});
|
|
116
|
-
return
|
|
117
|
-
if (
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
name:
|
|
121
|
-
options:
|
|
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({
|
|
97
|
+
name: o,
|
|
98
|
+
options: s
|
|
122
99
|
});
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return ((u = this._populated) == null ? void 0 : u[n]) || (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.
|
|
@@ -149,24 +125,24 @@ const I = {
|
|
|
149
125
|
*/
|
|
150
126
|
createModel({
|
|
151
127
|
mongoose: t,
|
|
152
|
-
name:
|
|
153
|
-
schema:
|
|
154
|
-
virtuals:
|
|
128
|
+
name: e,
|
|
129
|
+
schema: i,
|
|
130
|
+
virtuals: a = [],
|
|
155
131
|
pagination: r = !0,
|
|
156
|
-
aggregate:
|
|
157
|
-
middlewares:
|
|
132
|
+
aggregate: o = !0,
|
|
133
|
+
middlewares: s = []
|
|
158
134
|
}) {
|
|
159
|
-
if (!
|
|
135
|
+
if (!e)
|
|
160
136
|
throw new Error("Model name is required.");
|
|
161
|
-
if (t.models[
|
|
162
|
-
return t.models[
|
|
163
|
-
const
|
|
164
|
-
(r ||
|
|
165
|
-
r &&
|
|
166
|
-
|
|
167
|
-
]),
|
|
168
|
-
const
|
|
169
|
-
return
|
|
137
|
+
if (t.models[e])
|
|
138
|
+
return t.models[e];
|
|
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 I = {
|
|
|
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 !W.isEmpty(t);
|
|
187
|
-
});
|
|
160
|
+
return async function(t) {
|
|
161
|
+
return !J.isEmpty(t);
|
|
188
162
|
};
|
|
189
163
|
},
|
|
190
164
|
/**
|
|
@@ -197,13 +171,11 @@ const I = {
|
|
|
197
171
|
* @throws {Error} When fields is not a non-empty array of strings.
|
|
198
172
|
*/
|
|
199
173
|
isUnique(t) {
|
|
200
|
-
return function(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
return !(yield this.constructor.exists(e));
|
|
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 I = {
|
|
|
216
188
|
* @throws {Error} When regexArray is not an array of valid RegExp objects.
|
|
217
189
|
*/
|
|
218
190
|
matchesRegex(t) {
|
|
219
|
-
return (
|
|
220
|
-
if (!Array.isArray(t) || t.some((
|
|
191
|
+
return async (e) => {
|
|
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
|
-
return t.every((
|
|
223
|
-
}
|
|
194
|
+
return t.every((i) => i.test(e));
|
|
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
|
|
@@ -236,16 +209,11 @@ const I = {
|
|
|
236
209
|
* @param options - Migration configuration options to write to the config file.
|
|
237
210
|
*/
|
|
238
211
|
setConfig: (t) => {
|
|
239
|
-
const
|
|
212
|
+
const e = `// This file is automatically generated by the Cyberskill CLI.
|
|
240
213
|
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);
|
|
214
|
+
q(V.MIGRATE_MONGO_CONFIG, e), B(V.GIT_IGNORE, P);
|
|
247
215
|
}
|
|
248
|
-
}
|
|
216
|
+
},
|
|
249
217
|
/**
|
|
250
218
|
* Converts string values in a filter to regex patterns for case-insensitive search.
|
|
251
219
|
* This function recursively processes a filter object and converts string values in specified fields
|
|
@@ -255,23 +223,23 @@ ${V}
|
|
|
255
223
|
* @param fields - An array of field names to convert to regex patterns.
|
|
256
224
|
* @returns A new filter object with string values converted to regex patterns.
|
|
257
225
|
*/
|
|
258
|
-
regexify(t,
|
|
226
|
+
regexify(t, e) {
|
|
259
227
|
if (!t)
|
|
260
228
|
return {};
|
|
261
|
-
let
|
|
262
|
-
if (!
|
|
263
|
-
return
|
|
264
|
-
for (const
|
|
265
|
-
const r =
|
|
266
|
-
if (typeof
|
|
267
|
-
const
|
|
268
|
-
$regex: `.*${
|
|
229
|
+
let i = D(t);
|
|
230
|
+
if (!e || e.length === 0)
|
|
231
|
+
return i;
|
|
232
|
+
for (const a of e) {
|
|
233
|
+
const r = a.toString().split("."), o = k(i, r);
|
|
234
|
+
if (typeof o == "string" && o.length > 0) {
|
|
235
|
+
const s = {
|
|
236
|
+
$regex: `.*${U(o)}.*`,
|
|
269
237
|
$options: "i"
|
|
270
238
|
};
|
|
271
|
-
|
|
239
|
+
i = C(i, r, s);
|
|
272
240
|
}
|
|
273
241
|
}
|
|
274
|
-
return
|
|
242
|
+
return i;
|
|
275
243
|
},
|
|
276
244
|
/**
|
|
277
245
|
* Checks if a virtual options object has a dynamic ref function.
|
|
@@ -289,15 +257,13 @@ ${V}
|
|
|
289
257
|
* @param filterFn - Function to determine if a record already exists
|
|
290
258
|
* @returns Array of records that don't exist in the database
|
|
291
259
|
*/
|
|
292
|
-
getNewRecords(t,
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
) : i;
|
|
300
|
-
});
|
|
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;
|
|
301
267
|
},
|
|
302
268
|
/**
|
|
303
269
|
* Generic utility function to get existing records that match the filter criteria
|
|
@@ -306,293 +272,281 @@ ${V}
|
|
|
306
272
|
* @param filterFn - Function to determine if a record exists
|
|
307
273
|
* @returns Array of existing records that match the filter criteria
|
|
308
274
|
*/
|
|
309
|
-
getExistingRecords(t,
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
) : [];
|
|
317
|
-
});
|
|
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
|
+
) : [];
|
|
318
282
|
}
|
|
319
283
|
};
|
|
320
|
-
function
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
return i;
|
|
328
|
-
});
|
|
284
|
+
async function _(t, e, i, a, r) {
|
|
285
|
+
if (!e.length || !i)
|
|
286
|
+
return e;
|
|
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;
|
|
329
291
|
}
|
|
330
|
-
function
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const
|
|
348
|
-
if (
|
|
349
|
-
|
|
350
|
-
if (f
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const p = E(g);
|
|
354
|
-
t.models[p] && (c = t.models[p]);
|
|
355
|
-
}
|
|
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]);
|
|
356
315
|
}
|
|
357
316
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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]);
|
|
366
325
|
}
|
|
367
326
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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]);
|
|
376
335
|
}
|
|
377
336
|
}
|
|
378
|
-
if (Array.isArray(O))
|
|
379
|
-
for (const f of O)
|
|
380
|
-
f && typeof f == "object" && (yield P(t, f, R, o, u, c));
|
|
381
|
-
else O && typeof O == "object" && (yield P(t, O, R, o, u, c));
|
|
382
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);
|
|
383
342
|
}
|
|
384
|
-
}
|
|
343
|
+
}
|
|
385
344
|
}
|
|
386
|
-
function
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
t.models[O] && (R = t.models[O]);
|
|
406
|
-
}
|
|
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]);
|
|
407
364
|
}
|
|
408
365
|
}
|
|
409
|
-
if (!R && typeof u == "object" && u && "entityType" in u) {
|
|
410
|
-
const m = E(String(u.entityType));
|
|
411
|
-
t.models[m] && (R = t.models[m]);
|
|
412
|
-
}
|
|
413
|
-
if (u && typeof u == "object")
|
|
414
|
-
if (Array.isArray(u))
|
|
415
|
-
for (const m of u)
|
|
416
|
-
m && typeof m == "object" && (yield C(t, [m], l, o, R));
|
|
417
|
-
else u && typeof u == "object" && (yield C(t, [u], l, o, R));
|
|
418
366
|
}
|
|
419
|
-
|
|
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
|
+
}
|
|
420
377
|
}
|
|
421
|
-
function
|
|
422
|
-
if (!
|
|
378
|
+
function S(t, e, i, a) {
|
|
379
|
+
if (!i || !e || !e.schema)
|
|
423
380
|
return;
|
|
424
|
-
const r =
|
|
425
|
-
let
|
|
426
|
-
for (let
|
|
427
|
-
const
|
|
428
|
-
if (
|
|
429
|
-
const
|
|
430
|
-
if (
|
|
431
|
-
let
|
|
432
|
-
if (typeof
|
|
433
|
-
if (
|
|
434
|
-
return
|
|
435
|
-
const
|
|
436
|
-
if (
|
|
437
|
-
|
|
381
|
+
const r = i.split(".");
|
|
382
|
+
let o = e.schema;
|
|
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;
|
|
438
395
|
continue;
|
|
439
396
|
}
|
|
440
397
|
}
|
|
441
398
|
}
|
|
442
399
|
}
|
|
443
|
-
if (
|
|
444
|
-
const
|
|
445
|
-
if (
|
|
446
|
-
|
|
400
|
+
if (o && o.paths && u) {
|
|
401
|
+
const p = o.paths[u];
|
|
402
|
+
if (p && p.schema) {
|
|
403
|
+
o = p.schema;
|
|
447
404
|
continue;
|
|
448
405
|
}
|
|
449
406
|
}
|
|
450
407
|
return;
|
|
451
408
|
}
|
|
452
409
|
}
|
|
453
|
-
function
|
|
454
|
-
if (
|
|
455
|
-
for (const
|
|
456
|
-
const
|
|
457
|
-
if (r && (r.paths && r.paths[
|
|
458
|
-
return
|
|
410
|
+
function L(t, e) {
|
|
411
|
+
if (e)
|
|
412
|
+
for (const i of Object.keys(t.models)) {
|
|
413
|
+
const a = t.models[i], r = a?.schema;
|
|
414
|
+
if (r && (r.paths && r.paths[e] || r.virtuals && r.virtuals[e]))
|
|
415
|
+
return a;
|
|
459
416
|
}
|
|
460
417
|
}
|
|
461
|
-
function
|
|
462
|
-
const
|
|
463
|
-
if (
|
|
464
|
-
for (const
|
|
465
|
-
const r = t.models[
|
|
466
|
-
if (
|
|
418
|
+
function H(t, e) {
|
|
419
|
+
const i = (e || "").split(".")[0] || "";
|
|
420
|
+
if (i)
|
|
421
|
+
for (const a of Object.keys(t.models)) {
|
|
422
|
+
const r = t.models[a], o = r?.schema;
|
|
423
|
+
if (o && (o.paths && o.paths[i] || o.virtuals && o.virtuals[i]))
|
|
467
424
|
return r;
|
|
468
425
|
}
|
|
469
426
|
}
|
|
470
|
-
function
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
const
|
|
487
|
-
if (
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
const j = F(t, b, c, i);
|
|
491
|
-
j && (s = j);
|
|
492
|
-
}
|
|
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);
|
|
493
447
|
}
|
|
494
448
|
}
|
|
495
449
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
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);
|
|
502
456
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
if (s && t.models[s]) {
|
|
510
|
-
const c = t.models[s];
|
|
511
|
-
if (c && c.schema) {
|
|
512
|
-
const a = c.schema, f = e.split(".").pop() || "", g = (d, b = "root") => {
|
|
513
|
-
if (!d || !d.virtuals)
|
|
514
|
-
return;
|
|
515
|
-
const j = d.virtuals;
|
|
516
|
-
for (const _ of Object.keys(j))
|
|
517
|
-
if (_ === f) {
|
|
518
|
-
const v = j[_];
|
|
519
|
-
if (v && v.options && v.options.ref) {
|
|
520
|
-
let w;
|
|
521
|
-
if (typeof v.options.ref == "function" ? w = v.options.ref(i) : typeof v.options.ref == "string" && (w = v.options.ref), w && typeof w == "string")
|
|
522
|
-
return w;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
if (d.paths)
|
|
526
|
-
for (const _ of Object.keys(d.paths)) {
|
|
527
|
-
const v = d.paths[_];
|
|
528
|
-
if (v && v.schema) {
|
|
529
|
-
const w = g(v.schema, `${b}.${_}`);
|
|
530
|
-
if (w)
|
|
531
|
-
return w;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}, p = g(a);
|
|
535
|
-
p && (s = p);
|
|
536
|
-
}
|
|
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;
|
|
537
463
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
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)
|
|
544
469
|
return;
|
|
545
|
-
const
|
|
546
|
-
for (const
|
|
547
|
-
if (
|
|
548
|
-
const
|
|
549
|
-
if (
|
|
550
|
-
let
|
|
551
|
-
if (typeof
|
|
552
|
-
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;
|
|
553
478
|
}
|
|
554
479
|
}
|
|
555
|
-
if (
|
|
556
|
-
for (const
|
|
557
|
-
const
|
|
558
|
-
if (
|
|
559
|
-
const
|
|
560
|
-
if (
|
|
561
|
-
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;
|
|
562
487
|
}
|
|
563
488
|
}
|
|
564
|
-
},
|
|
565
|
-
|
|
566
|
-
}
|
|
567
|
-
if (!s && n) {
|
|
568
|
-
const a = F(t, n, e, i);
|
|
569
|
-
a && (s = a);
|
|
570
|
-
}
|
|
571
|
-
if (!s && o && o.length > 0) {
|
|
572
|
-
const a = o.find((f) => f.name === c);
|
|
573
|
-
if (a && a.options.ref) {
|
|
574
|
-
let f;
|
|
575
|
-
typeof a.options.ref == "function" ? f = a.options.ref(i) : typeof a.options.ref == "string" && (f = a.options.ref), f && typeof f == "string" && (s = f);
|
|
576
|
-
}
|
|
489
|
+
}, v = m(c);
|
|
490
|
+
v && (s = v);
|
|
577
491
|
}
|
|
578
492
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
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);
|
|
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
|
+
}
|
|
582
532
|
}
|
|
583
533
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
}
|
|
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);
|
|
537
|
+
}
|
|
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]);
|
|
593
547
|
}
|
|
594
548
|
export {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
549
|
+
_ as applyNestedPopulate,
|
|
550
|
+
A as convertEnumToModelName,
|
|
551
|
+
R as mongo
|
|
598
552
|
};
|