@cyberskill/shared 1.217.0 → 2.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.
Files changed (87) hide show
  1. package/README.md +330 -222
  2. package/dist/config/config.util.d.ts +17 -0
  3. package/dist/config/env/env.util.d.ts +26 -0
  4. package/dist/config/eslint/index.d.ts +4 -0
  5. package/dist/config/graphql-codegen/graphql-codegen.util.d.ts +23 -0
  6. package/dist/config/vitest/vitest.e2e.cjs +1 -1
  7. package/dist/config/vitest/vitest.e2e.d.ts +16 -0
  8. package/dist/config/vitest/vitest.e2e.js +1 -1
  9. package/dist/config/vitest/vitest.unit.cjs +1 -1
  10. package/dist/config/vitest/vitest.unit.d.ts +18 -0
  11. package/dist/config/vitest/vitest.unit.js +1 -1
  12. package/dist/constant/common.d.ts +4 -0
  13. package/dist/constant/index.d.ts +3 -0
  14. package/dist/node/apollo-server/apollo-server.util.d.ts +14 -0
  15. package/dist/node/command/command.type.d.ts +26 -6
  16. package/dist/node/command/command.util.d.ts +50 -0
  17. package/dist/node/express/express.util.d.ts +47 -0
  18. package/dist/node/fs/fs.type.d.ts +6 -0
  19. package/dist/node/fs/fs.util.d.ts +48 -1
  20. package/dist/node/log/log.type.d.ts +6 -1
  21. package/dist/node/log/log.util.cjs +1 -1
  22. package/dist/node/log/log.util.d.ts +30 -2
  23. package/dist/node/log/log.util.js +33 -20
  24. package/dist/node/mongo/mongo.constant.d.ts +5 -0
  25. package/dist/node/mongo/mongo.type.d.ts +4 -4
  26. package/dist/node/mongo/mongo.util.cjs +5 -5
  27. package/dist/node/mongo/mongo.util.d.ts +337 -3
  28. package/dist/node/mongo/mongo.util.js +406 -79
  29. package/dist/node/package/package.type.d.ts +2 -2
  30. package/dist/node/package/package.util.cjs +1 -1
  31. package/dist/node/package/package.util.d.ts +52 -1
  32. package/dist/node/package/package.util.js +97 -92
  33. package/dist/node/path/path.constant.d.ts +9 -0
  34. package/dist/node/path/path.util.d.ts +24 -0
  35. package/dist/node/storage/storage.util.d.ts +44 -0
  36. package/dist/node/storage/storage.util.js +39 -0
  37. package/dist/node/upload/upload.util.d.ts +21 -0
  38. package/dist/node/ws/ts.util.d.ts +16 -0
  39. package/dist/react/apollo-client/apollo-client.component.d.ts +19 -1
  40. package/dist/react/apollo-client/apollo-client.component.js +1 -4
  41. package/dist/react/apollo-client/apollo-client.constant.d.ts +5 -0
  42. package/dist/react/apollo-client/apollo-client.context.d.ts +15 -0
  43. package/dist/react/apollo-client/apollo-client.hook.d.ts +12 -0
  44. package/dist/react/apollo-client/apollo-client.util.d.ts +48 -0
  45. package/dist/react/apollo-client/apollo-client.util.js +9 -0
  46. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.d.ts +19 -1
  47. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js +1 -4
  48. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.d.ts +10 -0
  49. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.d.ts +10 -0
  50. package/dist/react/apollo-error/apollo-error.component.cjs +1 -1
  51. package/dist/react/apollo-error/apollo-error.component.d.ts +17 -0
  52. package/dist/react/apollo-error/apollo-error.component.js +10 -10
  53. package/dist/react/apollo-error/apollo-error.hook.d.ts +12 -0
  54. package/dist/react/apollo-error/apollo-error.provider.d.ts +15 -0
  55. package/dist/react/apollo-error/apollo-error.util.d.ts +17 -0
  56. package/dist/react/i18next/i18next.hook.d.ts +9 -0
  57. package/dist/react/i18next/i18next.util.d.ts +10 -0
  58. package/dist/react/loading/loading.component.d.ts +21 -0
  59. package/dist/react/loading/loading.hook.d.ts +12 -0
  60. package/dist/react/loading/loading.provider.d.ts +15 -0
  61. package/dist/react/log/log.util.d.ts +17 -0
  62. package/dist/react/next-intl/next-intl.constant.d.ts +9 -0
  63. package/dist/react/next-intl/next-intl.hoc.d.ts +16 -0
  64. package/dist/react/next-intl/next-intl.hook.d.ts +21 -0
  65. package/dist/react/next-intl/next-intl.provider.d.ts +21 -0
  66. package/dist/react/storage/storage.hook.d.ts +19 -0
  67. package/dist/react/storage/storage.hook.js +28 -30
  68. package/dist/react/storage/storage.util.d.ts +39 -0
  69. package/dist/react/storage/storage.util.js +33 -0
  70. package/dist/react/userback/userback.component.d.ts +18 -0
  71. package/dist/typescript/common.type.d.ts +6 -0
  72. package/dist/typescript/index.d.ts +3 -0
  73. package/dist/util/common/common.util.d.ts +19 -7
  74. package/dist/util/common/index.d.ts +3 -0
  75. package/dist/util/index.d.ts +3 -0
  76. package/dist/util/object/object.util.d.ts +25 -12
  77. package/dist/util/serializer/serializer.type.d.ts +1 -1
  78. package/dist/util/serializer/serializer.util.d.ts +8 -0
  79. package/dist/util/serializer/serializer.util.js +4 -4
  80. package/dist/util/string/string.util.cjs +1 -1
  81. package/dist/util/string/string.util.d.ts +30 -17
  82. package/dist/util/string/string.util.js +14 -16
  83. package/dist/util/validate/validate.util.d.ts +9 -3
  84. package/dist/util/validate/validate.util.js +5 -3
  85. package/package.json +7 -5
  86. /package/dist/node_modules/.pnpm/{vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.14_@vitest_browser@3.2.4_jiti@2.4.2_j_5b4f3b6d03b5e1745ce439b75ce4a42f → vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.15_@vitest_browser@3.2.4_jiti@2.4.2_j_e4a333d8aa4b05d17db10875e249d94f}/node_modules/vitest/dist/config.cjs +0 -0
  87. /package/dist/node_modules/.pnpm/{vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.14_@vitest_browser@3.2.4_jiti@2.4.2_j_5b4f3b6d03b5e1745ce439b75ce4a42f → vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.15_@vitest_browser@3.2.4_jiti@2.4.2_j_e4a333d8aa4b05d17db10875e249d94f}/node_modules/vitest/dist/config.js +0 -0
@@ -1,68 +1,110 @@
1
- import { cloneDeep as v, isObject as S } from "lodash-es";
2
- import w from "migrate-mongo";
3
- import { Document as I } from "mongoose";
4
- import C from "mongoose-aggregate-paginate-v2";
5
- import { default as ae } from "mongoose-aggregate-paginate-v2";
6
- import P from "mongoose-paginate-v2";
1
+ import { cloneDeep as C, isObject as N } from "lodash-es";
2
+ import I from "migrate-mongo";
3
+ import { Document as P } from "mongoose";
4
+ import w from "mongoose-aggregate-paginate-v2";
5
+ import { default as de } from "mongoose-aggregate-paginate-v2";
6
+ import A from "mongoose-paginate-v2";
7
7
  import { default as fe } from "mongoose-paginate-v2";
8
- import { v4 as N } from "uuid";
9
- import { getNestedValue as M, setNestedValue as A } from "../../util/object/object.util.js";
10
- import { regexSearchMapper as T } from "../../util/common/common.util.js";
11
- import { writeFileSync as D, pathExistsSync as j, readFileSync as F, appendFileSync as G } from "../fs/fs.util.js";
12
- import { PATH as g, MIGRATE_MONGO_CONFIG as x } from "../path/path.constant.js";
13
- import { validate as $ } from "../../util/validate/validate.util.js";
14
- import { generateShortId as q, generateSlug as O } from "../../util/string/string.util.js";
8
+ import { v4 as D } from "uuid";
9
+ import { getNestedValue as M, setNestedValue as T } from "../../util/object/object.util.js";
10
+ import { regexSearchMapper as j } from "../../util/common/common.util.js";
11
+ import { writeFileSync as x, pathExistsSync as $, readFileSync as F, appendFileSync as G } from "../fs/fs.util.js";
12
+ import { PATH as E, MIGRATE_MONGO_CONFIG as v } from "../path/path.constant.js";
13
+ import { validate as V } from "../../util/validate/validate.util.js";
14
+ import { generateShortId as q, generateSlug as _ } from "../../util/string/string.util.js";
15
15
  import { RESPONSE_STATUS as d } from "../../constant/response-status.js";
16
16
  import { catchError as i } from "../log/log.util.js";
17
- var V = Object.defineProperty, U = Object.defineProperties, L = Object.getOwnPropertyDescriptors, b = Object.getOwnPropertySymbols, Q = Object.prototype.hasOwnProperty, H = Object.prototype.propertyIsEnumerable, E = (n, t, e) => t in n ? V(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, f = (n, t) => {
17
+ var U = Object.defineProperty, L = Object.defineProperties, k = Object.getOwnPropertyDescriptors, b = Object.getOwnPropertySymbols, Q = Object.prototype.hasOwnProperty, H = Object.prototype.propertyIsEnumerable, R = (n, t, e) => t in n ? U(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, f = (n, t) => {
18
18
  for (var e in t || (t = {}))
19
- Q.call(t, e) && E(n, e, t[e]);
19
+ Q.call(t, e) && R(n, e, t[e]);
20
20
  if (b)
21
21
  for (var e of b(t))
22
- H.call(t, e) && E(n, e, t[e]);
22
+ H.call(t, e) && R(n, e, t[e]);
23
23
  return n;
24
- }, R = (n, t) => U(n, L(t)), J = (n, t, e) => E(n, typeof t != "symbol" ? t + "" : t, e), o = (n, t, e) => new Promise((r, s) => {
24
+ }, S = (n, t) => L(n, k(t)), J = (n, t, e) => R(n, typeof t != "symbol" ? t + "" : t, e), o = (n, t, e) => new Promise((r, s) => {
25
25
  var u = (a) => {
26
26
  try {
27
27
  l(e.next(a));
28
- } catch (m) {
29
- s(m);
28
+ } catch (h) {
29
+ s(h);
30
30
  }
31
31
  }, c = (a) => {
32
32
  try {
33
33
  l(e.throw(a));
34
- } catch (m) {
35
- s(m);
34
+ } catch (h) {
35
+ s(h);
36
36
  }
37
37
  }, l = (a) => a.done ? r(a.value) : Promise.resolve(a.value).then(u, c);
38
38
  l((e = e.apply(n, t)).next());
39
39
  });
40
- const h = {
40
+ const y = {
41
+ /**
42
+ * Creates generic fields that are commonly used across MongoDB documents.
43
+ * This function generates standard fields including a UUID, deletion flag, and timestamps
44
+ * that can be applied to any document schema.
45
+ *
46
+ * @returns An object containing generic document fields (id, isDel, createdAt, updatedAt).
47
+ */
41
48
  createGenericFields() {
42
49
  return {
43
- id: N(),
50
+ id: D(),
44
51
  isDel: !1,
45
52
  createdAt: /* @__PURE__ */ new Date(),
46
53
  updatedAt: /* @__PURE__ */ new Date()
47
54
  };
48
55
  },
56
+ /**
57
+ * Applies plugins to a Mongoose schema.
58
+ * This function filters out falsy plugins and applies the remaining valid plugins
59
+ * to the provided schema.
60
+ *
61
+ * @param schema - The Mongoose schema to apply plugins to.
62
+ * @param plugins - An array of plugin functions or false values to filter and apply.
63
+ */
49
64
  applyPlugins(n, t) {
50
65
  t.filter((e) => typeof e == "function").forEach((e) => n.plugin(e));
51
66
  },
67
+ /**
68
+ * Applies middleware functions to a Mongoose schema.
69
+ * This function configures pre and post middleware for specified methods on the schema.
70
+ *
71
+ * @param schema - The Mongoose schema to apply middleware to.
72
+ * @param middlewares - An array of middleware configurations with method, pre, and post functions.
73
+ */
52
74
  applyMiddlewares(n, t) {
53
75
  t.forEach(({ method: e, pre: r, post: s }) => {
54
76
  e && r && n.pre(e, r), e && s && n.post(e, s);
55
77
  });
56
78
  },
79
+ /**
80
+ * Creates a generic Mongoose schema with common fields.
81
+ * This function creates a base schema with UUID field and deletion flag,
82
+ * configured with automatic timestamps.
83
+ *
84
+ * @param mongoose - The Mongoose instance to create the schema with.
85
+ * @returns A Mongoose schema with generic document fields.
86
+ */
57
87
  createGenericSchema(n) {
58
88
  return new n.Schema(
59
89
  {
60
- id: { type: String, default: N, unique: !0 },
90
+ id: { type: String, default: D, unique: !0 },
61
91
  isDel: { type: Boolean, default: !1 }
62
92
  },
63
93
  { timestamps: !0 }
64
94
  );
65
95
  },
96
+ /**
97
+ * Creates a Mongoose schema with optional virtual fields and generic fields.
98
+ * This function creates a new Mongoose schema from the provided schema definition,
99
+ * optionally adds virtual fields, and includes generic fields (unless standalone is true).
100
+ *
101
+ * @param options - Configuration options including mongoose instance, schema definition, virtuals, and standalone flag.
102
+ * @param options.mongoose - The Mongoose instance to use for schema creation.
103
+ * @param options.schema - The schema definition object.
104
+ * @param options.virtuals - Optional array of virtual field configurations.
105
+ * @param options.standalone - Whether to exclude generic fields (default: false).
106
+ * @returns A configured Mongoose schema.
107
+ */
66
108
  createSchema({
67
109
  mongoose: n,
68
110
  schema: t,
@@ -73,8 +115,24 @@ const h = {
73
115
  return e.forEach(({ name: u, options: c, get: l }) => {
74
116
  const a = s.virtual(u, c);
75
117
  l && a.get(l);
76
- }), r || s.add(h.createGenericSchema(n)), s;
118
+ }), r || s.add(y.createGenericSchema(n)), s;
77
119
  },
120
+ /**
121
+ * Creates a Mongoose model with plugins, middleware, and pagination support.
122
+ * This function creates a model from a schema with optional pagination and aggregation plugins,
123
+ * and applies any specified middleware. If a model with the same name already exists, it returns the existing model.
124
+ *
125
+ * @param options - Configuration options including mongoose instance, model name, schema, and feature flags.
126
+ * @param options.mongoose - The Mongoose instance to use for model creation.
127
+ * @param options.name - The name of the model to create.
128
+ * @param options.schema - The schema definition for the model.
129
+ * @param options.pagination - Whether to enable pagination plugin (default: false).
130
+ * @param options.aggregate - Whether to enable aggregation pagination plugin (default: false).
131
+ * @param options.virtuals - Optional array of virtual field configurations.
132
+ * @param options.middlewares - Optional array of middleware configurations.
133
+ * @returns A configured Mongoose model with extended functionality.
134
+ * @throws {Error} When the model name is not provided.
135
+ */
78
136
  createModel({
79
137
  mongoose: n,
80
138
  name: t,
@@ -88,20 +146,40 @@ const h = {
88
146
  throw new Error("Model name is required.");
89
147
  if (n.models[t])
90
148
  return n.models[t];
91
- const l = h.createSchema({ mongoose: n, schema: e, virtuals: u });
92
- return h.applyPlugins(l, [
93
- r && P,
94
- s && C
95
- ]), h.applyMiddlewares(l, c), n.model(t, l);
149
+ const l = y.createSchema({ mongoose: n, schema: e, virtuals: u });
150
+ return y.applyPlugins(l, [
151
+ r && A,
152
+ s && w
153
+ ]), y.applyMiddlewares(l, c), n.model(t, l);
96
154
  },
155
+ /**
156
+ * Validation utilities for Mongoose schemas.
157
+ * This object provides common validation functions that can be used in Mongoose schema definitions.
158
+ */
97
159
  validator: {
160
+ /**
161
+ * Creates a required field validator.
162
+ * This function returns a validator that checks if a field value is not empty
163
+ * using the validate.isEmpty utility.
164
+ *
165
+ * @returns A validation function that returns true if the field is not empty.
166
+ */
98
167
  isRequired() {
99
168
  return function(n) {
100
169
  return o(this, null, function* () {
101
- return !$.isEmpty(n);
170
+ return !V.isEmpty(n);
102
171
  });
103
172
  };
104
173
  },
174
+ /**
175
+ * Creates a unique field validator.
176
+ * This function returns a validator that checks if a field value is unique
177
+ * across the specified fields in the collection.
178
+ *
179
+ * @param fields - An array of field names to check for uniqueness.
180
+ * @returns A validation function that returns true if the value is unique across the specified fields.
181
+ * @throws {Error} When fields is not a non-empty array of strings.
182
+ */
105
183
  isUnique(n) {
106
184
  return function(t) {
107
185
  return o(this, null, function* () {
@@ -112,6 +190,15 @@ const h = {
112
190
  });
113
191
  };
114
192
  },
193
+ /**
194
+ * Creates a regex pattern validator.
195
+ * This function returns a validator that checks if a string value matches
196
+ * all provided regular expressions.
197
+ *
198
+ * @param regexArray - An array of regular expressions to test against the value.
199
+ * @returns A validation function that returns true if the value matches all regex patterns.
200
+ * @throws {Error} When regexArray is not an array of valid RegExp objects.
201
+ */
115
202
  matchesRegex(n) {
116
203
  return function(t) {
117
204
  return o(this, null, function* () {
@@ -122,45 +209,78 @@ const h = {
122
209
  };
123
210
  }
124
211
  },
125
- migrate: R(f({}, w), {
212
+ /**
213
+ * Migration utilities for MongoDB.
214
+ * This object extends the migrate-mongo library with additional configuration utilities.
215
+ */
216
+ migrate: S(f({}, I), {
217
+ /**
218
+ * Sets the migration configuration and updates .gitignore.
219
+ * This function creates a migration configuration file and ensures it's properly
220
+ * excluded from version control.
221
+ *
222
+ * @param options - Migration configuration options to write to the config file.
223
+ */
126
224
  setConfig: (n) => {
127
225
  const t = `// This file is automatically generated by the Cyberskill CLI.
128
226
  module.exports = ${JSON.stringify(n, null, 4)}`;
129
- D(g.MIGRATE_MONGO_CONFIG, t);
227
+ x(E.MIGRATE_MONGO_CONFIG, t);
130
228
  const e = `
131
- ${x}
229
+ ${v}
132
230
  `;
133
- j(g.GIT_IGNORE) ? F(g.GIT_IGNORE, "utf-8").split(`
134
- `).includes(x) || G(g.GIT_IGNORE, e) : D(g.GIT_IGNORE, e);
231
+ $(E.GIT_IGNORE) ? F(E.GIT_IGNORE, "utf-8").split(`
232
+ `).includes(v) || G(E.GIT_IGNORE, e) : x(E.GIT_IGNORE, e);
135
233
  }
136
234
  }),
235
+ /**
236
+ * Converts string values in a filter to regex patterns for case-insensitive search.
237
+ * This function recursively processes a filter object and converts string values in specified fields
238
+ * to MongoDB regex patterns that support accented character matching.
239
+ *
240
+ * @param filter - The filter object to process.
241
+ * @param fields - An array of field names to convert to regex patterns.
242
+ * @returns A new filter object with string values converted to regex patterns.
243
+ */
137
244
  regexify(n, t) {
138
245
  if (!n)
139
246
  return {};
140
- let e = v(n);
247
+ let e = C(n);
141
248
  if (!t || t.length === 0)
142
249
  return e;
143
250
  for (const r of t) {
144
251
  const s = r.toString().split("."), u = M(e, s);
145
252
  if (typeof u == "string" && u.length > 0) {
146
253
  const c = {
147
- $regex: `.*${T(u)}.*`,
254
+ $regex: `.*${j(u)}.*`,
148
255
  $options: "i"
149
256
  };
150
- e = A(e, s, c);
257
+ e = T(e, s, c);
151
258
  }
152
259
  }
153
260
  return e;
154
261
  }
155
262
  };
156
- class ce {
263
+ class oe {
264
+ /**
265
+ * Creates a new MongoDB controller instance.
266
+ *
267
+ * @param db - The MongoDB database instance.
268
+ * @param collectionName - The name of the collection to operate on.
269
+ */
157
270
  constructor(t, e) {
158
271
  J(this, "collection"), this.collection = t.collection(e);
159
272
  }
273
+ /**
274
+ * Creates a single document in the collection.
275
+ * This method adds generic fields (id, isDel, timestamps) to the document before insertion.
276
+ *
277
+ * @param document - The document to create, with or without generic fields.
278
+ * @returns A promise that resolves to a standardized response with the created document.
279
+ */
160
280
  createOne(t) {
161
281
  return o(this, null, function* () {
162
282
  try {
163
- const e = f(f({}, h.createGenericFields()), t);
283
+ const e = f(f({}, y.createGenericFields()), t);
164
284
  return (yield this.collection.insertOne(e)).acknowledged ? {
165
285
  success: !0,
166
286
  message: "Document created successfully",
@@ -175,10 +295,17 @@ class ce {
175
295
  }
176
296
  });
177
297
  }
298
+ /**
299
+ * Creates multiple documents in the collection.
300
+ * This method adds generic fields to each document before bulk insertion.
301
+ *
302
+ * @param documents - An array of documents to create.
303
+ * @returns A promise that resolves to a standardized response with the created documents.
304
+ */
178
305
  createMany(t) {
179
306
  return o(this, null, function* () {
180
307
  try {
181
- const e = t.map((s) => f(f({}, h.createGenericFields()), s)), r = yield this.collection.insertMany(e);
308
+ const e = t.map((s) => f(f({}, y.createGenericFields()), s)), r = yield this.collection.insertMany(e);
182
309
  return r.insertedCount === 0 ? {
183
310
  success: !1,
184
311
  message: "No documents were inserted",
@@ -193,6 +320,12 @@ class ce {
193
320
  }
194
321
  });
195
322
  }
323
+ /**
324
+ * Finds a single document by filter criteria.
325
+ *
326
+ * @param filter - The filter criteria to find the document.
327
+ * @returns A promise that resolves to a standardized response with the found document.
328
+ */
196
329
  findOne(t) {
197
330
  return o(this, null, function* () {
198
331
  try {
@@ -203,6 +336,12 @@ class ce {
203
336
  }
204
337
  });
205
338
  }
339
+ /**
340
+ * Finds all documents matching the filter criteria.
341
+ *
342
+ * @param filter - The filter criteria to find documents (defaults to empty object for all documents).
343
+ * @returns A promise that resolves to a standardized response with the found documents.
344
+ */
206
345
  findAll() {
207
346
  return o(this, arguments, function* (t = {}) {
208
347
  try {
@@ -216,6 +355,12 @@ class ce {
216
355
  }
217
356
  });
218
357
  }
358
+ /**
359
+ * Counts documents matching the filter criteria.
360
+ *
361
+ * @param filter - The filter criteria to count documents (defaults to empty object for all documents).
362
+ * @returns A promise that resolves to a standardized response with the document count.
363
+ */
219
364
  count() {
220
365
  return o(this, arguments, function* (t = {}) {
221
366
  try {
@@ -229,6 +374,13 @@ class ce {
229
374
  }
230
375
  });
231
376
  }
377
+ /**
378
+ * Updates a single document matching the filter criteria.
379
+ *
380
+ * @param filter - The filter criteria to find the document to update.
381
+ * @param update - The update data to apply to the document.
382
+ * @returns A promise that resolves to a standardized response with the update result.
383
+ */
232
384
  updateOne(t, e) {
233
385
  return o(this, null, function* () {
234
386
  try {
@@ -249,6 +401,13 @@ class ce {
249
401
  }
250
402
  });
251
403
  }
404
+ /**
405
+ * Updates multiple documents matching the filter criteria.
406
+ *
407
+ * @param filter - The filter criteria to find documents to update.
408
+ * @param update - The update data to apply to the documents.
409
+ * @returns A promise that resolves to a standardized response with the update result.
410
+ */
252
411
  updateMany(t, e) {
253
412
  return o(this, null, function* () {
254
413
  try {
@@ -269,6 +428,12 @@ class ce {
269
428
  }
270
429
  });
271
430
  }
431
+ /**
432
+ * Deletes a single document matching the filter criteria.
433
+ *
434
+ * @param filter - The filter criteria to find the document to delete.
435
+ * @returns A promise that resolves to a standardized response with the delete result.
436
+ */
272
437
  deleteOne(t) {
273
438
  return o(this, null, function* () {
274
439
  try {
@@ -287,6 +452,12 @@ class ce {
287
452
  }
288
453
  });
289
454
  }
455
+ /**
456
+ * Deletes multiple documents matching the filter criteria.
457
+ *
458
+ * @param filter - The filter criteria to find documents to delete.
459
+ * @returns A promise that resolves to a standardized response with the delete result.
460
+ */
290
461
  deleteMany(t) {
291
462
  return o(this, null, function* () {
292
463
  try {
@@ -306,13 +477,32 @@ class ce {
306
477
  });
307
478
  }
308
479
  }
309
- class oe {
480
+ class ie {
481
+ /**
482
+ * Creates a new Mongoose controller instance.
483
+ *
484
+ * @param model - The Mongoose model to operate on.
485
+ */
310
486
  constructor(t) {
311
487
  this.model = t;
312
488
  }
489
+ /**
490
+ * Gets the model name for logging and error messages.
491
+ *
492
+ * @returns The name of the model.
493
+ */
313
494
  getModelName() {
314
495
  return this.model.modelName;
315
496
  }
497
+ /**
498
+ * Finds a single document with optional population and projection.
499
+ *
500
+ * @param filter - The filter criteria to find the document.
501
+ * @param projection - The fields to include/exclude in the result.
502
+ * @param options - Query options for the operation.
503
+ * @param populate - Population configuration for related documents.
504
+ * @returns A promise that resolves to a standardized response with the found document.
505
+ */
316
506
  findOne() {
317
507
  return o(this, arguments, function* (t = {}, e = {}, r = {}, s) {
318
508
  try {
@@ -329,6 +519,15 @@ class oe {
329
519
  }
330
520
  });
331
521
  }
522
+ /**
523
+ * Finds all documents with optional population and projection.
524
+ *
525
+ * @param filter - The filter criteria to find documents.
526
+ * @param projection - The fields to include/exclude in the result.
527
+ * @param options - Query options for the operation.
528
+ * @param populate - Population configuration for related documents.
529
+ * @returns A promise that resolves to a standardized response with the found documents.
530
+ */
332
531
  findAll() {
333
532
  return o(this, arguments, function* (t = {}, e = {}, r = {}, s) {
334
533
  try {
@@ -339,6 +538,13 @@ class oe {
339
538
  }
340
539
  });
341
540
  }
541
+ /**
542
+ * Finds documents with pagination support.
543
+ *
544
+ * @param filter - The filter criteria to find documents.
545
+ * @param options - Pagination options including page, limit, and population.
546
+ * @returns A promise that resolves to a standardized response with paginated results.
547
+ */
342
548
  findPaging() {
343
549
  return o(this, arguments, function* (t = {}, e = {}) {
344
550
  try {
@@ -348,6 +554,13 @@ class oe {
348
554
  }
349
555
  });
350
556
  }
557
+ /**
558
+ * Performs aggregation with pagination support.
559
+ *
560
+ * @param pipeline - The aggregation pipeline stages.
561
+ * @param options - Pagination options for the aggregation result.
562
+ * @returns A promise that resolves to a standardized response with paginated aggregation results.
563
+ */
351
564
  findPagingAggregate(t) {
352
565
  return o(this, arguments, function* (e, r = {}) {
353
566
  try {
@@ -360,6 +573,12 @@ class oe {
360
573
  }
361
574
  });
362
575
  }
576
+ /**
577
+ * Counts documents matching the filter criteria.
578
+ *
579
+ * @param filter - The filter criteria to count documents.
580
+ * @returns A promise that resolves to a standardized response with the document count.
581
+ */
363
582
  count() {
364
583
  return o(this, arguments, function* (t = {}) {
365
584
  try {
@@ -369,6 +588,12 @@ class oe {
369
588
  }
370
589
  });
371
590
  }
591
+ /**
592
+ * Creates a single document.
593
+ *
594
+ * @param doc - The document to create.
595
+ * @returns A promise that resolves to a standardized response with the created document.
596
+ */
372
597
  createOne(t) {
373
598
  return o(this, null, function* () {
374
599
  try {
@@ -378,15 +603,30 @@ class oe {
378
603
  }
379
604
  });
380
605
  }
606
+ /**
607
+ * Creates multiple documents with bulk insertion.
608
+ *
609
+ * @param docs - An array of documents to create.
610
+ * @param options - Options for the bulk insertion operation.
611
+ * @returns A promise that resolves to a standardized response with the created documents.
612
+ */
381
613
  createMany(t) {
382
614
  return o(this, arguments, function* (e, r = {}) {
383
615
  try {
384
- return { success: !0, result: (yield this.model.insertMany(e, r)).map((c) => c instanceof I ? c.toObject() : null).filter((c) => c !== null) };
616
+ return { success: !0, result: (yield this.model.insertMany(e, r)).map((c) => c instanceof P ? c.toObject() : null).filter((c) => c !== null) };
385
617
  } catch (s) {
386
618
  return i(s);
387
619
  }
388
620
  });
389
621
  }
622
+ /**
623
+ * Updates a single document and returns the updated version.
624
+ *
625
+ * @param filter - The filter criteria to find the document to update.
626
+ * @param update - The update data to apply.
627
+ * @param options - Options for the update operation.
628
+ * @returns A promise that resolves to a standardized response with the updated document.
629
+ */
390
630
  updateOne() {
391
631
  return o(this, arguments, function* (t = {}, e = {}, r = {}) {
392
632
  try {
@@ -403,6 +643,14 @@ class oe {
403
643
  }
404
644
  });
405
645
  }
646
+ /**
647
+ * Updates multiple documents matching the filter criteria.
648
+ *
649
+ * @param filter - The filter criteria to find documents to update.
650
+ * @param update - The update data to apply.
651
+ * @param options - Options for the update operation.
652
+ * @returns A promise that resolves to a standardized response with the update result.
653
+ */
406
654
  updateMany() {
407
655
  return o(this, arguments, function* (t = {}, e = {}, r = {}) {
408
656
  try {
@@ -412,6 +660,13 @@ class oe {
412
660
  }
413
661
  });
414
662
  }
663
+ /**
664
+ * Deletes a single document and returns the deleted version.
665
+ *
666
+ * @param filter - The filter criteria to find the document to delete.
667
+ * @param options - Options for the delete operation.
668
+ * @returns A promise that resolves to a standardized response with the deleted document.
669
+ */
415
670
  deleteOne() {
416
671
  return o(this, arguments, function* (t = {}, e = {}) {
417
672
  try {
@@ -426,6 +681,13 @@ class oe {
426
681
  }
427
682
  });
428
683
  }
684
+ /**
685
+ * Deletes multiple documents matching the filter criteria.
686
+ *
687
+ * @param filter - The filter criteria to find documents to delete.
688
+ * @param options - Options for the delete operation.
689
+ * @returns A promise that resolves to a standardized response with the delete result.
690
+ */
429
691
  deleteMany() {
430
692
  return o(this, arguments, function* (t = {}, e = {}) {
431
693
  try {
@@ -440,14 +702,24 @@ class oe {
440
702
  }
441
703
  });
442
704
  }
705
+ /**
706
+ * Creates a unique short ID based on a given ID.
707
+ * This method generates multiple short IDs with increasing lengths and finds the first available one.
708
+ *
709
+ * @param id - The base ID to generate short IDs from.
710
+ * @param length - The initial length for short ID generation (default: 4).
711
+ * @returns A promise that resolves to a standardized response with the unique short ID.
712
+ */
443
713
  createShortId(t, e = 4) {
444
714
  return o(this, null, function* () {
445
715
  try {
446
- const s = /* @__PURE__ */ new Set();
447
- for (let u = 0; u < 10; u++) {
448
- const c = q(t, u + e);
449
- if (!s.has(c) && (s.add(c), !(yield this.model.exists({ shortId: c }))))
450
- return { success: !0, result: c };
716
+ const s = Array.from({ length: 10 }, (l, a) => q(t, a + e)), c = (yield Promise.all(
717
+ s.map((l) => this.model.exists({ shortId: l }))
718
+ )).findIndex((l) => !l);
719
+ if (c !== -1) {
720
+ const l = s[c];
721
+ if (l)
722
+ return { success: !0, result: l };
451
723
  }
452
724
  return {
453
725
  success: !1,
@@ -459,43 +731,81 @@ class oe {
459
731
  }
460
732
  });
461
733
  }
734
+ /**
735
+ * Creates a query for slug existence checking.
736
+ * This method generates a query that checks for slug existence in both current and historical slug fields.
737
+ *
738
+ * @param options - Configuration for slug query generation including slug, field, and filter.
739
+ * @param options.slug - The slug string to check for existence.
740
+ * @param options.field - The field name for object-based slug checking.
741
+ * @param options.isObject - Whether the slug is stored as an object with nested fields.
742
+ * @param options.filter - Additional filter conditions to apply to the query.
743
+ * @returns A MongoDB query object for checking slug existence.
744
+ */
462
745
  createSlugQuery({ slug: t, field: e, isObject: r, filter: s }) {
463
746
  const u = f({}, s != null ? s : {});
464
- return r ? R(f({}, u), {
747
+ return r ? S(f({}, u), {
465
748
  $or: [
466
749
  { [`slug.${e}`]: t },
467
750
  { slugHistory: { $elemMatch: { [`slug.${e}`]: t } } }
468
751
  ]
469
- }) : R(f({}, u), {
752
+ }) : S(f({}, u), {
470
753
  $or: [
471
754
  { slug: t },
472
755
  { slugHistory: t }
473
756
  ]
474
757
  });
475
758
  }
759
+ /**
760
+ * Creates a unique slug based on a given string.
761
+ * This method generates multiple slug variations and finds the first available one.
762
+ *
763
+ * @param options - Configuration for slug generation including slug, field, and filter.
764
+ * @param options.slug - The base slug string to make unique.
765
+ * @param options.field - The field name for object-based slug checking.
766
+ * @param options.isObject - Whether the slug is stored as an object with nested fields.
767
+ * @param options.filter - Additional filter conditions to apply when checking slug existence.
768
+ * @returns A promise that resolves to a unique slug string.
769
+ */
476
770
  createUniqueSlug(t) {
477
771
  return o(this, arguments, function* ({ slug: e, field: r, isObject: s, filter: u }) {
478
- const c = O(e);
479
- let l = c, a = 1;
480
- for (; yield this.model.exists(this.createSlugQuery({ slug: l, field: r, isObject: s, filter: u })); )
481
- l = `${c}-${a++}`;
482
- return l;
772
+ const c = _(e), a = Array.from({ length: 100 }, (m, p) => p === 0 ? c : `${c}-${p}`), g = (yield Promise.all(
773
+ a.map(
774
+ (m) => this.model.exists(this.createSlugQuery({ slug: m, field: r, isObject: s, filter: u }))
775
+ )
776
+ )).findIndex((m) => !m);
777
+ if (g !== -1) {
778
+ const m = a[g];
779
+ if (m)
780
+ return m;
781
+ }
782
+ return `${c}-${Date.now()}`;
483
783
  });
484
784
  }
785
+ /**
786
+ * Creates a slug for a document field.
787
+ * This method handles both simple string fields and object fields with nested slug generation.
788
+ *
789
+ * @param options - Configuration for slug creation including field, source document, and filter.
790
+ * @param options.field - The field name to create a slug for.
791
+ * @param options.from - The source document containing the field value.
792
+ * @param options.filter - Additional filter conditions to apply when checking slug existence.
793
+ * @returns A promise that resolves to a standardized response with the created slug(s).
794
+ */
485
795
  createSlug(t) {
486
796
  return o(this, arguments, function* ({ field: e, from: r, filter: s }) {
487
797
  try {
488
798
  const u = r[e];
489
- return S(u) ? { success: !0, result: Object.fromEntries(
799
+ return N(u) ? { success: !0, result: Object.fromEntries(
490
800
  yield Promise.all(
491
- Object.entries(u).map((m) => o(this, [m], function* ([y, p]) {
492
- const _ = yield this.createUniqueSlug({
493
- slug: p,
494
- field: y,
801
+ Object.entries(u).map((h) => o(this, [h], function* ([g, m]) {
802
+ const p = yield this.createUniqueSlug({
803
+ slug: m,
804
+ field: g,
495
805
  isObject: !0,
496
806
  filter: s
497
807
  });
498
- return [y, _];
808
+ return [g, p];
499
809
  }))
500
810
  )
501
811
  ) } : { success: !0, result: yield this.createUniqueSlug({
@@ -509,24 +819,35 @@ class oe {
509
819
  }
510
820
  });
511
821
  }
822
+ /**
823
+ * Checks if a slug already exists in the collection.
824
+ * This method verifies slug existence in both current and historical slug fields.
825
+ *
826
+ * @param options - Configuration for slug checking including slug, field, source document, and filter.
827
+ * @param options.slug - The slug string to check for existence.
828
+ * @param options.field - The field name for object-based slug checking.
829
+ * @param options.from - The source document containing the field value.
830
+ * @param options.filter - Additional filter conditions to apply to the query.
831
+ * @returns A promise that resolves to a standardized response indicating whether the slug exists.
832
+ */
512
833
  checkSlug(t) {
513
834
  return o(this, arguments, function* ({ slug: e, field: r, from: s, filter: u }) {
514
835
  try {
515
836
  const c = s[r];
516
- if (S(c)) {
517
- for (const y of Object.values(c)) {
518
- const p = O(y);
519
- if (yield this.model.exists(this.createSlugQuery({
520
- slug: p,
521
- field: r,
522
- isObject: !0,
523
- filter: u
524
- })))
525
- return { success: !0, result: !0 };
526
- }
527
- return { success: !0, result: !1 };
837
+ if (N(c)) {
838
+ const m = Object.values(c).map((O) => _(O));
839
+ return (yield Promise.all(
840
+ m.map(
841
+ (O) => this.model.exists(this.createSlugQuery({
842
+ slug: O,
843
+ field: r,
844
+ isObject: !0,
845
+ filter: u
846
+ }))
847
+ )
848
+ )).some((O) => O) ? { success: !0, result: !0 } : { success: !0, result: !1 };
528
849
  }
529
- const a = O(e);
850
+ const a = _(e);
530
851
  return { success: !0, result: (yield this.model.exists(this.createSlugQuery({
531
852
  slug: a,
532
853
  field: r,
@@ -538,6 +859,12 @@ class oe {
538
859
  }
539
860
  });
540
861
  }
862
+ /**
863
+ * Performs aggregation operations on the collection.
864
+ *
865
+ * @param pipeline - The aggregation pipeline stages to execute.
866
+ * @returns A promise that resolves to a standardized response with the aggregation results.
867
+ */
541
868
  aggregate(t) {
542
869
  return o(this, null, function* () {
543
870
  try {
@@ -549,9 +876,9 @@ class oe {
549
876
  }
550
877
  }
551
878
  export {
552
- ce as MongoController,
553
- oe as MongooseController,
554
- ae as aggregatePaginate,
555
- h as mongo,
879
+ oe as MongoController,
880
+ ie as MongooseController,
881
+ de as aggregatePaginate,
882
+ y as mongo,
556
883
  fe as mongoosePaginate
557
884
  };