@cyberskill/shared 2.20.0 → 2.25.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 (63) hide show
  1. package/dist/config/eslint/index.cjs +1 -1
  2. package/dist/config/eslint/index.d.ts +2 -7
  3. package/dist/config/eslint/index.js +1 -1
  4. package/dist/config/storybook/storybook.main.cjs +1 -1
  5. package/dist/config/storybook/storybook.main.js +1 -1
  6. package/dist/config/vitest/vitest.e2e.cjs +1 -1
  7. package/dist/config/vitest/vitest.e2e.js +6 -6
  8. package/dist/config/vitest/vitest.unit.cjs +1 -1
  9. package/dist/config/vitest/vitest.unit.js +5 -5
  10. package/dist/config/vitest/vitest.unit.setup.d.ts +0 -1
  11. package/dist/node/cli/index.cjs +4 -4
  12. package/dist/node/cli/index.js +56 -51
  13. package/dist/node/command/command.util.cjs +2 -2
  14. package/dist/node/command/command.util.d.ts +4 -1
  15. package/dist/node/command/command.util.js +125 -112
  16. package/dist/node/express/express.util.cjs +1 -1
  17. package/dist/node/express/express.util.js +24 -23
  18. package/dist/node/mongo/index.cjs +1 -1
  19. package/dist/node/mongo/index.d.ts +1 -0
  20. package/dist/node/mongo/index.js +15 -12
  21. package/dist/node/mongo/mongo.controller.cjs +1 -0
  22. package/dist/node/mongo/mongo.controller.d.ts +317 -0
  23. package/dist/node/mongo/mongo.controller.js +956 -0
  24. package/dist/node/mongo/mongo.controller.test.unit.d.ts +1 -0
  25. package/dist/node/mongo/mongo.type.d.ts +9 -10
  26. package/dist/node/mongo/mongo.util.cjs +5 -5
  27. package/dist/node/mongo/mongo.util.d.ts +32 -515
  28. package/dist/node/mongo/mongo.util.js +314 -1239
  29. package/dist/node/mongo/mongo.util.test.unit.d.ts +1 -0
  30. package/dist/node/path/path.constant.cjs +1 -1
  31. package/dist/node/path/path.constant.d.ts +2 -2
  32. package/dist/node/path/path.constant.js +120 -116
  33. package/dist/node/path/path.test.unit.d.ts +1 -0
  34. package/dist/node/path/path.util.d.ts +2 -2
  35. package/dist/react/loading/loading.component.cjs +2 -2
  36. package/dist/react/loading/loading.component.js +32 -19
  37. package/dist/react/loading/loading.test.unit.d.ts +1 -0
  38. package/dist/react/loading/loading.type.d.ts +2 -1
  39. package/dist/util/common/common.test.unit.d.ts +1 -0
  40. package/dist/util/common/common.util.cjs +1 -1
  41. package/dist/util/common/common.util.d.ts +3 -0
  42. package/dist/util/common/common.util.js +35 -35
  43. package/dist/util/index.cjs +1 -1
  44. package/dist/util/index.js +16 -15
  45. package/dist/util/object/index.cjs +1 -1
  46. package/dist/util/object/index.js +4 -3
  47. package/dist/util/object/object.test.unit.d.ts +1 -0
  48. package/dist/util/object/object.util.cjs +1 -1
  49. package/dist/util/object/object.util.d.ts +10 -30
  50. package/dist/util/object/object.util.js +110 -73
  51. package/dist/util/serializer/serializer.test.unit.d.ts +1 -0
  52. package/dist/util/serializer/serializer.util.cjs +1 -1
  53. package/dist/util/serializer/serializer.util.js +19 -16
  54. package/dist/util/string/string.test.unit.d.ts +1 -0
  55. package/dist/util/string/string.util.cjs +1 -1
  56. package/dist/util/string/string.util.d.ts +4 -3
  57. package/dist/util/string/string.util.js +32 -41
  58. package/dist/util/validate/validate.test.unit.d.ts +1 -0
  59. package/dist/util/validate/validate.util.cjs +1 -1
  60. package/dist/util/validate/validate.util.js +9 -9
  61. package/package.json +44 -51
  62. /package/dist/node_modules/.pnpm/{vitest@4.0.13_@types_debug@4.1.12_@types_node@24.10.1_jiti@2.6.1_jsdom@27.2.0_sass@1.94.2_tsx@4.20.6_yaml@2.8.1 → vitest@4.0.16_@types_node@25.0.3_jiti@2.6.1_jsdom@27.4.0_sass@1.97.2_tsx@4.21.0_yaml@2.8.2}/node_modules/vitest/dist/config.cjs +0 -0
  63. /package/dist/node_modules/.pnpm/{vitest@4.0.13_@types_debug@4.1.12_@types_node@24.10.1_jiti@2.6.1_jsdom@27.2.0_sass@1.94.2_tsx@4.20.6_yaml@2.8.1 → vitest@4.0.16_@types_node@25.0.3_jiti@2.6.1_jsdom@27.4.0_sass@1.97.2_tsx@4.21.0_yaml@2.8.2}/node_modules/vitest/dist/config.js +0 -0
@@ -0,0 +1,317 @@
1
+ import { default as mongooseRaw } from 'mongoose';
2
+ import { I_Return } from '../../typescript/index.js';
3
+ import { C_Db, C_Document, I_DeleteOptionsExtended, I_ExtendedModel, I_Input_CheckSlug, I_Input_CreateSlug, I_Input_GenerateSlug, I_PaginateOptionsWithPopulate, I_UpdateOptionsExtended, T_AggregatePaginateResult, T_DeleteResult, T_Filter, T_Input_Populate, T_InsertManyOptions, T_PaginateResult, T_PipelineStage, T_ProjectionType, T_QueryFilter, T_QueryOptions, T_UpdateQuery, T_UpdateResult, T_WithId } from './mongo.type.js';
4
+ /**
5
+ * MongoDB native driver controller for direct database operations.
6
+ * This class provides a simplified interface for MongoDB operations using the native driver,
7
+ * with automatic generic field generation and standardized response formatting.
8
+ */
9
+ export declare class MongoController<D extends Partial<C_Document>> {
10
+ private collection;
11
+ /**
12
+ * Creates a new MongoDB controller instance.
13
+ *
14
+ * @param db - The MongoDB database instance.
15
+ * @param collectionName - The name of the collection to operate on.
16
+ */
17
+ constructor(db: C_Db, collectionName: string);
18
+ /**
19
+ * Creates a single document in the collection.
20
+ * This method adds generic fields (id, isDel, timestamps) to the document before insertion.
21
+ *
22
+ * @param document - The document to create, with or without generic fields.
23
+ * @returns A promise that resolves to a standardized response with the created document.
24
+ */
25
+ createOne(document: D | Partial<D>): Promise<I_Return<D | Partial<D>>>;
26
+ /**
27
+ * Creates multiple documents in the collection.
28
+ * This method adds generic fields to each document before bulk insertion.
29
+ *
30
+ * @param documents - An array of documents to create.
31
+ * @returns A promise that resolves to a standardized response with the created documents.
32
+ */
33
+ createMany(documents: (D | Partial<D>)[]): Promise<I_Return<(D | Partial<D>)[]>>;
34
+ /**
35
+ * Finds a single document by filter criteria.
36
+ *
37
+ * @param filter - The filter criteria to find the document.
38
+ * @returns A promise that resolves to a standardized response with the found document.
39
+ */
40
+ findOne(filter: T_Filter<D>): Promise<I_Return<T_WithId<D>>>;
41
+ /**
42
+ * Finds all documents matching the filter criteria.
43
+ *
44
+ * @param filter - The filter criteria to find documents (defaults to empty object for all documents).
45
+ * @returns A promise that resolves to a standardized response with the found documents.
46
+ */
47
+ findAll(filter?: T_Filter<D>): Promise<I_Return<T_WithId<D>[]>>;
48
+ /**
49
+ * Counts documents matching the filter criteria.
50
+ *
51
+ * @param filter - The filter criteria to count documents (defaults to empty object for all documents).
52
+ * @returns A promise that resolves to a standardized response with the document count.
53
+ */
54
+ count(filter?: T_Filter<D>): Promise<I_Return<number>>;
55
+ /**
56
+ * Updates a single document matching the filter criteria.
57
+ *
58
+ * @param filter - The filter criteria to find the document to update.
59
+ * @param update - The update data to apply to the document.
60
+ * @returns A promise that resolves to a standardized response with the update result.
61
+ */
62
+ updateOne(filter: T_Filter<D>, update: Partial<D>): Promise<I_Return<T_UpdateResult>>;
63
+ /**
64
+ * Updates multiple documents matching the filter criteria.
65
+ *
66
+ * @param filter - The filter criteria to find documents to update.
67
+ * @param update - The update data to apply to the documents.
68
+ * @returns A promise that resolves to a standardized response with the update result.
69
+ */
70
+ updateMany(filter: T_Filter<D>, update: Partial<D>): Promise<I_Return<T_UpdateResult>>;
71
+ /**
72
+ * Deletes a single document matching the filter criteria.
73
+ *
74
+ * @param filter - The filter criteria to find the document to delete.
75
+ * @returns A promise that resolves to a standardized response with the delete result.
76
+ */
77
+ deleteOne(filter: T_Filter<D>): Promise<I_Return<T_DeleteResult>>;
78
+ /**
79
+ * Deletes multiple documents matching the filter criteria.
80
+ *
81
+ * @param filter - The filter criteria to find documents to delete.
82
+ * @returns A promise that resolves to a standardized response with the delete result.
83
+ */
84
+ deleteMany(filter: T_Filter<D>): Promise<I_Return<T_DeleteResult>>;
85
+ }
86
+ /**
87
+ * Mongoose controller for database operations with advanced features.
88
+ * This class provides a comprehensive interface for Mongoose operations including
89
+ * pagination, aggregation, slug generation, and short ID creation.
90
+ */
91
+ export declare class MongooseController<T extends Partial<C_Document>> {
92
+ private model;
93
+ /**
94
+ * Creates a new Mongoose controller instance.
95
+ *
96
+ * @param model - The Mongoose model to operate on.
97
+ */
98
+ constructor(model: I_ExtendedModel<T>);
99
+ /**
100
+ * Gets the model name for logging and error messages.
101
+ *
102
+ * @returns The name of the model.
103
+ */
104
+ private getModelName;
105
+ /**
106
+ * Gets the dynamic virtuals configuration from the model instance.
107
+ *
108
+ * @returns Array of dynamic virtual configurations or undefined if none exist.
109
+ */
110
+ private getDynamicVirtuals;
111
+ /**
112
+ * Populates dynamic virtuals for a single document.
113
+ *
114
+ * @param result - The document to populate dynamic virtuals for.
115
+ * @param populate - The populate options to determine which virtuals to populate.
116
+ * @returns The document with dynamic virtuals populated.
117
+ */
118
+ private populateDynamicVirtualsForDocument;
119
+ /**
120
+ * Populates dynamic virtuals for an array of documents.
121
+ *
122
+ * @param results - The documents to populate dynamic virtuals for.
123
+ * @param populate - The populate options to determine which virtuals to populate.
124
+ * @returns The documents with dynamic virtuals populated.
125
+ */
126
+ private populateDynamicVirtualsForDocuments;
127
+ /**
128
+ * Finds a single document with optional population and projection.
129
+ * Automatically handles dynamic virtual population if configured.
130
+ *
131
+ * @param filter - The filter criteria to find the document.
132
+ * @param projection - The fields to include/exclude in the result.
133
+ * @param options - Query options for the operation.
134
+ * @param populate - Population configuration for related documents.
135
+ * @returns A promise that resolves to a standardized response with the found document.
136
+ */
137
+ findOne(filter?: T_QueryFilter<T>, projection?: T_ProjectionType<T>, options?: T_QueryOptions<T>, populate?: T_Input_Populate): Promise<I_Return<T>>;
138
+ /**
139
+ * Finds all documents with optional population and projection.
140
+ * Automatically handles dynamic virtual population if configured.
141
+ *
142
+ * @param filter - The filter criteria to find documents.
143
+ * @param projection - The fields to include/exclude in the result.
144
+ * @param options - Query options for the operation.
145
+ * @param populate - Population configuration for related documents.
146
+ * @returns A promise that resolves to a standardized response with the found documents.
147
+ */
148
+ findAll(filter?: T_QueryFilter<T>, projection?: T_ProjectionType<T>, options?: T_QueryOptions<T>, populate?: T_Input_Populate): Promise<I_Return<T[]>>;
149
+ /**
150
+ * Finds documents with pagination support.
151
+ * Automatically handles dynamic virtual population if configured.
152
+ *
153
+ * @param filter - The filter criteria to find documents.
154
+ * @param options - Pagination options including page, limit, and population.
155
+ * @returns A promise that resolves to a standardized response with paginated results.
156
+ */
157
+ findPaging(filter?: T_QueryFilter<T>, options?: I_PaginateOptionsWithPopulate): Promise<I_Return<T_PaginateResult<T>>>;
158
+ /**
159
+ * Performs aggregation with pagination support.
160
+ *
161
+ * @param pipeline - The aggregation pipeline stages.
162
+ * @param options - Pagination options for the aggregation result.
163
+ * @returns A promise that resolves to a standardized response with paginated aggregation results.
164
+ */
165
+ findPagingAggregate(pipeline: T_PipelineStage[], options?: I_PaginateOptionsWithPopulate): Promise<I_Return<T_AggregatePaginateResult<T>>>;
166
+ /**
167
+ * Counts documents matching the filter criteria.
168
+ *
169
+ * @param filter - The filter criteria to count documents.
170
+ * @returns A promise that resolves to a standardized response with the document count.
171
+ */
172
+ count(filter?: T_QueryFilter<T>): Promise<I_Return<number>>;
173
+ /**
174
+ * Creates a single document.
175
+ *
176
+ * @param doc - The document to create.
177
+ * @returns A promise that resolves to a standardized response with the created document.
178
+ */
179
+ createOne(doc: T | Partial<T>): Promise<I_Return<T>>;
180
+ /**
181
+ * Creates multiple documents with bulk insertion.
182
+ *
183
+ * @param docs - An array of documents to create.
184
+ * @param options - Options for the bulk insertion operation.
185
+ * @returns A promise that resolves to a standardized response with the created documents.
186
+ */
187
+ createMany(docs: (T | Partial<T>)[], options?: T_InsertManyOptions): Promise<I_Return<T[]>>;
188
+ /**
189
+ * Updates a single document and returns the updated version.
190
+ *
191
+ * @param filter - The filter criteria to find the document to update.
192
+ * @param update - The update data to apply.
193
+ * @param options - Options for the update operation.
194
+ * @returns A promise that resolves to a standardized response with the updated document.
195
+ */
196
+ updateOne(filter?: T_QueryFilter<T>, update?: T_UpdateQuery<T>, options?: I_UpdateOptionsExtended): Promise<I_Return<T>>;
197
+ /**
198
+ * Updates multiple documents matching the filter criteria.
199
+ *
200
+ * @param filter - The filter criteria to find documents to update.
201
+ * @param update - The update data to apply.
202
+ * @param options - Options for the update operation.
203
+ * @returns A promise that resolves to a standardized response with the update result.
204
+ */
205
+ updateMany(filter?: T_QueryFilter<T>, update?: T_UpdateQuery<T>, options?: I_UpdateOptionsExtended): Promise<I_Return<T_UpdateResult>>;
206
+ /**
207
+ * Deletes a single document and returns the deleted version.
208
+ *
209
+ * @param filter - The filter criteria to find the document to delete.
210
+ * @param options - Options for the delete operation.
211
+ * @returns A promise that resolves to a standardized response with the deleted document.
212
+ */
213
+ deleteOne(filter?: T_QueryFilter<T>, options?: I_DeleteOptionsExtended): Promise<I_Return<T>>;
214
+ /**
215
+ * Deletes multiple documents matching the filter criteria.
216
+ *
217
+ * @param filter - The filter criteria to find documents to delete.
218
+ * @param options - Options for the delete operation.
219
+ * @returns A promise that resolves to a standardized response with the delete result.
220
+ */
221
+ deleteMany(filter?: T_QueryFilter<T>, options?: I_DeleteOptionsExtended): Promise<I_Return<T_DeleteResult>>;
222
+ /**
223
+ * Creates a unique short ID based on a given ID.
224
+ * This method generates multiple short IDs with increasing lengths and finds the first available one.
225
+ *
226
+ * @param id - The base ID to generate short IDs from.
227
+ * @param length - The initial length for short ID generation (default: 4).
228
+ * @returns A promise that resolves to a standardized response with the unique short ID.
229
+ */
230
+ createShortId(id: string, length?: number): Promise<I_Return<string>>;
231
+ /**
232
+ * Creates a query for slug existence checking.
233
+ * This method generates a query that checks for slug existence in both current and historical slug fields.
234
+ *
235
+ * @param options - Configuration for slug query generation including slug, field, and filter.
236
+ * @param options.slug - The slug string to check for existence.
237
+ * @param options.field - The field name for object-based slug checking.
238
+ * @param options.isObject - Whether the slug is stored as an object with nested fields.
239
+ * @param options.haveHistory - Whether to check historical slug fields for existence.
240
+ * @param options.filter - Additional filter conditions to apply to the query.
241
+ * @returns A MongoDB query object for checking slug existence.
242
+ */
243
+ createSlugQuery({ slug, field, isObject, haveHistory, filter }: I_Input_GenerateSlug<T>): (mongooseRaw.QueryFilter<T> & {
244
+ $or: ({
245
+ [x: string]: string;
246
+ slugHistory?: undefined;
247
+ } | {
248
+ slugHistory: {
249
+ $elemMatch: {
250
+ [x: string]: string;
251
+ };
252
+ };
253
+ })[];
254
+ }) | (mongooseRaw.QueryFilter<T> & {
255
+ $or: ({
256
+ slug: string;
257
+ slugHistory?: undefined;
258
+ } | {
259
+ slugHistory: string;
260
+ slug?: undefined;
261
+ })[];
262
+ });
263
+ /**
264
+ * Creates a unique slug based on a given string.
265
+ * This method generates multiple slug variations and finds the first available one.
266
+ *
267
+ * @param options - Configuration for slug generation including slug, field, and filter.
268
+ * @param options.slug - The base slug string to make unique.
269
+ * @param options.field - The field name for object-based slug checking.
270
+ * @param options.isObject - Whether the slug is stored as an object with nested fields.
271
+ * @param options.haveHistory - Whether to check historical slug fields for uniqueness.
272
+ * @param options.filter - Additional filter conditions to apply when checking slug existence.
273
+ * @returns A promise that resolves to a unique slug string.
274
+ */
275
+ createUniqueSlug({ slug, field, isObject, haveHistory, filter }: I_Input_GenerateSlug<T>): Promise<string>;
276
+ /**
277
+ * Creates a slug for a document field.
278
+ * This method handles both simple string fields and object fields with nested slug generation.
279
+ *
280
+ * @param options - Configuration for slug creation including field, source document, and filter.
281
+ * @param options.field - The field name to create a slug for.
282
+ * @param options.from - The source document containing the field value.
283
+ * @param options.haveHistory - Whether to check historical slug fields for uniqueness.
284
+ * @param options.filter - Additional filter conditions to apply when checking slug existence.
285
+ * @returns A promise that resolves to a standardized response with the created slug(s).
286
+ */
287
+ createSlug<R = string>({ field, from, filter, haveHistory }: I_Input_CreateSlug<T>): Promise<I_Return<R>>;
288
+ /**
289
+ * Checks if a slug already exists in the collection.
290
+ * This method verifies slug existence in both current and historical slug fields.
291
+ *
292
+ * @param options - Configuration for slug checking including slug, field, source document, and filter.
293
+ * @param options.slug - The slug string to check for existence.
294
+ * @param options.field - The field name for object-based slug checking.
295
+ * @param options.from - The source document containing the field value.
296
+ * @param options.haveHistory - Whether to check historical slug fields for existence.
297
+ * @param options.filter - Additional filter conditions to apply to the query.
298
+ * @returns A promise that resolves to a standardized response indicating whether the slug exists.
299
+ */
300
+ checkSlug({ slug, field, from, filter, haveHistory }: I_Input_CheckSlug<T>): Promise<I_Return<boolean>>;
301
+ /**
302
+ * Performs aggregation operations on the collection.
303
+ *
304
+ * @param pipeline - The aggregation pipeline stages to execute.
305
+ * @returns A promise that resolves to a standardized response with the aggregation results.
306
+ */
307
+ aggregate(pipeline: T_PipelineStage[]): Promise<I_Return<T[]>>;
308
+ /**
309
+ * Retrieves distinct values for the specified key from the collection.
310
+ *
311
+ * @param key - The field for which to return distinct values.
312
+ * @param filter - The filter query to apply (optional).
313
+ * @param options - Additional options for the distinct operation (optional).
314
+ * @returns A promise that resolves to a standardized response with the array of distinct values.
315
+ */
316
+ distinct(key: string, filter?: T_QueryFilter<T>, options?: T_QueryOptions<T>): Promise<I_Return<unknown[]>>;
317
+ }