@kikiutils/mongoose 7.0.3 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/_internals.d.ts +5 -2
- package/dist/_internals.d.ts.map +1 -1
- package/dist/_internals.js +2 -1
- package/dist/_internals.js.map +1 -1
- package/dist/assertions.d.ts +1 -2
- package/dist/assertions.d.ts.map +1 -1
- package/dist/builders.d.ts +3 -4
- package/dist/builders.d.ts.map +1 -1
- package/dist/builders.js +2 -3
- package/dist/builders.js.map +1 -1
- package/dist/connection.d.ts +5 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +10 -0
- package/dist/connection.js.map +1 -0
- package/dist/options.d.ts +1 -2
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +2 -1
- package/dist/options.js.map +1 -1
- package/dist/plugins/assertions.d.ts +1 -2
- package/dist/plugins/assertions.d.ts.map +1 -1
- package/dist/plugins/normalize.d.ts +23 -17
- package/dist/plugins/normalize.d.ts.map +1 -1
- package/dist/plugins/normalize.js +19 -12
- package/dist/plugins/normalize.js.map +1 -1
- package/dist/schema-builders/base.d.ts +2 -3
- package/dist/schema-builders/base.d.ts.map +1 -1
- package/dist/schema-builders/base.js.map +1 -1
- package/dist/schema-builders/bigint.d.ts +48 -0
- package/dist/schema-builders/bigint.d.ts.map +1 -0
- package/dist/schema-builders/bigint.js +36 -0
- package/dist/schema-builders/bigint.js.map +1 -0
- package/dist/schema-builders/boolean.d.ts +2 -3
- 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 +2 -3
- package/dist/schema-builders/date.d.ts.map +1 -1
- package/dist/schema-builders/decimal128.d.ts +33 -15
- package/dist/schema-builders/decimal128.d.ts.map +1 -1
- package/dist/schema-builders/decimal128.js +23 -0
- package/dist/schema-builders/decimal128.js.map +1 -1
- package/dist/schema-builders/double.d.ts +48 -0
- package/dist/schema-builders/double.d.ts.map +1 -0
- package/dist/schema-builders/double.js +37 -0
- package/dist/schema-builders/double.js.map +1 -0
- package/dist/schema-builders/index.d.ts +6 -1
- package/dist/schema-builders/index.js +6 -1
- package/dist/schema-builders/int32.d.ts +48 -0
- package/dist/schema-builders/int32.d.ts.map +1 -0
- package/dist/schema-builders/int32.js +36 -0
- package/dist/schema-builders/int32.js.map +1 -0
- package/dist/schema-builders/mixed.d.ts +34 -0
- package/dist/schema-builders/mixed.d.ts.map +1 -0
- package/dist/schema-builders/mixed.js +8 -0
- package/dist/schema-builders/mixed.js.map +1 -0
- package/dist/schema-builders/number.d.ts +2 -3
- package/dist/schema-builders/number.d.ts.map +1 -1
- package/dist/schema-builders/object-id.d.ts +2 -3
- package/dist/schema-builders/object-id.d.ts.map +1 -1
- package/dist/schema-builders/ref.d.ts +2 -3
- package/dist/schema-builders/ref.d.ts.map +1 -1
- package/dist/schema-builders/string.d.ts +56 -19
- package/dist/schema-builders/string.d.ts.map +1 -1
- package/dist/schema-builders/string.js +13 -1
- package/dist/schema-builders/string.js.map +1 -1
- package/dist/schema-builders/uuid.d.ts +34 -0
- package/dist/schema-builders/uuid.d.ts.map +1 -0
- package/dist/schema-builders/uuid.js +8 -0
- package/dist/schema-builders/uuid.js.map +1 -0
- package/dist/types/_internals.d.ts +1 -2
- package/dist/types/_internals.d.ts.map +1 -1
- package/dist/types/aggregate-paginate.d.ts +30 -14
- package/dist/types/aggregate-paginate.d.ts.map +1 -1
- package/dist/types/data.d.ts +2 -3
- package/dist/types/data.d.ts.map +1 -1
- package/dist/types/index.d.ts +10 -14
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/options.d.ts +4 -4
- package/dist/types/options.d.ts.map +1 -1
- package/dist/types/paginate.d.ts +15 -11
- package/dist/types/paginate.d.ts.map +1 -1
- package/package.json +23 -18
- package/src/_internals.ts +3 -0
- package/src/builders.ts +3 -10
- package/src/connection.ts +14 -0
- package/src/options.ts +8 -1
- package/src/plugins/normalize.ts +23 -15
- package/src/schema-builders/base.ts +8 -1
- package/src/schema-builders/bigint.ts +134 -0
- package/src/schema-builders/boolean.ts +1 -4
- package/src/schema-builders/decimal128.ts +92 -12
- package/src/schema-builders/double.ts +135 -0
- package/src/schema-builders/index.ts +15 -0
- package/src/schema-builders/int32.ts +135 -0
- package/src/schema-builders/mixed.ts +37 -0
- package/src/schema-builders/string.ts +90 -17
- package/src/schema-builders/uuid.ts +48 -0
- package/src/types/aggregate-paginate.ts +29 -8
- package/src/types/index.ts +0 -5
- package/src/types/options.ts +3 -0
- package/src/types/paginate.ts +6 -2
- package/dist/constants.d.ts +0 -6
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -6
- package/dist/constants.js.map +0 -1
- package/dist/helpers.d.ts +0 -6
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js +0 -9
- package/dist/helpers.js.map +0 -1
- package/src/constants.ts +0 -3
- package/src/helpers.ts +0 -5
|
@@ -13,7 +13,7 @@ interface IpSchema<T extends string> {
|
|
|
13
13
|
validator: (value: string) => boolean;
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
interface StringSchemaBuilder<Props extends {
|
|
16
|
+
export interface StringSchemaBuilder<Props extends {
|
|
17
17
|
type: StringSchemaDefinition;
|
|
18
18
|
} = {
|
|
19
19
|
type: StringSchemaDefinition;
|
|
@@ -36,32 +36,37 @@ interface StringSchemaBuilder<Props extends {
|
|
|
36
36
|
index: T;
|
|
37
37
|
}>, ExtraOmitFields>;
|
|
38
38
|
/**
|
|
39
|
-
* Adds IPv4 validation
|
|
40
|
-
* Ensures the string is a valid IPv4 address and trims the input. The validation message can be customized.
|
|
39
|
+
* Adds IPv4 address validation and enables input trimming.
|
|
41
40
|
*
|
|
42
|
-
* @
|
|
43
|
-
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Replaces the configured custom validator and sets `trim` to `true` on this builder.
|
|
44
43
|
*
|
|
45
|
-
* @
|
|
44
|
+
* @param message - The validation error message. Defaults to the built-in IPv4 validation message.
|
|
45
|
+
*
|
|
46
|
+
* @returns This instance for chaining.
|
|
46
47
|
*/
|
|
47
|
-
ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendSchemaBuilder<Merge<Props, IpSchema<T>>, 'ipv4' | 'ipv6' | ExtraOmitFields>;
|
|
48
|
+
ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendSchemaBuilder<Merge<Props, IpSchema<T>>, 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields>;
|
|
48
49
|
/**
|
|
49
|
-
* Adds IPv6 validation
|
|
50
|
-
*
|
|
50
|
+
* Adds IPv6 address validation and enables input trimming.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* Replaces the configured custom validator and sets `trim` to `true` on this builder.
|
|
51
54
|
*
|
|
52
|
-
* @param message - The
|
|
53
|
-
* IPv6 validation message.
|
|
55
|
+
* @param message - The validation error message. Defaults to the built-in IPv6 validation message.
|
|
54
56
|
*
|
|
55
|
-
* @returns
|
|
57
|
+
* @returns This instance for chaining.
|
|
56
58
|
*/
|
|
57
|
-
ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendSchemaBuilder<Merge<Props, IpSchema<T>>, 'ipv4' | 'ipv6' | ExtraOmitFields>;
|
|
59
|
+
ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendSchemaBuilder<Merge<Props, IpSchema<T>>, 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields>;
|
|
58
60
|
/**
|
|
59
|
-
* Sets
|
|
60
|
-
*
|
|
61
|
+
* Sets equal minimum and maximum string lengths.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* Assigns the same value to `minlength` and `maxlength`, replacing any previously configured limits.
|
|
61
65
|
*
|
|
62
|
-
* @param value -
|
|
66
|
+
* @param value - The exact length in UTF-16 code units, or a tuple containing the length and a validation
|
|
67
|
+
* error message.
|
|
63
68
|
*
|
|
64
|
-
* @returns
|
|
69
|
+
* @returns This instance for chaining.
|
|
65
70
|
*/
|
|
66
71
|
length: <T extends L | Readonlyable<[L, S]>, L extends number, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
67
72
|
maxlength: T;
|
|
@@ -70,6 +75,20 @@ interface StringSchemaBuilder<Props extends {
|
|
|
70
75
|
lowercase: ExtendSchemaBuilder<Merge<Props, {
|
|
71
76
|
lowercase: true;
|
|
72
77
|
}>, ExtraOmitFields>;
|
|
78
|
+
/**
|
|
79
|
+
* Configures regular expression validation for the string field.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* Replaces any previously configured `match` option.
|
|
83
|
+
*
|
|
84
|
+
* @param regex - The regular expression used by Mongoose to validate the string.
|
|
85
|
+
* @param message - The validation error message. If omitted, Mongoose uses its default message.
|
|
86
|
+
*
|
|
87
|
+
* @returns This instance for chaining.
|
|
88
|
+
*/
|
|
89
|
+
match: <T extends RegExp, M extends string | undefined = undefined>(regex: T, message?: M) => ExtendSchemaBuilder<Merge<Props, {
|
|
90
|
+
match: M extends string ? Readonly<[T, M]> : T;
|
|
91
|
+
}>, ExtraOmitFields>;
|
|
73
92
|
maxlength: <T extends L | Readonlyable<[L, S]>, L extends number, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
74
93
|
maxlength: T;
|
|
75
94
|
}>, ExtraOmitFields>;
|
|
@@ -98,10 +117,28 @@ interface StringSchemaBuilder<Props extends {
|
|
|
98
117
|
uppercase: ExtendSchemaBuilder<Merge<Props, {
|
|
99
118
|
uppercase: true;
|
|
100
119
|
}>, ExtraOmitFields>;
|
|
120
|
+
/**
|
|
121
|
+
* Adds WHATWG URL parseability validation.
|
|
122
|
+
*
|
|
123
|
+
* @remarks
|
|
124
|
+
* Accepts URLs with credentials and non-HTTP schemes. Performs no DNS lookup or stored-value normalization,
|
|
125
|
+
* and does not enable trimming. Replaces the configured custom validator on this builder.
|
|
126
|
+
*
|
|
127
|
+
* @param message - The validation error message. Defaults to the built-in URL validation message.
|
|
128
|
+
*
|
|
129
|
+
* @returns This instance for chaining.
|
|
130
|
+
*/
|
|
131
|
+
url: <T extends string = typeof defaultUrlValidateMessage>(message?: T) => ExtendSchemaBuilder<Merge<Props, UrlSchema<T>>, 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields>;
|
|
132
|
+
}
|
|
133
|
+
interface UrlSchema<T extends string> {
|
|
134
|
+
validate: {
|
|
135
|
+
message: T;
|
|
136
|
+
validator: (value: string) => boolean;
|
|
137
|
+
};
|
|
101
138
|
}
|
|
102
139
|
declare const defaultIpv4ValidateMessage = "`{VALUE}` is not a valid IPv4 address for path `{PATH}`";
|
|
103
140
|
declare const defaultIpv6ValidateMessage = "`{VALUE}` is not a valid IPv6 address for path `{PATH}`";
|
|
104
|
-
declare
|
|
141
|
+
declare const defaultUrlValidateMessage = "`{VALUE}` is not a valid URL for path `{PATH}`";
|
|
142
|
+
export declare function stringSchemaBuilder(): StringSchemaBuilder;
|
|
105
143
|
//#endregion
|
|
106
|
-
export { StringSchemaBuilder, stringSchemaBuilder };
|
|
107
144
|
//# sourceMappingURL=string.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","names":[],"sources":["../../src/schema-builders/string.ts"],"mappings":";;;;KAiBK,oBACD,cAAc,WACd,kCACA,KACA,oBAAoB,OAAO,kBAC3B,wBAAwB;UAGlB;EACN,MAAM;;UAGA,SAAS;EACf;EACA;IAAY,SAAS;IAAG,YAAY;;;
|
|
1
|
+
{"version":3,"file":"string.d.ts","names":[],"sources":["../../src/schema-builders/string.ts"],"mappings":";;;;KAiBK,oBACD,cAAc,WACd,kCACA,KACA,oBAAoB,OAAO,kBAC3B,wBAAwB;UAGlB;EACN,MAAM;;UAGA,SAAS;EACf;EACA;IAAY,SAAS;IAAG,YAAY;;;iBAGvB,oBACb;EAAgB,MAAM;;EAA6B,MAAM;GACzD;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,UACE,aAAa,aAAa;KACvB,sBAAsB;;IACvB,UAAU;IAAG,QAAQ,aAAa,aAAa;KACnD,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,MAAM;MACrB;EAGJ,WAAW,oBAAoB,MAAM;IAAS;MAAoB;EAClE,QAAQ,oBAAoB,iBAAiB,cAAc,OAAO,MAAM,oBACpE,MAAM;IAAS,OAAO;MACtB;;;;;;;;;;;EAaJ,OAAO,0BAA0B,4BAA4B,UAAU,MAAM,oBACzE,MAAM,OAAO,SAAS,+BACI;;;;;;;;;;;EAa9B,OAAO,0BAA0B,4BAA4B,UAAU,MAAM,oBACzE,MAAM,OAAO,SAAS,+BACI;;;;;;;;;;;;EAc9B,SACI,UAAU,IAAI,cAAc,GAAG,KAC/B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,WAAW;IAAG,WAAW;MACxC;EAGJ,WAAW,oBAAoB,MAAM;IAAS;MAAoB;;;;;;;;;;;;EAalE,QACI,UAAU,QACV,0CACF,OAAO,GACL,UAAU,MAAM,oBAChB,MAAM;IAAS,OAAO,mBAAmB,UAAU,GAAG,MAAM;MAC5D;EAEJ,YACI,UAAU,IAAI,cAAc,GAAG,KAC/B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,WAAW;MAC1B;EAGJ,YACI,UAAU,IAAI,cAAc,GAAG,KAC/B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,WAAW;MAC1B;EAGJ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;EACzB,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,MAAM,oBAAoB,MAAM;IAAS;MAAe;EACxD,MAAM,oBAAoB,MAAM;IAAS;MAAe;EACxD,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,WAAW,oBAAoB,MAAM;IAAS;MAAoB;;;;;;;;;;;;EAalE,MAAM,0BAA0B,2BAA2B,UAAU,MAAM,oBACvE,MAAM,OAAO,UAAU,+BACG;;UAIxB,UAAU;EAChB;IAAY,SAAS;IAAG,YAAY;;;cAIlC;cACA;cACA;wBAKU,uBAiEP"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createBaseSchemaBuilderFactory } from "./base.js";
|
|
2
2
|
import { isIPv4, isIPv6 } from "node:net";
|
|
3
3
|
//#region src/schema-builders/string.ts
|
|
4
|
-
const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
|
|
5
4
|
const defaultIpv4ValidateMessage = "`{VALUE}` is not a valid IPv4 address for path `{PATH}`";
|
|
6
5
|
const defaultIpv6ValidateMessage = "`{VALUE}` is not a valid IPv6 address for path `{PATH}`";
|
|
6
|
+
const defaultUrlValidateMessage = "`{VALUE}` is not a valid URL for path `{PATH}`";
|
|
7
|
+
const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
|
|
7
8
|
function stringSchemaBuilder() {
|
|
8
9
|
const schema = {};
|
|
9
10
|
const baseBuilder = baseBuilderFactory(schema);
|
|
@@ -28,6 +29,17 @@ function stringSchemaBuilder() {
|
|
|
28
29
|
schema.maxlength = schema.minlength = value;
|
|
29
30
|
return receiver;
|
|
30
31
|
};
|
|
32
|
+
if (key === "match") return (regex, message) => {
|
|
33
|
+
schema.match = message === void 0 ? regex : [regex, message];
|
|
34
|
+
return receiver;
|
|
35
|
+
};
|
|
36
|
+
if (key === "url") return (message = defaultUrlValidateMessage) => {
|
|
37
|
+
schema.validate = {
|
|
38
|
+
message,
|
|
39
|
+
validator: (value) => URL.canParse(value)
|
|
40
|
+
};
|
|
41
|
+
return receiver;
|
|
42
|
+
};
|
|
31
43
|
return Reflect.get(target, key, receiver);
|
|
32
44
|
} });
|
|
33
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","names":[],"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
|
|
1
|
+
{"version":3,"file":"string.js","names":[],"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 address validation and enables input trimming.\n *\n * @remarks\n * Replaces the configured custom validator and sets `trim` to `true` on this builder.\n *\n * @param message - The validation error message. Defaults to the built-in IPv4 validation message.\n *\n * @returns This instance for chaining.\n */\n ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields\n >;\n\n /**\n * Adds IPv6 address validation and enables input trimming.\n *\n * @remarks\n * Replaces the configured custom validator and sets `trim` to `true` on this builder.\n *\n * @param message - The validation error message. Defaults to the built-in IPv6 validation message.\n *\n * @returns This instance for chaining.\n */\n ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields\n >;\n\n /**\n * Sets equal minimum and maximum string lengths.\n *\n * @remarks\n * Assigns the same value to `minlength` and `maxlength`, replacing any previously configured limits.\n *\n * @param value - The exact length in UTF-16 code units, or a tuple containing the length and a validation\n * error message.\n *\n * @returns This instance for chaining.\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\n /**\n * Configures regular expression validation for the string field.\n *\n * @remarks\n * Replaces any previously configured `match` option.\n *\n * @param regex - The regular expression used by Mongoose to validate the string.\n * @param message - The validation error message. If omitted, Mongoose uses its default message.\n *\n * @returns This instance for chaining.\n */\n match: <\n T extends RegExp,\n M extends string | undefined = undefined,\n >(regex: T,\n message?: M) => ExtendSchemaBuilder<\n Merge<Props, { match: M extends string ? Readonly<[T, M]> : T }>,\n ExtraOmitFields\n >;\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 /**\n * Adds WHATWG URL parseability validation.\n *\n * @remarks\n * Accepts URLs with credentials and non-HTTP schemes. Performs no DNS lookup or stored-value normalization,\n * and does not enable trimming. Replaces the configured custom validator on this builder.\n *\n * @param message - The validation error message. Defaults to the built-in URL validation message.\n *\n * @returns This instance for chaining.\n */\n url: <T extends string = typeof defaultUrlValidateMessage>(message?: T) => ExtendSchemaBuilder<\n Merge<Props, UrlSchema<T>>,\n 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields\n >;\n}\n\ninterface UrlSchema<T extends string> {\n validate: { message: T; validator: (value: string) => boolean };\n}\n\n// Constants/Variables\nconst defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`';\nconst defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`';\nconst defaultUrlValidateMessage = '`{VALUE}` is not a valid URL for path `{PATH}`';\n\n// Functions\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(String);\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 if (key === 'match') {\n return (regex: RegExp, message?: string) => {\n schema.match = message === undefined\n ? regex\n : [\n regex,\n message,\n ];\n\n return receiver;\n };\n }\n\n if (key === 'url') {\n return (message: string = defaultUrlValidateMessage) => {\n schema.validate = {\n message,\n validator: (value: string) => URL.canParse(value),\n };\n\n return receiver;\n };\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as StringSchemaBuilder;\n}\n"],"mappings":";;;AAwLA,MAAM,6BAA6B;AACnC,MAAM,6BAA6B;AACnC,MAAM,4BAA4B;AAGlC,MAAM,qBAAqB,+BAA+B,MAAM;AAEhE,SAAgB,sBAAsB;CAClC,MAAM,SAA8B,CAAC;CACrC,MAAM,cAAc,mBAAmB,MAAM;CAC7C,OAAO,IAAI,MACP,aACA,EACI,IAAI,QAAQ,KAAK,UAAU;EACvB,IAAI,QAAQ,QACR,QAAQ,UAAkB,+BAA+B;GACrD,OAAO,OAAO;GACd,OAAO,WAAW;IACd;IACA,YAAY,UAAkB,OAAO,KAAK;GAC9C;GAEA,OAAO;EACX;EAGJ,IAAI,QAAQ,QACR,QAAQ,UAAkB,+BAA+B;GACrD,OAAO,OAAO;GACd,OAAO,WAAW;IACd;IACA,YAAY,UAAkB,OAAO,KAAK;GAC9C;GAEA,OAAO;EACX;EAGJ,IAAI,QAAQ,UACR,QAAQ,UAAe;GACnB,OAAO,YAAY,OAAO,YAAY;GACtC,OAAO;EACX;EAGJ,IAAI,QAAQ,SACR,QAAQ,OAAe,YAAqB;GACxC,OAAO,QAAQ,YAAY,KAAA,IACrB,QACA,CACE,OACA,OACJ;GAEJ,OAAO;EACX;EAGJ,IAAI,QAAQ,OACR,QAAQ,UAAkB,8BAA8B;GACpD,OAAO,WAAW;IACd;IACA,YAAY,UAAkB,IAAI,SAAS,KAAK;GACpD;GAEA,OAAO;EACX;EAGJ,OAAO,QAAQ,IAAI,QAAQ,KAAK,QAAQ;CAC5C,EACJ,CACJ;AACJ"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IndexDirection, IndexOptions, Schema, Types } from "mongoose";
|
|
2
|
+
import { Merge } from "type-fest";
|
|
3
|
+
//#region src/schema-builders/uuid.d.ts
|
|
4
|
+
type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<UUIDSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
5
|
+
interface BaseProps {
|
|
6
|
+
type: typeof Schema.Types.UUID;
|
|
7
|
+
}
|
|
8
|
+
export interface UUIDSchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFields extends string = never> {
|
|
9
|
+
default: <T extends ((this: any, doc: any) => null | string | Types.UUID | undefined) | null | string | Types.UUID | undefined>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
10
|
+
default: T;
|
|
11
|
+
}>, ExtraOmitFields>;
|
|
12
|
+
immutable: ExtendSchemaBuilder<Merge<Props, {
|
|
13
|
+
immutable: true;
|
|
14
|
+
}>, ExtraOmitFields>;
|
|
15
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
16
|
+
index: T;
|
|
17
|
+
}>, ExtraOmitFields>;
|
|
18
|
+
nonRequired: Props;
|
|
19
|
+
private: ExtendSchemaBuilder<Merge<Props, {
|
|
20
|
+
private: true;
|
|
21
|
+
}>, ExtraOmitFields>;
|
|
22
|
+
required: Merge<Props, {
|
|
23
|
+
required: true;
|
|
24
|
+
}>;
|
|
25
|
+
sparse: ExtendSchemaBuilder<Merge<Props, {
|
|
26
|
+
sparse: true;
|
|
27
|
+
}>, ExtraOmitFields>;
|
|
28
|
+
unique: ExtendSchemaBuilder<Merge<Props, {
|
|
29
|
+
unique: true;
|
|
30
|
+
}>, ExtraOmitFields>;
|
|
31
|
+
}
|
|
32
|
+
export declare const uuidSchemaBuilder: (schema?: Record<string, any>) => UUIDSchemaBuilder<BaseProps, never>;
|
|
33
|
+
//#endregion
|
|
34
|
+
//# sourceMappingURL=uuid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.d.ts","names":[],"sources":["../../src/schema-builders/uuid.ts"],"mappings":";;;KAUK,oBACD,cAAc,WACd,kCACA,KACA,kBAAkB,OAAO,kBACzB,wBAAwB;UAGlB;EACN,aAAa,OAAO,MAAM;;iBAGb,kBAAkB,cAAc,YAAY,WAAW;EACpE,UACI,YACI,WAAW,6BAA6B,MAAM,oCAGhD,MAAM,kBAGR,OAAO,MACN,oBAAoB,MAAM;IAAS,SAAS;MAAM;EAEvD,WAAW,oBAAoB,MAAM;IAAS;MAAoB;EAClE,QAAQ,oBAAoB,iBAAiB,cAAc,OAAO,MAAM,oBACpE,MAAM;IAAS,OAAO;MACtB;EAGJ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;EACzB,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;;qBAGnD,oBAAiB,SAAA,wBAAA,kBAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createBaseSchemaBuilderFactory } from "./base.js";
|
|
2
|
+
import { Schema } from "mongoose";
|
|
3
|
+
//#region src/schema-builders/uuid.ts
|
|
4
|
+
const uuidSchemaBuilder = createBaseSchemaBuilderFactory(Schema.Types.UUID);
|
|
5
|
+
//#endregion
|
|
6
|
+
export { uuidSchemaBuilder };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=uuid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.js","names":[],"sources":["../../src/schema-builders/uuid.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type {\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n UUIDSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: typeof Schema.Types.UUID;\n}\n\nexport interface UUIDSchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFields extends string = never> {\n default: <\n T extends\n | ((this: any, doc: any) => null | string | Types.UUID | undefined)\n | null\n | string\n | Types.UUID\n | undefined,\n >(\n value: T,\n ) => ExtendSchemaBuilder<Merge<Props, { default: T }>, ExtraOmitFields>;\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 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 unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\nexport const uuidSchemaBuilder = createBaseSchemaBuilderFactory<UUIDSchemaBuilder>(Schema.Types.UUID);\n"],"mappings":";;;AA+CA,MAAa,oBAAoB,+BAAkD,OAAO,MAAM,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_internals.d.ts","names":[],"sources":["../../src/types/_internals.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"_internals.d.ts","names":[],"sources":["../../src/types/_internals.ts"],"mappings":";YAAY,aAAa,KAAK,SAAS,KAAK"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Aggregate, Model, PipelineStage, Schema } from "mongoose";
|
|
2
2
|
//#region src/types/aggregate-paginate.d.ts
|
|
3
3
|
type PrePaginatePipelineStage = '__PREPAGINATE__' | PipelineStage;
|
|
4
|
-
interface AggregateCustomLabels<T = boolean | string | undefined> {
|
|
4
|
+
export interface AggregateCustomLabels<T = boolean | string | undefined> {
|
|
5
5
|
docs?: T;
|
|
6
6
|
hasNextPage?: T;
|
|
7
7
|
hasPrevPage?: T;
|
|
@@ -14,10 +14,10 @@ interface AggregateCustomLabels<T = boolean | string | undefined> {
|
|
|
14
14
|
totalDocs?: T;
|
|
15
15
|
totalPages?: T;
|
|
16
16
|
}
|
|
17
|
-
interface AggregatePaginateModel<RawDocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
|
|
17
|
+
export interface AggregatePaginateModel<RawDocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
|
|
18
18
|
aggregatePaginate: <T>(query?: Aggregate<T[]> | PrePaginatePipelineStage[], options?: AggregatePaginateOptions, callback?: (err: any, result: AggregatePaginateResult<T>) => void) => Promise<AggregatePaginateResult<T>>;
|
|
19
19
|
}
|
|
20
|
-
interface AggregatePaginateOptions {
|
|
20
|
+
export interface AggregatePaginateOptions {
|
|
21
21
|
allowDiskUse?: boolean;
|
|
22
22
|
countQuery?: object;
|
|
23
23
|
customLabels?: AggregateCustomLabels;
|
|
@@ -25,29 +25,45 @@ interface AggregatePaginateOptions {
|
|
|
25
25
|
offset?: number;
|
|
26
26
|
page?: number;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* Whether to apply pagination to the aggregation results.
|
|
29
29
|
*
|
|
30
|
-
* @
|
|
30
|
+
* @remarks
|
|
31
|
+
* If `false`, the pagination plugin adds no pagination `$skip` or `$limit` stages. Existing pipeline stages
|
|
32
|
+
* still apply.
|
|
33
|
+
*
|
|
34
|
+
* @defaultValue `true`, unless overridden by plugin-wide defaults.
|
|
31
35
|
*/
|
|
32
36
|
pagination?: boolean;
|
|
33
37
|
sort?: object | string;
|
|
34
38
|
useFacet?: boolean;
|
|
35
39
|
}
|
|
36
|
-
interface AggregatePaginateQueryPopulateOptions {
|
|
37
|
-
/**
|
|
40
|
+
export interface AggregatePaginateQueryPopulateOptions {
|
|
41
|
+
/**
|
|
42
|
+
* The query conditions used to filter populated documents.
|
|
43
|
+
*/
|
|
38
44
|
match?: any;
|
|
39
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* The model or model name used to populate the referenced documents.
|
|
47
|
+
*/
|
|
40
48
|
model?: Model<any> | string;
|
|
41
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* The query options applied when retrieving populated documents, such as sorting and limits.
|
|
51
|
+
*/
|
|
42
52
|
options?: any;
|
|
43
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* The path or space-delimited paths to populate.
|
|
55
|
+
*/
|
|
44
56
|
path: string;
|
|
45
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* The nested population options applied to the populated documents.
|
|
59
|
+
*/
|
|
46
60
|
populate?: AggregatePaginateQueryPopulateOptions | AggregatePaginateQueryPopulateOptions[];
|
|
47
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* The field projection used when retrieving populated documents.
|
|
63
|
+
*/
|
|
48
64
|
select?: any;
|
|
49
65
|
}
|
|
50
|
-
interface AggregatePaginateResult<T> {
|
|
66
|
+
export interface AggregatePaginateResult<T> {
|
|
51
67
|
[customLabel: string]: boolean | null | number | T[] | undefined;
|
|
52
68
|
docs: T[];
|
|
53
69
|
hasNextPage: boolean;
|
|
@@ -63,5 +79,5 @@ interface AggregatePaginateResult<T> {
|
|
|
63
79
|
}
|
|
64
80
|
declare function _(schema: Schema): void;
|
|
65
81
|
//#endregion
|
|
66
|
-
export {
|
|
82
|
+
export { _ as default };
|
|
67
83
|
//# sourceMappingURL=aggregate-paginate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate-paginate.d.ts","names":[],"sources":["../../src/types/aggregate-paginate.ts"],"mappings":";;KAcK,+CAA+C;
|
|
1
|
+
{"version":3,"file":"aggregate-paginate.d.ts","names":[],"sources":["../../src/types/aggregate-paginate.ts"],"mappings":";;KAcK,+CAA+C;iBAEnC,sBAAsB;EACnC,OAAO;EACP,cAAc;EACd,cAAc;EACd,QAAQ;EACR,OAAO;EACP,WAAW;EACX,OAAO;EACP,gBAAgB;EAChB,WAAW;EACX,YAAY;EACZ,aAAa;;iBAGA,uBACb,YACA,uBACA,8CACM,MAAM,YAAY,cAAc;EACtC,oBAAoB,GAChB,QAAQ,UAAU,OAAO,4BACzB,UAAU,0BACV,YAAY,UAAU,QAAQ,wBAAwB,gBACrD,QAAQ,wBAAwB;;iBAGxB;EACb;EACA;EACA,eAAe;EACf;EACA;EACA;;;;;;;;;;EAWA;EACA;EACA;;iBAGa;;;;EAIb;;;;EAKA,QAAQ;;;;EAKR;;;;EAKA;;;;EAKA,WAAW,wCAAwC;;;;EAKnD;;iBAGa,wBAAwB;GACpC,gDAAgD;EACjD,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGa,EAAE,QAAQ"}
|
package/dist/types/data.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { BaseMongooseDocType, SetFieldsToObjectId } from "./index.js";
|
|
2
2
|
import { SetFieldType } from "type-fest";
|
|
3
3
|
//#region src/types/data.d.ts
|
|
4
|
-
type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = (CreatedAtField extends true ? {
|
|
4
|
+
export type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = (CreatedAtField extends true ? {
|
|
5
5
|
createdAt: string;
|
|
6
6
|
} : unknown) & (UpdatedAtField extends true ? {
|
|
7
7
|
updatedAt: string;
|
|
8
8
|
} : unknown) & {
|
|
9
9
|
id: string;
|
|
10
10
|
};
|
|
11
|
-
type DataToBaseMongooseDocType<T, ObjectIdFields extends keyof T = never, DateFields extends Exclude<keyof T, ObjectIdFields> = never, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = BaseMongooseDocType<SetFieldsToObjectId<SetFieldType<T, DateFields, Date>, ObjectIdFields>, CreatedAtField, UpdatedAtField>;
|
|
11
|
+
export type DataToBaseMongooseDocType<T, ObjectIdFields extends keyof T = never, DateFields extends Exclude<keyof T, ObjectIdFields> = never, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = BaseMongooseDocType<SetFieldsToObjectId<SetFieldType<T, DateFields, Date>, ObjectIdFields>, CreatedAtField, UpdatedAtField>;
|
|
12
12
|
//#endregion
|
|
13
|
-
export { BaseMongooseModelData, DataToBaseMongooseDocType };
|
|
14
13
|
//# sourceMappingURL=data.d.ts.map
|
package/dist/types/data.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","names":[],"sources":["../../src/types/data.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"data.d.ts","names":[],"sources":["../../src/types/data.ts"],"mappings":";;;YAOY,sBAAsB,uCAAuC,0CACpE;EAAgC;gBAChC;EAAgC;;EAC/B;;YAEM,0BACR,GACA,6BAA6B,WAC7B,mBAAmB,cAAc,GAAG,yBACpC,uCACA,yCACA,oBACA,oBAAoB,aAAa,GAAG,YAAY,OAAO,iBACvD,gBACA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import { AggregatePaginateModel } from "./aggregate-paginate.js";
|
|
2
2
|
import { PaginateModel } from "./paginate.js";
|
|
3
|
-
import {
|
|
3
|
+
import { HydratedDocument, QueryWithHelpers, Types } from "mongoose";
|
|
4
4
|
import { SetFieldType } from "type-fest";
|
|
5
5
|
//#region src/types/index.d.ts
|
|
6
|
-
type BaseMongooseDocType<T, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = (CreatedAtField extends true ? {
|
|
6
|
+
export type BaseMongooseDocType<T, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = (CreatedAtField extends true ? {
|
|
7
7
|
createdAt: Date;
|
|
8
8
|
} : unknown) & Omit<T, 'createdAt' | 'id' | 'updatedAt'> & (UpdatedAtField extends true ? {
|
|
9
9
|
updatedAt: Date;
|
|
10
10
|
} : unknown);
|
|
11
|
-
type BaseMongoosePaginateModel<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = AggregatePaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> & BaseMongooseModelStatics<RawDocType, InstanceMethodsAndOverrides, QueryHelpers> & PaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides>;
|
|
12
|
-
type ExceptMongooseTimestampAndOtherFields<T, K extends keyof T> = Omit<T, 'createdAt' | 'updatedAt' | K>;
|
|
13
|
-
type MongooseDocumentOrObjectId<D> = D | string | Types.ObjectId;
|
|
14
|
-
type MongooseFindOneReturnType<RawDocType, DocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> = QueryWithHelpers<DocType | null, DocType, QueryHelpers, RawDocType, 'findOne', InstanceMethodsAndOverrides>;
|
|
15
|
-
type MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = HydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>;
|
|
16
|
-
type OmitMongooseTimestampAndOtherFields<T, K extends number | string | symbol = never> = Omit<T, 'createdAt' | 'updatedAt' | K>;
|
|
17
|
-
type SetFieldsToObjectId<T, K extends keyof T> = SetFieldType<T, K, Types.ObjectId>;
|
|
18
|
-
interface BaseMongooseModelStatics<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> {}
|
|
19
|
-
interface MongooseConnections {
|
|
20
|
-
default?: Connection;
|
|
21
|
-
}
|
|
11
|
+
export type BaseMongoosePaginateModel<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = AggregatePaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> & BaseMongooseModelStatics<RawDocType, InstanceMethodsAndOverrides, QueryHelpers> & PaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides>;
|
|
12
|
+
export type ExceptMongooseTimestampAndOtherFields<T, K extends keyof T> = Omit<T, 'createdAt' | 'updatedAt' | K>;
|
|
13
|
+
export type MongooseDocumentOrObjectId<D> = D | string | Types.ObjectId;
|
|
14
|
+
export type MongooseFindOneReturnType<RawDocType, DocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> = QueryWithHelpers<DocType | null, DocType, QueryHelpers, RawDocType, 'findOne', InstanceMethodsAndOverrides>;
|
|
15
|
+
export type MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = HydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>;
|
|
16
|
+
export type OmitMongooseTimestampAndOtherFields<T, K extends number | string | symbol = never> = Omit<T, 'createdAt' | 'updatedAt' | K>;
|
|
17
|
+
export type SetFieldsToObjectId<T, K extends keyof T> = SetFieldType<T, K, Types.ObjectId>;
|
|
18
|
+
export interface BaseMongooseModelStatics<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> {}
|
|
22
19
|
//#endregion
|
|
23
|
-
export { BaseMongooseDocType, BaseMongooseModelStatics, BaseMongoosePaginateModel, ExceptMongooseTimestampAndOtherFields, MongooseConnections, MongooseDocumentOrObjectId, MongooseFindOneReturnType, MongooseHydratedDocument, OmitMongooseTimestampAndOtherFields, SetFieldsToObjectId };
|
|
24
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"mappings":";;;;;YAUY,oBAAoB,GAAG,uCAAuC,0CACrE;EAAgC,WAAW;eAC5C,KAAK,wCACJ;EAAgC,WAAW;;YAEpC,0BAA0B,YAAY,sCAAsC,yBACpF,uBAAuB,YAAY,cAAc,+BACjD,yBAAyB,YAAY,6BAA6B,gBAClE,cAAc,YAAY,cAAc;YAEhC,sCAAsC,GAAG,gBAAgB,KAAK,KAAK,+BAA+B;YAClG,2BAA2B,KAAK,aAAa,MAAM;YACnD,0BACR,YACA,SACA,uBACA,wCACA,iBACI,gBACA,SACA,cACA,uBAEA;YAGI,yBACR,SACA,sCACA,yBACA,iBACA,SACA,6BACA;YAGQ,oCAAoC,GAAG,8CAA8C,KAC7F,+BAC4B;YAGpB,oBAAoB,GAAG,gBAAgB,KAAK,aAAa,GAAG,GAAG,MAAM;iBAIhE,yBAAyB,YAAY,sCAAsC"}
|
package/dist/types/options.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { MongooseNormalizePluginOptions } from "../plugins/normalize.js";
|
|
2
2
|
import { BaseMongoosePaginateModel } from "./index.js";
|
|
3
|
-
import { Connection, Schema, SchemaTimestampsConfig } from "mongoose";
|
|
3
|
+
import { ConnectOptions, Connection, Schema, SchemaTimestampsConfig } from "mongoose";
|
|
4
4
|
//#region src/types/options.d.ts
|
|
5
|
-
interface BuildMongooseModelOptions {
|
|
5
|
+
export interface BuildMongooseModelOptions {
|
|
6
6
|
connection?: Connection;
|
|
7
7
|
enableNormalizePlugin?: boolean;
|
|
8
8
|
normalizePluginOptions?: MongooseNormalizePluginOptions;
|
|
9
9
|
normalizePluginRecursive?: boolean;
|
|
10
10
|
timestamps?: boolean | SchemaTimestampsConfig;
|
|
11
11
|
}
|
|
12
|
-
interface CustomMongooseOptions {
|
|
12
|
+
export interface CustomMongooseOptions {
|
|
13
13
|
beforeModelBuild?: <DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>) => void;
|
|
14
|
+
defaultConnectionOptions?: ConnectOptions;
|
|
14
15
|
}
|
|
15
16
|
//#endregion
|
|
16
|
-
export { BuildMongooseModelOptions, CustomMongooseOptions };
|
|
17
17
|
//# sourceMappingURL=options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","names":[],"sources":["../../src/types/options.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"options.d.ts","names":[],"sources":["../../src/types/options.ts"],"mappings":";;;;iBAWiB;EACb,aAAa;EACb;EACA,yBAAyB;EACzB;EACA,uBAAuB;;iBAGV;EACb,oBACI,SACA,cAAc,0BAA0B,SAAS,6BAA6B,eAC9E,sCACA,uBAEA,QAAQ,OACJ,SACA,OACA,6BACA;EAIR,2BAA2B"}
|
package/dist/types/paginate.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { HydratedDocument, Model, PopulateOptions, QueryFilter, QueryOptions, Schema, mongo } from "mongoose";
|
|
2
2
|
//#region src/types/paginate.d.ts
|
|
3
|
-
type PaginateDocument<T, TMethods, TQueryHelpers, O extends PaginateOptions = object> = O['lean'] extends true ? PaginateDocumentLeanResult<T, O> : HydratedDocument<T, TMethods, TQueryHelpers>;
|
|
3
|
+
export type PaginateDocument<T, TMethods, TQueryHelpers, O extends PaginateOptions = object> = O['lean'] extends true ? PaginateDocumentLeanResult<T, O> : HydratedDocument<T, TMethods, TQueryHelpers>;
|
|
4
4
|
type PaginateDocumentLeanResult<T, O extends PaginateOptions> = O['leanWithId'] extends true ? T & {
|
|
5
5
|
id: string;
|
|
6
6
|
} : O['leanWithVirtuals'] extends true ? T & {
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
} : T;
|
|
9
|
-
interface PaginateCustomLabels<T = boolean | string | undefined> {
|
|
9
|
+
export interface PaginateCustomLabels<T = boolean | string | undefined> {
|
|
10
10
|
docs?: T;
|
|
11
11
|
hasNextPage?: T;
|
|
12
12
|
hasPrevPage?: T;
|
|
@@ -19,14 +19,14 @@ interface PaginateCustomLabels<T = boolean | string | undefined> {
|
|
|
19
19
|
totalDocs?: T;
|
|
20
20
|
totalPages?: T;
|
|
21
21
|
}
|
|
22
|
-
interface PaginateModel<RawDocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
|
|
22
|
+
export interface PaginateModel<RawDocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
|
|
23
23
|
paginate: {
|
|
24
24
|
<O extends PaginateOptions>(query?: QueryFilter<RawDocType>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<RawDocType, InstanceMethodsAndOverrides, QueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<RawDocType, InstanceMethodsAndOverrides, QueryHelpers, O>>>;
|
|
25
25
|
<UserType = RawDocType, O extends PaginateOptions = PaginateOptions>(query?: QueryFilter<RawDocType>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, InstanceMethodsAndOverrides, QueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<UserType, InstanceMethodsAndOverrides, QueryHelpers, O>>>;
|
|
26
26
|
<UserType = RawDocType>(query?: QueryFilter<RawDocType>, options?: PaginateOptions, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, InstanceMethodsAndOverrides, QueryHelpers, PaginateOptions>>) => void): Promise<PaginateResult<PaginateDocument<UserType, InstanceMethodsAndOverrides, QueryHelpers, PaginateOptions>>>;
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
interface PaginateOptions {
|
|
29
|
+
export interface PaginateOptions {
|
|
30
30
|
allowDiskUse?: boolean;
|
|
31
31
|
collation?: mongo.CollationOptions;
|
|
32
32
|
customLabels?: PaginateCustomLabels;
|
|
@@ -39,9 +39,13 @@ interface PaginateOptions {
|
|
|
39
39
|
options?: QueryOptions;
|
|
40
40
|
page?: number;
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Whether to apply pagination to the query results.
|
|
43
43
|
*
|
|
44
|
-
* @
|
|
44
|
+
* @remarks
|
|
45
|
+
* If `false`, the pagination plugin does not apply its page-based `skip` or `limit`. Explicit query options
|
|
46
|
+
* and other query conditions still apply.
|
|
47
|
+
*
|
|
48
|
+
* @defaultValue `true`, unless overridden by plugin-wide defaults.
|
|
45
49
|
*/
|
|
46
50
|
pagination?: boolean;
|
|
47
51
|
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
@@ -52,11 +56,11 @@ interface PaginateOptions {
|
|
|
52
56
|
useCustomCountFn?: () => Promise<number>;
|
|
53
57
|
useEstimatedCount?: boolean;
|
|
54
58
|
}
|
|
55
|
-
interface PaginateReadOptions {
|
|
59
|
+
export interface PaginateReadOptions {
|
|
56
60
|
pref: string;
|
|
57
61
|
tags?: any[];
|
|
58
62
|
}
|
|
59
|
-
interface PaginateResult<T> {
|
|
63
|
+
export interface PaginateResult<T> {
|
|
60
64
|
[customLabel: string]: boolean | null | number | T[] | undefined;
|
|
61
65
|
docs: T[];
|
|
62
66
|
hasNextPage: boolean;
|
|
@@ -71,12 +75,12 @@ interface PaginateResult<T> {
|
|
|
71
75
|
totalDocs: number;
|
|
72
76
|
totalPages: number;
|
|
73
77
|
}
|
|
74
|
-
interface SubDocumentPagingOptions {
|
|
78
|
+
export interface SubDocumentPagingOptions {
|
|
75
79
|
limit?: number;
|
|
76
80
|
page?: number;
|
|
77
81
|
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
78
82
|
}
|
|
79
|
-
interface SubPaginateOptions {
|
|
83
|
+
export interface SubPaginateOptions {
|
|
80
84
|
pagination?: boolean;
|
|
81
85
|
pagingOptions?: SubDocumentPagingOptions;
|
|
82
86
|
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
@@ -94,5 +98,5 @@ declare module 'mongoose' {
|
|
|
94
98
|
}
|
|
95
99
|
declare function _(schema: Schema): void;
|
|
96
100
|
//#endregion
|
|
97
|
-
export {
|
|
101
|
+
export { _ as default };
|
|
98
102
|
//# sourceMappingURL=paginate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.d.ts","names":[],"sources":["../../src/types/paginate.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"paginate.d.ts","names":[],"sources":["../../src/types/paginate.ts"],"mappings":";;YAUY,iBACR,GACA,UACA,eACA,UAAU,4BACV,yBACE,2BAA2B,GAAG,KAC9B,iBAAiB,GAAG,UAAU;KAE/B,2BAA2B,GAAG,UAAU,mBACzC,+BACM;EAAM;IACN,qCACI;GAAO;IACP;iBAEG,qBAAqB;EAClC,OAAO;EACP,cAAc;EACd,cAAc;EACd,QAAQ;EACR,OAAO;EACP,WAAW;EACX,OAAO;EACP,gBAAgB;EAChB,WAAW;EACX,YAAY;EACZ,aAAa;;iBAGA,cAAc,YAAY,uBAAuB,8CAA8C,MAC5G,YACA,cACA;EAEA;KACK,UAAU,iBACP,QAAQ,YAAY,aACpB,UAAU,GACV,YACI,UACA,QAAQ,eAAe,iBAAiB,YAAY,6BAA6B,cAAc,eAEpG,QAAQ,eAAe,iBAAiB,YAAY,6BAA6B,cAAc;KAEjG,WAAW,YAAY,UAAU,kBAAkB,iBAChD,QAAQ,YAAY,aACpB,UAAU,GACV,YACI,UACA,QAAQ,eAAe,iBAAiB,UAAU,6BAA6B,cAAc,eAElG,QAAQ,eAAe,iBAAiB,UAAU,6BAA6B,cAAc;KAE/F,WAAW,YACR,QAAQ,YAAY,aACpB,UAAU,iBACV,YACI,UACA,QAAQ,eACJ,iBAAiB,UAAU,6BAA6B,cAAc,6BAG/E,QACC,eAAe,iBAAiB,UAAU,6BAA6B,cAAc;;;iBAKhF;EACb;EACA,YAAY,MAAM;EAClB,eAAe;EACf;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV;;;;;;;;;;EAWA;EACA,WAAW,kBAAkB;EAC7B;EACA,OAAO;EACP;EACA;EACA,yBAAyB;EACzB;;iBAGa;EACb;EACA;;iBAGa,eAAe;GAC3B,gDAAgD;EACjD,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGa;EACb;EACA;EACA,WAAW,kBAAkB;;iBAGhB;EACb;EACA,gBAAgB;EAChB,WAAW,kBAAkB;EAC7B,OAAO;EACP;;;YAKU,MACN,YACA,SACA,WAAW,sBACX,aAAa,SACb,mBACA,mBAAmB;IAEnB;OACK,UAAU,iBAAiB,UAAU,IAAI,QACtC,eAAe,iBAAiB,YAAY,kBAAkB,UAAU;OAG3E,WAAW,YAAY,UAAU,kBAAkB,iBAAiB,UAAU,IAAI,QAC/E,eAAe,iBAAiB,UAAU,kBAAkB,UAAU;OAGzE,WAAW,YAAY,UAAU,kBAAkB,QAChD,eAAe,iBAAiB,UAAU,kBAAkB,UAAU;;;;iBAMrE,EAAE,QAAQ"}
|