@kikiutils/mongoose 4.0.1 → 5.0.1

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 (164) hide show
  1. package/README.md +1 -1
  2. package/dist/_internals.js +6 -0
  3. package/dist/_internals.js.map +1 -0
  4. package/dist/constants.d.ts +7 -2
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/constants.js +13 -0
  7. package/dist/constants.js.map +1 -0
  8. package/dist/options.d.ts +8 -4
  9. package/dist/options.d.ts.map +1 -1
  10. package/dist/options.js +17 -0
  11. package/dist/options.js.map +1 -0
  12. package/dist/plugins/normalize.d.ts +20 -16
  13. package/dist/plugins/normalize.d.ts.map +1 -1
  14. package/dist/plugins/normalize.js +47 -0
  15. package/dist/plugins/normalize.js.map +1 -0
  16. package/dist/schema-builders/base.d.ts +6 -3
  17. package/dist/schema-builders/base.d.ts.map +1 -1
  18. package/dist/schema-builders/base.js +34 -0
  19. package/dist/schema-builders/base.js.map +1 -0
  20. package/dist/schema-builders/boolean.d.ts +30 -26
  21. package/dist/schema-builders/boolean.d.ts.map +1 -1
  22. package/dist/schema-builders/boolean.js +8 -0
  23. package/dist/schema-builders/boolean.js.map +1 -0
  24. package/dist/schema-builders/date.d.ts +47 -44
  25. package/dist/schema-builders/date.d.ts.map +1 -1
  26. package/dist/schema-builders/date.js +8 -0
  27. package/dist/schema-builders/date.js.map +1 -0
  28. package/dist/schema-builders/decimal128.d.ts +66 -64
  29. package/dist/schema-builders/decimal128.d.ts.map +1 -1
  30. package/dist/schema-builders/decimal128.js +27 -0
  31. package/dist/schema-builders/decimal128.js.map +1 -0
  32. package/dist/schema-builders/index.d.ts +8 -15
  33. package/dist/schema-builders/index.js +9 -0
  34. package/dist/schema-builders/number.d.ts +47 -44
  35. package/dist/schema-builders/number.d.ts.map +1 -1
  36. package/dist/schema-builders/number.js +8 -0
  37. package/dist/schema-builders/number.js.map +1 -0
  38. package/dist/schema-builders/object-id.d.ts +41 -39
  39. package/dist/schema-builders/object-id.d.ts.map +1 -1
  40. package/dist/schema-builders/object-id.js +9 -0
  41. package/dist/schema-builders/object-id.js.map +1 -0
  42. package/dist/schema-builders/ref.d.ts +42 -40
  43. package/dist/schema-builders/ref.d.ts.map +1 -1
  44. package/dist/schema-builders/ref.js +12 -0
  45. package/dist/schema-builders/ref.js.map +1 -0
  46. package/dist/schema-builders/string.d.ts +95 -92
  47. package/dist/schema-builders/string.d.ts.map +1 -1
  48. package/dist/schema-builders/string.js +38 -0
  49. package/dist/schema-builders/string.js.map +1 -0
  50. package/dist/types/aggregate-paginate.d.ts +68 -64
  51. package/dist/types/aggregate-paginate.d.ts.map +1 -1
  52. package/dist/types/aggregate-paginate.js +1 -0
  53. package/dist/types/data.d.ts +46 -43
  54. package/dist/types/data.d.ts.map +1 -1
  55. package/dist/types/data.js +1 -0
  56. package/dist/types/index.d.ts +80 -76
  57. package/dist/types/index.d.ts.map +1 -1
  58. package/dist/types/index.js +1 -0
  59. package/dist/types/options.d.ts +44 -40
  60. package/dist/types/options.d.ts.map +1 -1
  61. package/dist/types/options.js +1 -0
  62. package/dist/types/paginate.d.ts +110 -106
  63. package/dist/types/paginate.d.ts.map +1 -1
  64. package/dist/types/paginate.js +1 -0
  65. package/dist/types/utils.d.ts +5 -2
  66. package/dist/types/utils.d.ts.map +1 -1
  67. package/dist/types/utils.js +1 -0
  68. package/dist/utils.d.ts +12 -9
  69. package/dist/utils.d.ts.map +1 -1
  70. package/dist/utils.js +98 -0
  71. package/dist/utils.js.map +1 -0
  72. package/package.json +33 -31
  73. package/src/options.ts +2 -2
  74. package/src/plugins/normalize.ts +16 -10
  75. package/src/schema-builders/decimal128.ts +1 -1
  76. package/src/schema-builders/ref.ts +1 -1
  77. package/src/schema-builders/string.ts +1 -1
  78. package/src/types/aggregate-paginate.ts +2 -0
  79. package/src/types/index.ts +2 -2
  80. package/src/types/paginate.ts +2 -0
  81. package/src/utils.ts +4 -4
  82. package/dist/_internals.cjs +0 -6
  83. package/dist/_internals.cjs.map +0 -1
  84. package/dist/_internals.d.ts +0 -3
  85. package/dist/_internals.d.ts.map +0 -1
  86. package/dist/_internals.mjs +0 -4
  87. package/dist/_internals.mjs.map +0 -1
  88. package/dist/constants.cjs +0 -13
  89. package/dist/constants.cjs.map +0 -1
  90. package/dist/constants.mjs +0 -11
  91. package/dist/constants.mjs.map +0 -1
  92. package/dist/options.cjs +0 -17
  93. package/dist/options.cjs.map +0 -1
  94. package/dist/options.mjs +0 -15
  95. package/dist/options.mjs.map +0 -1
  96. package/dist/plugins/normalize.cjs +0 -64
  97. package/dist/plugins/normalize.cjs.map +0 -1
  98. package/dist/plugins/normalize.mjs +0 -56
  99. package/dist/plugins/normalize.mjs.map +0 -1
  100. package/dist/schema-builders/base.cjs +0 -43
  101. package/dist/schema-builders/base.cjs.map +0 -1
  102. package/dist/schema-builders/base.mjs +0 -41
  103. package/dist/schema-builders/base.mjs.map +0 -1
  104. package/dist/schema-builders/boolean.cjs +0 -8
  105. package/dist/schema-builders/boolean.cjs.map +0 -1
  106. package/dist/schema-builders/boolean.mjs +0 -6
  107. package/dist/schema-builders/boolean.mjs.map +0 -1
  108. package/dist/schema-builders/date.cjs +0 -8
  109. package/dist/schema-builders/date.cjs.map +0 -1
  110. package/dist/schema-builders/date.mjs +0 -6
  111. package/dist/schema-builders/date.mjs.map +0 -1
  112. package/dist/schema-builders/decimal128.cjs +0 -32
  113. package/dist/schema-builders/decimal128.cjs.map +0 -1
  114. package/dist/schema-builders/decimal128.mjs +0 -30
  115. package/dist/schema-builders/decimal128.mjs.map +0 -1
  116. package/dist/schema-builders/index.cjs +0 -27
  117. package/dist/schema-builders/index.cjs.map +0 -1
  118. package/dist/schema-builders/index.d.ts.map +0 -1
  119. package/dist/schema-builders/index.mjs +0 -8
  120. package/dist/schema-builders/index.mjs.map +0 -1
  121. package/dist/schema-builders/number.cjs +0 -8
  122. package/dist/schema-builders/number.cjs.map +0 -1
  123. package/dist/schema-builders/number.mjs +0 -6
  124. package/dist/schema-builders/number.mjs.map +0 -1
  125. package/dist/schema-builders/object-id.cjs +0 -9
  126. package/dist/schema-builders/object-id.cjs.map +0 -1
  127. package/dist/schema-builders/object-id.mjs +0 -7
  128. package/dist/schema-builders/object-id.mjs.map +0 -1
  129. package/dist/schema-builders/ref.cjs +0 -12
  130. package/dist/schema-builders/ref.cjs.map +0 -1
  131. package/dist/schema-builders/ref.mjs +0 -10
  132. package/dist/schema-builders/ref.mjs.map +0 -1
  133. package/dist/schema-builders/string.cjs +0 -46
  134. package/dist/schema-builders/string.cjs.map +0 -1
  135. package/dist/schema-builders/string.mjs +0 -44
  136. package/dist/schema-builders/string.mjs.map +0 -1
  137. package/dist/types/aggregate-paginate.cjs +0 -14
  138. package/dist/types/aggregate-paginate.cjs.map +0 -1
  139. package/dist/types/aggregate-paginate.mjs +0 -10
  140. package/dist/types/aggregate-paginate.mjs.map +0 -1
  141. package/dist/types/data.cjs +0 -3
  142. package/dist/types/data.cjs.map +0 -1
  143. package/dist/types/data.mjs +0 -2
  144. package/dist/types/data.mjs.map +0 -1
  145. package/dist/types/index.cjs +0 -3
  146. package/dist/types/index.cjs.map +0 -1
  147. package/dist/types/index.mjs +0 -2
  148. package/dist/types/index.mjs.map +0 -1
  149. package/dist/types/options.cjs +0 -3
  150. package/dist/types/options.cjs.map +0 -1
  151. package/dist/types/options.mjs +0 -2
  152. package/dist/types/options.mjs.map +0 -1
  153. package/dist/types/paginate.cjs +0 -8
  154. package/dist/types/paginate.cjs.map +0 -1
  155. package/dist/types/paginate.mjs +0 -4
  156. package/dist/types/paginate.mjs.map +0 -1
  157. package/dist/types/utils.cjs +0 -3
  158. package/dist/types/utils.cjs.map +0 -1
  159. package/dist/types/utils.mjs +0 -2
  160. package/dist/types/utils.mjs.map +0 -1
  161. package/dist/utils.cjs +0 -117
  162. package/dist/utils.cjs.map +0 -1
  163. package/dist/utils.mjs +0 -106
  164. package/dist/utils.mjs.map +0 -1
@@ -1,46 +1,49 @@
1
- import type { SetFieldType } from 'type-fest';
2
- import type { IfElse } from './utils';
1
+ import { IfElse } from "./utils.js";
2
+ import { SetFieldType } from "type-fest";
3
+
4
+ //#region src/types/data.d.ts
3
5
  declare global {
4
- /**
5
- * Type definition for the base data of a Mongoose model, optionally including timestamp fields.
6
- *
7
- * @template CreatedAtField - A boolean flag indicating whether the `createdAt` field should be included.
8
- * @template UpdatedAtField - A boolean flag indicating whether the `updatedAt` field should be included.
9
- */
10
- type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = IfElse<CreatedAtField, {
11
- createdAt: string;
12
- }, unknown> & IfElse<UpdatedAtField, {
13
- updatedAt: string;
14
- }, unknown> & {
15
- id: string;
16
- };
17
- type DataToBaseMongooseDocType<T, ObjectIdFields extends keyof T = never, DateFields extends Exclude<keyof T, ObjectIdFields> = never, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = BaseMongooseDocType<SetFieldsToObjectId<SetFieldType<T, DateFields, Date>, ObjectIdFields>, CreatedAtField, UpdatedAtField>;
18
- /**
19
- * Type definition to omit timestamp fields (`createdAt`, `updatedAt`)
20
- * and other specified fields (`K`) from a given type `T`.
21
- *
22
- * @template T - The type from which to omit fields.
23
- * @template K - Additional fields to omit, specified as a union of keys in `T`.
24
- */
25
- type ExceptMongooseTimestampAndOtherFields<T, K extends keyof T> = Omit<T, 'createdAt' | 'updatedAt' | K>;
26
- /**
27
- * Type definition to omit timestamp fields (`createdAt`, `updatedAt`)
28
- * and other specified fields (`K`) from a given type `T`.
29
- *
30
- * @template T - The type from which to omit fields.
31
- * @template K - Additional fields to omit, specified as a union of string, number, or symbol keys.
32
- */
33
- type OmitMongooseTimestampAndOtherFields<T, K extends number | string | symbol = never> = Omit<T, 'createdAt' | 'updatedAt' | K>;
34
- /**
35
- * Type definition for including timestamp fields conditionally based on the provided flags.
36
- *
37
- * @template CreatedAt - A boolean flag indicating whether the `createdAt` field should be included.
38
- * @template UpdatedAt - A boolean flag indicating whether the `updatedAt` field should be included.
39
- */
40
- type WithMongooseTimestampFieldsData<CreatedAt extends boolean = true, UpdatedAt extends boolean = true> = IfElse<CreatedAt, {
41
- createdAt: string;
42
- }, object> & IfElse<UpdatedAt, {
43
- updatedAt: string;
44
- }, object>;
6
+ /**
7
+ * Type definition for the base data of a Mongoose model, optionally including timestamp fields.
8
+ *
9
+ * @template CreatedAtField - A boolean flag indicating whether the `createdAt` field should be included.
10
+ * @template UpdatedAtField - A boolean flag indicating whether the `updatedAt` field should be included.
11
+ */
12
+ type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = IfElse<CreatedAtField, {
13
+ createdAt: string;
14
+ }, unknown> & IfElse<UpdatedAtField, {
15
+ updatedAt: string;
16
+ }, unknown> & {
17
+ id: string;
18
+ };
19
+ type DataToBaseMongooseDocType<T, ObjectIdFields extends keyof T = never, DateFields extends Exclude<keyof T, ObjectIdFields> = never, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = BaseMongooseDocType<SetFieldsToObjectId<SetFieldType<T, DateFields, Date>, ObjectIdFields>, CreatedAtField, UpdatedAtField>;
20
+ /**
21
+ * Type definition to omit timestamp fields (`createdAt`, `updatedAt`)
22
+ * and other specified fields (`K`) from a given type `T`.
23
+ *
24
+ * @template T - The type from which to omit fields.
25
+ * @template K - Additional fields to omit, specified as a union of keys in `T`.
26
+ */
27
+ type ExceptMongooseTimestampAndOtherFields<T, K extends keyof T> = Omit<T, 'createdAt' | 'updatedAt' | K>;
28
+ /**
29
+ * Type definition to omit timestamp fields (`createdAt`, `updatedAt`)
30
+ * and other specified fields (`K`) from a given type `T`.
31
+ *
32
+ * @template T - The type from which to omit fields.
33
+ * @template K - Additional fields to omit, specified as a union of string, number, or symbol keys.
34
+ */
35
+ type OmitMongooseTimestampAndOtherFields<T, K extends number | string | symbol = never> = Omit<T, 'createdAt' | 'updatedAt' | K>;
36
+ /**
37
+ * Type definition for including timestamp fields conditionally based on the provided flags.
38
+ *
39
+ * @template CreatedAt - A boolean flag indicating whether the `createdAt` field should be included.
40
+ * @template UpdatedAt - A boolean flag indicating whether the `updatedAt` field should be included.
41
+ */
42
+ type WithMongooseTimestampFieldsData<CreatedAt extends boolean = true, UpdatedAt extends boolean = true> = IfElse<CreatedAt, {
43
+ createdAt: string;
44
+ }, object> & IfElse<UpdatedAt, {
45
+ updatedAt: string;
46
+ }, object>;
45
47
  }
48
+ //# sourceMappingURL=data.d.ts.map
46
49
  //# sourceMappingURL=data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/types/data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,CAAC,MAAM,CAAC;IACX;;;;;OAKG;IACH,KAAK,qBAAqB,CACtB,cAAc,SAAS,OAAO,GAAG,IAAI,EACrC,cAAc,SAAS,OAAO,GAAG,IAAI,IAErC,MAAM,CAAC,cAAc,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,GACtD,MAAM,CAAC,cAAc,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,GACtD;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAEnB,KAAK,yBAAyB,CAC1B,CAAC,EACD,cAAc,SAAS,MAAM,CAAC,GAAG,KAAK,EACtC,UAAU,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC,GAAG,KAAK,EAC3D,cAAc,SAAS,OAAO,GAAG,IAAI,EACrC,cAAc,SAAS,OAAO,GAAG,IAAI,IACrC,mBAAmB,CACnB,mBAAmB,CAAC,YAAY,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,cAAc,CAAC,EACtE,cAAc,EACd,cAAc,CACjB,CAAC;IAEF;;;;;;OAMG;IACH,KAAK,qCAAqC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC;IAE1G;;;;;;OAMG;IACH,KAAK,mCAAmC,CACpC,CAAC,EACD,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,IAC1C,IAAI,CACJ,CAAC,EACD,WAAW,GAAG,WAAW,GAAG,CAAC,CAChC,CAAC;IAEF;;;;;OAKG;IACH,KAAK,+BAA+B,CAChC,SAAS,SAAS,OAAO,GAAG,IAAI,EAChC,SAAS,SAAS,OAAO,GAAG,IAAI,IAEhC,MAAM,CAAC,SAAS,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,MAAM,CAAC,GAChD,MAAM,CAAC,SAAS,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,MAAM,CAAC,CAAC;CACxD"}
1
+ {"version":3,"file":"data.d.ts","names":[],"sources":["../../src/types/data.ts"],"sourcesContent":[],"mappings":";;;;;;AAEsC;;;;;OAc9B,qBAAA,CAAA,uBAAA,OAAA,GAAA,IAAA,EAAA,uBAAA,OAAA,GAAA,IAAA,CAAA,GADA,MACA,CADO,cACP,EAAA;IAK6B,SAAA,EAAA,MAAA;KACI,OAAA,CAAA,GANjC,MAMiC,CAN1B,cAM0B,EAAA;IAAG,SAAA,EAAA,MAAA;KAAjB,OAAA,CAAA,GAAA;IAIc,EAAA,EAAA,MAAA;;OAAe,yBAAA,CAAA,CAAA,EAAA,uBAAA,MALnB,CAKmB,GAAA,KAAA,EAAA,mBAJ7B,OAI6B,CAAA,MAJf,CAIe,EAJZ,cAIY,CAAA,GAAA,KAAA,EAAA,uBAAA,OAAA,GAAA,IAAA,EAAA,uBAAA,OAAA,GAAA,IAAA,CAAA,GADhD,mBACgD,CAAhD,mBAAgD,CAA5B,YAA4B,CAAf,CAAe,EAAZ,UAAY,EAAA,IAAA,CAAA,EAAO,cAAP,CAAA,EAChD,cADgD,EAEhD,cAFgD,CAAA;;;;;;;;OAYoB,qCAAA,CAAA,CAAA,EAAA,UAAA,MAAV,CAAU,CAAA,GAAL,IAAK,CAAA,CAAA,EAAA,WAAA,GAAA,WAAA,GAA+B,CAA/B,CAAA;;;;;;;;OA4B7D,mCAAA,CAAA,CAAA,EAAA,UAAA,MAAA,GAAA,MAAA,GAAA,MAAA,GAAA,KAAA,CAAA,GAhBP,IAgBO,CAfP,CAeO,EAAA,WAAA,GAAA,WAAA,GAdqB,CAcrB,CAAA;;;;;;;6GADP,OAAO;;eACP,OAAO"}
@@ -0,0 +1 @@
1
+ export { };
@@ -1,80 +1,84 @@
1
- import type { AggregatePaginateModel, Connection, HydratedDocument, PaginateModel, QueryWithHelpers, Types } from 'mongoose';
2
- import type { SetFieldType } from 'type-fest';
3
- import type { IfElse } from './utils';
4
- export type {} from './aggregate-paginate';
5
- export type {} from './paginate';
6
- export interface BaseModelStatics<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> {
7
- }
8
- export interface MongooseConnections {
9
- default?: Connection;
1
+ import { IfElse } from "./utils.js";
2
+ import { DoNotRemoveOrUseThisType } from "./aggregate-paginate.js";
3
+ import { DoNotRemoveOrUseThisType as DoNotRemoveOrUseThisType$1 } from "./paginate.js";
4
+ import { AggregatePaginateModel, Connection, HydratedDocument, PaginateModel, QueryWithHelpers, Types } from "mongoose";
5
+ import { SetFieldType } from "type-fest";
6
+
7
+ //#region src/types/index.d.ts
8
+ interface BaseModelStatics<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> {}
9
+ interface MongooseConnections {
10
+ default?: Connection;
10
11
  }
11
12
  declare global {
12
- /**
13
- * Type definition for a base Mongoose document type.
14
- *
15
- * This type alias omits the `createdAt`, `id`, and `updatedAt` fields from type `T`,
16
- * and conditionally includes `createdAt` and `updatedAt` fields as `Date` based on
17
- * the `CreatedAtField` and `UpdatedAtField` flags.
18
- *
19
- * @template T - The original document type.
20
- * @template CreatedAtField - A boolean flag indicating whether the `createdAt` field should be included.
21
- * @template UpdatedAtField - A boolean flag indicating whether the `updatedAt` field should be included.
22
- */
23
- type BaseMongooseDocType<T, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = IfElse<CreatedAtField, {
24
- createdAt: Date;
25
- }, unknown> & IfElse<UpdatedAtField, {
26
- updatedAt: Date;
27
- }, unknown> & Omit<T, 'createdAt' | 'id' | 'updatedAt'>;
28
- /**
29
- * Type definition for a Mongoose model with pagination and aggregation capabilities.
30
- *
31
- * This type alias combines the `AggregatePaginateModel` and `PaginateModel` interfaces,
32
- * along with custom static methods defined in `BaseModelStatics`.
33
- *
34
- * @template RawDocType - The raw document type as stored in MongoDB.
35
- * @template InstanceMethodsAndOverrides - Optional type parameter for instance methods and overrides.
36
- * @template QueryHelpers - Optional type parameter for additional query helper methods.
37
- */
38
- type BaseMongoosePaginateModel<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = AggregatePaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> & BaseModelStatics<RawDocType, InstanceMethodsAndOverrides, QueryHelpers> & PaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides>;
39
- /**
40
- * Type definition for a Mongoose document or ObjectId.
41
- *
42
- * This type alias represents a value that can be either a Mongoose document, a string,
43
- * or an ObjectId. It is useful when working with Mongoose models where you might have
44
- * references to documents that are stored either as objects or as ObjectIds.
45
- *
46
- * @template D - The Mongoose document type.
47
- */
48
- type MongooseDocumentOrObjectId<D> = D | string | Types.ObjectId;
49
- /**
50
- * Type definition for the return type of a Mongoose `findOne` query.
51
- *
52
- * This type alias represents the return type of a `findOne` query in Mongoose.
53
- * It extends the `QueryWithHelpers` type, indicating that the query can return
54
- * either a document of type `DocType` or `null` if no document is found. The
55
- * `QueryHelpers` type parameter allows for the inclusion of additional query
56
- * helper methods.
57
- *
58
- * @template RawDocType - The raw document type as stored in MongoDB.
59
- * @template DocType - The Mongoose document type after applying schema transformations.
60
- * @template QueryHelpers - Optional type parameter for additional query helper methods.
61
- * @template InstanceMethodsAndOverrides - Optional type parameter for specifying custom instance methods
62
- * and overrides on the document.
63
- */
64
- type MongooseFindOneReturnType<RawDocType, DocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> = QueryWithHelpers<DocType | null, DocType, QueryHelpers, RawDocType, 'findOne', InstanceMethodsAndOverrides>;
65
- /**
66
- * Type definition for a hydrated Mongoose document.
67
- *
68
- * This type alias represents a hydrated document in Mongoose, which is a fully
69
- * populated document that includes instance methods and query helpers. It extends
70
- * the `HydratedDocument` type from Mongoose, allowing for additional instance
71
- * methods and query helpers to be specified.
72
- *
73
- * @template DocType - The Mongoose document type after applying schema transformations.
74
- * @template InstanceMethodsAndOverrides - Optional type parameter for instance methods and overrides.
75
- * @template QueryHelpers - Optional type parameter for additional query helper methods.
76
- */
77
- type MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = HydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>;
78
- type SetFieldsToObjectId<T, K extends keyof T> = SetFieldType<T, K, Types.ObjectId>;
13
+ /**
14
+ * Type definition for a base Mongoose document type.
15
+ *
16
+ * This type alias omits the `createdAt`, `id`, and `updatedAt` fields from type `T`,
17
+ * and conditionally includes `createdAt` and `updatedAt` fields as `Date` based on
18
+ * the `CreatedAtField` and `UpdatedAtField` flags.
19
+ *
20
+ * @template T - The original document type.
21
+ * @template CreatedAtField - A boolean flag indicating whether the `createdAt` field should be included.
22
+ * @template UpdatedAtField - A boolean flag indicating whether the `updatedAt` field should be included.
23
+ */
24
+ type BaseMongooseDocType<T, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = IfElse<CreatedAtField, {
25
+ createdAt: Date;
26
+ }, unknown> & IfElse<UpdatedAtField, {
27
+ updatedAt: Date;
28
+ }, unknown> & Omit<T, 'createdAt' | 'id' | 'updatedAt'>;
29
+ /**
30
+ * Type definition for a Mongoose model with pagination and aggregation capabilities.
31
+ *
32
+ * This type alias combines the `AggregatePaginateModel` and `PaginateModel` interfaces,
33
+ * along with custom static methods defined in `BaseModelStatics`.
34
+ *
35
+ * @template RawDocType - The raw document type as stored in MongoDB.
36
+ * @template InstanceMethodsAndOverrides - Optional type parameter for instance methods and overrides.
37
+ * @template QueryHelpers - Optional type parameter for additional query helper methods.
38
+ */
39
+ type BaseMongoosePaginateModel<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = AggregatePaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> & BaseModelStatics<RawDocType, InstanceMethodsAndOverrides, QueryHelpers> & PaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides>;
40
+ /**
41
+ * Type definition for a Mongoose document or ObjectId.
42
+ *
43
+ * This type alias represents a value that can be either a Mongoose document, a string,
44
+ * or an ObjectId. It is useful when working with Mongoose models where you might have
45
+ * references to documents that are stored either as objects or as ObjectIds.
46
+ *
47
+ * @template D - The Mongoose document type.
48
+ */
49
+ type MongooseDocumentOrObjectId<D> = D | string | Types.ObjectId;
50
+ /**
51
+ * Type definition for the return type of a Mongoose `findOne` query.
52
+ *
53
+ * This type alias represents the return type of a `findOne` query in Mongoose.
54
+ * It extends the `QueryWithHelpers` type, indicating that the query can return
55
+ * either a document of type `DocType` or `null` if no document is found. The
56
+ * `QueryHelpers` type parameter allows for the inclusion of additional query
57
+ * helper methods.
58
+ *
59
+ * @template RawDocType - The raw document type as stored in MongoDB.
60
+ * @template DocType - The Mongoose document type after applying schema transformations.
61
+ * @template QueryHelpers - Optional type parameter for additional query helper methods.
62
+ * @template InstanceMethodsAndOverrides - Optional type parameter for specifying custom instance methods
63
+ * and overrides on the document.
64
+ */
65
+ type MongooseFindOneReturnType<RawDocType, DocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> = QueryWithHelpers<DocType | null, DocType, QueryHelpers, RawDocType, 'findOne', InstanceMethodsAndOverrides>;
66
+ /**
67
+ * Type definition for a hydrated Mongoose document.
68
+ *
69
+ * This type alias represents a hydrated document in Mongoose, which is a fully
70
+ * populated document that includes instance methods and query helpers. It extends
71
+ * the `HydratedDocument` type from Mongoose, allowing for additional instance
72
+ * methods and query helpers to be specified.
73
+ *
74
+ * @template DocType - The Mongoose document type after applying schema transformations.
75
+ * @template InstanceMethodsAndOverrides - Optional type parameter for instance methods and overrides.
76
+ * @template QueryHelpers - Optional type parameter for additional query helper methods.
77
+ */
78
+ type MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = HydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>;
79
+ type SetFieldsToObjectId<T, K extends keyof T> = SetFieldType<T, K, Types.ObjectId>;
79
80
  }
81
+ //# sourceMappingURL=index.d.ts.map
82
+ //#endregion
83
+ export { BaseModelStatics, MongooseConnections, type DoNotRemoveOrUseThisType as _ADoNotRemoveOrUseThisType, type DoNotRemoveOrUseThisType$1 as _PDoNotRemoveOrUseThisType };
80
84
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,KAAK,EACR,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC3C,YAAY,EAAE,MAAM,YAAY,CAAC;AAIjC,MAAM,WAAW,gBAAgB,CAAC,UAAU,EAAE,2BAA2B,GAAG,MAAM,EAAE,YAAY,GAAG,MAAM;CAAI;AAE7G,MAAM,WAAW,mBAAmB;IAChC,OAAO,CAAC,EAAE,UAAU,CAAC;CACxB;AAED,OAAO,CAAC,MAAM,CAAC;IACX;;;;;;;;;;OAUG;IACH,KAAK,mBAAmB,CACpB,CAAC,EACD,cAAc,SAAS,OAAO,GAAG,IAAI,EACrC,cAAc,SAAS,OAAO,GAAG,IAAI,IAErC,MAAM,CAAC,cAAc,EAAE;QAAE,SAAS,EAAE,IAAI,CAAA;KAAE,EAAE,OAAO,CAAC,GACpD,MAAM,CAAC,cAAc,EAAE;QAAE,SAAS,EAAE,IAAI,CAAA;KAAE,EAAE,OAAO,CAAC,GACpD,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC;IAE9C;;;;;;;;;OASG;IACH,KAAK,yBAAyB,CAC1B,UAAU,EACV,2BAA2B,GAAG,MAAM,EACpC,YAAY,GAAG,MAAM,IAErB,sBAAsB,CAAC,UAAU,EAAE,YAAY,EAAE,2BAA2B,CAAC,GAC7E,gBAAgB,CAAC,UAAU,EAAE,2BAA2B,EAAE,YAAY,CAAC,GACvE,aAAa,CAAC,UAAU,EAAE,YAAY,EAAE,2BAA2B,CAAC,CAAC;IAEzE;;;;;;;;OAQG;IACH,KAAK,0BAA0B,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC;IAEjE;;;;;;;;;;;;;;OAcG;IACH,KAAK,yBAAyB,CAC1B,UAAU,EACV,OAAO,EACP,YAAY,GAAG,MAAM,EACrB,2BAA2B,GAAG,MAAM,IACpC,gBAAgB,CAChB,OAAO,GAAG,IAAI,EACd,OAAO,EACP,YAAY,EACZ,UAAU,EACV,SAAS,EACT,2BAA2B,CAC9B,CAAC;IAEF;;;;;;;;;;;OAWG;IACH,KAAK,wBAAwB,CACzB,OAAO,EACP,2BAA2B,GAAG,MAAM,EACpC,YAAY,GAAG,MAAM,IACrB,gBAAgB,CAChB,OAAO,EACP,2BAA2B,EAC3B,YAAY,CACf,CAAC;IAEF,KAAK,mBAAmB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CACvF"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":[],"mappings":";;;;;;;UAiBiB;AAAA,UAEA,mBAAA,CAFgB;EAEhB,OAAA,CAAA,EACH,UADG;AAEhB;QAAA,MAAA,CAAA;;;;;;;;;;;;OAsCO,mBAAA,CAAA,CAAA,EAAA,uBAAA,OAAA,GAAA,IAAA,EAAA,uBAAA,OAAA,GAAA,IAAA,CAAA,GAnBA,MAmBA,CAnBO,cAmBP,EAAA;IACiB,SAAA,EApBmB,IAoBnB;KAAY,OAAA,CAAA,GAnB7B,MAmB6B,CAnBtB,cAmBsB,EAAA;IAA6B,SAAA,EAnBtB,IAmBsB;KAA1D,OAAA,CAAA,GAlBA,IAkBA,CAlBK,CAkBL,EAAA,WAAA,GAAA,IAAA,GAAA,WAAA,CAAA;;;;;;;;;;;OAwCA,yBAAA,CAAA,UAAA,EAAA,8BAAA,MAAA,EAAA,eAAA,MAAA,CAAA,GAzCA,sBAyCA,CAzCuB,UAyCvB,EAzCmC,YAyCnC,EAzCiD,2BAyCjD,CAAA,GAxCA,gBAwCA,CAxCiB,UAwCjB,EAxC6B,2BAwC7B,EAxC0D,YAwC1D,CAAA,GAvCA,aAuCA,CAvCc,UAuCd,EAvC0B,YAuC1B,EAvCwC,2BAuCxC,CAAA;;;;;;;;;;OAyB6C,0BAAA,CAAA,CAAA,CAAA,GArDZ,CAqDY,GAAA,MAAA,GArDC,KAAA,CAAM,QAqDP;EAAY;;;;;;;;;;;;;;;qHA/BzD,iBACA,gBACA,SACA,cACA,uBAEA;;;;;;;;;;;;;wGAmBA,iBACA,SACA,6BACA;8CAGwC,KAAK,aAAa,GAAG,GAAG,KAAA,CAAM"}
@@ -0,0 +1 @@
1
+ export { };
@@ -1,7 +1,9 @@
1
- import type { Connection, Schema, SchemaTimestampsConfig } from 'mongoose';
2
- import type { MongooseNormalizePluginOptions } from '../plugins/normalize';
3
- import type { buildMongooseModel } from '../utils';
4
- export type DoNotRemoveOrUseThisType = typeof buildMongooseModel;
1
+ import { MongooseNormalizePluginOptions } from "../plugins/normalize.js";
2
+ import { buildMongooseModel } from "../utils.js";
3
+ import { Connection, Schema, SchemaTimestampsConfig } from "mongoose";
4
+
5
+ //#region src/types/options.d.ts
6
+ type DoNotRemoveOrUseThisType = typeof buildMongooseModel;
5
7
  /**
6
8
  * Interface for options used when building a Mongoose model.
7
9
  *
@@ -9,42 +11,44 @@ export type DoNotRemoveOrUseThisType = typeof buildMongooseModel;
9
11
  * when creating a Mongoose model. It includes options for specifying the database
10
12
  * connection, enabling the normalize plugin, and configuring timestamp fields.
11
13
  */
12
- export interface BuildMongooseModelOptions {
13
- /**
14
- * The Mongoose connection to be used for the model.
15
- *
16
- * This is an optional setting that allows specifying a custom connection
17
- * for the model.
18
- */
19
- connection?: Connection;
20
- /**
21
- * Flag to enable or disable the normalize plugin.
22
- *
23
- * This flag indicates whether the normalize plugin should be enabled.
24
- * The default value is `true`.
25
- *
26
- * @default true
27
- */
28
- enableNormalizePlugin?: boolean;
29
- normalizePluginOptions?: MongooseNormalizePluginOptions;
30
- /**
31
- * Configures Mongoose timestamps.
32
- *
33
- * This option enables or disables timestamps, or allows specifying a
34
- * custom timestamp configuration via {@link SchemaTimestampsConfig}.
35
- *
36
- * - If `timestamps` is explicitly set, it will be used.
37
- * - If `timestamps` is not provided, the schema's existing setting is used.
38
- * - If the schema has no existing setting, `true` is the default value.
39
- *
40
- * @default true
41
- */
42
- timestamps?: boolean | SchemaTimestampsConfig;
14
+ interface BuildMongooseModelOptions {
15
+ /**
16
+ * The Mongoose connection to be used for the model.
17
+ *
18
+ * This is an optional setting that allows specifying a custom connection
19
+ * for the model.
20
+ */
21
+ connection?: Connection;
22
+ /**
23
+ * Flag to enable or disable the normalize plugin.
24
+ *
25
+ * This flag indicates whether the normalize plugin should be enabled.
26
+ * The default value is `true`.
27
+ *
28
+ * @default true
29
+ */
30
+ enableNormalizePlugin?: boolean;
31
+ normalizePluginOptions?: MongooseNormalizePluginOptions;
32
+ /**
33
+ * Configures Mongoose timestamps.
34
+ *
35
+ * This option enables or disables timestamps, or allows specifying a
36
+ * custom timestamp configuration via {@link SchemaTimestampsConfig}.
37
+ *
38
+ * - If `timestamps` is explicitly set, it will be used.
39
+ * - If `timestamps` is not provided, the schema's existing setting is used.
40
+ * - If the schema has no existing setting, `true` is the default value.
41
+ *
42
+ * @default true
43
+ */
44
+ timestamps?: boolean | SchemaTimestampsConfig;
43
45
  }
44
- export interface CustomMongooseOptions {
45
- /**
46
- * A function that will be executed before the final build when using {@link buildMongooseModel}.
47
- */
48
- beforeModelBuild?: <DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>) => void;
46
+ interface CustomMongooseOptions {
47
+ /**
48
+ * A function that will be executed before the final build when using {@link buildMongooseModel}.
49
+ */
50
+ beforeModelBuild?: <DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>) => void;
49
51
  }
52
+ //#endregion
53
+ export { BuildMongooseModelOptions, CustomMongooseOptions, DoNotRemoveOrUseThisType };
50
54
  //# sourceMappingURL=options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,MAAM,EACN,sBAAsB,EACzB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,MAAM,MAAM,wBAAwB,GAAG,OAAO,kBAAkB,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB;;;;;;;OAOG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,sBAAsB,CAAC,EAAE,8BAA8B,CAAC;IAExD;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,sBAAsB,CAAC;CACjD;AAED,MAAM,WAAW,qBAAqB;IAClC;;OAEG;IACH,gBAAgB,CAAC,EAAE,CACf,OAAO,EACP,KAAK,SAAS,yBAAyB,CAAC,OAAO,EAAE,2BAA2B,EAAE,YAAY,CAAC,EAC3F,2BAA2B,GAAG,MAAM,EACpC,YAAY,GAAG,MAAM,EAErB,MAAM,EAAE,MAAM,CACV,OAAO,EACP,KAAK,EACL,2BAA2B,EAC3B,YAAY,CACf,KACA,IAAI,CAAC;CACb"}
1
+ {"version":3,"file":"options.d.ts","names":[],"sources":["../../src/types/options.ts"],"sourcesContent":[],"mappings":";;;;;KASY,wBAAA,UAAkC;;AAA9C;AASA;;;;;AAgCiD,UAhChC,yBAAA,CAgCgC;EAGhC;;;;;;YAWL,CAAA,EAvCK,UAuCL;;;;;;;;;;2BA5BiB;;;;;;;;;;;;;yBAcF;;UAGV,qBAAA;;;;6CAMK,0BAA0B,SAAS,6BAA6B,oFAItE,OACJ,SACA,OACA,6BACA"}
@@ -0,0 +1 @@
1
+ export { };
@@ -1,112 +1,116 @@
1
- import type { FilterQuery, mongo, PaginateOptions, Schema } from 'mongoose';
2
- import type { IfElse } from './utils';
1
+ import { IfElse } from "./utils.js";
2
+ import { FilterQuery, PaginateOptions, Schema, mongo } from "mongoose";
3
+
4
+ //#region src/types/paginate.d.ts
3
5
  declare module 'mongoose' {
4
- type PaginateDocument<T, TMethods, TQueryHelpers, O extends PaginateOptions = object> = IfElse<O['lean'], IfElse<O['leanWithId'], T & {
5
- id: string;
6
- }, IfElse<O['leanWithVirtuals'], T & {
7
- [key: string]: any;
8
- }, T>>, HydratedDocument<T, TMethods, TQueryHelpers>>;
9
- interface PaginateCustomLabels<T = boolean | string | undefined> {
10
- docs?: T;
11
- hasNextPage?: T;
12
- hasPrevPage?: T;
13
- limit?: T;
14
- meta?: T;
15
- nextPage?: T;
16
- page?: T;
17
- pagingCounter?: T;
18
- prevPage?: T;
19
- totalDocs?: T;
20
- totalPages?: T;
21
- }
22
- interface PaginateModel<T, TQueryHelpers = object, TMethods = object> extends Model<T, TQueryHelpers, TMethods> {
23
- paginate: {
24
- <O extends PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>>;
25
- <UserType = T, O extends PaginateOptions = PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>>;
26
- <UserType = T>(query?: FilterQuery<T>, options?: PaginateOptions, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>>;
27
- };
28
- }
29
- interface PaginateOptions {
30
- allowDiskUse?: boolean;
31
- collation?: mongo.CollationOptions;
32
- customLabels?: PaginateCustomLabels;
33
- forceCountFn?: boolean;
34
- lean?: boolean;
35
- leanWithId?: boolean;
36
- leanWithVirtuals?: boolean;
37
- limit?: number;
38
- offset?: number;
39
- options?: QueryOptions;
40
- page?: number;
41
- /**
42
- * If pagination is set to `false`, it will return all docs without adding limit condition.
43
- *
44
- * @default true
45
- */
46
- pagination?: boolean;
47
- populate?: PopulateOptions | PopulateOptions[] | string | string[];
48
- projection?: any;
49
- read?: PaginateReadOptions;
50
- select?: object | string;
51
- sort?: object | string;
52
- useCustomCountFn?: () => Promise<number>;
53
- useEstimatedCount?: boolean;
54
- }
55
- interface PaginateReadOptions {
56
- pref: string;
57
- tags?: any[];
58
- }
59
- interface PaginateResult<T> {
60
- [customLabel: string]: boolean | null | number | T[] | undefined;
61
- docs: T[];
62
- hasNextPage: boolean;
63
- hasPrevPage: boolean;
64
- limit: number;
65
- meta?: any;
66
- nextPage?: null | number;
67
- offset: number;
68
- page?: number;
69
- pagingCounter: number;
70
- prevPage?: null | number;
71
- totalDocs: number;
72
- totalPages: number;
73
- }
74
- interface Query<ResultType, DocType, THelpers = NonNullable<unknown>, RawDocType = DocType, _QueryOp = 'find', TInstanceMethods = Record<string, never>> {
75
- paginate: {
76
- <O extends PaginateOptions>(options?: O): Promise<PaginateResult<PaginateDocument<RawDocType, TInstanceMethods, THelpers, O>>>;
77
- <UserType = ResultType, O extends PaginateOptions = PaginateOptions>(options?: O): Promise<PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, O>>>;
78
- <UserType = ResultType>(options?: PaginateOptions): Promise<PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, PaginateOptions>>>;
79
- };
80
- }
81
- interface SubDocumentPagingOptions {
82
- limit?: number;
83
- page?: number;
84
- populate?: PopulateOptions | PopulateOptions[] | string | string[];
85
- }
86
- interface SubPaginateOptions {
87
- pagination?: boolean;
88
- pagingOptions?: SubDocumentPagingOptions;
89
- populate?: PopulateOptions | PopulateOptions[] | string | string[];
90
- read?: PaginateReadOptions;
91
- select?: object | string;
92
- }
6
+ type PaginateDocument<T, TMethods, TQueryHelpers, O extends PaginateOptions = object> = IfElse<O['lean'], IfElse<O['leanWithId'], T & {
7
+ id: string;
8
+ }, IfElse<O['leanWithVirtuals'], T & {
9
+ [key: string]: any;
10
+ }, T>>, HydratedDocument<T, TMethods, TQueryHelpers>>;
11
+ interface PaginateCustomLabels<T = boolean | string | undefined> {
12
+ docs?: T;
13
+ hasNextPage?: T;
14
+ hasPrevPage?: T;
15
+ limit?: T;
16
+ meta?: T;
17
+ nextPage?: T;
18
+ page?: T;
19
+ pagingCounter?: T;
20
+ prevPage?: T;
21
+ totalDocs?: T;
22
+ totalPages?: T;
23
+ }
24
+ interface PaginateModel<T, TQueryHelpers = object, TMethods = object> extends Model<T, TQueryHelpers, TMethods> {
25
+ paginate: {
26
+ <O extends PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>>;
27
+ <UserType = T, O extends PaginateOptions = PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>>;
28
+ <UserType = T>(query?: FilterQuery<T>, options?: PaginateOptions, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>>;
29
+ };
30
+ }
31
+ interface PaginateOptions {
32
+ allowDiskUse?: boolean;
33
+ collation?: mongo.CollationOptions;
34
+ customLabels?: PaginateCustomLabels;
35
+ forceCountFn?: boolean;
36
+ lean?: boolean;
37
+ leanWithId?: boolean;
38
+ leanWithVirtuals?: boolean;
39
+ limit?: number;
40
+ offset?: number;
41
+ options?: QueryOptions;
42
+ page?: number;
43
+ /**
44
+ * If pagination is set to `false`, it will return all docs without adding limit condition.
45
+ *
46
+ * @default true
47
+ */
48
+ pagination?: boolean;
49
+ populate?: PopulateOptions | PopulateOptions[] | string | string[];
50
+ projection?: any;
51
+ read?: PaginateReadOptions;
52
+ select?: object | string;
53
+ sort?: object | string;
54
+ useCustomCountFn?: () => Promise<number>;
55
+ useEstimatedCount?: boolean;
56
+ }
57
+ interface PaginateReadOptions {
58
+ pref: string;
59
+ tags?: any[];
60
+ }
61
+ interface PaginateResult<T> {
62
+ [customLabel: string]: boolean | null | number | T[] | undefined;
63
+ docs: T[];
64
+ hasNextPage: boolean;
65
+ hasPrevPage: boolean;
66
+ limit: number;
67
+ meta?: any;
68
+ nextPage?: null | number;
69
+ offset: number;
70
+ page?: number;
71
+ pagingCounter: number;
72
+ prevPage?: null | number;
73
+ totalDocs: number;
74
+ totalPages: number;
75
+ }
76
+ interface Query<ResultType, DocType, THelpers = NonNullable<unknown>, RawDocType = DocType, _QueryOp = 'find', TInstanceMethods = Record<string, never>> {
77
+ paginate: {
78
+ <O extends PaginateOptions>(options?: O): Promise<PaginateResult<PaginateDocument<RawDocType, TInstanceMethods, THelpers, O>>>;
79
+ <UserType = ResultType, O extends PaginateOptions = PaginateOptions>(options?: O): Promise<PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, O>>>;
80
+ <UserType = ResultType>(options?: PaginateOptions): Promise<PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, PaginateOptions>>>;
81
+ };
82
+ }
83
+ interface SubDocumentPagingOptions {
84
+ limit?: number;
85
+ page?: number;
86
+ populate?: PopulateOptions | PopulateOptions[] | string | string[];
87
+ }
88
+ interface SubPaginateOptions {
89
+ pagination?: boolean;
90
+ pagingOptions?: SubDocumentPagingOptions;
91
+ populate?: PopulateOptions | PopulateOptions[] | string | string[];
92
+ read?: PaginateReadOptions;
93
+ select?: object | string;
94
+ }
93
95
  }
94
96
  declare function _(schema: Schema): void;
95
97
  declare namespace _ {
96
- const paginate: {
97
- options: PaginateOptions;
98
- };
99
- const paginateSubDocs: {
100
- options: PaginateOptions;
101
- };
102
- class PaginationParameters<T, O extends PaginateOptions> {
103
- constructor(request: {
104
- query?: Record<string, any>;
105
- });
106
- get: () => [FilterQuery<T>, O];
107
- getOptions: () => O;
108
- getQuery: () => FilterQuery<T>;
109
- }
98
+ const paginate: {
99
+ options: PaginateOptions;
100
+ };
101
+ const paginateSubDocs: {
102
+ options: PaginateOptions;
103
+ };
104
+ class PaginationParameters<T, O extends PaginateOptions> {
105
+ constructor(request: {
106
+ query?: Record<string, any>;
107
+ });
108
+ get: () => [FilterQuery<T>, O];
109
+ getOptions: () => O;
110
+ getQuery: () => FilterQuery<T>;
111
+ }
110
112
  }
111
- export default _;
113
+ type DoNotRemoveOrUseThisType = unknown;
114
+ //#endregion
115
+ export { DoNotRemoveOrUseThisType, _ as default };
112
116
  //# sourceMappingURL=paginate.d.ts.map