@kikiutils/mongoose 6.1.1 → 6.2.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.
- package/dist/schema-builders/boolean.d.ts +13 -10
- package/dist/schema-builders/boolean.d.ts.map +1 -1
- package/dist/schema-builders/boolean.js.map +1 -1
- package/dist/schema-builders/date.d.ts +13 -10
- package/dist/schema-builders/date.d.ts.map +1 -1
- package/dist/schema-builders/date.js.map +1 -1
- package/dist/schema-builders/decimal128.d.ts +13 -10
- package/dist/schema-builders/decimal128.d.ts.map +1 -1
- package/dist/schema-builders/decimal128.js.map +1 -1
- package/dist/schema-builders/index.d.ts +8 -8
- package/dist/schema-builders/number.d.ts +13 -10
- 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 +11 -8
- package/dist/schema-builders/object-id.d.ts.map +1 -1
- package/dist/schema-builders/object-id.js.map +1 -1
- package/dist/schema-builders/ref.d.ts +11 -8
- package/dist/schema-builders/ref.d.ts.map +1 -1
- package/dist/schema-builders/ref.js.map +1 -1
- package/dist/schema-builders/string.d.ts +20 -17
- package/dist/schema-builders/string.d.ts.map +1 -1
- package/dist/schema-builders/string.js.map +1 -1
- package/package.json +8 -8
- package/src/schema-builders/boolean.ts +10 -9
- package/src/schema-builders/date.ts +10 -9
- package/src/schema-builders/decimal128.ts +10 -13
- package/src/schema-builders/number.ts +10 -9
- package/src/schema-builders/object-id.ts +8 -7
- package/src/schema-builders/ref.ts +8 -7
- package/src/schema-builders/string.ts +17 -16
|
@@ -3,7 +3,7 @@ import { DefaultType, IndexDirection, IndexOptions, StringSchemaDefinition } fro
|
|
|
3
3
|
import { Merge } from "type-fest";
|
|
4
4
|
|
|
5
5
|
//#region src/schema-builders/string.d.ts
|
|
6
|
-
type
|
|
6
|
+
type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<StringSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
7
7
|
interface BaseProps {
|
|
8
8
|
type: StringSchemaDefinition;
|
|
9
9
|
}
|
|
@@ -19,7 +19,7 @@ interface StringSchemaBuilder<Props extends {
|
|
|
19
19
|
} = {
|
|
20
20
|
type: StringSchemaDefinition;
|
|
21
21
|
}, ExtraOmitFields extends string = never> {
|
|
22
|
-
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends string>(value: T) =>
|
|
22
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
23
23
|
default: T;
|
|
24
24
|
}>, ExtraOmitFields>;
|
|
25
25
|
enum: <T extends Readonlyable<Array<null | S>> | {
|
|
@@ -27,10 +27,13 @@ interface StringSchemaBuilder<Props extends {
|
|
|
27
27
|
} | {
|
|
28
28
|
message?: M;
|
|
29
29
|
values: Readonlyable<Array<null | S>>;
|
|
30
|
-
}, M extends string, S extends string>(value: T) =>
|
|
30
|
+
}, M extends string, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
31
31
|
enum: T;
|
|
32
32
|
}>, ExtraOmitFields>;
|
|
33
|
-
|
|
33
|
+
immutable: ExtendSchemaBuilder<Merge<Props, {
|
|
34
|
+
immutable: true;
|
|
35
|
+
}>, ExtraOmitFields>;
|
|
36
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
34
37
|
index: T;
|
|
35
38
|
}>, ExtraOmitFields>;
|
|
36
39
|
/**
|
|
@@ -42,7 +45,7 @@ interface StringSchemaBuilder<Props extends {
|
|
|
42
45
|
*
|
|
43
46
|
* @returns A schema builder with IPv4 validation and the `trim` option enabled.
|
|
44
47
|
*/
|
|
45
|
-
ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) =>
|
|
48
|
+
ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendSchemaBuilder<Merge<Props, IpSchema<T>>, 'ipv4' | 'ipv6' | ExtraOmitFields>;
|
|
46
49
|
/**
|
|
47
50
|
* Adds IPv6 validation to the string schema.
|
|
48
51
|
* Ensures the string is a valid IPv6 address and trims the input. The validation message can be customized.
|
|
@@ -52,7 +55,7 @@ interface StringSchemaBuilder<Props extends {
|
|
|
52
55
|
*
|
|
53
56
|
* @returns A schema builder with IPv6 validation and the `trim` option enabled.
|
|
54
57
|
*/
|
|
55
|
-
ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) =>
|
|
58
|
+
ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendSchemaBuilder<Merge<Props, IpSchema<T>>, 'ipv4' | 'ipv6' | ExtraOmitFields>;
|
|
56
59
|
/**
|
|
57
60
|
* Sets both the maximum and minimum length of the string.
|
|
58
61
|
* This method ensures the string length is exactly or within a specified range.
|
|
@@ -61,39 +64,39 @@ interface StringSchemaBuilder<Props extends {
|
|
|
61
64
|
*
|
|
62
65
|
* @returns A schema builder with both `maxlength` and `minlength` options applied.
|
|
63
66
|
*/
|
|
64
|
-
length: <T extends L | Readonlyable<[L, S]>, L extends number, S extends string>(value: T) =>
|
|
67
|
+
length: <T extends L | Readonlyable<[L, S]>, L extends number, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
65
68
|
maxlength: T;
|
|
66
69
|
minlength: T;
|
|
67
70
|
}>, ExtraOmitFields>;
|
|
68
|
-
lowercase:
|
|
71
|
+
lowercase: ExtendSchemaBuilder<Merge<Props, {
|
|
69
72
|
lowercase: true;
|
|
70
73
|
}>, ExtraOmitFields>;
|
|
71
|
-
maxlength: <T extends L | Readonlyable<[L, S]>, L extends number, S extends string>(value: T) =>
|
|
74
|
+
maxlength: <T extends L | Readonlyable<[L, S]>, L extends number, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
72
75
|
maxlength: T;
|
|
73
76
|
}>, ExtraOmitFields>;
|
|
74
|
-
minlength: <T extends L | Readonlyable<[L, S]>, L extends number, S extends string>(value: T) =>
|
|
77
|
+
minlength: <T extends L | Readonlyable<[L, S]>, L extends number, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
75
78
|
minlength: T;
|
|
76
79
|
}>, ExtraOmitFields>;
|
|
77
80
|
nonRequired: Props;
|
|
78
|
-
private:
|
|
81
|
+
private: ExtendSchemaBuilder<Merge<Props, {
|
|
79
82
|
private: true;
|
|
80
83
|
}>, ExtraOmitFields>;
|
|
81
84
|
required: Merge<Props, {
|
|
82
85
|
required: true;
|
|
83
86
|
}>;
|
|
84
|
-
sparse:
|
|
87
|
+
sparse: ExtendSchemaBuilder<Merge<Props, {
|
|
85
88
|
sparse: true;
|
|
86
89
|
}>, ExtraOmitFields>;
|
|
87
|
-
text:
|
|
90
|
+
text: ExtendSchemaBuilder<Merge<Props, {
|
|
88
91
|
text: true;
|
|
89
92
|
}>, ExtraOmitFields>;
|
|
90
|
-
trim:
|
|
93
|
+
trim: ExtendSchemaBuilder<Merge<Props, {
|
|
91
94
|
trim: true;
|
|
92
95
|
}>, ExtraOmitFields>;
|
|
93
|
-
unique:
|
|
96
|
+
unique: ExtendSchemaBuilder<Merge<Props, {
|
|
94
97
|
unique: true;
|
|
95
98
|
}>, ExtraOmitFields>;
|
|
96
|
-
uppercase:
|
|
99
|
+
uppercase: ExtendSchemaBuilder<Merge<Props, {
|
|
97
100
|
uppercase: true;
|
|
98
101
|
}>, ExtraOmitFields>;
|
|
99
102
|
}
|
|
@@ -101,5 +104,5 @@ declare const defaultIpv4ValidateMessage = "`{VALUE}` is not a valid IPv4 addres
|
|
|
101
104
|
declare const defaultIpv6ValidateMessage = "`{VALUE}` is not a valid IPv6 address for path `{PATH}`";
|
|
102
105
|
declare function stringSchemaBuilder(): StringSchemaBuilder;
|
|
103
106
|
//#endregion
|
|
104
|
-
export {
|
|
107
|
+
export { StringSchemaBuilder, stringSchemaBuilder };
|
|
105
108
|
//# sourceMappingURL=string.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","names":[],"sources":["../../src/schema-builders/string.ts"],"sourcesContent":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"string.d.ts","names":[],"sources":["../../src/schema-builders/string.ts"],"sourcesContent":[],"mappings":";;;;;KAiBK,kCACa,6CAEd,KACA,oBAAoB,OAAO,kBAC3B,wBAAwB;UAGlB,SAAA;EARL,IAAA,EASK,sBATc;;UAYd,QAXQ,CAAA,UAAA,MAAA,CAAA,CAAA;MAGM,EAAA,IAAA;UAAO,EAAA;IAA3B,OAAA,EAUqB,CAVrB;IACA,SAAA,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,GAAA,OAAA;;;AAFI,UAcS,mBAdT,CAAA,cAAA;EAKE,IAAA,EAUgB,sBAThB;AAAsB,CAAA,GAGtB;EAKO,IAAA,EAC4C,sBADzB;CAAA,EAAA,wBAAA,MAAA,GAAA,KAAA,CAAA,CAAA;SACV,EAAA,CAAA,UAAA,CAAA,CAAA,IAAA,EAAA,GAAA,EAAA,GAAA,EAAA,GAAA,EAAA,GAIkB,WAJlB,CAI8B,CAJ9B,CAAA,CAAA,GAIoC,WAJpC,CAIgD,CAJhD,CAAA,GAAA,IAAA,EAAA,UAAA,MAAA,CAAA,CAAA,KAAA,EAMb,CANa,EAAA,GAMP,mBANO,CAOlB,KAPkB,CAOZ,KAPY,EAAA;IAAmC,OAAA,EAO7B,CAP6B;MAQrD,eAJgD,CAAA;MAAZ,EAAA,CAAA,UASlC,YATkC,CASrB,KATqB,CAAA,IAAA,GASR,CATQ,CAAA,CAAA,GAAA;IAA8B,CAAA,IAAA,EAAA,MAAA,CAAA,EAAA,IAAA,GAUvC,CAVuC;MAAZ;IAEjD,OAAA,CAAA,EASS,CATT;IACC,MAAA,EAQmB,YARnB,CAQgC,KARhC,CAAA,IAAA,GAQ6C,CAR7C,CAAA,CAAA;KAAkB,UAAA,MAAA,EAAA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AnBlB,CAmBwB,KAnBxB,EAAA;IAAoB,MAAA,EAAA,IAAA;MAmB8B,eAnBxD,CAAA;WACA,EAmBO,mBAnBP,CAmB2B,KAnB3B,CAmBiC,KAnBjC,EAAA;IAFW,SAAA,EAAA,IAAA;MAqBmD,eAfpD,CAAA;;cAmBZ,0BAAA,GAnBiC,yDAAA;cAoBjC,0BAAA,GApBgB,yDAAA;AAGT,iBAmBG,mBAAA,CAAA,CAnBH,EA4DJ,mBA5DI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","names":["schema: Record<string, any>"],"sources":["../../src/schema-builders/string.ts"],"sourcesContent":["import {\n isIPv4,\n isIPv6,\n} from 'node:net';\n\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n StringSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\
|
|
1
|
+
{"version":3,"file":"string.js","names":["schema: Record<string, any>"],"sources":["../../src/schema-builders/string.ts"],"sourcesContent":["import {\n isIPv4,\n isIPv6,\n} from 'node:net';\n\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n StringSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n StringSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: StringSchemaDefinition;\n}\n\ninterface IpSchema<T extends string> {\n trim: true;\n validate: { message: T; validator: (value: string) => boolean };\n}\n\nexport interface StringSchemaBuilder<\n Props extends { type: StringSchemaDefinition } = { type: StringSchemaDefinition },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<null | S>>\n | { [path: string]: null | S }\n | { message?: M; values: Readonlyable<Array<null | S>> },\n M extends string,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n /**\n * Adds IPv4 validation to the string schema.\n * Ensures the string is a valid IPv4 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv4 validation message.\n *\n * @returns A schema builder with IPv4 validation and the `trim` option enabled.\n */\n ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | ExtraOmitFields\n >;\n\n /**\n * Adds IPv6 validation to the string schema.\n * Ensures the string is a valid IPv6 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv6 validation message.\n *\n * @returns A schema builder with IPv6 validation and the `trim` option enabled.\n */\n ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | ExtraOmitFields\n >;\n\n /**\n * Sets both the maximum and minimum length of the string.\n * This method ensures the string length is exactly or within a specified range.\n *\n * @param value - A number representing the exact length or an array specifying [minimum, maximum] length.\n *\n * @returns A schema builder with both `maxlength` and `minlength` options applied.\n */\n length: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendSchemaBuilder<Merge<Props, { lowercase: true }>, ExtraOmitFields>;\n maxlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { maxlength: T }>,\n ExtraOmitFields\n >;\n\n minlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { minlength: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n text: ExtendSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendSchemaBuilder<Merge<Props, { uppercase: true }>, ExtraOmitFields>;\n}\n\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(String);\nconst defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`';\nconst defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`';\n\nexport function stringSchemaBuilder() {\n const schema: Record<string, any> = {};\n const baseBuilder = baseBuilderFactory(schema);\n return new Proxy(\n baseBuilder,\n {\n get(target, key, receiver) {\n if (key === 'ipv4') {\n return (message: string = defaultIpv4ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => isIPv4(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'ipv6') {\n return (message: string = defaultIpv6ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => isIPv6(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'length') {\n return (value: any) => {\n schema.maxlength = schema.minlength = value;\n return receiver;\n };\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as StringSchemaBuilder;\n}\n"],"mappings":";;;;AA0IA,MAAM,qBAAqB,+BAA+B,OAAO;AACjE,MAAM,6BAA6B;AACnC,MAAM,6BAA6B;AAEnC,SAAgB,sBAAsB;CAClC,MAAMA,SAA8B,EAAE;CACtC,MAAM,cAAc,mBAAmB,OAAO;AAC9C,QAAO,IAAI,MACP,aACA,EACI,IAAI,QAAQ,KAAK,UAAU;AACvB,MAAI,QAAQ,OACR,SAAQ,UAAkB,+BAA+B;AACrD,UAAO,OAAO;AACd,UAAO,WAAW;IACd;IACA,YAAY,UAAkB,OAAO,MAAM;IAC9C;AAED,UAAO;;AAIf,MAAI,QAAQ,OACR,SAAQ,UAAkB,+BAA+B;AACrD,UAAO,OAAO;AACd,UAAO,WAAW;IACd;IACA,YAAY,UAAkB,OAAO,MAAM;IAC9C;AAED,UAAO;;AAIf,MAAI,QAAQ,SACR,SAAQ,UAAe;AACnB,UAAO,YAAY,OAAO,YAAY;AACtC,UAAO;;AAIf,SAAO,QAAQ,IAAI,QAAQ,KAAK,SAAS;IAEhD,CACJ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/mongoose",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.2.0",
|
|
5
5
|
"description": "A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.",
|
|
6
6
|
"author": "kiki-kanri",
|
|
7
7
|
"license": "MIT",
|
|
@@ -77,22 +77,22 @@
|
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"decimal.js": "^10.6.0",
|
|
79
79
|
"es-toolkit": "^1.39.10",
|
|
80
|
-
"mongoose": "^8.
|
|
80
|
+
"mongoose": "^8.19.1",
|
|
81
81
|
"mongoose-aggregate-paginate-v2": "^1.1.4",
|
|
82
82
|
"mongoose-paginate-v2": "^1.9.1",
|
|
83
83
|
"type-fest": "^5.0.1"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@kikiutils/
|
|
87
|
-
"@kikiutils/eslint-config": "^3.0.1",
|
|
86
|
+
"@kikiutils/eslint-config": "^4.0.0",
|
|
88
87
|
"@kikiutils/tsconfigs": "^5.0.5",
|
|
89
|
-
"@types/node": "^24.
|
|
88
|
+
"@types/node": "^24.7.0",
|
|
90
89
|
"@vitest/coverage-v8": "^3.2.4",
|
|
90
|
+
"changelogen": "^0.6.2",
|
|
91
91
|
"depcheck": "^1.4.7",
|
|
92
|
-
"publint": "^0.3.
|
|
92
|
+
"publint": "^0.3.14",
|
|
93
93
|
"ts-unused-exports": "^11.0.1",
|
|
94
|
-
"tsdown": "^0.15.
|
|
95
|
-
"typescript": "^5.9.
|
|
94
|
+
"tsdown": "^0.15.6",
|
|
95
|
+
"typescript": "^5.9.3",
|
|
96
96
|
"unplugin-unused": "^0.5.3",
|
|
97
97
|
"vitest": "^3.2.4"
|
|
98
98
|
},
|
|
@@ -8,40 +8,41 @@ import type { Merge } from 'type-fest';
|
|
|
8
8
|
|
|
9
9
|
import { createBaseSchemaBuilderFactory } from './base';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
Props extends
|
|
11
|
+
type ExtendSchemaBuilder<
|
|
12
|
+
Props extends BaseProps,
|
|
13
13
|
ExtraOmitFields extends string,
|
|
14
14
|
> = Omit<
|
|
15
15
|
BooleanSchemaBuilder<Props, ExtraOmitFields>,
|
|
16
16
|
ExtraOmitFields | keyof Props
|
|
17
17
|
>;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
interface BaseProps {
|
|
20
20
|
type: BooleanSchemaDefinition;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface BooleanSchemaBuilder<
|
|
24
|
-
Props extends
|
|
24
|
+
Props extends BaseProps = BaseProps,
|
|
25
25
|
ExtraOmitFields extends string = never,
|
|
26
26
|
> {
|
|
27
27
|
default: <
|
|
28
28
|
T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,
|
|
29
29
|
D extends boolean,
|
|
30
|
-
>(value: T) =>
|
|
30
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
31
31
|
Merge<Props, { default: T }>,
|
|
32
32
|
ExtraOmitFields
|
|
33
33
|
>;
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;
|
|
36
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<
|
|
36
37
|
Merge<Props, { index: T }>,
|
|
37
38
|
ExtraOmitFields
|
|
38
39
|
>;
|
|
39
40
|
|
|
40
41
|
nonRequired: Props;
|
|
41
|
-
private:
|
|
42
|
+
private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;
|
|
42
43
|
required: Merge<Props, { required: true }>;
|
|
43
|
-
sparse:
|
|
44
|
-
unique:
|
|
44
|
+
sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;
|
|
45
|
+
unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export const booleanSchemaBuilder = createBaseSchemaBuilderFactory<BooleanSchemaBuilder>(Boolean);
|
|
@@ -10,7 +10,7 @@ import type { Readonlyable } from '../types/_internals';
|
|
|
10
10
|
|
|
11
11
|
import { createBaseSchemaBuilderFactory } from './base';
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
type ExtendSchemaBuilder<
|
|
14
14
|
Props extends BaseProps,
|
|
15
15
|
ExtraOmitFields extends string,
|
|
16
16
|
> = Omit<
|
|
@@ -29,7 +29,7 @@ export interface DateSchemaBuilder<
|
|
|
29
29
|
default: <
|
|
30
30
|
T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,
|
|
31
31
|
D extends NativeDate,
|
|
32
|
-
>(value: T) =>
|
|
32
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
33
33
|
Merge<Props, { default: T }>,
|
|
34
34
|
ExtraOmitFields
|
|
35
35
|
>;
|
|
@@ -41,12 +41,13 @@ export interface DateSchemaBuilder<
|
|
|
41
41
|
| { message?: M; values: Readonlyable<Array<D | null>> },
|
|
42
42
|
D extends NativeDate,
|
|
43
43
|
M extends string,
|
|
44
|
-
>(value: T) =>
|
|
44
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
45
45
|
Merge<Props, { enum: T }>,
|
|
46
46
|
ExtraOmitFields
|
|
47
47
|
>;
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;
|
|
50
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<
|
|
50
51
|
Merge<Props, { index: T }>,
|
|
51
52
|
ExtraOmitFields
|
|
52
53
|
>;
|
|
@@ -55,7 +56,7 @@ export interface DateSchemaBuilder<
|
|
|
55
56
|
T extends D | Readonlyable<[D, S]>,
|
|
56
57
|
D extends NativeDate,
|
|
57
58
|
S extends string,
|
|
58
|
-
>(value: T) =>
|
|
59
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
59
60
|
Merge<Props, { max: T }>,
|
|
60
61
|
ExtraOmitFields
|
|
61
62
|
>;
|
|
@@ -64,16 +65,16 @@ export interface DateSchemaBuilder<
|
|
|
64
65
|
T extends D | Readonlyable<[D, S]>,
|
|
65
66
|
D extends NativeDate,
|
|
66
67
|
S extends string,
|
|
67
|
-
>(value: T) =>
|
|
68
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
68
69
|
Merge<Props, { min: T }>,
|
|
69
70
|
ExtraOmitFields
|
|
70
71
|
>;
|
|
71
72
|
|
|
72
73
|
nonRequired: Props;
|
|
73
|
-
private:
|
|
74
|
+
private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;
|
|
74
75
|
required: Merge<Props, { required: true }>;
|
|
75
|
-
sparse:
|
|
76
|
-
unique:
|
|
76
|
+
sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;
|
|
77
|
+
unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
export const dateSchemaBuilder = createBaseSchemaBuilderFactory<DateSchemaBuilder>(Date);
|
|
@@ -12,7 +12,7 @@ import type { Readonlyable } from '../types/_internals';
|
|
|
12
12
|
|
|
13
13
|
import { createBaseSchemaBuilderFactory } from './base';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
type ExtendSchemaBuilder<
|
|
16
16
|
Props extends BaseProps,
|
|
17
17
|
ExtraOmitFields extends string,
|
|
18
18
|
> = Omit<
|
|
@@ -31,7 +31,7 @@ export interface Decimal128SchemaBuilder<
|
|
|
31
31
|
default: <
|
|
32
32
|
T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,
|
|
33
33
|
D extends Types.Decimal128,
|
|
34
|
-
>(value: T) =>
|
|
34
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
35
35
|
Merge<Props, { default: T }>,
|
|
36
36
|
ExtraOmitFields
|
|
37
37
|
>;
|
|
@@ -43,18 +43,19 @@ export interface Decimal128SchemaBuilder<
|
|
|
43
43
|
| { message?: M; values: Readonlyable<Array<D | null>> },
|
|
44
44
|
D extends Types.Decimal128,
|
|
45
45
|
M extends string,
|
|
46
|
-
>(value: T) =>
|
|
46
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
47
47
|
Merge<Props, { enum: T }>,
|
|
48
48
|
ExtraOmitFields
|
|
49
49
|
>;
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;
|
|
52
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<
|
|
52
53
|
Merge<Props, { index: T }>,
|
|
53
54
|
ExtraOmitFields
|
|
54
55
|
>;
|
|
55
56
|
|
|
56
57
|
nonRequired: Props;
|
|
57
|
-
private:
|
|
58
|
+
private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;
|
|
58
59
|
required: Merge<Props, { required: true }>;
|
|
59
60
|
|
|
60
61
|
/**
|
|
@@ -67,7 +68,7 @@ export interface Decimal128SchemaBuilder<
|
|
|
67
68
|
*
|
|
68
69
|
* @returns A schema builder with the rounding and toFixed behavior applied to the `set` option in Mongoose.
|
|
69
70
|
*/
|
|
70
|
-
setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) =>
|
|
71
|
+
setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendSchemaBuilder<
|
|
71
72
|
Merge<Props, ToStringSetterSchema>,
|
|
72
73
|
'setRoundAndToFixedSetter' | ExtraOmitFields
|
|
73
74
|
>;
|
|
@@ -81,13 +82,9 @@ export interface Decimal128SchemaBuilder<
|
|
|
81
82
|
* @returns A schema builder with the custom `get` behavior applied to convert the Decimal128 field to a string
|
|
82
83
|
* when accessed in the application.
|
|
83
84
|
*/
|
|
84
|
-
setToStringGetter:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
>;
|
|
88
|
-
|
|
89
|
-
sparse: ExtendDecimal128SchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;
|
|
90
|
-
unique: ExtendDecimal128SchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
85
|
+
setToStringGetter: ExtendSchemaBuilder<Merge<Props, ToStringGetterSchema>, 'setToStringGetter' | ExtraOmitFields>;
|
|
86
|
+
sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;
|
|
87
|
+
unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
91
88
|
}
|
|
92
89
|
|
|
93
90
|
interface ToStringGetterSchema {
|
|
@@ -10,7 +10,7 @@ import type { Readonlyable } from '../types/_internals';
|
|
|
10
10
|
|
|
11
11
|
import { createBaseSchemaBuilderFactory } from './base';
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
type ExtendSchemaBuilder<
|
|
14
14
|
Props extends BaseProps,
|
|
15
15
|
ExtraOmitFields extends string,
|
|
16
16
|
> = Omit<
|
|
@@ -29,7 +29,7 @@ export interface NumberSchemaBuilder<
|
|
|
29
29
|
default: <
|
|
30
30
|
T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,
|
|
31
31
|
D extends number,
|
|
32
|
-
>(value: T) =>
|
|
32
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
33
33
|
Merge<Props, { default: T }>,
|
|
34
34
|
ExtraOmitFields
|
|
35
35
|
>;
|
|
@@ -41,12 +41,13 @@ export interface NumberSchemaBuilder<
|
|
|
41
41
|
| { message?: M; values: Readonlyable<Array<N | null>> },
|
|
42
42
|
M extends string,
|
|
43
43
|
N extends number,
|
|
44
|
-
>(value: T) =>
|
|
44
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
45
45
|
Merge<Props, { enum: T }>,
|
|
46
46
|
ExtraOmitFields
|
|
47
47
|
>;
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
immutable: ExtendSchemaBuilder<Merge<Props, { privaimmutablete: true }>, ExtraOmitFields>;
|
|
50
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<
|
|
50
51
|
Merge<Props, { index: T }>,
|
|
51
52
|
ExtraOmitFields
|
|
52
53
|
>;
|
|
@@ -55,7 +56,7 @@ export interface NumberSchemaBuilder<
|
|
|
55
56
|
T extends N | Readonlyable<[N, S]>,
|
|
56
57
|
N extends number,
|
|
57
58
|
S extends string,
|
|
58
|
-
>(value: T) =>
|
|
59
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
59
60
|
Merge<Props, { max: T }>,
|
|
60
61
|
ExtraOmitFields
|
|
61
62
|
>;
|
|
@@ -64,16 +65,16 @@ export interface NumberSchemaBuilder<
|
|
|
64
65
|
T extends N | Readonlyable<[N, S]>,
|
|
65
66
|
N extends number,
|
|
66
67
|
S extends string,
|
|
67
|
-
>(value: T) =>
|
|
68
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
68
69
|
Merge<Props, { min: T }>,
|
|
69
70
|
ExtraOmitFields
|
|
70
71
|
>;
|
|
71
72
|
|
|
72
73
|
nonRequired: Props;
|
|
73
|
-
private:
|
|
74
|
+
private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;
|
|
74
75
|
required: Merge<Props, { required: true }>;
|
|
75
|
-
sparse:
|
|
76
|
-
unique:
|
|
76
|
+
sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;
|
|
77
|
+
unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
export const numberSchemaBuilder = createBaseSchemaBuilderFactory<NumberSchemaBuilder>(Number);
|
|
@@ -11,7 +11,7 @@ import type { Readonlyable } from '../types/_internals';
|
|
|
11
11
|
|
|
12
12
|
import { createBaseSchemaBuilderFactory } from './base';
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
type ExtendSchemaBuilder<
|
|
15
15
|
Props extends BaseProps,
|
|
16
16
|
ExtraOmitFields extends string,
|
|
17
17
|
> = Omit<
|
|
@@ -30,7 +30,7 @@ export interface ObjectIdSchemaBuilder<
|
|
|
30
30
|
default: <
|
|
31
31
|
T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,
|
|
32
32
|
D extends Types.ObjectId,
|
|
33
|
-
>(value: T) =>
|
|
33
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
34
34
|
Merge<Props, { default: T }>,
|
|
35
35
|
ExtraOmitFields
|
|
36
36
|
>;
|
|
@@ -42,21 +42,22 @@ export interface ObjectIdSchemaBuilder<
|
|
|
42
42
|
| { message?: M; values: Readonlyable<Array<null | O>> },
|
|
43
43
|
M extends string,
|
|
44
44
|
O extends Types.ObjectId,
|
|
45
|
-
>(value: T) =>
|
|
45
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
46
46
|
Merge<Props, { enum: T }>,
|
|
47
47
|
ExtraOmitFields
|
|
48
48
|
>;
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;
|
|
51
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<
|
|
51
52
|
Merge<Props, { index: T }>,
|
|
52
53
|
ExtraOmitFields
|
|
53
54
|
>;
|
|
54
55
|
|
|
55
56
|
nonRequired: Props;
|
|
56
|
-
private:
|
|
57
|
+
private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;
|
|
57
58
|
required: Merge<Props, { required: true }>;
|
|
58
|
-
sparse:
|
|
59
|
-
unique:
|
|
59
|
+
sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;
|
|
60
|
+
unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
export const objectIdSchemaBuilder = createBaseSchemaBuilderFactory<ObjectIdSchemaBuilder>(Schema.Types.ObjectId);
|
|
@@ -12,7 +12,7 @@ import type { Readonlyable } from '../types/_internals';
|
|
|
12
12
|
|
|
13
13
|
import { createBaseSchemaBuilderFactory } from './base';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
type ExtendSchemaBuilder<
|
|
16
16
|
Props extends BaseProps,
|
|
17
17
|
ExtraOmitFields extends string,
|
|
18
18
|
> = Omit<
|
|
@@ -31,7 +31,7 @@ export interface RefSchemaBuilder<
|
|
|
31
31
|
default: <
|
|
32
32
|
T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,
|
|
33
33
|
D extends Types.ObjectId,
|
|
34
|
-
>(value: T) =>
|
|
34
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
35
35
|
Merge<Props, { default: T }>,
|
|
36
36
|
ExtraOmitFields
|
|
37
37
|
>;
|
|
@@ -43,21 +43,22 @@ export interface RefSchemaBuilder<
|
|
|
43
43
|
| { message?: M; values: Readonlyable<Array<null | O>> },
|
|
44
44
|
M extends string,
|
|
45
45
|
O extends Types.ObjectId,
|
|
46
|
-
>(value: T) =>
|
|
46
|
+
>(value: T) => ExtendSchemaBuilder<
|
|
47
47
|
Merge<Props, { enum: T }>,
|
|
48
48
|
ExtraOmitFields
|
|
49
49
|
>;
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;
|
|
52
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<
|
|
52
53
|
Merge<Props, { index: T }>,
|
|
53
54
|
ExtraOmitFields
|
|
54
55
|
>;
|
|
55
56
|
|
|
56
57
|
nonRequired: Props;
|
|
57
|
-
private:
|
|
58
|
+
private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;
|
|
58
59
|
required: Merge<Props, { required: true }>;
|
|
59
|
-
sparse:
|
|
60
|
-
unique:
|
|
60
|
+
sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;
|
|
61
|
+
unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.ObjectId);
|