@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
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,OAAuC,MAAM,SAAS,CAAA;AAE7D,wBAAsB,SAAS,6BAU9B"}
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,OAAuC,MAAM,SAAS,CAAC;AAE9D,wBAAsB,SAAS,6BAU9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"base-usecase.d.ts","sourceRoot":"","sources":["../../src/base-usecase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,MAAM,EAAE,SAAS,CAAA;IACjB,IAAI,EAAE,CAAC,CAAA;CACR;AAGD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE;QACP,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KACxB,CAAA;CACF;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,QAAQ,CAAC;IACjB,KAAK,EAAE,aAAa,CAAA;CACrB;AAED;;;;;;;;;GASG;AACH,8BAAsB,WAAW,CAC/B,MAAM,EACN,a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C,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,oBAAoB;IAU1D;;;;;;OAMG;aACa,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,YAAY,CAAC,GAAG,oBAAoB,CAAC;CAC3G"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.command.d.ts","sourceRoot":"","sources":["../../../../../src/console/commands/make-command/index.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAS,MAAM,wBAAwB,CAAA;AAO3D,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,WAAW;;IAe5C,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CA6B9B"}
1
+ {"version":3,"file":"index.command.d.ts","sourceRoot":"","sources":["../../../../../src/console/commands/make-command/index.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAS,MAAM,wBAAwB,CAAC;AAO5D,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,WAAW;;IAe5C,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CA6B9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.command.d.ts","sourceRoot":"","sources":["../../../../../src/console/commands/make-middleware/index.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAS,MAAM,wBAAwB,CAAA;AAO3D,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,WAAW;;IAuB/C,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB7B,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,2BAA2B;CAkBpC"}
1
+ {"version":3,"file":"index.command.d.ts","sourceRoot":"","sources":["../../../../../src/console/commands/make-middleware/index.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAS,MAAM,wBAAwB,CAAC;AAO5D,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,WAAW;;IAuB/C,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IA+B7B,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,2BAA2B;CAkBpC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/console/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAKnD,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAY;gBAEf,OAAO,EAAE,UAAU;IAI/B;;;;;OAKG;IACG,QAAQ;CAIf"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/console/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKpD,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAa;gBAEhB,OAAO,EAAE,UAAU;IAI/B;;;;;OAKG;IACG,QAAQ;CAIf"}
@@ -0,0 +1,51 @@
1
+ import { BaseError, type IError } from '@point-hub/express-error-handler';
2
+ import { MongoServerError } from 'mongodb';
3
+ /**
4
+ * Converts a MongoDB schema validation error into an HTTP validation error.
5
+ *
6
+ * Extracts missing required properties from MongoDB schema validation details
7
+ * and generates a validation message for each missing property.
8
+ *
9
+ * @param err - MongoDB server error with code 121.
10
+ * @param error - HTTP validation error to populate.
11
+ * @returns The HTTP validation error containing missing property errors.
12
+ */
13
+ export declare function handleSchemaValidation(err: MongoServerError, error: IError): IError;
14
+ /**
15
+ * Converts a MongoDB duplicate key error into an HTTP validation error.
16
+ *
17
+ * Generates a validation message for a single duplicated field or a
18
+ * combination of fields when a compound unique index is violated.
19
+ *
20
+ * @param err - MongoDB server error with code 11000.
21
+ * @param error - HTTP validation error to populate.
22
+ * @returns The HTTP validation error containing duplicate key errors.
23
+ */
24
+ export declare function handleUniqueValidation(err: MongoServerError, error: IError): IError;
25
+ /**
26
+ * Handles MongoDB server errors and converts supported errors into
27
+ * HTTP 422 validation errors.
28
+ *
29
+ * Supported MongoDB error codes:
30
+ * - 121: Document schema validation failure.
31
+ * - 11000: Duplicate key constraint violation.
32
+ *
33
+ * @extends BaseError
34
+ */
35
+ export declare class MongoErrorHandler extends BaseError {
36
+ /**
37
+ * Creates a MongoDB error handler.
38
+ *
39
+ * @param err - MongoDB server error to handle.
40
+ */
41
+ constructor(err: MongoServerError);
42
+ /**
43
+ * Indicates whether the error is operational and expected to be handled.
44
+ */
45
+ get isOperational(): boolean;
46
+ /**
47
+ * Returns the error class name.
48
+ */
49
+ get name(): string;
50
+ }
51
+ //# sourceMappingURL=mongo-error-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo-error-handler.d.ts","sourceRoot":"","sources":["../../../../src/database/mongodb/mongo-error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,KAAK,MAAM,EAEZ,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAYnF;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAuBnF;AAED;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C;;;;OAIG;gBACS,GAAG,EAAE,gBAAgB;IAejC;;OAEG;IACH,IAAI,aAAa,YAEhB;IAED;;OAEG;IACH,IAAa,IAAI,WAEhB;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mongo-error-handler.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo-error-handler.spec.d.ts","sourceRoot":"","sources":["../../../../src/database/mongodb/mongo-error-handler.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,483 @@
1
+ import type { SortDirection } from 'mongodb';
2
+ export interface IFieldsObject {
3
+ [key: string]: number;
4
+ }
5
+ export interface ISortObject {
6
+ [key: string]: SortDirection;
7
+ }
8
+ export interface IMongoUpdate {
9
+ $set?: Record<string, unknown>;
10
+ $unset?: Record<string, true>;
11
+ }
12
+ /**
13
+ * Parses a page query parameter into a positive integer.
14
+ *
15
+ * @param value - Page number as a string or number. Defaults to `1`.
16
+ * @returns Parsed page number or `1` if the value is invalid.
17
+ *
18
+ * @example
19
+ * parsePage('10') // => 10
20
+ * parsePage(10) // => 10
21
+ * parsePage('abc') // => 1
22
+ * parsePage(0) // => 1
23
+ */
24
+ export declare function parsePage(value?: string | number): number;
25
+ /**
26
+ * Parses a page size query parameter into a positive integer.
27
+ *
28
+ * @param value - Number of records per page. Defaults to `10`.
29
+ * @returns Parsed page size or `10` if the value is invalid.
30
+ *
31
+ * @example
32
+ * parsePageSize('10') // => 10
33
+ * parsePageSize(10) // => 10
34
+ * parsePageSize('abc') // => 10
35
+ * parsePageSize(0) // => 10
36
+ */
37
+ export declare function parsePageSize(value?: string | number): number;
38
+ /**
39
+ * Calculates the number of records to skip for pagination.
40
+ *
41
+ * @param currentPage - Current page number.
42
+ * @param pageSize - Number of records per page.
43
+ * @returns Number of records to skip.
44
+ *
45
+ * @example
46
+ * calculateSkip(1, 10) // => 0
47
+ * calculateSkip(2, 10) // => 10
48
+ * calculateSkip(3, 10) // => 20
49
+ */
50
+ export declare function calculateSkip(currentPage: string | number, pageSize: string | number): number;
51
+ /**
52
+ * Converts a comma-separated or space-separated field string
53
+ * into a MongoDB projection object.
54
+ *
55
+ * Supports either inclusion or exclusion projections.
56
+ * Excluded fields cannot be combined with included fields,
57
+ * except for MongoDB's special `_id` field.
58
+ *
59
+ * @param value - Comma-separated or space-separated field names to include.
60
+ * @param excludedFields - Field names to exclude.
61
+ * @returns MongoDB projection object.
62
+ *
63
+ * @example
64
+ * parseProjection('name, address')
65
+ * // => { name: 1, address: 1 }
66
+ *
67
+ * parseProjection('', ['password', 'token'])
68
+ * // => { password: 0, token: 0 }
69
+ *
70
+ * parseProjection('name, address', ['_id'])
71
+ * // => { name: 1, address: 1, _id: 0 }
72
+ */
73
+ export declare function parseProjection(value?: string, excludedFields?: string[]): IFieldsObject;
74
+ /**
75
+ * Converts a comma-separated or space-separated string into an array of field names.
76
+ *
77
+ * @param value - String containing field names.
78
+ * @returns Array of trimmed, non-empty field names.
79
+ *
80
+ * @example
81
+ * parseFieldList('name, address')
82
+ * // => ['name', 'address']
83
+ *
84
+ * parseFieldList('name address')
85
+ * // => ['name', 'address']
86
+ *
87
+ * parseFieldList(' name, address ')
88
+ * // => ['name', 'address']
89
+ */
90
+ export declare function parseFieldList(value: string): string[];
91
+ /**
92
+ * Creates a MongoDB projection object from an array of field names.
93
+ *
94
+ * @param fields - Array of field names.
95
+ * @param value - Projection value assigned to each field. Defaults to `1`.
96
+ * @returns MongoDB projection object.
97
+ *
98
+ * @example
99
+ * createProjection(['name', 'address'])
100
+ * // => { name: 1, address: 1 }
101
+ *
102
+ * createProjection(['name', 'address'], 0)
103
+ * // => { name: 0, address: 0 }
104
+ */
105
+ export declare function createProjection(fields: string[], value?: number): IFieldsObject;
106
+ /**
107
+ * Creates a MongoDB sort object from an array of field names.
108
+ *
109
+ * A field prefixed with `-` is sorted in descending order.
110
+ * Fields without a prefix are sorted in ascending order.
111
+ *
112
+ * @param fields - Array of field names with optional negative prefixes.
113
+ * @returns MongoDB sort object.
114
+ *
115
+ * @example
116
+ * createSort(['-firstName', 'lastName', 'created_at'])
117
+ * // => { firstName: -1, lastName: 1, created_at: 1 }
118
+ */
119
+ export declare function createSort(fields: string[]): Record<string, 1 | -1>;
120
+ /**
121
+ * Excludes specified fields from a MongoDB projection object.
122
+ *
123
+ * Modifies the original projection object by assigning `0`
124
+ * to each excluded field.
125
+ *
126
+ * @param projection - MongoDB projection object to modify.
127
+ * @param fields - Array of field names to exclude.
128
+ * @returns The modified projection object.
129
+ *
130
+ * @example
131
+ * excludeFields({ name: 1, address: 1 }, ['_id'])
132
+ * // => { name: 1, address: 1, _id: 0 }
133
+ */
134
+ export declare function excludeFields(projection: IFieldsObject, fields: string[]): IFieldsObject;
135
+ /**
136
+ * Parses a comma-separated field string into a MongoDB sort object.
137
+ *
138
+ * A field prefixed with `-` is sorted in descending order.
139
+ * Fields without a prefix are sorted in ascending order.
140
+ *
141
+ * @param value - Comma-separated field names with optional negative prefixes.
142
+ * @returns MongoDB sort object.
143
+ *
144
+ * @example
145
+ * parseSort('name, -createdAt')
146
+ * // => { name: 1, createdAt: -1 }
147
+ *
148
+ * parseSort('-createdAt, name')
149
+ * // => { createdAt: -1, name: 1 }
150
+ */
151
+ export declare function parseSort(value: string): ISortObject;
152
+ /**
153
+ * Adds a case-insensitive regex filter to the filters array if a value is provided.
154
+ *
155
+ * @param filters - An array of MongoDB filter objects to be modified.
156
+ * @param field - The field name to apply the regex on.
157
+ * @param value - The string value to search for (optional). If empty or only whitespace, no filter is added.
158
+ *
159
+ * @example
160
+ * const filters: Record<string, unknown>[] = []
161
+ *
162
+ * addRegexFilter(filters, 'name', 'john')
163
+ *
164
+ * // Result:
165
+ * // [{ name: { $regex: 'john', $options: 'i' } }]
166
+ */
167
+ export declare const addRegexFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void;
168
+ /**
169
+ * Adds an exact-match filter to the filters array if a value is provided.
170
+ *
171
+ * @param filters - An array of MongoDB filter objects to be modified.
172
+ * @param field - The field name to match exactly.
173
+ * @param value - The exact value to match (optional). If empty or only whitespace, no filter is added.
174
+ *
175
+ * @example
176
+ * const filters: Record<string, unknown>[] = []
177
+ *
178
+ * addExactFilter(filters, 'status', 'active')
179
+ *
180
+ * // Result:
181
+ * // [{ status: 'active' }]
182
+ */
183
+ export declare const addExactFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void;
184
+ /**
185
+ * Parses a boolean value from a string or boolean input.
186
+ *
187
+ * - Accepts `true` / `false` booleans directly.
188
+ * - Converts string values `"true"` and `"false"` to booleans.
189
+ * - Returns `undefined` for any other value.
190
+ *
191
+ * @param value - A boolean or a string representation of a boolean.
192
+ * @returns `true`, `false`, or `undefined` if the value cannot be parsed.
193
+ *
194
+ * @example
195
+ * parseBoolean(true) // true
196
+ * parseBoolean('true') // true
197
+ * parseBoolean('false') // false
198
+ * parseBoolean('invalid') // undefined
199
+ * parseBoolean() // undefined
200
+ */
201
+ export declare const parseBoolean: (value?: string | boolean) => boolean | undefined;
202
+ /**
203
+ * Adds a boolean exact-match filter to the filters array.
204
+ *
205
+ * The filter is only added if the value can be successfully parsed
206
+ * into a boolean (`true` or `false`).
207
+ *
208
+ * @param filters - An array of MongoDB filter objects to be modified.
209
+ * @param field - The field name to match.
210
+ * @param value - A boolean or string (`"true"` / `"false"`) to match.
211
+ *
212
+ * @example
213
+ * const filters: Record<string, unknown>[] = []
214
+ *
215
+ * addBooleanFilter(filters, 'is_active', 'true')
216
+ * addBooleanFilter(filters, 'is_verified', false)
217
+ *
218
+ * // Result:
219
+ * // [
220
+ * // { is_active: true },
221
+ * // { is_verified: false }
222
+ * // ]
223
+ */
224
+ export declare const addBooleanFilter: (filters: Record<string, unknown>[], field: string, value?: string | boolean) => void;
225
+ /**
226
+ * Adds a MongoDB date range filter (`$gte` / `$lte`) to the filters array.
227
+ *
228
+ * The filter is only added if at least one of `value_from` or `value_to`
229
+ * is provided and non-empty.
230
+ *
231
+ * @param filters - An array of MongoDB filter objects to be modified.
232
+ * @param field - The date field name to apply the range filter on.
233
+ * @param value_from - The start date (inclusive) as a string.
234
+ * @param value_to - The end date (inclusive) as a string.
235
+ *
236
+ * @example
237
+ * const filters: Record<string, unknown>[] = []
238
+ *
239
+ * addDateRangeFilter(filters, 'created_at', '2026-01-01', '2026-12-31')
240
+ *
241
+ * // Result:
242
+ * // [
243
+ * // {
244
+ * // created_at: {
245
+ * // $gte: new Date('2026-01-01'),
246
+ * // $lte: new Date('2026-12-31')
247
+ * // }
248
+ * // }
249
+ * // ]
250
+ *
251
+ * @example
252
+ * const filters: Record<string, unknown>[] = []
253
+ *
254
+ * addDateRangeFilter(filters, 'created_at', '2026-01-01')
255
+ *
256
+ * // Result:
257
+ * // [{ created_at: { $gte: new Date('2026-01-01') } }]
258
+ */
259
+ export declare const addDateRangeFilter: (filters: Record<string, unknown>[], field: string, value_from?: string, value_to?: string) => void;
260
+ /**
261
+ * Adds a numeric filter to the filters array based on comparison operators or a single value.
262
+ *
263
+ * Accepts expressions like `">10<20"`, `"<=15"`, `"=5"` or `"50"` (interpreted as equality).
264
+ *
265
+ * @param filters - An array of MongoDB filter objects to be modified.
266
+ * @param field - The field name to apply the numeric comparison on.
267
+ * @param value - A string representing the numeric comparison(s).
268
+ *
269
+ * @example
270
+ * const filters: Record<string, unknown>[] = []
271
+ *
272
+ * addNumberFilter(filters, 'age', '>=18<65')
273
+ * addNumberFilter(filters, 'score', '90')
274
+ *
275
+ * // Result:
276
+ * // [
277
+ * // { age: { $gte: 18, $lt: 65 } },
278
+ * // { score: 90 }
279
+ * // ]
280
+ */
281
+ export declare const addNumberFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void;
282
+ /**
283
+ * Parses a string expression into MongoDB-style numeric comparison operators.
284
+ *
285
+ * Supported formats:
286
+ * - `"50"` → `{ eq: 50 }`
287
+ * - `">10"` → `{ gt: 10 }`
288
+ * - `"<=15"` → `{ lte: 15 }`
289
+ * - `">=5<20"` → `{ gte: 5, lt: 20 }`
290
+ *
291
+ * Constraints:
292
+ * - Only one lower-bound (`>` or `>=`) and one upper-bound (`<` or `<=`) operator are allowed.
293
+ * - Returns an empty object for malformed or ambiguous expressions.
294
+ *
295
+ * @param expr - A string representing numeric comparisons.
296
+ * @returns An object with numeric comparison constraints.
297
+ *
298
+ * @example
299
+ * parseComparisons('50')
300
+ * // { eq: 50 }
301
+ *
302
+ * parseComparisons('>10')
303
+ * // { gt: 10 }
304
+ *
305
+ * parseComparisons('>=5<20')
306
+ * // { gte: 5, lt: 20 }
307
+ *
308
+ * parseComparisons('<=15')
309
+ * // { lte: 15 }
310
+ *
311
+ * parseComparisons('invalid')
312
+ * // {}
313
+ *
314
+ * @throws Will throw an API error if the input format is invalid or has duplicate bounds.
315
+ */
316
+ export declare const parseComparisons: (expr: string) => {
317
+ gt?: number;
318
+ gte?: number;
319
+ lt?: number;
320
+ lte?: number;
321
+ eq?: number;
322
+ };
323
+ /**
324
+ * Checks whether a value is a plain object.
325
+ *
326
+ * Plain objects have either Object.prototype or null as their prototype.
327
+ * Arrays, Dates, ObjectIds, and other class instances are excluded.
328
+ *
329
+ * @param value - Value to check.
330
+ * @returns True if the value is a plain object.
331
+ */
332
+ export declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
333
+ /**
334
+ * Builds a MongoDB update document from input data.
335
+ *
336
+ * Nested plain objects are recursively flattened into dot-notation paths.
337
+ * Arrays and other non-plain objects are treated as complete values and
338
+ * assigned using `$set`.
339
+ *
340
+ * Explicit dot-notation keys can be used to update individual nested fields
341
+ * or array indexes without replacing the entire array.
342
+ *
343
+ * Value handling:
344
+ * - `undefined`: Ignored; the existing field remains unchanged.
345
+ * - `null`: Added to `$unset` to remove the existing field.
346
+ * - Plain object: Recursively flattened into dot-notation paths.
347
+ * - Array: Added to `$set` as a complete array.
348
+ * - Other values: Added to `$set`.
349
+ *
350
+ * @param rawInput - Input data to convert into MongoDB update operations.
351
+ * @returns MongoDB update document containing `$set` and/or `$unset`.
352
+ * Returns an empty object when there are no applicable updates.
353
+ *
354
+ * @example
355
+ * // Update primitive and nested fields.
356
+ * buildUpdateData({
357
+ * name: 'John',
358
+ * profile: {
359
+ * city: 'Surabaya',
360
+ * postal_code: '60123',
361
+ * },
362
+ * });
363
+ *
364
+ * // Returns:
365
+ * {
366
+ * $set: {
367
+ * name: 'John',
368
+ * 'profile.city': 'Surabaya',
369
+ * 'profile.postal_code': '60123',
370
+ * },
371
+ * }
372
+ *
373
+ * @example
374
+ * // Replace an entire array.
375
+ * buildUpdateData({
376
+ * tags: ['developer', 'admin'],
377
+ * });
378
+ *
379
+ * // Returns:
380
+ * {
381
+ * $set: {
382
+ * tags: ['developer', 'admin'],
383
+ * },
384
+ * }
385
+ *
386
+ * @example
387
+ * // Update a specific array index without replacing the entire array.
388
+ * buildUpdateData({
389
+ * 'tags.500': 'admin',
390
+ * });
391
+ *
392
+ * // Returns:
393
+ * {
394
+ * $set: {
395
+ * 'tags.500': 'admin',
396
+ * },
397
+ * }
398
+ *
399
+ * @example
400
+ * // Update a nested property inside an array.
401
+ * buildUpdateData({
402
+ * 'tasks.500.completed': true,
403
+ * });
404
+ *
405
+ * // Returns:
406
+ * {
407
+ * $set: {
408
+ * 'tasks.500.completed': true,
409
+ * },
410
+ * }
411
+ *
412
+ * @example
413
+ * // Remove fields using null values.
414
+ * buildUpdateData({
415
+ * department_id: null,
416
+ * profile: {
417
+ * avatar: null,
418
+ * },
419
+ * });
420
+ *
421
+ * // Returns:
422
+ * {
423
+ * $unset: {
424
+ * department_id: true,
425
+ * 'profile.avatar': true,
426
+ * },
427
+ * }
428
+ *
429
+ * @example
430
+ * // Ignore undefined values.
431
+ * buildUpdateData({
432
+ * name: undefined,
433
+ * email: undefined,
434
+ * });
435
+ *
436
+ * // Returns:
437
+ * {}
438
+ *
439
+ * @example
440
+ * // Preserve Date and other non-plain object values.
441
+ * buildUpdateData({
442
+ * updated_at: new Date(),
443
+ * });
444
+ *
445
+ * // Returns:
446
+ * {
447
+ * $set: {
448
+ * updated_at: Date,
449
+ * },
450
+ * }
451
+ */
452
+ export declare const buildUpdateData: (rawInput: Record<string, unknown>) => IMongoUpdate;
453
+ /**
454
+ * Collection of utility functions.
455
+ */
456
+ declare const _default: {
457
+ parsePage: typeof parsePage;
458
+ parsePageSize: typeof parsePageSize;
459
+ calculateSkip: typeof calculateSkip;
460
+ parseProjection: typeof parseProjection;
461
+ parseSort: typeof parseSort;
462
+ parseFieldList: typeof parseFieldList;
463
+ createProjection: typeof createProjection;
464
+ createSort: typeof createSort;
465
+ excludeFields: typeof excludeFields;
466
+ addRegexFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void;
467
+ addExactFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void;
468
+ parseBoolean: (value?: string | boolean) => boolean | undefined;
469
+ addBooleanFilter: (filters: Record<string, unknown>[], field: string, value?: string | boolean) => void;
470
+ addDateRangeFilter: (filters: Record<string, unknown>[], field: string, value_from?: string, value_to?: string) => void;
471
+ addNumberFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void;
472
+ parseComparisons: (expr: string) => {
473
+ gt?: number;
474
+ gte?: number;
475
+ lt?: number;
476
+ lte?: number;
477
+ eq?: number;
478
+ };
479
+ isPlainObject: (value: unknown) => value is Record<string, unknown>;
480
+ buildUpdateData: (rawInput: Record<string, unknown>) => IMongoUpdate;
481
+ };
482
+ export default _default;
483
+ //# sourceMappingURL=mongo-query-builder.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo-query-builder.utils.d.ts","sourceRoot":"","sources":["../../../../src/database/mongodb/mongo-query-builder.utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;CAC7B;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,KAAK,GAAE,MAAM,GAAG,MAAU,GAAG,MAAM,CAI5D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,KAAK,GAAE,MAAM,GAAG,MAAW,GAAG,MAAM,CAIjE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,WA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AAE,SAAS,MAAM,UAAU,MAAM;8BAqBxD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,MAAM,UAAU,MAAM;2BAuB3D,MAAM,GAAG,OAAO,KAAG,OAAO,GAAG,SAAS;gCAsChE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAC3B,MAAM,UACL,MAAM,GAAG,OAAO;kCA2CkB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,MAAM,eAAe,MAAM,aAAa,MAAM;+BAkCnF,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,MAAM,UAAU,MAAM;6BAwDzF,MAAM,KACX;QACD,EAAE,CAAC,EAAE,MAAM,CAAA;QACX,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,EAAE,CAAC,EAAE,MAAM,CAAA;QACX,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,EAAE,CAAC,EAAE,MAAM,CAAA;KACZ;2BAyDoC,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gCAkInE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAChC,YAAY;;AAwCf,wBAmBE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mongo-query-builder.utils.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo-query-builder.utils.spec.d.ts","sourceRoot":"","sources":["../../../../src/database/mongodb/mongo-query-builder.utils.spec.ts"],"names":[],"mappings":""}