@kikiutils/mongoose 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/options.cjs +1 -1
- package/options.mjs +1 -1
- package/package.json +6 -6
- package/plugins/normalize.cjs +1 -1
- package/plugins/normalize.mjs +1 -1
- package/schema-builders/base.cjs +6 -2
- package/schema-builders/base.mjs +6 -2
- package/schema-builders/boolean.d.ts +1 -1
- package/schema-builders/date.d.ts +3 -3
- package/schema-builders/decimal128.cjs +1 -1
- package/schema-builders/decimal128.d.ts +5 -5
- package/schema-builders/decimal128.mjs +1 -1
- package/schema-builders/index.d.ts +1 -1
- package/schema-builders/number.d.ts +3 -3
- package/schema-builders/object-id.d.ts +5 -5
- package/schema-builders/ref.d.ts +6 -6
- package/schema-builders/string.cjs +9 -3
- package/schema-builders/string.d.ts +7 -7
- package/schema-builders/string.mjs +9 -3
- package/types/aggregate-paginate.d.ts +30 -25
- package/types/data.d.ts +1 -1
- package/types/index.d.ts +3 -3
- package/types/paginate.d.ts +37 -32
- package/types/utils.d.ts +1 -1
package/options.cjs
CHANGED
|
@@ -9,6 +9,6 @@ const _internals = require('./_internals.cjs');
|
|
|
9
9
|
* every time {@link buildMongooseModel} is used. Inside this function, you can modify
|
|
10
10
|
* the schema, allowing you to apply common settings to all global schemas.
|
|
11
11
|
*/
|
|
12
|
-
const setCustomMongooseOptions = (key, value) =>
|
|
12
|
+
const setCustomMongooseOptions = (key, value) => _internals.customMongooseOptions[key] = value;
|
|
13
13
|
|
|
14
14
|
exports.setCustomMongooseOptions = setCustomMongooseOptions;
|
package/options.mjs
CHANGED
|
@@ -7,6 +7,6 @@ import { customMongooseOptions } from './_internals.mjs';
|
|
|
7
7
|
* every time {@link buildMongooseModel} is used. Inside this function, you can modify
|
|
8
8
|
* the schema, allowing you to apply common settings to all global schemas.
|
|
9
9
|
*/
|
|
10
|
-
const setCustomMongooseOptions = (key, value) =>
|
|
10
|
+
const setCustomMongooseOptions = (key, value) => customMongooseOptions[key] = value;
|
|
11
11
|
|
|
12
12
|
export { setCustomMongooseOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/mongoose",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.",
|
|
5
5
|
"author": "kiki-kanri",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,21 +55,21 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"decimal.js": "^10.4.3",
|
|
57
57
|
"lodash": "^4.17.21",
|
|
58
|
-
"mongoose": "^8.8.
|
|
58
|
+
"mongoose": "^8.8.4",
|
|
59
59
|
"mongoose-aggregate-paginate-v2": "^1.1.2",
|
|
60
60
|
"mongoose-paginate-v2": "^1.8.5",
|
|
61
|
-
"type-fest": "^4.
|
|
61
|
+
"type-fest": "^4.30.1"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@kikiutils/changelogen": "^0.7.0",
|
|
65
|
-
"@kikiutils/eslint-config": "^0.
|
|
65
|
+
"@kikiutils/eslint-config": "^0.7.1",
|
|
66
66
|
"@kikiutils/tsconfigs": "^3.0.2",
|
|
67
67
|
"@types/jest": "^29.5.14",
|
|
68
68
|
"@types/lodash": "^4.17.13",
|
|
69
|
-
"@types/node": "^22.
|
|
69
|
+
"@types/node": "^22.10.2",
|
|
70
70
|
"jest": "^29.7.0",
|
|
71
71
|
"ts-jest": "^29.2.5",
|
|
72
|
-
"ts-project-builder": "^3.3.
|
|
72
|
+
"ts-project-builder": "^3.3.3",
|
|
73
73
|
"tslib": "^2.8.1"
|
|
74
74
|
}
|
|
75
75
|
}
|
package/plugins/normalize.cjs
CHANGED
|
@@ -8,7 +8,7 @@ const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e
|
|
|
8
8
|
|
|
9
9
|
const lodash__default = /*#__PURE__*/_interopDefaultCompat(lodash);
|
|
10
10
|
|
|
11
|
-
const { get: lodashGet, set: lodashSet, unset: lodashUnset } = lodash__default;
|
|
11
|
+
const { get: lodashGet, set: lodashSet, unset: lodashUnset, } = lodash__default;
|
|
12
12
|
/**
|
|
13
13
|
* Mongoose plugin to normalize the JSON output of documents.
|
|
14
14
|
*
|
package/plugins/normalize.mjs
CHANGED
package/schema-builders/base.cjs
CHANGED
|
@@ -26,8 +26,12 @@ function createBaseSchemaBuilderFactory(type) {
|
|
|
26
26
|
}
|
|
27
27
|
if (key === 'nonRequired')
|
|
28
28
|
return { ...schema };
|
|
29
|
-
if (key === 'required')
|
|
30
|
-
return {
|
|
29
|
+
if (key === 'required') {
|
|
30
|
+
return {
|
|
31
|
+
...schema,
|
|
32
|
+
required: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
31
35
|
schema[key] = true;
|
|
32
36
|
return receiver;
|
|
33
37
|
},
|
package/schema-builders/base.mjs
CHANGED
|
@@ -24,8 +24,12 @@ function createBaseSchemaBuilderFactory(type) {
|
|
|
24
24
|
}
|
|
25
25
|
if (key === 'nonRequired')
|
|
26
26
|
return { ...schema };
|
|
27
|
-
if (key === 'required')
|
|
28
|
-
return {
|
|
27
|
+
if (key === 'required') {
|
|
28
|
+
return {
|
|
29
|
+
...schema,
|
|
30
|
+
required: true,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
29
33
|
schema[key] = true;
|
|
30
34
|
return receiver;
|
|
31
35
|
},
|
|
@@ -5,7 +5,7 @@ export interface BaseBooleanSchemaProps {
|
|
|
5
5
|
type: BooleanSchemaDefinition;
|
|
6
6
|
}
|
|
7
7
|
export interface BooleanSchemaBuilder<Props extends BaseBooleanSchemaProps = BaseBooleanSchemaProps, ExtraOmitFields extends string = never> {
|
|
8
|
-
default: <T extends
|
|
8
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends boolean>(value: T) => ExtendBooleanSchemaBuilder<Merge<Props, {
|
|
9
9
|
default: T;
|
|
10
10
|
}>, ExtraOmitFields>;
|
|
11
11
|
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendBooleanSchemaBuilder<Merge<Props, {
|
|
@@ -10,14 +10,14 @@ export interface DateSchemaBuilder<Props extends {
|
|
|
10
10
|
} = {
|
|
11
11
|
type: DateSchemaDefinition;
|
|
12
12
|
}, ExtraOmitFields extends string = never> {
|
|
13
|
-
default: <T extends
|
|
13
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends NativeDate>(value: T) => ExtendDateSchemaBuilder<Merge<Props, {
|
|
14
14
|
default: T;
|
|
15
15
|
}>, ExtraOmitFields>;
|
|
16
16
|
enum: <T extends Readonlyable<Array<D | null>> | {
|
|
17
|
+
[path: string]: D | null;
|
|
18
|
+
} | {
|
|
17
19
|
message?: M;
|
|
18
20
|
values: Readonlyable<Array<D | null>>;
|
|
19
|
-
} | {
|
|
20
|
-
[path: string]: D | null;
|
|
21
21
|
}, D extends NativeDate, M extends string>(value: T) => ExtendDateSchemaBuilder<Merge<Props, {
|
|
22
22
|
enum: T;
|
|
23
23
|
}>, ExtraOmitFields>;
|
|
@@ -20,14 +20,14 @@ export interface Decimal128SchemaBuilder<Props extends {
|
|
|
20
20
|
} = {
|
|
21
21
|
type: Schema.Types.Decimal128;
|
|
22
22
|
}, ExtraOmitFields extends string = never> {
|
|
23
|
-
default: <T extends
|
|
23
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends Types.Decimal128>(value: T) => ExtendDecimal128SchemaBuilder<Merge<Props, {
|
|
24
24
|
default: T;
|
|
25
25
|
}>, ExtraOmitFields>;
|
|
26
26
|
enum: <T extends Readonlyable<Array<D | null>> | {
|
|
27
|
+
[path: string]: D | null;
|
|
28
|
+
} | {
|
|
27
29
|
message?: M;
|
|
28
30
|
values: Readonlyable<Array<D | null>>;
|
|
29
|
-
} | {
|
|
30
|
-
[path: string]: D | null;
|
|
31
31
|
}, D extends Types.Decimal128, M extends string>(value: T) => ExtendDecimal128SchemaBuilder<Merge<Props, {
|
|
32
32
|
enum: T;
|
|
33
33
|
}>, ExtraOmitFields>;
|
|
@@ -51,7 +51,7 @@ export interface Decimal128SchemaBuilder<Props extends {
|
|
|
51
51
|
*
|
|
52
52
|
* @returns A schema builder with the rounding and toFixed behavior applied to the `set` option in Mongoose.
|
|
53
53
|
*/
|
|
54
|
-
setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendDecimal128SchemaBuilder<Merge<Props, ToStringSetterSchema>,
|
|
54
|
+
setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendDecimal128SchemaBuilder<Merge<Props, ToStringSetterSchema>, 'setRoundAndToFixedSetter' | ExtraOmitFields>;
|
|
55
55
|
/**
|
|
56
56
|
* Sets the toString behavior for Decimal128 fields.
|
|
57
57
|
* This method defines how the Decimal128 field should be converted to a string when processing or
|
|
@@ -61,7 +61,7 @@ export interface Decimal128SchemaBuilder<Props extends {
|
|
|
61
61
|
* @returns A schema builder with the custom `get` behavior applied to convert the Decimal128 field to a string
|
|
62
62
|
* when accessed in the application.
|
|
63
63
|
*/
|
|
64
|
-
setToStringGetter: ExtendDecimal128SchemaBuilder<Merge<Props, ToStringGetterSchema>,
|
|
64
|
+
setToStringGetter: ExtendDecimal128SchemaBuilder<Merge<Props, ToStringGetterSchema>, 'setToStringGetter' | ExtraOmitFields>;
|
|
65
65
|
sparse: ExtendDecimal128SchemaBuilder<Merge<Props, {
|
|
66
66
|
sparse: true;
|
|
67
67
|
}>, ExtraOmitFields>;
|
|
@@ -18,7 +18,7 @@ export declare const schemaBuilders: {
|
|
|
18
18
|
objectId: (schema?: Record<string, any>) => import("./object-id").ObjectIdSchemaBuilder<{
|
|
19
19
|
type: import("mongoose").ObjectIdSchemaDefinition;
|
|
20
20
|
}, never>;
|
|
21
|
-
ref: <T extends
|
|
21
|
+
ref: <T extends ((this: any, doc: any) => import("mongoose").Model<any> | string) | import("mongoose").Model<any> | string>(ref: T) => import("./ref").RefSchemaBuilder<{
|
|
22
22
|
ref: T;
|
|
23
23
|
type: import("mongoose").ObjectIdSchemaDefinition;
|
|
24
24
|
}>;
|
|
@@ -10,14 +10,14 @@ export interface NumberSchemaBuilder<Props extends {
|
|
|
10
10
|
} = {
|
|
11
11
|
type: NumberSchemaDefinition;
|
|
12
12
|
}, ExtraOmitFields extends string = never> {
|
|
13
|
-
default: <T extends
|
|
13
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends number>(value: T) => ExtendNumberSchemaBuilder<Merge<Props, {
|
|
14
14
|
default: T;
|
|
15
15
|
}>, ExtraOmitFields>;
|
|
16
16
|
enum: <T extends Readonlyable<Array<N | null>> | {
|
|
17
|
+
[path: string]: N | null;
|
|
18
|
+
} | {
|
|
17
19
|
message?: M;
|
|
18
20
|
values: Readonlyable<Array<N | null>>;
|
|
19
|
-
} | {
|
|
20
|
-
[path: string]: N | null;
|
|
21
21
|
}, M extends string, N extends number>(value: T) => ExtendNumberSchemaBuilder<Merge<Props, {
|
|
22
22
|
enum: T;
|
|
23
23
|
}>, ExtraOmitFields>;
|
|
@@ -10,14 +10,14 @@ export interface ObjectIdSchemaBuilder<Props extends {
|
|
|
10
10
|
} = {
|
|
11
11
|
type: ObjectIdSchemaDefinition;
|
|
12
12
|
}, ExtraOmitFields extends string = never> {
|
|
13
|
-
default: <T extends
|
|
13
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends Types.ObjectId>(value: T) => ExtendObjectIdSchemaBuilder<Merge<Props, {
|
|
14
14
|
default: T;
|
|
15
15
|
}>, ExtraOmitFields>;
|
|
16
|
-
enum: <T extends Readonlyable<Array<
|
|
17
|
-
|
|
18
|
-
values: Readonlyable<Array<O | null>>;
|
|
16
|
+
enum: <T extends Readonlyable<Array<null | O>> | {
|
|
17
|
+
[path: string]: null | O;
|
|
19
18
|
} | {
|
|
20
|
-
|
|
19
|
+
message?: M;
|
|
20
|
+
values: Readonlyable<Array<null | O>>;
|
|
21
21
|
}, M extends string, O extends Types.ObjectId>(value: T) => ExtendObjectIdSchemaBuilder<Merge<Props, {
|
|
22
22
|
enum: T;
|
|
23
23
|
}>, ExtraOmitFields>;
|
package/schema-builders/ref.d.ts
CHANGED
|
@@ -10,14 +10,14 @@ export interface RefSchemaBuilder<Props extends {
|
|
|
10
10
|
} = {
|
|
11
11
|
type: ObjectIdSchemaDefinition;
|
|
12
12
|
}, ExtraOmitFields extends string = never> {
|
|
13
|
-
default: <T extends
|
|
13
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends Types.ObjectId>(value: T) => ExtendRefSchemaBuilder<Merge<Props, {
|
|
14
14
|
default: T;
|
|
15
15
|
}>, ExtraOmitFields>;
|
|
16
|
-
enum: <T extends Readonlyable<Array<
|
|
17
|
-
|
|
18
|
-
values: Readonlyable<Array<O | null>>;
|
|
16
|
+
enum: <T extends Readonlyable<Array<null | O>> | {
|
|
17
|
+
[path: string]: null | O;
|
|
19
18
|
} | {
|
|
20
|
-
|
|
19
|
+
message?: M;
|
|
20
|
+
values: Readonlyable<Array<null | O>>;
|
|
21
21
|
}, M extends string, O extends Types.ObjectId>(value: T) => ExtendRefSchemaBuilder<Merge<Props, {
|
|
22
22
|
enum: T;
|
|
23
23
|
}>, ExtraOmitFields>;
|
|
@@ -38,7 +38,7 @@ export interface RefSchemaBuilder<Props extends {
|
|
|
38
38
|
unique: true;
|
|
39
39
|
}>, ExtraOmitFields>;
|
|
40
40
|
}
|
|
41
|
-
export declare const refSchemaBuilder: <T extends
|
|
41
|
+
export declare const refSchemaBuilder: <T extends ((this: any, doc: any) => Model<any> | string) | Model<any> | string>(ref: T) => RefSchemaBuilder<{
|
|
42
42
|
ref: T;
|
|
43
43
|
type: ObjectIdSchemaDefinition;
|
|
44
44
|
}>;
|
|
@@ -18,20 +18,26 @@ function stringSchemaBuilder() {
|
|
|
18
18
|
if (key === 'ipv4') {
|
|
19
19
|
return (message = defaultIPv4ValidateMessage) => {
|
|
20
20
|
schema.trim = true;
|
|
21
|
-
schema.validate = {
|
|
21
|
+
schema.validate = {
|
|
22
|
+
message,
|
|
23
|
+
validator: (value) => net__default.isIPv4(value),
|
|
24
|
+
};
|
|
22
25
|
return receiver;
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
28
|
if (key === 'ipv6') {
|
|
26
29
|
return (message = defaultIPv6ValidateMessage) => {
|
|
27
30
|
schema.trim = true;
|
|
28
|
-
schema.validate = {
|
|
31
|
+
schema.validate = {
|
|
32
|
+
message,
|
|
33
|
+
validator: (value) => net__default.isIPv6(value),
|
|
34
|
+
};
|
|
29
35
|
return receiver;
|
|
30
36
|
};
|
|
31
37
|
}
|
|
32
38
|
if (key === 'length') {
|
|
33
39
|
return (value) => {
|
|
34
|
-
|
|
40
|
+
schema.maxlength = schema.minlength = value;
|
|
35
41
|
return receiver;
|
|
36
42
|
};
|
|
37
43
|
}
|
|
@@ -17,14 +17,14 @@ export interface StringSchemaBuilder<Props extends {
|
|
|
17
17
|
} = {
|
|
18
18
|
type: StringSchemaDefinition;
|
|
19
19
|
}, ExtraOmitFields extends string = never> {
|
|
20
|
-
default: <T extends
|
|
20
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends string>(value: T) => ExtendStringSchemaBuilder<Merge<Props, {
|
|
21
21
|
default: T;
|
|
22
22
|
}>, ExtraOmitFields>;
|
|
23
|
-
enum: <T extends Readonlyable<Array<
|
|
24
|
-
|
|
25
|
-
values: Readonlyable<Array<S | null>>;
|
|
23
|
+
enum: <T extends Readonlyable<Array<null | S>> | {
|
|
24
|
+
[path: string]: null | S;
|
|
26
25
|
} | {
|
|
27
|
-
|
|
26
|
+
message?: M;
|
|
27
|
+
values: Readonlyable<Array<null | S>>;
|
|
28
28
|
}, M extends string, S extends string>(value: T) => ExtendStringSchemaBuilder<Merge<Props, {
|
|
29
29
|
enum: T;
|
|
30
30
|
}>, ExtraOmitFields>;
|
|
@@ -39,7 +39,7 @@ export interface StringSchemaBuilder<Props extends {
|
|
|
39
39
|
*
|
|
40
40
|
* @returns A schema builder with IPv4 validation and the `trim` option enabled.
|
|
41
41
|
*/
|
|
42
|
-
ipv4: <T extends string = typeof defaultIPv4ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<Merge<Props, IPSchema<T>>,
|
|
42
|
+
ipv4: <T extends string = typeof defaultIPv4ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<Merge<Props, IPSchema<T>>, 'ipv4' | 'ipv6' | ExtraOmitFields>;
|
|
43
43
|
/**
|
|
44
44
|
* Adds IPv6 validation to the string schema.
|
|
45
45
|
* Ensures the string is a valid IPv6 address and trims the input. The validation message can be customized.
|
|
@@ -48,7 +48,7 @@ export interface StringSchemaBuilder<Props extends {
|
|
|
48
48
|
*
|
|
49
49
|
* @returns A schema builder with IPv6 validation and the `trim` option enabled.
|
|
50
50
|
*/
|
|
51
|
-
ipv6: <T extends string = typeof defaultIPv6ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<Merge<Props, IPSchema<T>>,
|
|
51
|
+
ipv6: <T extends string = typeof defaultIPv6ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<Merge<Props, IPSchema<T>>, 'ipv4' | 'ipv6' | ExtraOmitFields>;
|
|
52
52
|
/**
|
|
53
53
|
* Sets both the maximum and minimum length of the string.
|
|
54
54
|
* This method ensures the string length is exactly or within a specified range.
|
|
@@ -12,20 +12,26 @@ function stringSchemaBuilder() {
|
|
|
12
12
|
if (key === 'ipv4') {
|
|
13
13
|
return (message = defaultIPv4ValidateMessage) => {
|
|
14
14
|
schema.trim = true;
|
|
15
|
-
schema.validate = {
|
|
15
|
+
schema.validate = {
|
|
16
|
+
message,
|
|
17
|
+
validator: (value) => net.isIPv4(value),
|
|
18
|
+
};
|
|
16
19
|
return receiver;
|
|
17
20
|
};
|
|
18
21
|
}
|
|
19
22
|
if (key === 'ipv6') {
|
|
20
23
|
return (message = defaultIPv6ValidateMessage) => {
|
|
21
24
|
schema.trim = true;
|
|
22
|
-
schema.validate = {
|
|
25
|
+
schema.validate = {
|
|
26
|
+
message,
|
|
27
|
+
validator: (value) => net.isIPv6(value),
|
|
28
|
+
};
|
|
23
29
|
return receiver;
|
|
24
30
|
};
|
|
25
31
|
}
|
|
26
32
|
if (key === 'length') {
|
|
27
33
|
return (value) => {
|
|
28
|
-
|
|
34
|
+
schema.maxlength = schema.minlength = value;
|
|
29
35
|
return receiver;
|
|
30
36
|
};
|
|
31
37
|
}
|
|
@@ -1,56 +1,61 @@
|
|
|
1
1
|
import type { AggregatePaginateOptions, Schema } from 'mongoose';
|
|
2
2
|
declare module 'mongoose' {
|
|
3
|
-
interface AggregateCustomLabels<T =
|
|
4
|
-
totalDocs?: T;
|
|
3
|
+
interface AggregateCustomLabels<T = boolean | string | undefined> {
|
|
5
4
|
docs?: T;
|
|
5
|
+
hasNextPage?: T;
|
|
6
|
+
hasPrevPage?: T;
|
|
6
7
|
limit?: T;
|
|
7
|
-
|
|
8
|
+
meta?: T;
|
|
8
9
|
nextPage?: T;
|
|
10
|
+
page?: T;
|
|
11
|
+
pagingCounter?: T;
|
|
9
12
|
prevPage?: T;
|
|
10
|
-
|
|
11
|
-
hasPrevPage?: T;
|
|
13
|
+
totalDocs?: T;
|
|
12
14
|
totalPages?: T;
|
|
13
|
-
pagingCounter?: T;
|
|
14
|
-
meta?: T;
|
|
15
15
|
}
|
|
16
16
|
interface AggregatePaginateOptions {
|
|
17
|
-
|
|
17
|
+
allowDiskUse?: boolean;
|
|
18
|
+
countQuery?: object;
|
|
19
|
+
customLabels?: AggregateCustomLabels;
|
|
20
|
+
limit?: number;
|
|
18
21
|
offset?: number;
|
|
19
22
|
page?: number;
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
/**
|
|
24
|
+
* If pagination is set to `false`, it will return all docs without adding limit condition.
|
|
25
|
+
*
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
22
28
|
pagination?: boolean;
|
|
23
|
-
|
|
24
|
-
countQuery?: object;
|
|
29
|
+
sort?: object | string;
|
|
25
30
|
useFacet?: boolean;
|
|
26
31
|
}
|
|
27
32
|
interface AggregatePaginateQueryPopulateOptions {
|
|
28
|
-
/** space delimited path(s) to populate */
|
|
29
|
-
path: string;
|
|
30
|
-
/** optional fields to select */
|
|
31
|
-
select?: any;
|
|
32
33
|
/** optional query conditions to match */
|
|
33
34
|
match?: any;
|
|
34
35
|
/** optional model to use for population */
|
|
35
|
-
model?:
|
|
36
|
+
model?: Model<any> | string;
|
|
36
37
|
/** optional query options like sort, limit, etc */
|
|
37
38
|
options?: any;
|
|
39
|
+
/** space delimited path(s) to populate */
|
|
40
|
+
path: string;
|
|
38
41
|
/** deep populate */
|
|
39
42
|
populate?: AggregatePaginateQueryPopulateOptions | AggregatePaginateQueryPopulateOptions[];
|
|
43
|
+
/** optional fields to select */
|
|
44
|
+
select?: any;
|
|
40
45
|
}
|
|
41
46
|
interface AggregatePaginateResult<T> {
|
|
47
|
+
[customLabel: string]: boolean | null | number | T[] | undefined;
|
|
42
48
|
docs: T[];
|
|
43
|
-
|
|
49
|
+
hasNextPage: boolean;
|
|
50
|
+
hasPrevPage: boolean;
|
|
44
51
|
limit: number;
|
|
52
|
+
meta?: any;
|
|
53
|
+
nextPage?: null | number;
|
|
45
54
|
page?: number;
|
|
46
|
-
totalPages: number;
|
|
47
|
-
nextPage?: number | null;
|
|
48
|
-
prevPage?: number | null;
|
|
49
55
|
pagingCounter: number;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
[customLabel: string]: T[] | number | boolean | null | undefined;
|
|
56
|
+
prevPage?: null | number;
|
|
57
|
+
totalDocs: number;
|
|
58
|
+
totalPages: number;
|
|
54
59
|
}
|
|
55
60
|
interface AggregatePaginateModel<RawDocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
|
|
56
61
|
aggregatePaginate: <T>(query?: Aggregate<T[]>, options?: AggregatePaginateOptions, callback?: (err: any, result: AggregatePaginateResult<T>) => void) => Promise<AggregatePaginateResult<T>>;
|
package/types/data.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ declare global {
|
|
|
62
62
|
* @template T - The type from which to omit fields.
|
|
63
63
|
* @template OT - Additional fields to omit, specified as a union of string, number, or symbol keys.
|
|
64
64
|
*/
|
|
65
|
-
type OmitMongooseTimestampAndOtherFields<T, OT extends number |
|
|
65
|
+
type OmitMongooseTimestampAndOtherFields<T, OT extends number | string | symbol = never> = Omit<T, 'createdAt' | 'updatedAt' | OT>;
|
|
66
66
|
/**
|
|
67
67
|
* Type definition for including timestamp fields conditionally based on the provided flags.
|
|
68
68
|
*
|
package/types/index.d.ts
CHANGED
|
@@ -18,9 +18,9 @@ declare global {
|
|
|
18
18
|
* @template CreatedAtField - A boolean flag indicating whether the `createdAt` field should be included.
|
|
19
19
|
* @template UpdatedAtField - A boolean flag indicating whether the `updatedAt` field should be included.
|
|
20
20
|
*/
|
|
21
|
-
type BaseMongooseDocType<T, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> =
|
|
21
|
+
type BaseMongooseDocType<T, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = (CreatedAtField extends true ? {
|
|
22
22
|
createdAt: Date;
|
|
23
|
-
} : object) & (UpdatedAtField extends true ? {
|
|
23
|
+
} : object) & Omit<T, 'createdAt' | 'id' | 'updatedAt'> & (UpdatedAtField extends true ? {
|
|
24
24
|
updatedAt: Date;
|
|
25
25
|
} : object);
|
|
26
26
|
/**
|
|
@@ -33,7 +33,7 @@ declare global {
|
|
|
33
33
|
* @template InstanceMethodsAndOverrides - Optional type parameter for instance methods and overrides.
|
|
34
34
|
* @template QueryHelpers - Optional type parameter for additional query helper methods.
|
|
35
35
|
*/
|
|
36
|
-
type BaseMongoosePaginateModel<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = AggregatePaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> &
|
|
36
|
+
type BaseMongoosePaginateModel<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = AggregatePaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> & BaseModelStatics<RawDocType, InstanceMethodsAndOverrides, QueryHelpers> & PaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides>;
|
|
37
37
|
/**
|
|
38
38
|
* Type definition for a Mongoose document or ObjectId.
|
|
39
39
|
*
|
package/types/paginate.d.ts
CHANGED
|
@@ -1,68 +1,73 @@
|
|
|
1
1
|
import type { FilterQuery, mongo, PaginateOptions, Schema } from 'mongoose';
|
|
2
2
|
declare module 'mongoose' {
|
|
3
|
-
interface PaginateCustomLabels<T =
|
|
4
|
-
totalDocs?: T;
|
|
3
|
+
interface PaginateCustomLabels<T = boolean | string | undefined> {
|
|
5
4
|
docs?: T;
|
|
5
|
+
hasNextPage?: T;
|
|
6
|
+
hasPrevPage?: T;
|
|
6
7
|
limit?: T;
|
|
7
|
-
|
|
8
|
+
meta?: T;
|
|
8
9
|
nextPage?: T;
|
|
10
|
+
page?: T;
|
|
11
|
+
pagingCounter?: T;
|
|
9
12
|
prevPage?: T;
|
|
10
|
-
|
|
11
|
-
hasPrevPage?: T;
|
|
13
|
+
totalDocs?: T;
|
|
12
14
|
totalPages?: T;
|
|
13
|
-
pagingCounter?: T;
|
|
14
|
-
meta?: T;
|
|
15
15
|
}
|
|
16
16
|
interface PaginateReadOptions {
|
|
17
17
|
pref: string;
|
|
18
18
|
tags?: any[];
|
|
19
19
|
}
|
|
20
20
|
interface PaginateOptions {
|
|
21
|
-
|
|
21
|
+
allowDiskUse?: boolean;
|
|
22
22
|
collation?: mongo.CollationOptions;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
projection?: any;
|
|
23
|
+
customLabels?: PaginateCustomLabels;
|
|
24
|
+
forceCountFn?: boolean;
|
|
26
25
|
lean?: boolean;
|
|
27
26
|
leanWithId?: boolean;
|
|
27
|
+
limit?: number;
|
|
28
28
|
offset?: number;
|
|
29
|
+
options?: QueryOptions;
|
|
29
30
|
page?: number;
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* If pagination is set to `false`, it will return all docs without adding limit condition.
|
|
33
|
+
*
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
32
36
|
pagination?: boolean;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
forceCountFn?: boolean;
|
|
36
|
-
allowDiskUse?: boolean;
|
|
37
|
+
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
38
|
+
projection?: any;
|
|
37
39
|
read?: PaginateReadOptions;
|
|
38
|
-
|
|
40
|
+
select?: object | string;
|
|
41
|
+
sort?: object | string;
|
|
42
|
+
useCustomCountFn?: () => Promise<number>;
|
|
43
|
+
useEstimatedCount?: boolean;
|
|
39
44
|
}
|
|
40
45
|
interface SubPaginateOptions {
|
|
41
|
-
select?: object | string;
|
|
42
|
-
populate?: PopulateOptions[] | string[] | PopulateOptions | string;
|
|
43
46
|
pagination?: boolean;
|
|
44
|
-
read?: PaginateReadOptions;
|
|
45
47
|
pagingOptions: SubDocumentPagingOptions | undefined;
|
|
48
|
+
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
49
|
+
read?: PaginateReadOptions;
|
|
50
|
+
select?: object | string;
|
|
46
51
|
}
|
|
47
52
|
interface SubDocumentPagingOptions {
|
|
48
|
-
populate?: PopulateOptions[] | string[] | PopulateOptions | string;
|
|
49
|
-
page?: number;
|
|
50
53
|
limit?: number;
|
|
54
|
+
page?: number;
|
|
55
|
+
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
51
56
|
}
|
|
52
57
|
interface PaginateResult<T> {
|
|
58
|
+
[customLabel: string]: boolean | null | number | T[] | undefined;
|
|
53
59
|
docs: T[];
|
|
54
|
-
totalDocs: number;
|
|
55
|
-
limit: number;
|
|
56
|
-
hasPrevPage: boolean;
|
|
57
60
|
hasNextPage: boolean;
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
hasPrevPage: boolean;
|
|
62
|
+
limit: number;
|
|
63
|
+
meta?: any;
|
|
64
|
+
nextPage?: null | number;
|
|
60
65
|
offset: number;
|
|
61
|
-
|
|
62
|
-
nextPage?: number | null;
|
|
66
|
+
page?: number;
|
|
63
67
|
pagingCounter: number;
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
prevPage?: null | number;
|
|
69
|
+
totalDocs: number;
|
|
70
|
+
totalPages: number;
|
|
66
71
|
}
|
|
67
72
|
type PaginateDocument<T, TMethods, TQueryHelpers, O extends PaginateOptions = object> = O['lean'] extends true ? (O['leanWithId'] extends true ? T & {
|
|
68
73
|
id: string;
|
package/types/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type Readonlyable<T> = T |
|
|
1
|
+
export type Readonlyable<T> = Readonly<T> | T;
|