@kikiutils/mongoose 5.2.0 → 6.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 (77) hide show
  1. package/dist/assertions.d.ts +7 -0
  2. package/dist/assertions.d.ts.map +1 -0
  3. package/dist/assertions.js +10 -0
  4. package/dist/assertions.js.map +1 -0
  5. package/dist/builders.d.ts +11 -0
  6. package/dist/builders.d.ts.map +1 -0
  7. package/dist/builders.js +26 -0
  8. package/dist/builders.js.map +1 -0
  9. package/dist/constants.d.ts +0 -8
  10. package/dist/constants.d.ts.map +1 -1
  11. package/dist/constants.js +0 -7
  12. package/dist/constants.js.map +1 -1
  13. package/dist/helpers.d.ts +7 -0
  14. package/dist/helpers.d.ts.map +1 -0
  15. package/dist/helpers.js +10 -0
  16. package/dist/helpers.js.map +1 -0
  17. package/dist/options.d.ts +1 -10
  18. package/dist/options.d.ts.map +1 -1
  19. package/dist/options.js +0 -7
  20. package/dist/options.js.map +1 -1
  21. package/dist/plugins/assertions.d.ts +12 -0
  22. package/dist/plugins/assertions.d.ts.map +1 -0
  23. package/dist/plugins/assertions.js +12 -0
  24. package/dist/plugins/assertions.js.map +1 -0
  25. package/dist/plugins/normalize.js +13 -11
  26. package/dist/plugins/normalize.js.map +1 -1
  27. package/dist/schema-builders/boolean.d.ts.map +1 -1
  28. package/dist/schema-builders/date.d.ts +1 -1
  29. package/dist/schema-builders/date.js.map +1 -1
  30. package/dist/schema-builders/decimal128.d.ts +1 -1
  31. package/dist/schema-builders/decimal128.js.map +1 -1
  32. package/dist/schema-builders/number.d.ts +1 -1
  33. package/dist/schema-builders/number.js.map +1 -1
  34. package/dist/schema-builders/object-id.d.ts +1 -1
  35. package/dist/schema-builders/object-id.js.map +1 -1
  36. package/dist/schema-builders/ref.d.ts +1 -1
  37. package/dist/schema-builders/ref.js.map +1 -1
  38. package/dist/schema-builders/string.d.ts +1 -1
  39. package/dist/schema-builders/string.js.map +1 -1
  40. package/dist/types/{utils.d.ts → _internals.d.ts} +2 -2
  41. package/dist/types/_internals.d.ts.map +1 -0
  42. package/dist/types/aggregate-paginate.d.ts +62 -68
  43. package/dist/types/aggregate-paginate.d.ts.map +1 -1
  44. package/dist/types/data.d.ts +12 -45
  45. package/dist/types/data.d.ts.map +1 -1
  46. package/dist/types/index.d.ts +18 -76
  47. package/dist/types/index.d.ts.map +1 -1
  48. package/dist/types/options.d.ts +2 -50
  49. package/dist/types/options.d.ts.map +1 -1
  50. package/dist/types/paginate.d.ts +85 -102
  51. package/dist/types/paginate.d.ts.map +1 -1
  52. package/package.json +10 -6
  53. package/src/assertions.ts +13 -0
  54. package/src/builders.ts +58 -0
  55. package/src/constants.ts +0 -7
  56. package/src/helpers.ts +5 -0
  57. package/src/options.ts +0 -10
  58. package/src/plugins/assertions.ts +40 -0
  59. package/src/plugins/normalize.ts +29 -13
  60. package/src/schema-builders/date.ts +1 -1
  61. package/src/schema-builders/decimal128.ts +1 -1
  62. package/src/schema-builders/number.ts +1 -1
  63. package/src/schema-builders/object-id.ts +1 -1
  64. package/src/schema-builders/ref.ts +1 -1
  65. package/src/schema-builders/string.ts +1 -1
  66. package/src/types/aggregate-paginate.ts +71 -83
  67. package/src/types/data.ts +20 -63
  68. package/src/types/index.ts +45 -110
  69. package/src/types/options.ts +1 -53
  70. package/src/types/paginate.ts +119 -136
  71. package/dist/types/utils.d.ts.map +0 -1
  72. package/dist/utils.d.ts +0 -81
  73. package/dist/utils.d.ts.map +0 -1
  74. package/dist/utils.js +0 -102
  75. package/dist/utils.js.map +0 -1
  76. package/src/utils.ts +0 -160
  77. /package/src/types/{utils.ts → _internals.ts} +0 -0
@@ -1,127 +1,62 @@
1
1
  import type {
2
- AggregatePaginateModel,
3
2
  Connection,
4
3
  HydratedDocument,
5
- PaginateModel,
6
4
  QueryWithHelpers,
7
5
  Types,
8
6
  } from 'mongoose';
9
7
  import type { SetFieldType } from 'type-fest';
10
8
 
11
- import type { IfElse } from './utils';
12
-
13
- export type { _LoadAggregatePaginateTypes } from './aggregate-paginate';
14
- export type { _LoadPaginateTypes } from './paginate';
15
-
16
- // @ts-expect-error Ignore this error.
17
- // eslint-disable-next-line unused-imports/no-unused-vars
18
- export interface BaseModelStatics<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> {}
19
-
20
- export interface MongooseConnections {
21
- default?: Connection;
22
- }
23
-
24
- declare global {
25
- /**
26
- * Type definition for a base Mongoose document type.
27
- *
28
- * This type alias omits the `createdAt`, `id`, and `updatedAt` fields from type `T`,
29
- * and conditionally includes `createdAt` and `updatedAt` fields as `Date` based on
30
- * the `CreatedAtField` and `UpdatedAtField` flags.
31
- *
32
- * @template T - The original document type.
33
- * @template CreatedAtField - A boolean flag indicating whether the `createdAt` field should be included.
34
- * @template UpdatedAtField - A boolean flag indicating whether the `updatedAt` field should be included.
35
- */
36
- type BaseMongooseDocType<
37
- T,
38
- CreatedAtField extends boolean = true,
39
- UpdatedAtField extends boolean = true,
40
- > =
41
- & IfElse<CreatedAtField, { createdAt: Date }, unknown>
42
- & IfElse<UpdatedAtField, { updatedAt: Date }, unknown>
43
- & Omit<T, 'createdAt' | 'id' | 'updatedAt'>;
44
-
45
- /**
46
- * Type definition for a Mongoose model with pagination and aggregation capabilities.
47
- *
48
- * This type alias combines the `AggregatePaginateModel` and `PaginateModel` interfaces,
49
- * along with custom static methods defined in `BaseModelStatics`.
50
- *
51
- * @template RawDocType - The raw document type as stored in MongoDB.
52
- * @template InstanceMethodsAndOverrides - Optional type parameter for instance methods and overrides.
53
- * @template QueryHelpers - Optional type parameter for additional query helper methods.
54
- */
55
- type BaseMongoosePaginateModel<
56
- RawDocType,
57
- InstanceMethodsAndOverrides = object,
58
- QueryHelpers = object,
59
- > =
60
- & AggregatePaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides>
61
- & BaseModelStatics<RawDocType, InstanceMethodsAndOverrides, QueryHelpers>
62
- & PaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides>;
63
-
64
- /**
65
- * Type definition for a Mongoose document or ObjectId.
66
- *
67
- * This type alias represents a value that can be either a Mongoose document, a string,
68
- * or an ObjectId. It is useful when working with Mongoose models where you might have
69
- * references to documents that are stored either as objects or as ObjectIds.
70
- *
71
- * @template D - The Mongoose document type.
72
- */
73
- type MongooseDocumentOrObjectId<D> = D | string | Types.ObjectId;
74
-
75
- /**
76
- * Type definition for the return type of a Mongoose `findOne` query.
77
- *
78
- * This type alias represents the return type of a `findOne` query in Mongoose.
79
- * It extends the `QueryWithHelpers` type, indicating that the query can return
80
- * either a document of type `DocType` or `null` if no document is found. The
81
- * `QueryHelpers` type parameter allows for the inclusion of additional query
82
- * helper methods.
83
- *
84
- * @template RawDocType - The raw document type as stored in MongoDB.
85
- * @template DocType - The Mongoose document type after applying schema transformations.
86
- * @template QueryHelpers - Optional type parameter for additional query helper methods.
87
- * @template InstanceMethodsAndOverrides - Optional type parameter for specifying custom instance methods
88
- * and overrides on the document.
89
- */
90
- type MongooseFindOneReturnType<
91
- RawDocType,
92
- DocType,
93
- QueryHelpers = object,
94
- InstanceMethodsAndOverrides = object,
95
- > = QueryWithHelpers<
9
+ import type { IfElse } from './_internals';
10
+ import type { AggregatePaginateModel } from './aggregate-paginate';
11
+ import type { PaginateModel } from './paginate';
12
+
13
+ export type BaseMongooseDocType<T, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> =
14
+ & IfElse<CreatedAtField, { createdAt: Date }, unknown>
15
+ & IfElse<UpdatedAtField, { updatedAt: Date }, unknown>
16
+ & Omit<T, 'createdAt' | 'id' | 'updatedAt'>;
17
+
18
+ export type BaseMongoosePaginateModel<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> =
19
+ & AggregatePaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides>
20
+ & BaseMongooseModelStatics<RawDocType, InstanceMethodsAndOverrides, QueryHelpers>
21
+ & PaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides>;
22
+
23
+ export type ExceptMongooseTimestampAndOtherFields<T, K extends keyof T> = Omit<T, 'createdAt' | 'updatedAt' | K>;
24
+ export type MongooseDocumentOrObjectId<D> = D | string | Types.ObjectId;
25
+ export type MongooseFindOneReturnType<
26
+ RawDocType,
27
+ DocType,
28
+ QueryHelpers = object,
29
+ InstanceMethodsAndOverrides = object,
30
+ > = QueryWithHelpers<
96
31
  DocType | null,
97
32
  DocType,
98
33
  QueryHelpers,
99
34
  RawDocType,
100
35
  'findOne',
101
36
  InstanceMethodsAndOverrides
102
- >;
37
+ >;
103
38
 
104
- /**
105
- * Type definition for a hydrated Mongoose document.
106
- *
107
- * This type alias represents a hydrated document in Mongoose, which is a fully
108
- * populated document that includes instance methods and query helpers. It extends
109
- * the `HydratedDocument` type from Mongoose, allowing for additional instance
110
- * methods and query helpers to be specified.
111
- *
112
- * @template DocType - The Mongoose document type after applying schema transformations.
113
- * @template InstanceMethodsAndOverrides - Optional type parameter for instance methods and overrides.
114
- * @template QueryHelpers - Optional type parameter for additional query helper methods.
115
- */
116
- type MongooseHydratedDocument<
117
- DocType,
118
- InstanceMethodsAndOverrides = object,
119
- QueryHelpers = object,
120
- > = HydratedDocument<
121
- DocType,
122
- InstanceMethodsAndOverrides,
123
- QueryHelpers
124
- >;
39
+ export type MongooseHydratedDocument<
40
+ DocType,
41
+ InstanceMethodsAndOverrides = object,
42
+ QueryHelpers = object,
43
+ > = HydratedDocument<
44
+ DocType,
45
+ InstanceMethodsAndOverrides,
46
+ QueryHelpers
47
+ >;
48
+
49
+ export type OmitMongooseTimestampAndOtherFields<T, K extends number | string | symbol = never> = Omit<
50
+ T,
51
+ 'createdAt' | 'updatedAt' | K
52
+ >;
125
53
 
126
- type SetFieldsToObjectId<T, K extends keyof T> = SetFieldType<T, K, Types.ObjectId>;
54
+ export type SetFieldsToObjectId<T, K extends keyof T> = SetFieldType<T, K, Types.ObjectId>;
55
+
56
+ // @ts-expect-error Ignore this error.
57
+ // eslint-disable-next-line unused-imports/no-unused-vars
58
+ export interface BaseMongooseModelStatics<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> {}
59
+
60
+ export interface MongooseConnections {
61
+ default?: Connection;
127
62
  }
@@ -5,70 +5,18 @@ import type {
5
5
  } from 'mongoose';
6
6
 
7
7
  import type { MongooseNormalizePluginOptions } from '../plugins/normalize';
8
- import type { buildMongooseModel } from '../utils';
9
8
 
10
- export type DoNotRemoveOrUseThisType = typeof buildMongooseModel;
9
+ import type { BaseMongoosePaginateModel } from './';
11
10
 
12
- /**
13
- * Interface for options used when building a Mongoose model.
14
- *
15
- * This interface defines the optional configuration settings that can be provided
16
- * when creating a Mongoose model. It includes options for specifying the database
17
- * connection, enabling the normalize plugin, and configuring timestamp fields.
18
- */
19
11
  export interface BuildMongooseModelOptions {
20
- /**
21
- * The Mongoose connection to be used for the model.
22
- *
23
- * This is an optional setting that allows specifying a custom connection
24
- * for the model.
25
- */
26
12
  connection?: Connection;
27
-
28
- /**
29
- * Flag to enable or disable the normalize plugin.
30
- *
31
- * This flag indicates whether the normalize plugin should be enabled.
32
- * The default value is `true`.
33
- *
34
- * @default true
35
- */
36
13
  enableNormalizePlugin?: boolean;
37
-
38
- /**
39
- * Options for the normalize plugin.
40
- */
41
14
  normalizePluginOptions?: MongooseNormalizePluginOptions;
42
-
43
- /**
44
- * Whether to recursively register the normalize plugin on child schemas.
45
- *
46
- * If `true`, the plugin will be automatically applied to all nested schemas.
47
- * If `false`, only the root schema will be affected.
48
- *
49
- * @default true
50
- */
51
15
  normalizePluginRecursive?: boolean;
52
-
53
- /**
54
- * Configures Mongoose timestamps.
55
- *
56
- * This option enables or disables timestamps, or allows specifying a
57
- * custom timestamp configuration via {@link SchemaTimestampsConfig}.
58
- *
59
- * - If `timestamps` is explicitly set, it will be used.
60
- * - If `timestamps` is not provided, the schema's existing setting is used.
61
- * - If the schema has no existing setting, `true` is the default value.
62
- *
63
- * @default true
64
- */
65
16
  timestamps?: boolean | SchemaTimestampsConfig;
66
17
  }
67
18
 
68
19
  export interface CustomMongooseOptions {
69
- /**
70
- * A function that will be executed before the final build when using {@link buildMongooseModel}.
71
- */
72
20
  beforeModelBuild?: <
73
21
  DocType,
74
22
  Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,
@@ -1,123 +1,135 @@
1
1
  import type {
2
2
  FilterQuery,
3
+ HydratedDocument,
4
+ Model,
3
5
  mongo,
4
- PaginateOptions,
6
+ PopulateOptions,
7
+ QueryOptions,
5
8
  Schema,
6
9
  } from 'mongoose';
7
10
 
8
- import type { IfElse } from './utils';
11
+ import type { IfElse } from './_internals';
9
12
 
10
- declare module 'mongoose' {
11
- type PaginateDocument<
12
- T,
13
- TMethods,
14
- TQueryHelpers,
15
- O extends PaginateOptions = object,
16
- > = IfElse<
17
- O['lean'],
13
+ export type PaginateDocument<T, TMethods, TQueryHelpers, O extends PaginateOptions = object> = IfElse<
14
+ O['lean'],
15
+ IfElse<
16
+ O['leanWithId'],
17
+ T & { id: string },
18
18
  IfElse<
19
- O['leanWithId'],
20
- T & { id: string },
21
- IfElse<
22
- O['leanWithVirtuals'],
23
- T & { [key: string]: any },
24
- T
25
- >
26
- >,
27
- HydratedDocument<T, TMethods, TQueryHelpers>
28
- >;
29
-
30
- interface PaginateCustomLabels<T = boolean | string | undefined> {
31
- docs?: T;
32
- hasNextPage?: T;
33
- hasPrevPage?: T;
34
- limit?: T;
35
- meta?: T;
36
- nextPage?: T;
37
- page?: T;
38
- pagingCounter?: T;
39
- prevPage?: T;
40
- totalDocs?: T;
41
- totalPages?: T;
42
- }
19
+ O['leanWithVirtuals'],
20
+ T & { [key: string]: any },
21
+ T
22
+ >
23
+ >,
24
+ HydratedDocument<T, TMethods, TQueryHelpers>
25
+ >;
26
+
27
+ export interface PaginateCustomLabels<T = boolean | string | undefined> {
28
+ docs?: T;
29
+ hasNextPage?: T;
30
+ hasPrevPage?: T;
31
+ limit?: T;
32
+ meta?: T;
33
+ nextPage?: T;
34
+ page?: T;
35
+ pagingCounter?: T;
36
+ prevPage?: T;
37
+ totalDocs?: T;
38
+ totalPages?: T;
39
+ }
43
40
 
44
- interface PaginateModel<T, TQueryHelpers = object, TMethods = object> extends Model<T, TQueryHelpers, TMethods> {
45
- paginate: {
46
- <O extends PaginateOptions>(
47
- query?: FilterQuery<T>,
48
- options?: O,
49
- callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>) => void
50
- ): Promise<PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>>;
51
-
52
- <UserType = T, O extends PaginateOptions = PaginateOptions>(
53
- query?: FilterQuery<T>,
54
- options?: O,
55
- callback?: (
56
- err: any,
57
- result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>
58
- ) => void
59
- ): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>>;
60
-
61
- <UserType = T>(
62
- query?: FilterQuery<T>,
63
- options?: PaginateOptions,
64
- callback?: (
65
- err: any,
66
- result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>
67
- ) => void
68
- ): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>>;
69
- };
70
- }
41
+ export interface PaginateModel<T, TQueryHelpers = object, TMethods = object> extends Model<T, TQueryHelpers, TMethods> {
42
+ paginate: {
43
+ <O extends PaginateOptions>(
44
+ query?: FilterQuery<T>,
45
+ options?: O,
46
+ callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>) => void
47
+ ): Promise<PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>>;
48
+
49
+ <UserType = T, O extends PaginateOptions = PaginateOptions>(
50
+ query?: FilterQuery<T>,
51
+ options?: O,
52
+ callback?: (
53
+ err: any,
54
+ result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>
55
+ ) => void
56
+ ): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>>;
57
+
58
+ <UserType = T>(
59
+ query?: FilterQuery<T>,
60
+ options?: PaginateOptions,
61
+ callback?: (
62
+ err: any,
63
+ result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>
64
+ ) => void
65
+ ): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>>;
66
+ };
67
+ }
71
68
 
72
- interface PaginateOptions {
73
- allowDiskUse?: boolean;
74
- collation?: mongo.CollationOptions;
75
- customLabels?: PaginateCustomLabels;
76
- forceCountFn?: boolean;
77
- lean?: boolean;
78
- leanWithId?: boolean;
79
- leanWithVirtuals?: boolean;
80
- limit?: number;
81
- offset?: number;
82
- options?: QueryOptions;
83
- page?: number;
84
-
85
- /**
86
- * If pagination is set to `false`, it will return all docs without adding limit condition.
87
- *
88
- * @default true
89
- */
90
- pagination?: boolean;
91
- populate?: PopulateOptions | PopulateOptions[] | string | string[];
92
- projection?: any;
93
- read?: PaginateReadOptions;
94
- select?: object | string;
95
- sort?: object | string;
96
- useCustomCountFn?: () => Promise<number>;
97
- useEstimatedCount?: boolean;
98
- }
69
+ export interface PaginateOptions {
70
+ allowDiskUse?: boolean;
71
+ collation?: mongo.CollationOptions;
72
+ customLabels?: PaginateCustomLabels;
73
+ forceCountFn?: boolean;
74
+ lean?: boolean;
75
+ leanWithId?: boolean;
76
+ leanWithVirtuals?: boolean;
77
+ limit?: number;
78
+ offset?: number;
79
+ options?: QueryOptions;
80
+ page?: number;
81
+
82
+ /**
83
+ * If pagination is set to `false`, it will return all docs without adding limit condition.
84
+ *
85
+ * @default true
86
+ */
87
+ pagination?: boolean;
88
+ populate?: PopulateOptions | PopulateOptions[] | string | string[];
89
+ projection?: any;
90
+ read?: PaginateReadOptions;
91
+ select?: object | string;
92
+ sort?: object | string;
93
+ useCustomCountFn?: () => Promise<number>;
94
+ useEstimatedCount?: boolean;
95
+ }
99
96
 
100
- interface PaginateReadOptions {
101
- pref: string;
102
- tags?: any[];
103
- }
97
+ export interface PaginateReadOptions {
98
+ pref: string;
99
+ tags?: any[];
100
+ }
104
101
 
105
- interface PaginateResult<T> {
106
- [customLabel: string]: boolean | null | number | T[] | undefined;
107
- docs: T[];
108
- hasNextPage: boolean;
109
- hasPrevPage: boolean;
110
- limit: number;
111
- meta?: any;
112
- nextPage?: null | number;
113
- offset: number;
114
- page?: number;
115
- pagingCounter: number;
116
- prevPage?: null | number;
117
- totalDocs: number;
118
- totalPages: number;
119
- }
102
+ export interface PaginateResult<T> {
103
+ [customLabel: string]: boolean | null | number | T[] | undefined;
104
+ docs: T[];
105
+ hasNextPage: boolean;
106
+ hasPrevPage: boolean;
107
+ limit: number;
108
+ meta?: any;
109
+ nextPage?: null | number;
110
+ offset: number;
111
+ page?: number;
112
+ pagingCounter: number;
113
+ prevPage?: null | number;
114
+ totalDocs: number;
115
+ totalPages: number;
116
+ }
120
117
 
118
+ export interface SubDocumentPagingOptions {
119
+ limit?: number;
120
+ page?: number;
121
+ populate?: PopulateOptions | PopulateOptions[] | string | string[];
122
+ }
123
+
124
+ export interface SubPaginateOptions {
125
+ pagination?: boolean;
126
+ pagingOptions?: SubDocumentPagingOptions;
127
+ populate?: PopulateOptions | PopulateOptions[] | string | string[];
128
+ read?: PaginateReadOptions;
129
+ select?: object | string;
130
+ }
131
+
132
+ declare module 'mongoose' {
121
133
  // @ts-expect-error Ignore this error.
122
134
  interface Query<
123
135
  ResultType,
@@ -141,37 +153,8 @@ declare module 'mongoose' {
141
153
  >;
142
154
  };
143
155
  }
144
-
145
- interface SubDocumentPagingOptions {
146
- limit?: number;
147
- page?: number;
148
- populate?: PopulateOptions | PopulateOptions[] | string | string[];
149
- }
150
-
151
- interface SubPaginateOptions {
152
- pagination?: boolean;
153
- pagingOptions?: SubDocumentPagingOptions;
154
- populate?: PopulateOptions | PopulateOptions[] | string | string[];
155
- read?: PaginateReadOptions;
156
- select?: object | string;
157
- }
158
156
  }
159
157
 
160
158
  declare function _(schema: Schema): void;
161
159
 
162
- // eslint-disable-next-line ts/no-namespace
163
- declare namespace _ {
164
- const paginate: { options: PaginateOptions };
165
- const paginateSubDocs: { options: PaginateOptions };
166
-
167
- class PaginationParameters<T, O extends PaginateOptions> {
168
- constructor(request: { query?: Record<string, any> });
169
- get: () => [FilterQuery<T>, O];
170
- getOptions: () => O;
171
- getQuery: () => FilterQuery<T>;
172
- }
173
- }
174
-
175
- export type _LoadPaginateTypes = unknown;
176
-
177
160
  export default _;
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/types/utils.ts"],"sourcesContent":[],"mappings":";KAAY,2DAKR,kBAAkB,qBAAqB,OAAO;AALtC,KAOA,YAPM,CAAA,CAAA,CAAA,GAOY,QAPZ,CAOqB,CAPrB,CAAA,GAO0B,CAP1B"}
package/dist/utils.d.ts DELETED
@@ -1,81 +0,0 @@
1
- import { MongooseNormalizePluginOptions } from "./plugins/normalize.js";
2
- import { setCustomMongooseOptions } from "./options.js";
3
- import { BuildMongooseModelOptions } from "./types/options.js";
4
- import { Schema, Types, mongo } from "mongoose";
5
-
6
- //#region src/utils.d.ts
7
- type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;
8
- /**
9
- * Asserts that a Mongoose update operation was successful by checking that it was acknowledged
10
- * and that at least the expected number of documents were modified.
11
- *
12
- * This function is intended for use with `updateOne`, `updateMany`, or any update operation
13
- * that returns a MongoDB `UpdateResult`.
14
- *
15
- * @template T - The shape of the document being updated.
16
- * @param updatePromise - A promise returned from a Mongoose update operation.
17
- * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.
18
- * @throws Will throw an error if:
19
- * - The operation was not acknowledged by MongoDB,
20
- * - Fewer documents were modified than expected.
21
- */
22
- declare function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(updatePromise: Promise<mongo.UpdateResult<T>>, expectedModifiedCount?: number): Promise<void>;
23
- /**
24
- * Builds and returns a Mongoose model with specified schema and options.
25
- *
26
- * This function sets up a Mongoose model with optional plugins and timestamp settings.
27
- * It can optionally use a specified connection or the default connection.
28
- *
29
- * Determine the connection to use:
30
- * 1. Use the connection provided in the options, if available.
31
- * 2. Otherwise, use the default connection stored in `mongooseConnections`.
32
- * 3. If there's no default connection, create one using the MongoDB URI from the environment variables,
33
- * or fallback to a local MongoDB instance.
34
- *
35
- * You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.
36
- * However, ensure that this option is configured before calling {@link buildMongooseModel}.
37
- *
38
- * @template DocType - The type of the document.
39
- * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.
40
- * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.
41
- * @template QueryHelpers - The type for additional query helpers.
42
- *
43
- * @param collection - The name of the collection.
44
- * @param name - The name of the model.
45
- * @param schema - The Mongoose schema to use for the model.
46
- * @param options - Optional settings for building the model.
47
- *
48
- * @returns The created Mongoose model.
49
- */
50
- declare function buildMongooseModel<DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(collection: string, name: string, schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>, options?: BuildMongooseModelOptions): Model;
51
- /**
52
- * Converts a document or ObjectId to a document using the specified model.
53
- *
54
- * This function takes a document or ObjectId and returns the corresponding document
55
- * from the database using the specified model. Optionally, specific fields can be selected.
56
- *
57
- * @template D - The type of the hydrated document.
58
- * @template DocType - The type of the document.
59
- * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.
60
- * @template QueryHelpers - The type for additional query helpers.
61
- *
62
- * @param documentOrObjectId - The document or ObjectId to convert.
63
- * @param model - The Mongoose model to use for the conversion.
64
- * @param selectFields - Optional fields to select from the document.
65
- *
66
- * @returns The corresponding document or null if not found.
67
- */
68
- declare function mongooseDocumentOrObjectIdToDocument<D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>, DocType, InstanceMethodsAndOverrides, QueryHelpers>(documentOrObjectId: MongooseDocumentOrObjectId<D>, model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, selectFields?: string[]): Promise<D | null>;
69
- declare function registerMongooseNormalizePlugin<DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>, recursive?: boolean, options?: MongooseNormalizePluginOptions): void;
70
- /**
71
- * Converts the input, which can be a MongoDB ObjectId or a string,
72
- * into a 24-character hexadecimal string representation of the ObjectId.
73
- *
74
- * @param {string | Types.ObjectId} id - The ObjectId instance or its string representation
75
- *
76
- * @returns {string} The hexadecimal string representation of the ObjectId
77
- */
78
- declare function toObjectIdHexString(id: string | Types.ObjectId): string;
79
- //#endregion
80
- export { DoNotRemoveOrUseThisType, assertMongooseUpdateSuccess, buildMongooseModel, mongooseDocumentOrObjectIdToDocument, registerMongooseNormalizePlugin, toObjectIdHexString };
81
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","names":[],"sources":["../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;KAeY,wBAAA,UAAkC;AAA9C;AAkBA;;;;;;;;AAuCA;;;;;AAEkB,iBAzCI,2BAyCJ,CAAA,UAzC0C,KAAA,CAAM,IAAA,CAAK,QAyCrD,CAAA,CAAA,aAAA,EAxCC,OAwCD,CAxCS,KAAA,CAAM,YAwCf,CAxC4B,CAwC5B,CAAA,CAAA,EAAA,qBAAA,CAAA,EAAA,MAAA,CAAA,EAvCW,OAuCX,CAAA,IAAA,CAAA;;;;;;;;;AAuClB;;;;;;;;;;;;;;;AAiBA;;;;AAEkF,iBA5DlE,kBA4DkE,CAAA,OAAA,EAAA,cA1DhE,yBA0DgE,CA1DtC,OA0DsC,EA1D7B,2BA0D6B,EA1DA,YA0DA,CAAA,EAAA,8BAAA,MAAA,EAAA,eAAA,MAAA,CAAA,CAAA,UAAA,EAAA,MAAA,EAAA,IAAA,EAAA,MAAA,EAAA,MAAA,EApDtE,MAoDsE,CApD/D,OAoD+D,EApDtD,KAoDsD,EApD/C,2BAoD+C,EApDlB,YAoDkB,CAAA,EAAA,OAAA,CAAA,EAnDpE,yBAmDoE,CAAA,EAlD/E,KAkD+E;;;;;;;;;AAyBlF;;;;;;;;;iBA5CsB,+CACR,yBAAyB,SAAS,6BAA6B,uFAKrD,2BAA2B,WACxC,0BAA0B,SAAS,6BAA6B,yCAChD,QAAA;iBASX,uDAEE,0BAA0B,SAAS,6BAA6B,oFAItE,OAAO,SAAS,OAAO,6BAA6B,8CAElD;;;;;;;;;iBAmBE,mBAAA,cAAiC,KAAA,CAAM"}