@point-hub/papi 0.6.6 → 0.7.2

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 (66) hide show
  1. package/lib/index.js +57453 -58118
  2. package/lib/src/app.d.ts.map +1 -1
  3. package/lib/src/base-usecase.d.ts.map +1 -1
  4. package/lib/src/console/commands/make-command/index.command.d.ts.map +1 -1
  5. package/lib/src/console/commands/make-middleware/index.command.d.ts.map +1 -1
  6. package/lib/src/console/index.d.ts.map +1 -1
  7. package/lib/src/database/mongodb/mongo-error-handler.d.ts +51 -0
  8. package/lib/src/database/mongodb/mongo-error-handler.d.ts.map +1 -0
  9. package/lib/src/database/mongodb/mongo-error-handler.spec.d.ts +2 -0
  10. package/lib/src/database/mongodb/mongo-error-handler.spec.d.ts.map +1 -0
  11. package/lib/src/database/mongodb/mongo-query-builder.utils.d.ts +483 -0
  12. package/lib/src/database/mongodb/mongo-query-builder.utils.d.ts.map +1 -0
  13. package/lib/src/database/mongodb/mongo-query-builder.utils.spec.d.ts +2 -0
  14. package/lib/src/database/mongodb/mongo-query-builder.utils.spec.d.ts.map +1 -0
  15. package/lib/src/database/mongodb/mongo-test.service.d.ts +149 -0
  16. package/lib/src/database/mongodb/mongo-test.service.d.ts.map +1 -0
  17. package/lib/src/database/mongodb/mongo-test.service.spec.d.ts +2 -0
  18. package/lib/src/database/mongodb/mongo-test.service.spec.d.ts.map +1 -0
  19. package/lib/src/database/mongodb/mongo.service.d.ts +264 -0
  20. package/lib/src/database/mongodb/mongo.service.d.ts.map +1 -0
  21. package/lib/src/database/mongodb/mongo.service.spec.d.ts +2 -0
  22. package/lib/src/database/mongodb/mongo.service.spec.d.ts.map +1 -0
  23. package/lib/src/index.d.ts +7 -33
  24. package/lib/src/index.d.ts.map +1 -1
  25. package/lib/src/interfaces/types.d.ts +14 -60
  26. package/lib/src/interfaces/types.d.ts.map +1 -1
  27. package/lib/src/server.d.ts.map +1 -1
  28. package/lib/stub/middleware/configurable.middleware.d.ts +3 -0
  29. package/lib/stub/middleware/configurable.middleware.d.ts.map +1 -0
  30. package/lib/stub/middleware/configurable.spec.d.ts +2 -0
  31. package/lib/stub/middleware/configurable.spec.d.ts.map +1 -0
  32. package/lib/stub/middleware/new.middleware.d.ts +3 -0
  33. package/lib/stub/middleware/new.middleware.d.ts.map +1 -0
  34. package/lib/stub/middleware/new.spec.d.ts +2 -0
  35. package/lib/stub/middleware/new.spec.d.ts.map +1 -0
  36. package/package.json +9 -9
  37. package/stub/middleware/configurable.middleware.ts +7 -0
  38. package/stub/middleware/configurable.spec.ts +13 -0
  39. package/stub/middleware/new.middleware.ts +5 -0
  40. package/stub/middleware/new.spec.ts +13 -0
  41. package/lib/src/database/connection.d.ts +0 -37
  42. package/lib/src/database/connection.d.ts.map +0 -1
  43. package/lib/src/database/mongodb/connection.d.ts +0 -43
  44. package/lib/src/database/mongodb/connection.d.ts.map +0 -1
  45. package/lib/src/database/mongodb/mongodb-compose.d.ts +0 -23
  46. package/lib/src/database/mongodb/mongodb-compose.d.ts.map +0 -1
  47. package/lib/src/database/mongodb/mongodb-compose.spec.d.ts +0 -2
  48. package/lib/src/database/mongodb/mongodb-compose.spec.d.ts.map +0 -1
  49. package/lib/src/database/mongodb/mongodb-error-handler.d.ts +0 -10
  50. package/lib/src/database/mongodb/mongodb-error-handler.d.ts.map +0 -1
  51. package/lib/src/database/mongodb/mongodb-helper.d.ts +0 -79
  52. package/lib/src/database/mongodb/mongodb-helper.d.ts.map +0 -1
  53. package/lib/src/database/mongodb/mongodb-helper.spec.d.ts +0 -2
  54. package/lib/src/database/mongodb/mongodb-helper.spec.d.ts.map +0 -1
  55. package/lib/src/database/mongodb/mongodb-query-filters.d.ts +0 -101
  56. package/lib/src/database/mongodb/mongodb-query-filters.d.ts.map +0 -1
  57. package/lib/src/database/mongodb/mongodb-query-filters.spec.d.ts +0 -2
  58. package/lib/src/database/mongodb/mongodb-query-filters.spec.d.ts.map +0 -1
  59. package/lib/src/database/mongodb/mongodb-querystring.d.ts +0 -93
  60. package/lib/src/database/mongodb/mongodb-querystring.d.ts.map +0 -1
  61. package/lib/src/database/mongodb/mongodb-querystring.spec.d.ts +0 -2
  62. package/lib/src/database/mongodb/mongodb-querystring.spec.d.ts.map +0 -1
  63. package/lib/src/middleware/mongodb-error-handler.middleware.d.ts +0 -3
  64. package/lib/src/middleware/mongodb-error-handler.middleware.d.ts.map +0 -1
  65. package/lib/src/test/utils.d.ts +0 -13
  66. package/lib/src/test/utils.d.ts.map +0 -1
@@ -0,0 +1,149 @@
1
+ import { Db, MongoClient } from 'mongodb';
2
+ import type { ISchema } from '../../interfaces/types';
3
+ import { MongoService } from './mongo.service';
4
+ /**
5
+ * Provides utilities for managing a MongoDB database during tests.
6
+ *
7
+ * Handles database connections, collection creation, schema validation,
8
+ * index creation, and database cleanup.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const database = new MongoTestService(process.env.MONGO_URI!, 'api_test')
13
+ *
14
+ * await database.open()
15
+ *
16
+ * try {
17
+ * await database.createCollections(listSchema)
18
+ * // Run tests
19
+ * } finally {
20
+ * await database.close()
21
+ * }
22
+ * ```
23
+ */
24
+ export declare class MongoTestService {
25
+ private mongoClient;
26
+ private mongoService;
27
+ private db;
28
+ /**
29
+ * Creates a MongoDB test service.
30
+ *
31
+ * Initializes the MongoDB client and database reference.
32
+ * The connection is not established until {@link open} is called.
33
+ *
34
+ * @param uri - MongoDB connection URI.
35
+ * @param name - Name of the test database.
36
+ */
37
+ constructor(uri: string, name: string);
38
+ /**
39
+ * Provides access to the MongoDB client.
40
+ *
41
+ * Use this to access native MongoDB client functionality,
42
+ * such as creating sessions and managing transactions.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const session = mongoTestService.client.startSession()
47
+ * ```
48
+ */
49
+ get client(): MongoClient;
50
+ /**
51
+ * Provides access to the MongoDB database.
52
+ *
53
+ * Use this to perform direct database operations in tests,
54
+ * such as inserting fixtures and querying documents.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * await mongoTestService.database.collection('users').insertOne({
59
+ * email: 'john@example.com'
60
+ * })
61
+ * ```
62
+ */
63
+ get database(): Db;
64
+ /**
65
+ * Provides access to the MongoDB service.
66
+ *
67
+ * Use this to perform MongoDB operations through the service abstraction
68
+ * instead of accessing the database directly.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * await mongoTestService.service.createUnique('users', { email: 1 })
73
+ * ```
74
+ */
75
+ get service(): MongoService;
76
+ /**
77
+ * Establishes a connection to MongoDB.
78
+ *
79
+ * @returns A promise that resolves when the connection is established.
80
+ */
81
+ open(): Promise<void>;
82
+ /**
83
+ * Closes the MongoDB connection.
84
+ *
85
+ * @returns A promise that resolves when the connection is closed.
86
+ */
87
+ close(): Promise<void>;
88
+ /**
89
+ * Creates collections defined in the provided schema configuration.
90
+ *
91
+ * For each collection, this method:
92
+ * - Creates the collection if it does not exist.
93
+ * - Applies the collection's JSON schema validation.
94
+ * - Creates unique indexes.
95
+ * - Creates unique sparse indexes for fields that may be missing or null.
96
+ *
97
+ * Existing collections are not dropped or recreated.
98
+ *
99
+ * @param listSchema - Grouped collection schema configurations.
100
+ * @returns A promise that resolves when all collections and indexes are configured.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * await database.createCollections(listSchema)
105
+ * ```
106
+ */
107
+ createCollections(listSchema: ISchema[][]): Promise<void>;
108
+ /**
109
+ * Drops the entire test database, including all its collections and indexes.
110
+ *
111
+ * Use this when a complete database cleanup is required.
112
+ *
113
+ * @returns A promise that resolves when the database has been dropped.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * await database.dropDatabase()
118
+ * ```
119
+ */
120
+ dropDatabase(): Promise<void>;
121
+ /**
122
+ * Drops every collection in the test database.
123
+ *
124
+ * Unlike {@link dropDatabase}, this keeps the database itself.
125
+ *
126
+ * @returns A promise that resolves when all collections have been dropped.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * await database.dropAllCollections()
131
+ * ```
132
+ */
133
+ dropAllCollections(): Promise<void>;
134
+ /**
135
+ * Removes all documents from every collection in the test database.
136
+ *
137
+ * Collections, indexes, and schema validation rules are preserved.
138
+ *
139
+ * @returns A promise that resolves when all collections have been cleared.
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * // Clear test data before each test.
144
+ * await database.reset()
145
+ * ```
146
+ */
147
+ reset(): Promise<void>;
148
+ }
149
+ //# sourceMappingURL=mongo-test.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo-test.service.d.ts","sourceRoot":"","sources":["../../../../src/database/mongodb/mongo-test.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,WAAW,EAAsB,MAAM,SAAS,CAAC;AAE9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,EAAE,CAAK;IAEf;;;;;;;;OAQG;gBACS,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAWrC;;;;;;;;;;OAUG;IACH,IAAW,MAAM,IAAI,WAAW,CAE/B;IAED;;;;;;;;;;;;OAYG;IACH,IAAW,QAAQ,IAAI,EAAE,CAExB;IAED;;;;;;;;;;OAUG;IACH,IAAW,OAAO,IAAI,YAAY,CAEjC;IAED;;;;OAIG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC;;;;OAIG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAInC;;;;;;;;;;;;;;;;;;OAkBG;IACU,iBAAiB,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAkCtE;;;;;;;;;;;OAWG;IACU,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1C;;;;;;;;;;;OAWG;IACU,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAShD;;;;;;;;;;;;OAYG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAOpC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mongo-test.service.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo-test.service.spec.d.ts","sourceRoot":"","sources":["../../../../src/database/mongodb/mongo-test.service.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,264 @@
1
+ import { type AggregateOptions, type CreateIndexesOptions, type Db, type Document, type IndexSpecification } from 'mongodb';
2
+ import { type IPagination } from '../../index';
3
+ /**
4
+ * Represents the result of a paginated MongoDB query.
5
+ *
6
+ * @typeParam T - The document structure returned by the query.
7
+ */
8
+ interface IRetrievePaginated<T> {
9
+ /** The documents retrieved for the current page. */
10
+ data: T[];
11
+ /** Pagination metadata, including page count and total documents. */
12
+ pagination: IPagination;
13
+ }
14
+ /**
15
+ * Options for retrieving paginated MongoDB documents.
16
+ */
17
+ export interface IRetrievePaginatedOptions {
18
+ /** The page number to retrieve. */
19
+ page?: number;
20
+ /** The maximum number of documents per page. */
21
+ pageSize?: number;
22
+ /**
23
+ * Sort expression using field names.
24
+ * Prefix a field with `-` for descending order.
25
+ *
26
+ * @example
27
+ * '-createdAt'
28
+ * 'name,-createdAt'
29
+ */
30
+ sort?: string;
31
+ /**
32
+ * Additional aggregation stages appended after pagination.
33
+ *
34
+ * Useful for operations such as `$lookup` or `$project`
35
+ * that should execute after `$skip` and `$limit`.
36
+ */
37
+ afterPagination?: Document[];
38
+ /** Additional MongoDB aggregation options. */
39
+ aggregateOptions?: AggregateOptions;
40
+ }
41
+ /**
42
+ * Provides methods for managing MongoDB collections, indexes,
43
+ * schema validation, and document retrieval.
44
+ *
45
+ * Supports standard queries and aggregation-based pagination.
46
+ *
47
+ * @see https://www.mongodb.com/docs/drivers/node/current/fundamentals/indexes/
48
+ * @see https://www.mongodb.com/docs/manual/reference/collation/
49
+ * @see https://www.mongodb.com/docs/manual/core/index-sparse/
50
+ * @see https://www.mongodb.com/docs/manual/core/index-partial/
51
+ */
52
+ export declare class MongoService {
53
+ private db;
54
+ /**
55
+ * Creates a MongoDB service instance.
56
+ *
57
+ * @param db - The MongoDB database instance used by this service.
58
+ */
59
+ constructor(db: Db);
60
+ /**
61
+ * Creates a unique index on the specified collection.
62
+ *
63
+ * Uses case-insensitive collation to prevent duplicate values
64
+ * that differ only in letter casing.
65
+ *
66
+ * @param collection - The name of the collection to index.
67
+ * @param spec - The index specification containing the fields and sort order.
68
+ *
69
+ * @example
70
+ * // Create a unique index on the name field.
71
+ * await mongoDBService.createUnique('users', {
72
+ * name: 1
73
+ * })
74
+ *
75
+ * @example
76
+ * // Create a compound unique index on firstName and lastName.
77
+ * await mongoDBService.createUnique('users', {
78
+ * firstName: 1,
79
+ * lastName: 1
80
+ * })
81
+ */
82
+ createUnique(collection: string, spec: IndexSpecification): Promise<void>;
83
+ /**
84
+ * Creates a unique sparse index on the specified collection.
85
+ *
86
+ * Documents that do not contain the indexed field are excluded
87
+ * from the index. Documents containing the indexed field must
88
+ * have unique values.
89
+ *
90
+ * Uses case-insensitive collation.
91
+ *
92
+ * @param collection - The name of the collection to index.
93
+ * @param spec - The index specification containing the fields and sort order.
94
+ *
95
+ * @example
96
+ * // Allow multiple documents without an email field,
97
+ * // but enforce uniqueness when email is present.
98
+ * await mongoDBService.createUniqueIfNotNull('users', {
99
+ * email: 1
100
+ * })
101
+ */
102
+ createUniqueIfNotNull(collection: string, spec: IndexSpecification): Promise<void>;
103
+ /**
104
+ * Creates an index on the specified collection.
105
+ *
106
+ * Supports standard MongoDB index options, including unique,
107
+ * sparse, partialFilterExpression, and expireAfterSeconds.
108
+ *
109
+ * @param collection - The name of the collection to index.
110
+ * @param spec - The index specification containing the fields and sort order.
111
+ * @param options - Optional MongoDB index creation options.
112
+ *
113
+ * @example
114
+ * // Create a standard index on the createdAt field.
115
+ * await mongoDBService.createIndex('users', {
116
+ * createdAt: -1
117
+ * })
118
+ *
119
+ * @example
120
+ * // Create a partial index for active users.
121
+ * await mongoDBService.createIndex(
122
+ * 'users',
123
+ * { email: 1 },
124
+ * {
125
+ * partialFilterExpression: {
126
+ * status: 'active'
127
+ * }
128
+ * }
129
+ * )
130
+ */
131
+ createIndex(collection: string, spec: IndexSpecification, options?: CreateIndexesOptions): Promise<void>;
132
+ /**
133
+ * Checks whether a collection exists in the current database.
134
+ *
135
+ * @param name - The name of the collection to check.
136
+ * @returns True if the collection exists; otherwise, false.
137
+ *
138
+ * @example
139
+ * const exists = await mongoDBService.isExists('users')
140
+ */
141
+ isExists(name: string): Promise<boolean>;
142
+ /**
143
+ * Updates the JSON Schema validator of an existing MongoDB collection.
144
+ *
145
+ * Uses the `collMod` command to modify the collection's validation rules
146
+ * without dropping or recreating the collection.
147
+ *
148
+ * @param name - Name of the collection to update.
149
+ * @param schema - JSON Schema definition used to validate collection documents.
150
+ * @throws {Error} If the database connection is not available.
151
+ */
152
+ updateSchema(name: string, schema: unknown): Promise<void>;
153
+ /**
154
+ * Retrieves paginated documents from a MongoDB collection using an aggregation pipeline.
155
+ *
156
+ * Executes the aggregation pipeline twice:
157
+ * - The count pipeline calculates the total number of documents matching the pipeline.
158
+ * - The data pipeline retrieves documents for the requested page, applying sorting,
159
+ * skipping, and limiting when applicable.
160
+ *
161
+ * @typeParam T - The expected document structure of the retrieved data.
162
+ *
163
+ * @param collection - The name of the MongoDB collection.
164
+ * @param pipeline - The aggregation pipeline used to filter or transform documents.
165
+ * @param options - Pagination, sorting, and aggregation options.
166
+ *
167
+ * @returns The retrieved documents and pagination metadata.
168
+ *
169
+ * @throws RangeError If the page or page size is invalid.
170
+ *
171
+ * @example
172
+ * // Retrieve the first page of active users, sorted by creation date.
173
+ * const result = await mongoDBService.retrievePaginated<IUser>(
174
+ * 'users',
175
+ * [
176
+ * {
177
+ * $match: {
178
+ * status: 'active',
179
+ * },
180
+ * },
181
+ * ],
182
+ * {
183
+ * page: 1,
184
+ * pageSize: 10,
185
+ * sort: '-createdAt',
186
+ * },
187
+ * );
188
+ *
189
+ * @example
190
+ * // Retrieve users with their associated profiles.
191
+ * const result = await mongoDBService.retrievePaginated<IUser>(
192
+ * 'users',
193
+ * [
194
+ * {
195
+ * $lookup: {
196
+ * from: 'profiles',
197
+ * localField: '_id',
198
+ * foreignField: 'user_id',
199
+ * as: 'profile',
200
+ * },
201
+ * },
202
+ * ],
203
+ * {
204
+ * page: 2,
205
+ * pageSize: 20,
206
+ * },
207
+ * );
208
+ */
209
+ retrievePaginated<T extends Document>(collection: string, pipeline?: Document[], options?: IRetrievePaginatedOptions): Promise<IRetrievePaginated<T>>;
210
+ /**
211
+ * Retrieves the first document matching an aggregation pipeline.
212
+ *
213
+ * Executes the provided aggregation pipeline and returns the first
214
+ * matching document. Returns `null` if no document is found.
215
+ *
216
+ * @typeParam T - The expected document structure of the retrieved data.
217
+ *
218
+ * @param collection - The name of the MongoDB collection.
219
+ * @param pipeline - The aggregation pipeline used to filter or transform documents.
220
+ * @param options - MongoDB aggregation options.
221
+ *
222
+ * @returns The first matching document, or `null` if no document is found.
223
+ *
224
+ * @example
225
+ * // Retrieve an active user by email.
226
+ * const user = await mongoDBService.retrieveOne<IUser>(
227
+ * 'users',
228
+ * [
229
+ * {
230
+ * $match: {
231
+ * email: 'john@example.com',
232
+ * status: 'active',
233
+ * },
234
+ * },
235
+ * ],
236
+ * {},
237
+ * );
238
+ *
239
+ * @example
240
+ * // Retrieve a user with their associated profile.
241
+ * const user = await mongoDBService.retrieveOne<IUser>(
242
+ * 'users',
243
+ * [
244
+ * {
245
+ * $match: {
246
+ * _id: userId,
247
+ * },
248
+ * },
249
+ * {
250
+ * $lookup: {
251
+ * from: 'profiles',
252
+ * localField: '_id',
253
+ * foreignField: 'user_id',
254
+ * as: 'profile',
255
+ * },
256
+ * },
257
+ * ],
258
+ * {},
259
+ * );
260
+ */
261
+ retrieveOne<T extends Document>(collection: string, pipeline: Document[] | undefined, options: AggregateOptions): Promise<T | null>;
262
+ }
263
+ export {};
264
+ //# sourceMappingURL=mongo.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo.service.d.ts","sourceRoot":"","sources":["../../../../src/database/mongodb/mongo.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,KAAK,EAAE,EAAE,KAAK,QAAQ,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE5H,OAAO,EAAE,KAAK,WAAW,EAAqB,MAAM,aAAa,CAAC;AAElE;;;;GAIG;AACH,UAAU,kBAAkB,CAAC,CAAC;IAC5B,oDAAoD;IACpD,IAAI,EAAE,CAAC,EAAE,CAAC;IAEV,qEAAqE;IACrE,UAAU,EAAE,WAAW,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,mCAAmC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IACH,eAAe,CAAC,EAAE,QAAQ,EAAE,CAAC;IAE7B,8CAA8C;IAC9C,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,EAAE,CAAK;IAEf;;;;OAIG;gBACS,EAAE,EAAE,EAAE;IAIlB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACU,YAAY,CACvB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,IAAI,CAAC;IAUhB;;;;;;;;;;;;;;;;;;OAkBG;IACU,qBAAqB,CAChC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,IAAI,CAAC;IAWhB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACU,WAAW,CACtB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,kBAAkB,EACxB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,IAAI,CAAC;IAIhB;;;;;;;;OAQG;IACU,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMrD;;;;;;;;;OASG;IACU,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAavE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuDG;IACU,iBAAiB,CAAC,CAAC,SAAS,QAAQ,EAC/C,UAAU,EAAE,MAAM,EAClB,QAAQ,GAAE,QAAQ,EAAO,EACzB,OAAO,GAAE,yBAGR,GACA,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IA+CjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkDG;IACU,WAAW,CAAC,CAAC,SAAS,QAAQ,EACzC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,QAAQ,EAAE,YAAK,EACzB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;CAQrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mongo.service.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo.service.spec.d.ts","sourceRoot":"","sources":["../../../../src/database/mongodb/mongo.service.spec.ts"],"names":[],"mappings":""}
@@ -1,49 +1,23 @@
1
- import { BaseCommand } from '@point-hub/express-cli';
2
1
  import { ApiError, BaseError, errorHandlerMiddleware, find, invalidPathMiddleware, type TypeCodeStatus } from '@point-hub/express-error-handler';
3
- import { MongoServerError } from 'mongodb';
4
- import { ConsoleKernel } from './console';
5
- import { DatabaseConnection } from './database/connection';
6
- import { MongoDBConnection } from './database/mongodb/connection';
7
- import { MongoErrorHandler } from './database/mongodb/mongodb-error-handler';
8
- import { MongoDBHelper } from './database/mongodb/mongodb-helper';
9
- import mongodbErrorHandlerMiddleware from './middleware/mongodb-error-handler.middleware';
10
2
  export declare const stubDir: string;
11
3
  export type { IUseCaseError, IUseCaseOutputFailed, IUseCaseOutputSuccess } from './base-usecase';
12
4
  export { BaseUseCase } from './base-usecase';
13
- export { ExpressCli as BaseConsoleCli } from '@point-hub/express-cli';
14
- export declare const BaseConsoleCommand: typeof BaseCommand;
15
- export declare const BaseConsoleKernel: typeof ConsoleKernel;
16
- export { composeUpdate } from './database/mongodb/mongodb-compose';
17
- export { DatabaseTestUtil } from './test/utils';
18
- export declare const BaseDatabaseConnection: typeof DatabaseConnection;
19
- export declare const BaseMongoDBConnection: typeof MongoDBConnection;
20
- export declare const BaseMongoDBHelper: typeof MongoDBHelper;
21
- export declare const BaseMongoDBQuerystring: {
22
- page: typeof import("./database/mongodb/mongodb-querystring").page;
23
- limit: typeof import("./database/mongodb/mongodb-querystring").limit;
24
- skip: typeof import("./database/mongodb/mongodb-querystring").skip;
25
- sort: typeof import("./database/mongodb/mongodb-querystring").sort;
26
- fields: typeof import("./database/mongodb/mongodb-querystring").fields;
27
- filter: typeof import("./database/mongodb/mongodb-querystring").filter;
28
- filterExludeFields: typeof import("./database/mongodb/mongodb-querystring").filterExludeFields;
29
- convertStringToArray: typeof import("./database/mongodb/mongodb-querystring").convertStringToArray;
30
- convertFieldObject: typeof import("./database/mongodb/mongodb-querystring").convertFieldObject;
31
- convertSortObject: typeof import("./database/mongodb/mongodb-querystring").convertSortObject;
32
- };
33
- export { default as BaseMongoDBQueryFilters } from './database/mongodb/mongodb-query-filters';
34
- export declare const BaseMongoServerError: typeof MongoServerError;
35
- export declare const BaseMongoErrorHandler: typeof MongoErrorHandler;
5
+ export { ConsoleKernel } from './console';
6
+ export { BaseCommand, ExpressCli } from '@point-hub/express-cli';
7
+ export { MongoService } from './database/mongodb/mongo.service';
8
+ export { MongoErrorHandler } from './database/mongodb/mongo-error-handler';
9
+ export { default as MongoQueryBuilder } from './database/mongodb/mongo-query-builder.utils';
10
+ export { MongoTestService } from './database/mongodb/mongo-test.service';
36
11
  export { default as BaseFactory } from '@point-hub/express-factory';
37
12
  export declare const BaseErrorHandler: {
38
13
  ApiError: typeof ApiError;
39
14
  BaseError: typeof BaseError;
40
15
  isTrustedError: (err: Error) => boolean;
41
16
  getHttpError: typeof find;
42
- mongodbErrorHandlerMiddleware: typeof mongodbErrorHandlerMiddleware;
43
17
  errorHandlerMiddleware: typeof errorHandlerMiddleware;
44
18
  invalidPathMiddleware: typeof invalidPathMiddleware;
45
19
  };
46
20
  export { Server as BaseServer } from './server';
47
21
  export type { TypeCodeStatus };
48
- export type { IAggregateOutput, IAggregateRepository, IAppInput, IBaseRouterInput, IClientSession, IController, IControllerInput, IControllerOutput, ICreateManyOutput, ICreateManyRepository, ICreateOutput, ICreateRepository, IDatabase, IDeleteManyOutput, IDeleteManyRepository, IDeleteOutput, IDeleteRepository, IDocument, IMakeControllerInput, IMakeMiddlewareInput, IMiddleware, IMiddlewareInput, IMongoDBConfig, IPagination, IPipeline, IQuery, IRetrieveAllOutput, IRetrieveAllRepository, IRetrieveManyOutput, IRetrieveManyRepository, IRetrieveRepository, ISchema, ISchemaValidation, IServerConfig, IUpdateManyOutput, IUpdateManyRepository, IUpdateOutput, IUpdateRepository } from './interfaces/types';
22
+ export type { IAggregateOutput, IAggregateRepository, IAppInput, IBaseRouterInput, IController, IControllerInput, IControllerOutput, ICreateManyOutput, ICreateManyRepository, ICreateOutput, ICreateRepository, IDeleteManyOutput, IDeleteManyRepository, IDeleteOutput, IDeleteRepository, IDocument, IMakeControllerInput, IMakeMiddlewareInput, IMiddleware, IMiddlewareInput, IMongoDBConfig, IPagination, IPipeline, IQuery, IRetrieveManyOutput, IRetrieveManyRepository, IRetrieveRepository, ISchema, ISchemaValidation, IServerConfig, IUpdateManyOutput, IUpdateManyRepository, IUpdateOutput, IUpdateRepository, } from './interfaces/types';
49
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EACL,QAAQ,EACR,SAAS,EACT,sBAAsB,EACtB,IAAI,EACJ,qBAAqB,EAErB,KAAK,cAAc,EACpB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAA;AAEjE,OAAO,6BAA6B,MAAM,+CAA+C,CAAA;AAEzF,eAAO,MAAM,OAAO,QAAqF,CAAA;AAGzG,YAAY,EAAE,aAAa,EAAC,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAC/F,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACrE,eAAO,MAAM,kBAAkB,oBAAc,CAAA;AAC7C,eAAO,MAAM,iBAAiB,sBAAgB,CAAA;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,eAAO,MAAM,sBAAsB,2BAAqB,CAAA;AACxD,eAAO,MAAM,qBAAqB,0BAAoB,CAAA;AACtD,eAAO,MAAM,iBAAiB,sBAAgB,CAAA;AAC9C,eAAO,MAAM,sBAAsB;;;;;;;;;;;CAAc,CAAA;AACjD,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,0CAA0C,CAAA;AAC7F,eAAO,MAAM,oBAAoB,yBAAmB,CAAA;AACpD,eAAO,MAAM,qBAAqB,0BAAoB,CAAA;AAEtD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAEnE,eAAO,MAAM,gBAAgB;;;;;;;;CAQ5B,CAAA;AAED,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,UAAU,CAAA;AAE/C,YAAY,EAAE,cAAc,EAAE,CAAA;AAC9B,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,SAAS,EACT,MAAM,EACN,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,OAAO,EACP,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EAClB,MAAM,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,sBAAsB,EACtB,IAAI,EACJ,qBAAqB,EAErB,KAAK,cAAc,EACpB,MAAM,kCAAkC,CAAC;AAE1C,eAAO,MAAM,OAAO,QAA2C,CAAC;AAEhE,YAAY,EAAE,aAAa,EAAC,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAEzE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEpE,eAAO,MAAM,gBAAgB;;;;;;;CAO5B,CAAC;AAEF,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,UAAU,CAAC;AAEhD,YAAY,EAAE,cAAc,EAAE,CAAC;AAC/B,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,SAAS,EACT,MAAM,EACN,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,OAAO,EACP,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACb,iBAAiB,GAClB,MAAM,oBAAoB,CAAC"}
@@ -1,12 +1,13 @@
1
- import type { Request, RequestHandler, Response } from 'express';
2
- import { ClientSession } from 'mongodb';
1
+ import type { NextFunction, Request, RequestHandler, Response } from 'express';
2
+ import { MongoClient, ObjectId } from 'mongodb';
3
3
  /**
4
4
  * Controller
5
5
  */
6
6
  export interface IControllerInput {
7
7
  req: Request;
8
8
  res: Response;
9
- dbConnection: IDatabase;
9
+ next: NextFunction;
10
+ mongoClient: MongoClient;
10
11
  }
11
12
  export interface IController {
12
13
  (input: IControllerInput): Promise<IControllerOutput | void>;
@@ -22,7 +23,8 @@ export interface IControllerOutput {
22
23
  export interface IMiddlewareInput {
23
24
  req: Request;
24
25
  res: Response;
25
- dbConnection: IDatabase;
26
+ next: NextFunction;
27
+ mongoClient: MongoClient;
26
28
  }
27
29
  export type IAppMiddleware = (input: IMiddlewareInput) => Promise<void> | void;
28
30
  export type IMiddleware = RequestHandler | IAppMiddleware;
@@ -39,28 +41,22 @@ export interface ICreateRepository {
39
41
  handle(document: IDocument, options?: unknown): Promise<ICreateOutput>;
40
42
  }
41
43
  export interface IDeleteManyRepository {
42
- handle(_ids: string[], options?: unknown): Promise<IDeleteManyOutput>;
44
+ handle(_ids: (string | ObjectId)[], options?: unknown): Promise<IDeleteManyOutput>;
43
45
  }
44
46
  export interface IDeleteRepository {
45
- handle(_id: string, options?: unknown): Promise<IDeleteOutput>;
46
- }
47
- /**
48
- * @deprecated
49
- */
50
- export interface IRetrieveAllRepository<TData> {
51
- handle(query: IQuery, options?: unknown): Promise<TData>;
47
+ handle(_id: (string | ObjectId), options?: unknown): Promise<IDeleteOutput>;
52
48
  }
53
49
  export interface IRetrieveManyRepository<TData> {
54
50
  handle(query: IQuery, options?: unknown): Promise<TData>;
55
51
  }
56
52
  export interface IRetrieveRepository<TOutput extends object> {
57
- handle(_id: string, options?: unknown): Promise<TOutput>;
53
+ handle(_id: (string | ObjectId), options?: unknown): Promise<TOutput>;
58
54
  }
59
55
  export interface IUpdateManyRepository {
60
56
  handle(filter: IDocument, document: IDocument, options?: unknown): Promise<IUpdateManyOutput>;
61
57
  }
62
58
  export interface IUpdateRepository {
63
- handle(_id: string, document: IDocument, options?: unknown): Promise<IUpdateOutput>;
59
+ handle(_id: (string | ObjectId), document: IDocument, options?: unknown): Promise<IUpdateOutput>;
64
60
  }
65
61
  /**
66
62
  * Database
@@ -105,13 +101,6 @@ export interface IPagination {
105
101
  page_size: number;
106
102
  total_document: number;
107
103
  }
108
- /**
109
- * @deprecated
110
- */
111
- export interface IRetrieveAllOutput<TData> {
112
- data: TData[];
113
- pagination: IPagination;
114
- }
115
104
  export interface IRetrieveManyOutput<TData> {
116
105
  data: TData[];
117
106
  pagination: IPagination;
@@ -134,60 +123,25 @@ export interface IAggregateOutput<TData> {
134
123
  data: TData[];
135
124
  pagination: IPagination;
136
125
  }
137
- export interface IClientSession extends ClientSession {
138
- }
139
- export interface IDatabase {
140
- session: unknown;
141
- open(): Promise<void>;
142
- close(): Promise<void>;
143
- database(name: string, options?: unknown): this;
144
- collection(name: string, options?: unknown): this;
145
- listCollections(): Promise<{
146
- name: string;
147
- }[]>;
148
- startSession(): ClientSession;
149
- endSession(): Promise<void>;
150
- startTransaction(): void;
151
- commitTransaction(): Promise<void>;
152
- abortTransaction(): Promise<void>;
153
- createIndex(name: string, spec: unknown, options?: unknown): Promise<void>;
154
- createCollection(name: string, options?: unknown): Promise<void>;
155
- dropCollection(name: string, options?: unknown): Promise<void>;
156
- dropDatabase(options?: unknown): Promise<void>;
157
- updateSchema(name: string, schema: unknown): Promise<void>;
158
- command(document: IDocument, options?: unknown): Promise<IDocument>;
159
- create(document: IDocument, options?: unknown): Promise<ICreateOutput>;
160
- createMany(documents: IDocument[], options?: unknown): Promise<ICreateManyOutput>;
161
- retrieveAll<TData>(query: IQuery, options?: unknown): Promise<IRetrieveAllOutput<TData>>;
162
- retrieveMany<TData>(query: IQuery, options?: unknown): Promise<IRetrieveManyOutput<TData>>;
163
- retrieve<TOutput extends object>(_id: string, options?: unknown): Promise<TOutput | null>;
164
- update(filter: string | IDocument, document: IDocument, options?: unknown): Promise<IUpdateOutput>;
165
- updateOne(filter: IDocument, document: IDocument, options?: unknown): Promise<IUpdateOutput>;
166
- updateMany(filter: IDocument, document: IDocument, options?: unknown): Promise<IUpdateManyOutput>;
167
- delete(_id: string, options?: unknown): Promise<IDeleteOutput>;
168
- deleteMany(input: string[] | Record<string, unknown>, options?: unknown): Promise<IDeleteManyOutput>;
169
- deleteAll(options?: unknown): Promise<IDeleteManyOutput>;
170
- aggregate<TData>(pipeline?: IPipeline[], query?: IQuery, options?: unknown): Promise<IAggregateOutput<TData>>;
171
- }
172
126
  /**
173
127
  * Express App
174
128
  */
175
129
  export interface IAppInput {
176
- dbConnection: IDatabase;
130
+ mongoClient: MongoClient;
177
131
  }
178
132
  export interface IMakeControllerInput {
179
133
  controller: IController;
180
- dbConnection: IDatabase;
134
+ mongoClient: MongoClient;
181
135
  }
182
136
  export interface IMakeMiddlewareInput {
183
137
  middleware: IMiddleware;
184
- dbConnection: IDatabase;
138
+ mongoClient: MongoClient;
185
139
  }
186
140
  /**
187
141
  * Router
188
142
  */
189
143
  export interface IBaseRouterInput {
190
- dbConnection: IDatabase;
144
+ mongoClient: MongoClient;
191
145
  }
192
146
  /**
193
147
  * Schema Validation