@kikiutils/mongoose 5.2.0 → 6.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.
- package/dist/assertions.d.ts +7 -0
- package/dist/assertions.d.ts.map +1 -0
- package/dist/assertions.js +10 -0
- package/dist/assertions.js.map +1 -0
- package/dist/builders.d.ts +13 -0
- package/dist/builders.d.ts.map +1 -0
- package/dist/builders.js +26 -0
- package/dist/builders.js.map +1 -0
- package/dist/constants.d.ts +0 -8
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +0 -7
- package/dist/constants.js.map +1 -1
- package/dist/helpers.d.ts +7 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +10 -0
- package/dist/helpers.js.map +1 -0
- package/dist/options.d.ts +1 -10
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +0 -7
- package/dist/options.js.map +1 -1
- package/dist/plugins/assertions.d.ts +12 -0
- package/dist/plugins/assertions.d.ts.map +1 -0
- package/dist/plugins/assertions.js +12 -0
- package/dist/plugins/assertions.js.map +1 -0
- package/dist/plugins/normalize.js +13 -11
- package/dist/plugins/normalize.js.map +1 -1
- package/dist/schema-builders/date.d.ts +1 -1
- package/dist/schema-builders/date.js.map +1 -1
- package/dist/schema-builders/decimal128.d.ts +1 -1
- package/dist/schema-builders/decimal128.js.map +1 -1
- package/dist/schema-builders/number.d.ts +1 -1
- package/dist/schema-builders/number.d.ts.map +1 -1
- package/dist/schema-builders/number.js.map +1 -1
- package/dist/schema-builders/object-id.d.ts +1 -1
- package/dist/schema-builders/object-id.js.map +1 -1
- package/dist/schema-builders/ref.d.ts +1 -1
- package/dist/schema-builders/ref.js.map +1 -1
- package/dist/schema-builders/string.d.ts +1 -1
- package/dist/schema-builders/string.js.map +1 -1
- package/dist/types/{utils.d.ts → _internals.d.ts} +2 -2
- package/dist/types/_internals.d.ts.map +1 -0
- package/dist/types/aggregate-paginate.d.ts +62 -68
- package/dist/types/aggregate-paginate.d.ts.map +1 -1
- package/dist/types/data.d.ts +12 -45
- package/dist/types/data.d.ts.map +1 -1
- package/dist/types/index.d.ts +18 -76
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/options.d.ts +2 -50
- package/dist/types/options.d.ts.map +1 -1
- package/dist/types/paginate.d.ts +85 -102
- package/dist/types/paginate.d.ts.map +1 -1
- package/package.json +10 -6
- package/src/assertions.ts +16 -0
- package/src/builders.ts +60 -0
- package/src/constants.ts +0 -7
- package/src/helpers.ts +5 -0
- package/src/options.ts +0 -10
- package/src/plugins/assertions.ts +40 -0
- package/src/plugins/normalize.ts +29 -13
- package/src/schema-builders/date.ts +1 -1
- package/src/schema-builders/decimal128.ts +1 -1
- package/src/schema-builders/number.ts +1 -1
- package/src/schema-builders/object-id.ts +1 -1
- package/src/schema-builders/ref.ts +1 -1
- package/src/schema-builders/string.ts +1 -1
- package/src/types/aggregate-paginate.ts +71 -83
- package/src/types/data.ts +20 -63
- package/src/types/index.ts +45 -110
- package/src/types/options.ts +1 -53
- package/src/types/paginate.ts +119 -136
- package/dist/types/utils.d.ts.map +0 -1
- package/dist/utils.d.ts +0 -81
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -102
- package/dist/utils.js.map +0 -1
- package/src/utils.ts +0 -160
- /package/src/types/{utils.ts → _internals.ts} +0 -0
package/src/types/index.ts
CHANGED
|
@@ -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 './
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/types/options.ts
CHANGED
|
@@ -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
|
-
|
|
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>,
|
package/src/types/paginate.ts
CHANGED
|
@@ -1,123 +1,135 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
FilterQuery,
|
|
3
|
+
HydratedDocument,
|
|
4
|
+
Model,
|
|
3
5
|
mongo,
|
|
4
|
-
|
|
6
|
+
PopulateOptions,
|
|
7
|
+
QueryOptions,
|
|
5
8
|
Schema,
|
|
6
9
|
} from 'mongoose';
|
|
7
10
|
|
|
8
|
-
import type { IfElse } from './
|
|
11
|
+
import type { IfElse } from './_internals';
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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['
|
|
20
|
-
T & {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
export interface PaginateReadOptions {
|
|
98
|
+
pref: string;
|
|
99
|
+
tags?: any[];
|
|
100
|
+
}
|
|
104
101
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
package/dist/utils.d.ts.map
DELETED
|
@@ -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"}
|