reslib 1.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 (200) hide show
  1. package/README.md +298 -0
  2. package/build/auth/index.d.ts +2034 -0
  3. package/build/auth/index.js +5 -0
  4. package/build/auth/types.d.ts +465 -0
  5. package/build/auth/types.js +1 -0
  6. package/build/countries/countries.d.ts +1454 -0
  7. package/build/countries/countries.js +1 -0
  8. package/build/countries/index.d.ts +159 -0
  9. package/build/countries/index.js +5 -0
  10. package/build/countries/types.d.ts +65 -0
  11. package/build/countries/types.js +1 -0
  12. package/build/currency/currencies.d.ts +8 -0
  13. package/build/currency/currencies.js +1 -0
  14. package/build/currency/index.d.ts +51 -0
  15. package/build/currency/index.js +5 -0
  16. package/build/currency/session.d.ts +23 -0
  17. package/build/currency/session.js +5 -0
  18. package/build/currency/types.d.ts +1039 -0
  19. package/build/currency/types.js +1 -0
  20. package/build/currency/utils.d.ts +25 -0
  21. package/build/currency/utils.js +1 -0
  22. package/build/i18n/index.d.ts +640 -0
  23. package/build/i18n/index.js +5 -0
  24. package/build/inputFormatter/index.d.ts +396 -0
  25. package/build/inputFormatter/index.js +5 -0
  26. package/build/inputFormatter/types.d.ts +544 -0
  27. package/build/inputFormatter/types.js +1 -0
  28. package/build/logger/index.d.ts +235 -0
  29. package/build/logger/index.js +5 -0
  30. package/build/observable/index.d.ts +329 -0
  31. package/build/observable/index.js +1 -0
  32. package/build/platform/index.d.ts +32 -0
  33. package/build/platform/index.js +1 -0
  34. package/build/resources/ResourcePaginationHelper.d.ts +537 -0
  35. package/build/resources/ResourcePaginationHelper.js +2 -0
  36. package/build/resources/decorators/create.decorator.d.ts +20 -0
  37. package/build/resources/decorators/create.decorator.js +1 -0
  38. package/build/resources/decorators/index.d.ts +41 -0
  39. package/build/resources/decorators/index.js +1 -0
  40. package/build/resources/fields/index.d.ts +33 -0
  41. package/build/resources/fields/index.js +1 -0
  42. package/build/resources/filters.d.ts +62 -0
  43. package/build/resources/filters.js +1 -0
  44. package/build/resources/index.d.ts +854 -0
  45. package/build/resources/index.js +6 -0
  46. package/build/resources/types/filters.d.ts +508 -0
  47. package/build/resources/types/filters.js +1 -0
  48. package/build/resources/types/index.d.ts +4138 -0
  49. package/build/resources/types/index.js +1 -0
  50. package/build/session/index.d.ts +1474 -0
  51. package/build/session/index.js +1 -0
  52. package/build/translations/auth.en.d.ts +3 -0
  53. package/build/translations/auth.en.js +1 -0
  54. package/build/translations/countries.en.d.ts +6 -0
  55. package/build/translations/countries.en.js +1 -0
  56. package/build/translations/currencies.en.d.ts +5 -0
  57. package/build/translations/currencies.en.js +1 -0
  58. package/build/translations/date.en.d.ts +19 -0
  59. package/build/translations/date.en.js +1 -0
  60. package/build/translations/index.d.ts +1583 -0
  61. package/build/translations/index.js +5 -0
  62. package/build/translations/resources.en.d.ts +6 -0
  63. package/build/translations/resources.en.js +1 -0
  64. package/build/translations/validator.en.d.ts +104 -0
  65. package/build/translations/validator.en.js +5 -0
  66. package/build/types/date.d.ts +44 -0
  67. package/build/types/date.js +1 -0
  68. package/build/types/dictionary.d.ts +29 -0
  69. package/build/types/dictionary.js +1 -0
  70. package/build/types/i18n.d.ts +121 -0
  71. package/build/types/i18n.js +1 -0
  72. package/build/types/index.d.ts +145 -0
  73. package/build/types/index.js +1 -0
  74. package/build/utils/areEquals.d.ts +19 -0
  75. package/build/utils/areEquals.js +1 -0
  76. package/build/utils/date/dateHelper.d.ts +371 -0
  77. package/build/utils/date/dateHelper.js +5 -0
  78. package/build/utils/date/index.d.ts +212 -0
  79. package/build/utils/date/index.js +5 -0
  80. package/build/utils/date/isDateObj.d.ts +14 -0
  81. package/build/utils/date/isDateObj.js +1 -0
  82. package/build/utils/debounce.d.ts +52 -0
  83. package/build/utils/debounce.js +1 -0
  84. package/build/utils/defaultArray.d.ts +18 -0
  85. package/build/utils/defaultArray.js +1 -0
  86. package/build/utils/defaultBool.d.ts +14 -0
  87. package/build/utils/defaultBool.js +1 -0
  88. package/build/utils/defaultStr.d.ts +17 -0
  89. package/build/utils/defaultStr.js +1 -0
  90. package/build/utils/defaultVal.d.ts +18 -0
  91. package/build/utils/defaultVal.js +1 -0
  92. package/build/utils/dom/index.d.ts +65 -0
  93. package/build/utils/dom/index.js +1 -0
  94. package/build/utils/dom/isDOMElement.d.ts +11 -0
  95. package/build/utils/dom/isDOMElement.js +1 -0
  96. package/build/utils/file/index.d.ts +26 -0
  97. package/build/utils/file/index.js +1 -0
  98. package/build/utils/global.d.ts +53 -0
  99. package/build/utils/global.js +1 -0
  100. package/build/utils/image.d.ts +56 -0
  101. package/build/utils/image.js +1 -0
  102. package/build/utils/index.d.ts +39 -0
  103. package/build/utils/index.js +6 -0
  104. package/build/utils/interpolate.d.ts +105 -0
  105. package/build/utils/interpolate.js +1 -0
  106. package/build/utils/isEmail.d.ts +57 -0
  107. package/build/utils/isEmail.js +1 -0
  108. package/build/utils/isEmpty.d.ts +18 -0
  109. package/build/utils/isEmpty.js +1 -0
  110. package/build/utils/isNonNullString.d.ts +17 -0
  111. package/build/utils/isNonNullString.js +1 -0
  112. package/build/utils/isNullable.d.ts +7 -0
  113. package/build/utils/isNullable.js +1 -0
  114. package/build/utils/isNumber.d.ts +36 -0
  115. package/build/utils/isNumber.js +1 -0
  116. package/build/utils/isPrimitive.d.ts +16 -0
  117. package/build/utils/isPrimitive.js +1 -0
  118. package/build/utils/isPromise.d.ts +14 -0
  119. package/build/utils/isPromise.js +1 -0
  120. package/build/utils/isRegex.d.ts +15 -0
  121. package/build/utils/isRegex.js +1 -0
  122. package/build/utils/isTime.d.ts +18 -0
  123. package/build/utils/isTime.js +1 -0
  124. package/build/utils/json.d.ts +224 -0
  125. package/build/utils/json.js +1 -0
  126. package/build/utils/numbers.d.ts +148 -0
  127. package/build/utils/numbers.js +5 -0
  128. package/build/utils/object.d.ts +567 -0
  129. package/build/utils/object.js +1 -0
  130. package/build/utils/sort.d.ts +67 -0
  131. package/build/utils/sort.js +1 -0
  132. package/build/utils/string.d.ts +165 -0
  133. package/build/utils/string.js +1 -0
  134. package/build/utils/stringify.d.ts +23 -0
  135. package/build/utils/stringify.js +1 -0
  136. package/build/utils/uniqid.d.ts +18 -0
  137. package/build/utils/uniqid.js +1 -0
  138. package/build/utils/uri/index.d.ts +333 -0
  139. package/build/utils/uri/index.js +2 -0
  140. package/build/validator/index.d.ts +4 -0
  141. package/build/validator/index.js +6 -0
  142. package/build/validator/rules/array.d.ts +848 -0
  143. package/build/validator/rules/array.js +5 -0
  144. package/build/validator/rules/boolean.d.ts +87 -0
  145. package/build/validator/rules/boolean.js +5 -0
  146. package/build/validator/rules/date.d.ts +551 -0
  147. package/build/validator/rules/date.js +5 -0
  148. package/build/validator/rules/default.d.ts +367 -0
  149. package/build/validator/rules/default.js +5 -0
  150. package/build/validator/rules/enum.d.ts +155 -0
  151. package/build/validator/rules/enum.js +5 -0
  152. package/build/validator/rules/file.d.ts +356 -0
  153. package/build/validator/rules/file.js +5 -0
  154. package/build/validator/rules/format.d.ts +2825 -0
  155. package/build/validator/rules/format.js +6 -0
  156. package/build/validator/rules/index.d.ts +16 -0
  157. package/build/validator/rules/index.js +6 -0
  158. package/build/validator/rules/multiRules.d.ts +475 -0
  159. package/build/validator/rules/multiRules.js +5 -0
  160. package/build/validator/rules/numeric.d.ts +1135 -0
  161. package/build/validator/rules/numeric.js +5 -0
  162. package/build/validator/rules/string.d.ts +504 -0
  163. package/build/validator/rules/string.js +5 -0
  164. package/build/validator/rules/target.d.ts +137 -0
  165. package/build/validator/rules/target.js +5 -0
  166. package/build/validator/rules/utils.d.ts +1 -0
  167. package/build/validator/rules/utils.js +1 -0
  168. package/build/validator/rulesMarkers.d.ts +11 -0
  169. package/build/validator/rulesMarkers.js +1 -0
  170. package/build/validator/types.d.ts +2906 -0
  171. package/build/validator/types.js +1 -0
  172. package/build/validator/validator.d.ts +3692 -0
  173. package/build/validator/validator.js +5 -0
  174. package/lib/cjs/auth.js +1 -0
  175. package/lib/cjs/countries.js +1 -0
  176. package/lib/cjs/currency.js +1 -0
  177. package/lib/cjs/i18n.js +1 -0
  178. package/lib/cjs/inputFormatter.js +1 -0
  179. package/lib/cjs/logger.js +1 -0
  180. package/lib/cjs/observable.js +1 -0
  181. package/lib/cjs/platform.js +1 -0
  182. package/lib/cjs/resources.js +1 -0
  183. package/lib/cjs/session.js +1 -0
  184. package/lib/cjs/types.js +1 -0
  185. package/lib/cjs/utils.js +1 -0
  186. package/lib/cjs/validator.js +1 -0
  187. package/lib/esm/auth.mjs +1 -0
  188. package/lib/esm/countries.mjs +1 -0
  189. package/lib/esm/currency.mjs +1 -0
  190. package/lib/esm/i18n.mjs +1 -0
  191. package/lib/esm/inputFormatter.mjs +1 -0
  192. package/lib/esm/logger.mjs +1 -0
  193. package/lib/esm/observable.mjs +1 -0
  194. package/lib/esm/platform.mjs +1 -0
  195. package/lib/esm/resources.mjs +1 -0
  196. package/lib/esm/session.mjs +1 -0
  197. package/lib/esm/types.mjs +1 -0
  198. package/lib/esm/utils.mjs +1 -0
  199. package/lib/esm/validator.mjs +1 -0
  200. package/package.json +244 -0
@@ -0,0 +1,508 @@
1
+ /**
2
+ * Interface representing various comparison operators for filtering operations.
3
+ *
4
+ * This interface allows you to specify conditions for querying data based on
5
+ * different comparison criteria. Each property corresponds to a specific
6
+ * comparison operation that can be applied to filter results.
7
+ *
8
+ * @example
9
+ * // Example of using MongoComparisonOperators
10
+ * const filter: MongoComparisonOperators = {
11
+ * $eq: "example", // Matches documents where the field equals "example"
12
+ * $ne: 42, // Matches documents where the field is not equal to 42
13
+ * $gt: 100, // Matches documents where the field is greater than 100
14
+ * $gte: 50, // Matches documents where the field is greater than or equal to 50
15
+ * $lt: 10, // Matches documents where the field is less than 10
16
+ * $lte: 5, // Matches documents where the field is less than or equal to 5
17
+ * $in: ["apple", "banana"], // Matches documents where the field is in the specified array
18
+ * $nin: [1, 2, 3], // Matches documents where the field is not in the specified array
19
+ * $exists: true, // Matches documents where the field exists
20
+ * $type: "string", // Matches documents where the field is of type string
21
+ * $regex: "^test.*",
22
+ * $options: "i" // Case insensitive match
23
+ * $size: 3, // Matches documents where the field is an array of size 3
24
+ * $mod: [2, 0], // Matches documents where the field modulo 2 equals 0
25
+ * $all: [1, 2], // Matches documents where the array contains all specified values
26
+ * $elemMatch: { // Matches documents where at least one element in the array matches the criteria
27
+ * field: { $gt: 10 }
28
+ * }
29
+ * };
30
+ */
31
+ export interface MongoComparisonOperators<T = unknown> extends MongoArrayOperators<T> {
32
+ $eq?: T;
33
+ $ne?: T;
34
+ $gt?: T;
35
+ $gte?: T;
36
+ $lt?: T;
37
+ $lte?: T;
38
+ $exists?: boolean;
39
+ $type?: string;
40
+ $regex?: string | RegExp;
41
+ $options?: string;
42
+ $size?: number;
43
+ /***
44
+ * modulo operator.
45
+ * example :
46
+ * { age: { $mod: [5, 0] } } - finds documents where age mod 5 equals 0
47
+ */
48
+ $mod?: [divisor: number, remainder: number];
49
+ }
50
+ /**
51
+ * Interface representing logical operators for filtering operations.
52
+ *
53
+ * This interface allows you to combine multiple filter conditions using logical
54
+ * operators. It provides a way to create complex queries by specifying how
55
+ * different conditions relate to each other.
56
+ *
57
+ * @example
58
+ * // Example of using MongoLogicalOperators
59
+ * const filter: MongoLogicalOperators = {
60
+ * $and: [
61
+ * { age: { $gte: 18 } }, // Must be 18 or older
62
+ * { status: "active" } // Must be active
63
+ * ],
64
+ * $or: [
65
+ * { role: "admin" }, // Either role is admin
66
+ * { role: "editor" } // Or role is editor
67
+ * ],
68
+ * $nor: [
69
+ * { deleted: true } // Must not be deleted
70
+ * ],
71
+ * $not: { // Must not match this condition
72
+ * status: "inactive" // Must not be inactive
73
+ * }
74
+ * };
75
+ */
76
+ export interface MongoLogicalOperators<T = unknown> {
77
+ $and?: MongoQuery<T>[];
78
+ $or?: MongoQuery<T>[];
79
+ $nor?: MongoQuery<T>[];
80
+ $not?: MongoQuery<T>;
81
+ }
82
+ /**
83
+ * Represents the names of logical operators defined in the `MongoLogicalOperators` interface.
84
+ *
85
+ * The `MongoLogicalOperatorName` type is a union of the keys from the `MongoLogicalOperators` interface.
86
+ * It provides a concise and type-safe way to refer to logical operator names used in MongoDB queries.
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const logicalOperator: MongoLogicalOperatorName = "$and"; // Valid, as $and is a logical operator
91
+ * const invalidOperator: MongoLogicalOperatorName = "$invalid"; // Error: "$invalid" is not a valid logical operator
92
+ * ```
93
+ *
94
+ * @remarks
95
+ * - This type is particularly useful when you need to validate or restrict the usage of logical operator names in MongoDB queries.
96
+ * - It ensures type safety and reduces the risk of typos in operator names.
97
+ *
98
+ * @see {@link MongoLogicalOperators} for the structure of logical operators.
99
+ */
100
+ export type MongoLogicalOperatorName = keyof MongoLogicalOperators;
101
+ /**
102
+ * @interface MongoOperators
103
+ * Combines logical and comparison operators for MongoDB queries.
104
+ *
105
+ * This interface represents a union of logical and comparison operators, allowing you to construct
106
+ * complex MongoDB queries with both logical conditions and value-based comparisons.
107
+ *
108
+ * @template T - The type of the data being queried (default is `unknown`).
109
+ *
110
+ * @example
111
+ * // Example usage of MongoOperators
112
+ * interface User {
113
+ * name: string;
114
+ * age: number;
115
+ * tags: string[];
116
+ * }
117
+ *
118
+ * const query: MongoOperators<User> = {
119
+ * $and: [
120
+ * { age: { $gte: 18 } }, // Logical AND: age must be greater than or equal to 18
121
+ * { tags: { $in: ["active", "premium"] } } // Logical AND: tags must include "active" or "premium"
122
+ * ],
123
+ * $or: [
124
+ * { name: { $regex: "^John", $options: "i" } }, // Logical OR: name starts with "John" (case-insensitive)
125
+ * { age: { $lt: 30 } } // Logical OR: age is less than 30
126
+ * ]
127
+ * };
128
+ *
129
+ * // This query will match documents where:
130
+ * // - The age is greater than or equal to 18 AND the tags include "active" or "premium".
131
+ * // - OR the name starts with "John" (case-insensitive) OR the age is less than 30.
132
+ *
133
+ * @see {@link MongoLogicalOperators} for logical operators.
134
+ * @see {@link MongoComparisonOperators} for comparison operators.
135
+ */
136
+ export interface MongoOperators extends MongoLogicalOperators, MongoComparisonOperators {
137
+ }
138
+ /**
139
+ * @typedef MongoOperatorName
140
+ * Represents the names of all available operators (logical and comparison) defined in the `MongoOperators` interface.
141
+ *
142
+ * This type is a union of the keys from the `MongoOperators` interface, allowing for a concise way to refer to nknown operator name
143
+ * that can be used in MongoDB queries. It ensures type safety and reduces the risk of typos in operator names.
144
+ *
145
+ * @example
146
+ * // Example usage of MongoOperatorName
147
+ * const operator1: MongoOperatorName = "$and"; // Valid, as $and is a logical operator
148
+ * const operator2: MongoOperatorName = "$eq"; // Valid, as $eq is a comparison operator
149
+ *
150
+ * // The following would cause a TypeScript error, as "$invalid" is not a defined operator
151
+ * // const invalidOperator: MongoOperatorName = "$invalid"; // Error: Type '"$invalid"' is not assignable to type 'MongoOperatorName'
152
+ *
153
+ * @remarks
154
+ * This type is particularly useful when you need to validate or restrict the usage of operator names in MongoDB queries.
155
+ * It provides a type-safe way to reference operator names, ensuring that only valid operators are used.
156
+ *
157
+ * @see {@link MongoOperators} for the full list of logical and comparison operators.
158
+ */
159
+ export type MongoOperatorName = keyof MongoOperators;
160
+ /**
161
+ * A type that represents the depth limit for recursion in MongoDB queries.
162
+ *
163
+ * This type is used to limit the depth of nested objects in a query, preventing infinite recursion.
164
+ *
165
+ * @typedef {number[]} MongoQueryDepth
166
+ * @example
167
+ * // Example usage of MongoQueryDepth
168
+ * const depthLimit: MongoQueryDepth = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
169
+ */
170
+ type MongoQueryDepth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
171
+ /**
172
+ * A type that generates dot notation paths with a depth limit.
173
+ *
174
+ * This type is used to create a list of possible dot notation paths in a MongoDB query, taking into account the depth limit.
175
+ *
176
+ * @typedef {object} MongoCreateDotPaths
177
+ * @template T - The type of the object being queried.
178
+ * @template D - The depth limit for the query (default is 9).
179
+ * @template Prefix - The prefix for the dot notation path (default is an empty string).
180
+ * @property {string} [key] - A key in the object being queried.
181
+ * @returns {string | never} - The dot notation path for the key, or never if the key is not a string or the depth limit is reached.
182
+ * @example
183
+ * // Example usage of MongoCreateDotPaths
184
+ * const paths: MongoCreateDotPaths<{ a: { b: { c: string } } }> = {
185
+ * 'a': 'a',
186
+ * 'a.b': 'a.b',
187
+ * 'a.b.c': 'a.b.c',
188
+ * };
189
+ */
190
+ type MongoCreateDotPaths<T, D extends number = 9, Prefix extends string = ''> = D extends 0 ? never : T extends object ? {
191
+ [K in keyof T]: K extends string ? T[K] extends object ? `${Prefix}${K}` | MongoCreateDotPaths<T[K], MongoQueryDepth[D], `${Prefix}${K}.`> : `${Prefix}${K}` : never;
192
+ }[keyof T] : never;
193
+ /**
194
+ * A type that resolves the type of a value at a given path in an object.
195
+ *
196
+ * This type is used to navigate through nested objects and retrieve the type of a value at a specific path.
197
+ *
198
+ * @typedef {object} MongoTypeAtPath
199
+ * @template T - The type of the object being queried.
200
+ * @template Path - The path to the value in the object (e.g. "a.b.c").
201
+ * @template D - The depth limit for the query (default is 9).
202
+ * @returns {T[Path] | never} - The type of the value at the given path, or never if the path is invalid or the depth limit is reached.
203
+ * @example
204
+ * // Example usage of MongoTypeAtPath
205
+ * const typeAtPath: MongoTypeAtPath<{ a: { b: { c: string } } }, 'a.b.c'> = string;
206
+ *
207
+ * // This would resolve to the type of the value at the path 'a.b.c' in the object.
208
+ *
209
+ * @example
210
+ * // Example usage of MongoTypeAtPath with an invalid path
211
+ * const invalidTypeAtPath: MongoTypeAtPath<{ a: { b: { c: string } } }, 'a.b.d'> = never;
212
+ *
213
+ * // This would resolve to never, because the path 'a.b.d' is invalid.
214
+ */
215
+ type MongoTypeAtPath<T, Path extends string, D extends number = 9> = D extends 0 ? never : Path extends keyof T ? T[Path] : Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? MongoTypeAtPath<T[Key], Rest, MongoQueryDepth[D]> : never : never;
216
+ /**
217
+ * @interface MongoQuery
218
+ * A type that represents a MongoDB query.
219
+ *
220
+ * This type is used to define a query that can be used to filter data in a MongoDB collection.
221
+ *
222
+ * @typedef {object} MongoQuery
223
+ * @template T - The type of the data being queried (default is nknown).
224
+ * @template D - The depth limit for the query (default is 9).
225
+ * @property {string} [key] - A key in the data being queried.
226
+ * @property {T[key]} [value] - The value of the key in the data being queried.
227
+ * @property {MongoComparisonOperators<T[key]>} [comparisonOperator] - A comparison operator to apply to the value.
228
+ * @property {MongoQuery<T[key], MongoQueryDepth[D]>} [nestedQuery] - A nested query to apply to the value.
229
+ * @property {MongoLogicalOperators<T>} [logicalOperator] - A logical operator to apply to the query.
230
+ * @returns {object} - The query object.
231
+ * @example
232
+ * // Example usage of MongoQuery
233
+ * ```typescript
234
+ * interface TestDocument {
235
+ name: string;
236
+ age: number;
237
+ address: {
238
+ street: string;
239
+ city: {
240
+ name: string;
241
+ country: {
242
+ code: string;
243
+ name: string;
244
+ };
245
+ };
246
+ };
247
+ tags: string[];
248
+ scores: Array<{
249
+ subject: string;
250
+ value: number;
251
+ }>;
252
+ }
253
+
254
+ // These should all work now
255
+ const query1: MongoQuery<TestDocument> = {
256
+ 'address.city.country.name': { $eq: 'France' },
257
+ age: { $gt: 18 },
258
+ tags: { $all: ['active', 'premium'] },
259
+ scores: {
260
+ $elemMatch: {
261
+ subject: { $eq: 'math' },
262
+ value: { $gte: 90 }
263
+ }
264
+ }
265
+ };
266
+ const query2: MongoQuery<TestDocument> = {
267
+ $or: [
268
+ { 'address.city.country.code': 'FR' },
269
+ {
270
+ $and: [
271
+ { age: { $gte: 18 } },
272
+ { tags: { $in: ['vip'] } }
273
+ ]
274
+ }
275
+ ]
276
+ };
277
+ *
278
+ * // This would create a query that filters data where the name is 'John', the age is greater than 18, and the occupation is either 'Developer' or 'Engineer'.
279
+ * ```
280
+ * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/} for more information on MongoDB query operators.
281
+ * @see {@link MongoArrayOperators} for more information on MongoDB array operators.
282
+ * @see {@link MongoComparisonOperators} for more information on MongoDB comparison operators.
283
+ * @see {@link MongoLogicalOperators} for more information on MongoDB logical operators.
284
+ */
285
+ export type MongoQuery<T = unknown, D extends number = 9> = D extends 0 ? never : {
286
+ [P in MongoCreateDotPaths<T, D> | keyof T]?: P extends keyof T ? T[P] | MongoComparisonOperators<T[P]> | (T[P] extends object ? MongoQuery<T[P], MongoQueryDepth[D]> : never) : P extends string ? MongoTypeAtPath<T, P, D> | MongoComparisonOperators<MongoTypeAtPath<T, P, D>> : never;
287
+ } & MongoLogicalOperators<T>;
288
+ /**
289
+ * Interface representing array operators for filtering operations.
290
+ *
291
+ * This interface allows you to specify conditions for querying data that involves
292
+ * arrays. It provides options to match documents based on the contents of arrays
293
+ * and their elements.
294
+ *
295
+ * @example
296
+ * // Example of using MongoArrayOperators
297
+ * const filter: MongoArrayOperators = {
298
+ * $all: [1, 2, 3], // Matches documents where the array contains all specified values
299
+ * $elemMatch: { // Matches documents where at least one element in the array matches the criteria
300
+ * field: { $gt: 10 } // At least one element must be greater than 10
301
+ * }
302
+ * };
303
+ */
304
+ export interface MongoArrayOperators<T = unknown> {
305
+ $in?: T extends Array<any> ? T : T[];
306
+ $nin?: T extends Array<any> ? T : T[];
307
+ $all?: T extends Array<any> ? T : T[];
308
+ $elemMatch?: T extends Array<any> ? MongoQuery<T[number]> : never;
309
+ }
310
+ /**
311
+ * A type that represents the names of all available comparison operators
312
+ * defined in the `MongoComparisonOperators` interface.
313
+ *
314
+ * This type is a union of the keys from the `MongoComparisonOperators` interface,
315
+ * allowing for a concise way to refer to any comparison operator name that can
316
+ * be used in MongoDB queries. It ensures type safety and reduces the risk
317
+ * of typos in operator names.
318
+ *
319
+ * @type MongoComparisonOperatorName
320
+ * @example
321
+ * // Example usage of MongoComparisonOperatorName
322
+ * const comparisonOperator1: MongoComparisonOperatorName = "$eq"; // Valid, as $eq is a comparison operator
323
+ * const comparisonOperator2: MongoComparisonOperatorName = "$gt"; // Valid, as $gt is a comparison operator
324
+ *
325
+ * // The following would cause a TypeScript error, as "$invalid" is not a defined comparison operator
326
+ * // const invalidComparisonOperator: MongoComparisonOperatorName = "$invalid"; // Error: Type '"$invalid"' is not assignable to type 'MongoComparisonOperatorName'
327
+ *
328
+ * @see {@link MongoComparisonOperators} for a list of comparison operators.
329
+ */
330
+ export type MongoComparisonOperatorName = keyof MongoComparisonOperators;
331
+ /**
332
+ * Represents the ordering specification for resource queries.
333
+ *
334
+ * This type defines how to specify sorting criteria for database queries, supporting both ascending and descending orders
335
+ * on any leaf property (non-object, non-array values) within the resource type `T`. It allows single-field sorting,
336
+ * multi-field sorting with arrays, and handles nested object properties using dot notation.
337
+ *
338
+ * @template T - The resource type to generate ordering paths for. Must be an object type.
339
+ *
340
+ * @remarks
341
+ * - Ascending order is specified by the field path as a string (e.g., `"name"`, `"address.city"`).
342
+ * - Descending order is specified by prefixing the field path with a minus sign (e.g., `"-name"`, `"-address.city"`).
343
+ * - Multiple sorting criteria can be provided as an array, where each element follows the same rules.
344
+ * - FieldMeta paths are limited to a depth of 4 levels to prevent excessive recursion and maintain performance.
345
+ * - Only leaf properties (primitives, dates, etc.) can be used for sorting; object and array properties are excluded.
346
+ *
347
+ * @example
348
+ * Basic usage with a simple user interface:
349
+ * ```typescript
350
+ * interface User {
351
+ * id: number;
352
+ * name: string;
353
+ * age: number;
354
+ * email: string;
355
+ * }
356
+ *
357
+ * // Single ascending field
358
+ * const orderBy1: ResourceQueryOrderBy<User> = "name";
359
+ *
360
+ * // Single descending field
361
+ * const orderBy2: ResourceQueryOrderBy<User> = "-age";
362
+ *
363
+ * // Multiple fields (name ascending, then age descending)
364
+ * const orderBy3: ResourceQueryOrderBy<User> = ["name", "-age"];
365
+ * ```
366
+ *
367
+ * @example
368
+ * Usage with nested object properties:
369
+ * ```typescript
370
+ * interface User {
371
+ * id: number;
372
+ * name: string;
373
+ * profile: {
374
+ * age: number;
375
+ * address: {
376
+ * city: string;
377
+ * country: {
378
+ * name: string;
379
+ * code: string;
380
+ * };
381
+ * };
382
+ * };
383
+ * tags: string[];
384
+ * }
385
+ *
386
+ * // Sorting by nested properties
387
+ * const orderBy1: ResourceQueryOrderBy<User> = "profile.age"; // Ascending by age
388
+ * const orderBy2: ResourceQueryOrderBy<User> = "-profile.address.city"; // Descending by city
389
+ * const orderBy3: ResourceQueryOrderBy<User> = "profile.address.country.name"; // Ascending by country name
390
+ *
391
+ * // Multiple nested fields
392
+ * const orderBy4: ResourceQueryOrderBy<User> = [
393
+ * "profile.address.country.name", // Country name ascending
394
+ * "-profile.age", // Age descending
395
+ * "name" // Name ascending (as tiebreaker)
396
+ * ];
397
+ * ```
398
+ *
399
+ * @example
400
+ * Usage with complex nested structures including arrays (note: arrays themselves cannot be sorted, only their leaf elements if accessed):
401
+ * ```typescript
402
+ * interface Product {
403
+ * id: string;
404
+ * name: string;
405
+ * metadata: {
406
+ * createdAt: Date;
407
+ * updatedAt: Date;
408
+ * stats: {
409
+ * views: number;
410
+ * likes: number;
411
+ * ratings: {
412
+ * average: number;
413
+ * count: number;
414
+ * };
415
+ * };
416
+ * };
417
+ * categories: string[]; // Arrays cannot be used directly for sorting
418
+ * }
419
+ *
420
+ * // Valid sorting options
421
+ * const orderBy1: ResourceQueryOrderBy<Product> = "-metadata.createdAt"; // Newest first
422
+ * const orderBy2: ResourceQueryOrderBy<Product> = "metadata.stats.likes"; // Most liked first
423
+ * const orderBy3: ResourceQueryOrderBy<Product> = "metadata.stats.ratings.average"; // Highest rated first
424
+ *
425
+ * // Complex multi-field sorting
426
+ * const orderBy4: ResourceQueryOrderBy<Product> = [
427
+ * "-metadata.stats.ratings.average", // Highest rated first
428
+ * "-metadata.stats.likes", // Then most liked
429
+ * "metadata.createdAt" // Then newest (as tiebreaker)
430
+ * ];
431
+ * ```
432
+ *
433
+ * @example
434
+ * Invalid usage examples (these will cause TypeScript errors):
435
+ * ```typescript
436
+ * interface User {
437
+ * id: number;
438
+ * name: string;
439
+ * tags: string[];
440
+ * profile: {
441
+ * address: {
442
+ * coordinates: [number, number]; // Array type
443
+ * };
444
+ * };
445
+ * }
446
+ *
447
+ * // ❌ Invalid: Cannot sort by array properties
448
+ * // const invalid1: ResourceQueryOrderBy<User> = "tags";
449
+ *
450
+ * // ❌ Invalid: Cannot sort by array elements
451
+ * // const invalid2: ResourceQueryOrderBy<User> = "profile.address.coordinates";
452
+ *
453
+ * // ❌ Invalid: Cannot sort by object properties
454
+ * // const invalid3: ResourceQueryOrderBy<User> = "profile";
455
+ * ```
456
+ */
457
+ export type ResourceQueryOrderBy<T> = NestedPaths<T, 8> | `-${NestedPaths<T, 8>}` | Array<NestedPaths<T, 8> | `-${NestedPaths<T, 8>}`>;
458
+ type Join<K, P, S extends string = '.'> = K extends string | number ? P extends string | number ? `${K}${'' extends P ? '' : S}${P}` : never : never;
459
+ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]];
460
+ /**
461
+ * Generates all nested paths that terminate in leaf values (non-object, non-array properties).
462
+ *
463
+ * This utility type recursively traverses an object type `T` up to a maximum depth `D` and produces
464
+ * a union of all possible nested paths that point to leaf properties. Leaf properties are
465
+ * considered to be any non-object values (primitives, dates, etc.). The separator between path
466
+ * segments can be customized.
467
+ *
468
+ * @template T - The object type to generate paths for
469
+ * @template D - The maximum recursion depth (default: 3)
470
+ * @template S - The separator string to use between path segments (default: ".")
471
+ *
472
+ * @example
473
+ * ```typescript
474
+ * interface User {
475
+ * id: number;
476
+ * name: string;
477
+ * profile: {
478
+ * age: number;
479
+ * address: {
480
+ * city: string;
481
+ * country: string;
482
+ * };
483
+ * };
484
+ * }
485
+ *
486
+ * type UserPaths = NestedPaths<User>;
487
+ * // Results in: "id" | "name" | "profile.age" | "profile.address.city" | "profile.address.country"
488
+ * ```
489
+ *
490
+ * @example
491
+ * With custom depth:
492
+ * ```typescript
493
+ * type DeepPaths = NestedPaths<VeryDeepObject, 5>; // Allow up to 5 levels deep
494
+ * ```
495
+ *
496
+ * @example
497
+ * With custom separator:
498
+ * ```typescript
499
+ * type BracketPaths = NestedPaths<User, 3, "[]">;
500
+ * // Results in: "id" | "name" | "profile[]age" | "profile[]address[]city" | "profile[]address[]country"
501
+ * ```
502
+ */
503
+ export type NestedPaths<T, D extends number = 3, S extends string = '.'> = [
504
+ D
505
+ ] extends [never] ? never : T extends object ? {
506
+ [K in keyof T]-?: K extends string | number ? Join<K, NestedPaths<T[K], Prev[D], S>, S> : never;
507
+ }[keyof T] : '';
508
+ export {};
@@ -0,0 +1 @@
1
+ 'use strict';