@kikiutils/mongoose 9.0.1 → 9.0.3
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/_internals.d.ts +0 -2
- package/dist/_internals.d.ts.map +1 -1
- package/dist/_internals.js +1 -2
- package/dist/assertions.d.ts +0 -2
- package/dist/assertions.d.ts.map +1 -1
- package/dist/assertions.js +1 -2
- package/dist/assertions.js.map +1 -1
- package/dist/builders.d.ts +1 -3
- package/dist/builders.d.ts.map +1 -1
- package/dist/builders.js +1 -2
- package/dist/connection.d.ts +0 -2
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1 -2
- package/dist/options.d.ts +0 -2
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +1 -2
- package/dist/plugins/assertions.d.ts +0 -2
- package/dist/plugins/assertions.d.ts.map +1 -1
- package/dist/plugins/assertions.js +5 -6
- package/dist/plugins/assertions.js.map +1 -1
- package/dist/plugins/lean-decimal128-to-string.d.ts +6 -4
- package/dist/plugins/lean-decimal128-to-string.d.ts.map +1 -1
- package/dist/plugins/lean-decimal128-to-string.js +6 -6
- package/dist/plugins/lean-decimal128-to-string.js.map +1 -1
- package/dist/plugins/normalize.d.ts +3 -3
- package/dist/plugins/normalize.d.ts.map +1 -1
- package/dist/plugins/normalize.js +3 -3
- package/dist/plugins/normalize.js.map +1 -1
- package/dist/schema-builders/_internals.d.ts +18 -0
- package/dist/schema-builders/_internals.d.ts.map +1 -0
- package/dist/schema-builders/_internals.js +36 -0
- package/dist/schema-builders/_internals.js.map +1 -0
- package/dist/schema-builders/base.d.ts +1 -2
- package/dist/schema-builders/base.d.ts.map +1 -1
- package/dist/schema-builders/base.js +2 -3
- package/dist/schema-builders/base.js.map +1 -1
- package/dist/schema-builders/bigint.d.ts +6 -27
- package/dist/schema-builders/bigint.d.ts.map +1 -1
- package/dist/schema-builders/bigint.js +10 -21
- package/dist/schema-builders/bigint.js.map +1 -1
- package/dist/schema-builders/boolean.d.ts +1 -2
- package/dist/schema-builders/boolean.d.ts.map +1 -1
- package/dist/schema-builders/boolean.js +1 -2
- package/dist/schema-builders/date.d.ts +5 -11
- package/dist/schema-builders/date.d.ts.map +1 -1
- package/dist/schema-builders/date.js +1 -2
- package/dist/schema-builders/date.js.map +1 -1
- package/dist/schema-builders/decimal128.d.ts +7 -26
- package/dist/schema-builders/decimal128.d.ts.map +1 -1
- package/dist/schema-builders/decimal128.js +5 -8
- package/dist/schema-builders/decimal128.js.map +1 -1
- package/dist/schema-builders/double.d.ts +6 -27
- package/dist/schema-builders/double.d.ts.map +1 -1
- package/dist/schema-builders/double.js +10 -21
- package/dist/schema-builders/double.js.map +1 -1
- package/dist/schema-builders/int32.d.ts +6 -27
- package/dist/schema-builders/int32.d.ts.map +1 -1
- package/dist/schema-builders/int32.js +10 -21
- package/dist/schema-builders/int32.js.map +1 -1
- package/dist/schema-builders/mixed.d.ts +1 -2
- package/dist/schema-builders/mixed.d.ts.map +1 -1
- package/dist/schema-builders/mixed.js +1 -2
- package/dist/schema-builders/number.d.ts +5 -11
- package/dist/schema-builders/number.d.ts.map +1 -1
- package/dist/schema-builders/number.js +1 -2
- package/dist/schema-builders/number.js.map +1 -1
- package/dist/schema-builders/object-id.d.ts +3 -9
- package/dist/schema-builders/object-id.d.ts.map +1 -1
- package/dist/schema-builders/object-id.js +1 -2
- package/dist/schema-builders/object-id.js.map +1 -1
- package/dist/schema-builders/ref.d.ts +3 -9
- package/dist/schema-builders/ref.d.ts.map +1 -1
- package/dist/schema-builders/ref.js +1 -2
- package/dist/schema-builders/ref.js.map +1 -1
- package/dist/schema-builders/string.d.ts +6 -12
- package/dist/schema-builders/string.d.ts.map +1 -1
- package/dist/schema-builders/string.js +1 -2
- package/dist/schema-builders/string.js.map +1 -1
- package/dist/schema-builders/uuid.d.ts +1 -2
- package/dist/schema-builders/uuid.d.ts.map +1 -1
- package/dist/schema-builders/uuid.js +1 -2
- package/dist/types/_internals.d.ts +22 -2
- package/dist/types/_internals.d.ts.map +1 -1
- package/dist/types/_internals.js +1 -0
- package/dist/types/aggregate-paginate.d.ts +2 -3
- package/dist/types/aggregate-paginate.d.ts.map +1 -1
- package/dist/types/aggregate-paginate.js +1 -0
- package/dist/types/data.d.ts +3 -3
- package/dist/types/data.d.ts.map +1 -1
- package/dist/types/data.js +1 -0
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/options.d.ts +6 -4
- package/dist/types/options.d.ts.map +1 -1
- package/dist/types/options.js +1 -0
- package/dist/types/paginate.d.ts +0 -2
- package/dist/types/paginate.d.ts.map +1 -1
- package/dist/types/paginate.js +1 -0
- package/package.json +40 -43
- package/src/assertions.ts +0 -1
- package/src/plugins/assertions.ts +4 -4
- package/src/plugins/lean-decimal128-to-string.ts +18 -7
- package/src/plugins/normalize.ts +5 -2
- package/src/schema-builders/_internals.ts +64 -0
- package/src/schema-builders/base.ts +1 -1
- package/src/schema-builders/bigint.ts +33 -67
- package/src/schema-builders/date.ts +7 -7
- package/src/schema-builders/decimal128.ts +25 -41
- package/src/schema-builders/double.ts +35 -67
- package/src/schema-builders/int32.ts +33 -67
- package/src/schema-builders/number.ts +7 -7
- package/src/schema-builders/object-id.ts +2 -5
- package/src/schema-builders/ref.ts +2 -5
- package/src/schema-builders/string.ts +8 -8
- package/src/types/_internals.ts +26 -0
- package/src/types/aggregate-paginate.ts +2 -1
- package/src/types/data.ts +3 -1
- package/src/types/options.ts +6 -2
|
@@ -6,8 +6,22 @@ import type {
|
|
|
6
6
|
} from 'mongoose';
|
|
7
7
|
import type { Merge } from 'type-fest';
|
|
8
8
|
|
|
9
|
-
import type {
|
|
10
|
-
|
|
9
|
+
import type {
|
|
10
|
+
EnumInput,
|
|
11
|
+
EnumValidator,
|
|
12
|
+
LimitValidator,
|
|
13
|
+
ValidationSchema,
|
|
14
|
+
ValueWithMessage,
|
|
15
|
+
} from '../types/_internals';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
defaultEnumValidateMessage,
|
|
19
|
+
defaultLimitValidateMessages,
|
|
20
|
+
hasSchemaValidator,
|
|
21
|
+
normalizeEnumValues,
|
|
22
|
+
normalizeValueWithMessage,
|
|
23
|
+
setSchemaValidator,
|
|
24
|
+
} from './_internals';
|
|
11
25
|
import { createBaseSchemaBuilderFactory } from './base';
|
|
12
26
|
|
|
13
27
|
type ExtendSchemaBuilder<
|
|
@@ -20,25 +34,12 @@ type ExtendSchemaBuilder<
|
|
|
20
34
|
|
|
21
35
|
type Int32Limit = number;
|
|
22
36
|
|
|
37
|
+
type Int32ValidationSchema = ValidationSchema<EnumValidator<number> | LimitValidator<number>>;
|
|
38
|
+
|
|
23
39
|
interface BaseProps {
|
|
24
40
|
type: typeof Schema.Types.Int32;
|
|
25
41
|
}
|
|
26
42
|
|
|
27
|
-
interface Int32EnumValidator {
|
|
28
|
-
enumValues: (null | number)[];
|
|
29
|
-
message: string;
|
|
30
|
-
type: 'enum';
|
|
31
|
-
validator: (value: null | number | undefined) => boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface Int32LimitValidator {
|
|
35
|
-
max?: number;
|
|
36
|
-
message: string;
|
|
37
|
-
min?: number;
|
|
38
|
-
type: 'max' | 'min';
|
|
39
|
-
validator: (value: null | number | undefined) => boolean;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
43
|
export interface Int32SchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFields extends string = never> {
|
|
43
44
|
default: <
|
|
44
45
|
T extends ((this: any, doc: any) => DefaultType<D> | null | undefined) | DefaultType<D> | null | undefined,
|
|
@@ -49,10 +50,7 @@ export interface Int32SchemaBuilder<Props extends BaseProps = BaseProps, ExtraOm
|
|
|
49
50
|
>;
|
|
50
51
|
|
|
51
52
|
enum: <
|
|
52
|
-
T extends
|
|
53
|
-
| Readonlyable<(N | null)[]>
|
|
54
|
-
| { [path: string]: N | null }
|
|
55
|
-
| { message?: M; values: Readonlyable<(N | null)[]> },
|
|
53
|
+
T extends EnumInput<N | null, M>,
|
|
56
54
|
M extends string,
|
|
57
55
|
N extends number,
|
|
58
56
|
>(value: T) => ExtendSchemaBuilder<
|
|
@@ -67,7 +65,7 @@ export interface Int32SchemaBuilder<Props extends BaseProps = BaseProps, ExtraOm
|
|
|
67
65
|
>;
|
|
68
66
|
|
|
69
67
|
max: <
|
|
70
|
-
T extends
|
|
68
|
+
T extends ValueWithMessage<L, S>,
|
|
71
69
|
L extends Int32Limit,
|
|
72
70
|
S extends string,
|
|
73
71
|
>(value: T) => ExtendSchemaBuilder<
|
|
@@ -76,7 +74,7 @@ export interface Int32SchemaBuilder<Props extends BaseProps = BaseProps, ExtraOm
|
|
|
76
74
|
>;
|
|
77
75
|
|
|
78
76
|
min: <
|
|
79
|
-
T extends
|
|
77
|
+
T extends ValueWithMessage<L, S>,
|
|
80
78
|
L extends Int32Limit,
|
|
81
79
|
S extends string,
|
|
82
80
|
>(value: T) => ExtendSchemaBuilder<
|
|
@@ -91,33 +89,19 @@ export interface Int32SchemaBuilder<Props extends BaseProps = BaseProps, ExtraOm
|
|
|
91
89
|
unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
92
90
|
}
|
|
93
91
|
|
|
94
|
-
interface Int32ValidationSchema {
|
|
95
|
-
validate: (Int32EnumValidator | Int32LimitValidator)[];
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Constants/Variables
|
|
99
|
-
const defaultEnumValidateMessage = 'Path `{PATH}` ({VALUE}) is not a valid enum value.';
|
|
100
|
-
const defaultMinValidateMessage = 'Path `{PATH}` ({VALUE}) is less than minimum allowed value ({MIN}).';
|
|
101
|
-
const defaultMaxValidateMessage = 'Path `{PATH}` ({VALUE}) is more than maximum allowed value ({MAX}).';
|
|
102
|
-
|
|
103
92
|
// Functions
|
|
104
93
|
const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Int32);
|
|
105
94
|
|
|
106
95
|
function createLimitValidator(
|
|
107
96
|
type: 'max' | 'min',
|
|
108
|
-
value:
|
|
109
|
-
):
|
|
110
|
-
const [numericLimit, message] =
|
|
111
|
-
? value as Readonly<[Int32Limit, string]>
|
|
112
|
-
: [
|
|
113
|
-
value as Int32Limit,
|
|
114
|
-
undefined,
|
|
115
|
-
];
|
|
97
|
+
value: ValueWithMessage<Int32Limit>,
|
|
98
|
+
): LimitValidator<number> {
|
|
99
|
+
const [numericLimit, message] = normalizeValueWithMessage(value);
|
|
116
100
|
|
|
117
101
|
if (!Number.isFinite(numericLimit)) throw new RangeError(`Int32 ${type} limit must be finite`);
|
|
118
102
|
|
|
119
103
|
return {
|
|
120
|
-
message: message ??
|
|
104
|
+
message: message ?? defaultLimitValidateMessages[type],
|
|
121
105
|
[type]: numericLimit,
|
|
122
106
|
type,
|
|
123
107
|
validator: (value) => {
|
|
@@ -129,56 +113,38 @@ function createLimitValidator(
|
|
|
129
113
|
}
|
|
130
114
|
|
|
131
115
|
export function int32SchemaBuilder() {
|
|
132
|
-
const schema: Record<string, any> = {};
|
|
116
|
+
const schema: Partial<Int32ValidationSchema> & Record<string, any> = {};
|
|
133
117
|
const baseBuilder = baseBuilderFactory(schema);
|
|
134
118
|
return new Proxy(
|
|
135
119
|
baseBuilder,
|
|
136
120
|
{
|
|
137
121
|
get(target, key, receiver) {
|
|
138
122
|
if (key === 'enum') {
|
|
139
|
-
if (schema
|
|
123
|
+
if (hasSchemaValidator(schema, 'enum')) {
|
|
140
124
|
throw new Error('Duplicate schema attribute: enum');
|
|
141
125
|
}
|
|
142
126
|
|
|
143
|
-
return (
|
|
144
|
-
|
|
145
|
-
| { [path: string]: null | number }
|
|
146
|
-
| { message?: string; values: Readonlyable<(null | number)[]> },
|
|
147
|
-
) => {
|
|
148
|
-
let enumValues: (null | number)[];
|
|
149
|
-
let message: string | undefined;
|
|
150
|
-
|
|
151
|
-
if (Array.isArray(value)) enumValues = [...value];
|
|
152
|
-
else if ('values' in value && Array.isArray(value.values)) {
|
|
153
|
-
enumValues = [...value.values];
|
|
154
|
-
if ('message' in value && typeof value.message === 'string') message = value.message;
|
|
155
|
-
} else enumValues = Object.values(value);
|
|
127
|
+
return (value: EnumInput<null | number>) => {
|
|
128
|
+
const { enumValues, message } = normalizeEnumValues(value);
|
|
156
129
|
|
|
157
130
|
const allowedValues = new Set(enumValues);
|
|
158
|
-
const validator:
|
|
131
|
+
const validator: EnumValidator<number> = {
|
|
159
132
|
enumValues,
|
|
160
133
|
message: message ?? defaultEnumValidateMessage,
|
|
161
134
|
type: 'enum',
|
|
162
135
|
validator: (value) => value === null || value === undefined || allowedValues.has(value),
|
|
163
136
|
};
|
|
164
137
|
|
|
165
|
-
schema
|
|
166
|
-
...schema.validate ?? [],
|
|
167
|
-
validator,
|
|
168
|
-
];
|
|
138
|
+
setSchemaValidator(schema, validator);
|
|
169
139
|
|
|
170
140
|
return receiver;
|
|
171
141
|
};
|
|
172
142
|
}
|
|
173
143
|
|
|
174
144
|
if (key === 'max' || key === 'min') {
|
|
175
|
-
return (value:
|
|
145
|
+
return (value: ValueWithMessage<Int32Limit>) => {
|
|
176
146
|
const validator = createLimitValidator(key, value);
|
|
177
|
-
|
|
178
|
-
schema.validate = [
|
|
179
|
-
...validators.filter(({ type }) => type !== key),
|
|
180
|
-
validator,
|
|
181
|
-
];
|
|
147
|
+
setSchemaValidator(schema, validator);
|
|
182
148
|
|
|
183
149
|
return receiver;
|
|
184
150
|
};
|
|
@@ -6,7 +6,10 @@ import type {
|
|
|
6
6
|
} from 'mongoose';
|
|
7
7
|
import type { Merge } from 'type-fest';
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
EnumInput,
|
|
11
|
+
ValueWithMessage,
|
|
12
|
+
} from '../types/_internals';
|
|
10
13
|
|
|
11
14
|
import { createBaseSchemaBuilderFactory } from './base';
|
|
12
15
|
|
|
@@ -35,10 +38,7 @@ export interface NumberSchemaBuilder<
|
|
|
35
38
|
>;
|
|
36
39
|
|
|
37
40
|
enum: <
|
|
38
|
-
T extends
|
|
39
|
-
| Readonlyable<(N | null)[]>
|
|
40
|
-
| { [path: string]: N | null }
|
|
41
|
-
| { message?: M; values: Readonlyable<(N | null)[]> },
|
|
41
|
+
T extends EnumInput<N | null, M>,
|
|
42
42
|
M extends string,
|
|
43
43
|
N extends number,
|
|
44
44
|
>(value: T) => ExtendSchemaBuilder<
|
|
@@ -53,7 +53,7 @@ export interface NumberSchemaBuilder<
|
|
|
53
53
|
>;
|
|
54
54
|
|
|
55
55
|
max: <
|
|
56
|
-
T extends
|
|
56
|
+
T extends ValueWithMessage<N, S>,
|
|
57
57
|
N extends number,
|
|
58
58
|
S extends string,
|
|
59
59
|
>(value: T) => ExtendSchemaBuilder<
|
|
@@ -62,7 +62,7 @@ export interface NumberSchemaBuilder<
|
|
|
62
62
|
>;
|
|
63
63
|
|
|
64
64
|
min: <
|
|
65
|
-
T extends
|
|
65
|
+
T extends ValueWithMessage<N, S>,
|
|
66
66
|
N extends number,
|
|
67
67
|
S extends string,
|
|
68
68
|
>(value: T) => ExtendSchemaBuilder<
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
} from 'mongoose';
|
|
8
8
|
import type { Merge } from 'type-fest';
|
|
9
9
|
|
|
10
|
-
import type {
|
|
10
|
+
import type { EnumInput } from '../types/_internals';
|
|
11
11
|
|
|
12
12
|
import { createBaseSchemaBuilderFactory } from './base';
|
|
13
13
|
|
|
@@ -36,10 +36,7 @@ export interface ObjectIdSchemaBuilder<
|
|
|
36
36
|
>;
|
|
37
37
|
|
|
38
38
|
enum: <
|
|
39
|
-
T extends
|
|
40
|
-
| Readonlyable<(null | O)[]>
|
|
41
|
-
| { [path: string]: null | O }
|
|
42
|
-
| { message?: M; values: Readonlyable<(null | O)[]> },
|
|
39
|
+
T extends EnumInput<null | O, M>,
|
|
43
40
|
M extends string,
|
|
44
41
|
O extends Types.ObjectId,
|
|
45
42
|
>(value: T) => ExtendSchemaBuilder<
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
} from 'mongoose';
|
|
9
9
|
import type { Merge } from 'type-fest';
|
|
10
10
|
|
|
11
|
-
import type {
|
|
11
|
+
import type { EnumInput } from '../types/_internals';
|
|
12
12
|
|
|
13
13
|
import { createBaseSchemaBuilderFactory } from './base';
|
|
14
14
|
|
|
@@ -37,10 +37,7 @@ export interface RefSchemaBuilder<
|
|
|
37
37
|
>;
|
|
38
38
|
|
|
39
39
|
enum: <
|
|
40
|
-
T extends
|
|
41
|
-
| Readonlyable<(null | O)[]>
|
|
42
|
-
| { [path: string]: null | O }
|
|
43
|
-
| { message?: M; values: Readonlyable<(null | O)[]> },
|
|
40
|
+
T extends EnumInput<null | O, M>,
|
|
44
41
|
M extends string,
|
|
45
42
|
O extends Types.ObjectId,
|
|
46
43
|
>(value: T) => ExtendSchemaBuilder<
|
|
@@ -11,7 +11,10 @@ import type {
|
|
|
11
11
|
} from 'mongoose';
|
|
12
12
|
import type { Merge } from 'type-fest';
|
|
13
13
|
|
|
14
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
EnumInput,
|
|
16
|
+
ValueWithMessage,
|
|
17
|
+
} from '../types/_internals';
|
|
15
18
|
|
|
16
19
|
import { createBaseSchemaBuilderFactory } from './base';
|
|
17
20
|
|
|
@@ -45,10 +48,7 @@ export interface StringSchemaBuilder<
|
|
|
45
48
|
>;
|
|
46
49
|
|
|
47
50
|
enum: <
|
|
48
|
-
T extends
|
|
49
|
-
| Readonlyable<(null | S)[]>
|
|
50
|
-
| { [path: string]: null | S }
|
|
51
|
-
| { message?: M; values: Readonlyable<(null | S)[]> },
|
|
51
|
+
T extends EnumInput<null | S, M>,
|
|
52
52
|
M extends string,
|
|
53
53
|
S extends string,
|
|
54
54
|
>(value: T) => ExtendSchemaBuilder<
|
|
@@ -104,7 +104,7 @@ export interface StringSchemaBuilder<
|
|
|
104
104
|
* @returns This instance for chaining.
|
|
105
105
|
*/
|
|
106
106
|
length: <
|
|
107
|
-
T extends
|
|
107
|
+
T extends ValueWithMessage<L, S>,
|
|
108
108
|
L extends number,
|
|
109
109
|
S extends string,
|
|
110
110
|
>(value: T) => ExtendSchemaBuilder<
|
|
@@ -134,7 +134,7 @@ export interface StringSchemaBuilder<
|
|
|
134
134
|
ExtraOmitFields
|
|
135
135
|
>;
|
|
136
136
|
maxlength: <
|
|
137
|
-
T extends
|
|
137
|
+
T extends ValueWithMessage<L, S>,
|
|
138
138
|
L extends number,
|
|
139
139
|
S extends string,
|
|
140
140
|
>(value: T) => ExtendSchemaBuilder<
|
|
@@ -143,7 +143,7 @@ export interface StringSchemaBuilder<
|
|
|
143
143
|
>;
|
|
144
144
|
|
|
145
145
|
minlength: <
|
|
146
|
-
T extends
|
|
146
|
+
T extends ValueWithMessage<L, S>,
|
|
147
147
|
L extends number,
|
|
148
148
|
S extends string,
|
|
149
149
|
>(value: T) => ExtendSchemaBuilder<
|
package/src/types/_internals.ts
CHANGED
|
@@ -1 +1,27 @@
|
|
|
1
|
+
export type EnumInput<T, M extends string = string> = EnumOptions<T, M> | Readonlyable<T[]> | Record<string, T>;
|
|
1
2
|
export type Readonlyable<T> = Readonly<T> | T;
|
|
3
|
+
export type ValueWithMessage<T, M extends string = string> = Readonlyable<[T, M]> | T;
|
|
4
|
+
|
|
5
|
+
export interface EnumOptions<T, M extends string = string> {
|
|
6
|
+
message?: M;
|
|
7
|
+
values: Readonlyable<T[]>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface EnumValidator<T, V = T> {
|
|
11
|
+
enumValues: Array<null | T>;
|
|
12
|
+
message: string;
|
|
13
|
+
type: 'enum';
|
|
14
|
+
validator: (value: null | undefined | V) => boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface LimitValidator<L, V = L> {
|
|
18
|
+
max?: L;
|
|
19
|
+
message: string;
|
|
20
|
+
min?: L;
|
|
21
|
+
type: 'max' | 'min';
|
|
22
|
+
validator: (value: null | undefined | V) => boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ValidationSchema<T> {
|
|
26
|
+
validate: T[];
|
|
27
|
+
}
|
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
PipelineStage,
|
|
12
12
|
Schema,
|
|
13
13
|
} from 'mongoose';
|
|
14
|
+
import type { Arrayable } from 'type-fest';
|
|
14
15
|
|
|
15
16
|
type PrePaginatePipelineStage = '__PREPAGINATE__' | PipelineStage;
|
|
16
17
|
|
|
@@ -86,7 +87,7 @@ export interface AggregatePaginateQueryPopulateOptions {
|
|
|
86
87
|
/**
|
|
87
88
|
* The nested population options applied to the populated documents.
|
|
88
89
|
*/
|
|
89
|
-
populate?: AggregatePaginateQueryPopulateOptions
|
|
90
|
+
populate?: Arrayable<AggregatePaginateQueryPopulateOptions>;
|
|
90
91
|
|
|
91
92
|
/**
|
|
92
93
|
* The field projection used when retrieving populated documents.
|
package/src/types/data.ts
CHANGED
|
@@ -10,7 +10,9 @@ export type BaseMongooseModelData<CreatedAtField extends boolean = true, Updated
|
|
|
10
10
|
& (UpdatedAtField extends true ? { updatedAt: string } : unknown)
|
|
11
11
|
& { id: string };
|
|
12
12
|
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Converts data fields to document fields using the same `_id` rules as BaseMongooseDocType.
|
|
15
|
+
*/
|
|
14
16
|
export type DataToBaseMongooseDocType<
|
|
15
17
|
T,
|
|
16
18
|
ObjectIdFields extends keyof T = never,
|
package/src/types/options.ts
CHANGED
|
@@ -13,10 +13,14 @@ import type { BaseMongoosePaginateModel } from './';
|
|
|
13
13
|
export interface BuildMongooseModelOptions {
|
|
14
14
|
connection?: Connection;
|
|
15
15
|
plugins?: {
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Register lean conversion for marked Decimal128 fields. Defaults to true.
|
|
18
|
+
*/
|
|
17
19
|
leanDecimal128ToString?: boolean | MongooseLeanDecimal128ToStringPluginOptions;
|
|
18
20
|
|
|
19
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Register JSON normalization. Defaults to true; an object enables it with custom options.
|
|
23
|
+
*/
|
|
20
24
|
normalize?: boolean | MongooseNormalizePluginOptions;
|
|
21
25
|
};
|
|
22
26
|
|