@kikiutils/mongoose 4.0.1 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/_internals.js +6 -0
- package/dist/_internals.js.map +1 -0
- package/dist/constants.d.ts +7 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +13 -0
- package/dist/constants.js.map +1 -0
- package/dist/options.d.ts +8 -4
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +17 -0
- package/dist/options.js.map +1 -0
- package/dist/plugins/normalize.d.ts +20 -16
- package/dist/plugins/normalize.d.ts.map +1 -1
- package/dist/plugins/normalize.js +47 -0
- package/dist/plugins/normalize.js.map +1 -0
- package/dist/schema-builders/base.d.ts +6 -3
- package/dist/schema-builders/base.d.ts.map +1 -1
- package/dist/schema-builders/base.js +34 -0
- package/dist/schema-builders/base.js.map +1 -0
- package/dist/schema-builders/boolean.d.ts +30 -26
- package/dist/schema-builders/boolean.d.ts.map +1 -1
- package/dist/schema-builders/boolean.js +8 -0
- package/dist/schema-builders/boolean.js.map +1 -0
- package/dist/schema-builders/date.d.ts +47 -44
- package/dist/schema-builders/date.d.ts.map +1 -1
- package/dist/schema-builders/date.js +8 -0
- package/dist/schema-builders/date.js.map +1 -0
- package/dist/schema-builders/decimal128.d.ts +66 -64
- package/dist/schema-builders/decimal128.d.ts.map +1 -1
- package/dist/schema-builders/decimal128.js +27 -0
- package/dist/schema-builders/decimal128.js.map +1 -0
- package/dist/schema-builders/index.d.ts +8 -15
- package/dist/schema-builders/index.js +9 -0
- package/dist/schema-builders/number.d.ts +47 -44
- package/dist/schema-builders/number.d.ts.map +1 -1
- package/dist/schema-builders/number.js +8 -0
- package/dist/schema-builders/number.js.map +1 -0
- package/dist/schema-builders/object-id.d.ts +41 -39
- package/dist/schema-builders/object-id.d.ts.map +1 -1
- package/dist/schema-builders/object-id.js +9 -0
- package/dist/schema-builders/object-id.js.map +1 -0
- package/dist/schema-builders/ref.d.ts +42 -40
- package/dist/schema-builders/ref.d.ts.map +1 -1
- package/dist/schema-builders/ref.js +12 -0
- package/dist/schema-builders/ref.js.map +1 -0
- package/dist/schema-builders/string.d.ts +95 -92
- package/dist/schema-builders/string.d.ts.map +1 -1
- package/dist/schema-builders/string.js +38 -0
- package/dist/schema-builders/string.js.map +1 -0
- package/dist/types/aggregate-paginate.d.ts +68 -64
- package/dist/types/aggregate-paginate.d.ts.map +1 -1
- package/dist/types/aggregate-paginate.js +1 -0
- package/dist/types/data.d.ts +46 -43
- package/dist/types/data.d.ts.map +1 -1
- package/dist/types/data.js +1 -0
- package/dist/types/index.d.ts +80 -76
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/options.d.ts +44 -40
- package/dist/types/options.d.ts.map +1 -1
- package/dist/types/options.js +1 -0
- package/dist/types/paginate.d.ts +110 -106
- package/dist/types/paginate.d.ts.map +1 -1
- package/dist/types/paginate.js +1 -0
- package/dist/types/utils.d.ts +5 -2
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/utils.js +1 -0
- package/dist/utils.d.ts +12 -9
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +98 -0
- package/dist/utils.js.map +1 -0
- package/package.json +33 -31
- package/src/options.ts +2 -2
- package/src/plugins/normalize.ts +16 -10
- package/src/schema-builders/decimal128.ts +1 -1
- package/src/schema-builders/ref.ts +1 -1
- package/src/schema-builders/string.ts +1 -1
- package/src/types/aggregate-paginate.ts +2 -0
- package/src/types/index.ts +2 -2
- package/src/types/paginate.ts +2 -0
- package/src/utils.ts +4 -4
- package/dist/_internals.cjs +0 -6
- package/dist/_internals.cjs.map +0 -1
- package/dist/_internals.d.ts +0 -3
- package/dist/_internals.d.ts.map +0 -1
- package/dist/_internals.mjs +0 -4
- package/dist/_internals.mjs.map +0 -1
- package/dist/constants.cjs +0 -13
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.mjs +0 -11
- package/dist/constants.mjs.map +0 -1
- package/dist/options.cjs +0 -17
- package/dist/options.cjs.map +0 -1
- package/dist/options.mjs +0 -15
- package/dist/options.mjs.map +0 -1
- package/dist/plugins/normalize.cjs +0 -64
- package/dist/plugins/normalize.cjs.map +0 -1
- package/dist/plugins/normalize.mjs +0 -56
- package/dist/plugins/normalize.mjs.map +0 -1
- package/dist/schema-builders/base.cjs +0 -43
- package/dist/schema-builders/base.cjs.map +0 -1
- package/dist/schema-builders/base.mjs +0 -41
- package/dist/schema-builders/base.mjs.map +0 -1
- package/dist/schema-builders/boolean.cjs +0 -8
- package/dist/schema-builders/boolean.cjs.map +0 -1
- package/dist/schema-builders/boolean.mjs +0 -6
- package/dist/schema-builders/boolean.mjs.map +0 -1
- package/dist/schema-builders/date.cjs +0 -8
- package/dist/schema-builders/date.cjs.map +0 -1
- package/dist/schema-builders/date.mjs +0 -6
- package/dist/schema-builders/date.mjs.map +0 -1
- package/dist/schema-builders/decimal128.cjs +0 -32
- package/dist/schema-builders/decimal128.cjs.map +0 -1
- package/dist/schema-builders/decimal128.mjs +0 -30
- package/dist/schema-builders/decimal128.mjs.map +0 -1
- package/dist/schema-builders/index.cjs +0 -27
- package/dist/schema-builders/index.cjs.map +0 -1
- package/dist/schema-builders/index.d.ts.map +0 -1
- package/dist/schema-builders/index.mjs +0 -8
- package/dist/schema-builders/index.mjs.map +0 -1
- package/dist/schema-builders/number.cjs +0 -8
- package/dist/schema-builders/number.cjs.map +0 -1
- package/dist/schema-builders/number.mjs +0 -6
- package/dist/schema-builders/number.mjs.map +0 -1
- package/dist/schema-builders/object-id.cjs +0 -9
- package/dist/schema-builders/object-id.cjs.map +0 -1
- package/dist/schema-builders/object-id.mjs +0 -7
- package/dist/schema-builders/object-id.mjs.map +0 -1
- package/dist/schema-builders/ref.cjs +0 -12
- package/dist/schema-builders/ref.cjs.map +0 -1
- package/dist/schema-builders/ref.mjs +0 -10
- package/dist/schema-builders/ref.mjs.map +0 -1
- package/dist/schema-builders/string.cjs +0 -46
- package/dist/schema-builders/string.cjs.map +0 -1
- package/dist/schema-builders/string.mjs +0 -44
- package/dist/schema-builders/string.mjs.map +0 -1
- package/dist/types/aggregate-paginate.cjs +0 -14
- package/dist/types/aggregate-paginate.cjs.map +0 -1
- package/dist/types/aggregate-paginate.mjs +0 -10
- package/dist/types/aggregate-paginate.mjs.map +0 -1
- package/dist/types/data.cjs +0 -3
- package/dist/types/data.cjs.map +0 -1
- package/dist/types/data.mjs +0 -2
- package/dist/types/data.mjs.map +0 -1
- package/dist/types/index.cjs +0 -3
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.mjs +0 -2
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/options.cjs +0 -3
- package/dist/types/options.cjs.map +0 -1
- package/dist/types/options.mjs +0 -2
- package/dist/types/options.mjs.map +0 -1
- package/dist/types/paginate.cjs +0 -8
- package/dist/types/paginate.cjs.map +0 -1
- package/dist/types/paginate.mjs +0 -4
- package/dist/types/paginate.mjs.map +0 -1
- package/dist/types/utils.cjs +0 -3
- package/dist/types/utils.cjs.map +0 -1
- package/dist/types/utils.mjs +0 -2
- package/dist/types/utils.mjs.map +0 -1
- package/dist/utils.cjs +0 -117
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.mjs +0 -106
- package/dist/utils.mjs.map +0 -1
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const node_net = require('node:net');
|
|
4
|
-
const base = require('./base.cjs');
|
|
5
|
-
|
|
6
|
-
const baseBuilderFactory = base.createBaseSchemaBuilderFactory(String);
|
|
7
|
-
const defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`';
|
|
8
|
-
const defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`';
|
|
9
|
-
function stringSchemaBuilder() {
|
|
10
|
-
const schema = {};
|
|
11
|
-
const baseBuilder = baseBuilderFactory(schema);
|
|
12
|
-
return new Proxy(baseBuilder, {
|
|
13
|
-
get(target, key, receiver) {
|
|
14
|
-
if (key === 'ipv4') {
|
|
15
|
-
return (message = defaultIpv4ValidateMessage) => {
|
|
16
|
-
schema.trim = true;
|
|
17
|
-
schema.validate = {
|
|
18
|
-
message,
|
|
19
|
-
validator: (value) => node_net.isIPv4(value),
|
|
20
|
-
};
|
|
21
|
-
return receiver;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
if (key === 'ipv6') {
|
|
25
|
-
return (message = defaultIpv6ValidateMessage) => {
|
|
26
|
-
schema.trim = true;
|
|
27
|
-
schema.validate = {
|
|
28
|
-
message,
|
|
29
|
-
validator: (value) => node_net.isIPv6(value),
|
|
30
|
-
};
|
|
31
|
-
return receiver;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (key === 'length') {
|
|
35
|
-
return (value) => {
|
|
36
|
-
schema.maxlength = schema.minlength = value;
|
|
37
|
-
return receiver;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
return Reflect.get(target, key, receiver);
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
exports.stringSchemaBuilder = stringSchemaBuilder;
|
|
46
|
-
//# sourceMappingURL=string.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"string.cjs","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/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendStringSchemaBuilder<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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { minlength: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendStringSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendStringSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n text: ExtendStringSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendStringSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendStringSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendStringSchemaBuilder<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"],"names":["createBaseSchemaBuilderFactory","isIPv4","isIPv6"],"mappings":";;;;;AAyIA,MAAM,kBAAkB,GAAGA,mCAA8B,CAAC,MAAM,CAAC;AACjE,MAAM,0BAA0B,GAAG,yDAAyD;AAC5F,MAAM,0BAA0B,GAAG,yDAAyD;SAE5E,mBAAmB,GAAA;IAC/B,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,OAAO,IAAI,KAAK,CACZ,WAAW,EACX;AACI,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACrB,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAKC,eAAM,CAAC,KAAK,CAAC;qBAC9C;AAED,oBAAA,OAAO,QAAQ;AACnB,gBAAA,CAAC;YACL;AAEA,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAKC,eAAM,CAAC,KAAK,CAAC;qBAC9C;AAED,oBAAA,OAAO,QAAQ;AACnB,gBAAA,CAAC;YACL;AAEA,YAAA,IAAI,GAAG,KAAK,QAAQ,EAAE;gBAClB,OAAO,CAAC,KAAU,KAAI;oBAClB,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,GAAG,KAAK;AAC3C,oBAAA,OAAO,QAAQ;AACnB,gBAAA,CAAC;YACL;YAEA,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;QAC7C,CAAC;AACJ,KAAA,CACmB;AAC5B;;;;"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { isIPv4, isIPv6 } from 'node:net';
|
|
2
|
-
import { createBaseSchemaBuilderFactory } from './base.mjs';
|
|
3
|
-
|
|
4
|
-
const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
|
|
5
|
-
const defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`';
|
|
6
|
-
const defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`';
|
|
7
|
-
function stringSchemaBuilder() {
|
|
8
|
-
const schema = {};
|
|
9
|
-
const baseBuilder = baseBuilderFactory(schema);
|
|
10
|
-
return new Proxy(baseBuilder, {
|
|
11
|
-
get(target, key, receiver) {
|
|
12
|
-
if (key === 'ipv4') {
|
|
13
|
-
return (message = defaultIpv4ValidateMessage) => {
|
|
14
|
-
schema.trim = true;
|
|
15
|
-
schema.validate = {
|
|
16
|
-
message,
|
|
17
|
-
validator: (value) => isIPv4(value),
|
|
18
|
-
};
|
|
19
|
-
return receiver;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
if (key === 'ipv6') {
|
|
23
|
-
return (message = defaultIpv6ValidateMessage) => {
|
|
24
|
-
schema.trim = true;
|
|
25
|
-
schema.validate = {
|
|
26
|
-
message,
|
|
27
|
-
validator: (value) => isIPv6(value),
|
|
28
|
-
};
|
|
29
|
-
return receiver;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (key === 'length') {
|
|
33
|
-
return (value) => {
|
|
34
|
-
schema.maxlength = schema.minlength = value;
|
|
35
|
-
return receiver;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
return Reflect.get(target, key, receiver);
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { stringSchemaBuilder };
|
|
44
|
-
//# sourceMappingURL=string.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"string.mjs","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/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendStringSchemaBuilder<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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { minlength: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendStringSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendStringSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n text: ExtendStringSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendStringSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendStringSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendStringSchemaBuilder<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"],"names":[],"mappings":";;;AAyIA,MAAM,kBAAkB,GAAG,8BAA8B,CAAC,MAAM,CAAC;AACjE,MAAM,0BAA0B,GAAG,yDAAyD;AAC5F,MAAM,0BAA0B,GAAG,yDAAyD;SAE5E,mBAAmB,GAAA;IAC/B,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,OAAO,IAAI,KAAK,CACZ,WAAW,EACX;AACI,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACrB,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAK,MAAM,CAAC,KAAK,CAAC;qBAC9C;AAED,oBAAA,OAAO,QAAQ;AACnB,gBAAA,CAAC;YACL;AAEA,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAK,MAAM,CAAC,KAAK,CAAC;qBAC9C;AAED,oBAAA,OAAO,QAAQ;AACnB,gBAAA,CAAC;YACL;AAEA,YAAA,IAAI,GAAG,KAAK,QAAQ,EAAE;gBAClB,OAAO,CAAC,KAAU,KAAI;oBAClB,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,GAAG,KAAK;AAC3C,oBAAA,OAAO,QAAQ;AACnB,gBAAA,CAAC;YACL;YAEA,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;QAC7C,CAAC;AACJ,KAAA,CACmB;AAC5B;;;;"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
//
|
|
6
|
-
// Based on type declarations for mongoose-paginate-v2 1.3.
|
|
7
|
-
//
|
|
8
|
-
// Thanks to knyuwork <https://github.com/knyuwork>
|
|
9
|
-
// and LiRen Tu <https://github.com/tuliren> for their contribution
|
|
10
|
-
// Used with mongoose-paginate, redefined and renamed here to avoid conflicts.
|
|
11
|
-
const mongooseAggregatePaginate$1 = mongooseAggregatePaginate;
|
|
12
|
-
|
|
13
|
-
exports.default = mongooseAggregatePaginate$1;
|
|
14
|
-
//# sourceMappingURL=aggregate-paginate.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate-paginate.cjs","sources":["../../src/types/aggregate-paginate.ts"],"sourcesContent":["//\n// Based on type declarations for mongoose-paginate-v2 1.3.\n//\n// Thanks to knyuwork <https://github.com/knyuwork>\n// and LiRen Tu <https://github.com/tuliren> for their contribution\n// Used with mongoose-paginate, redefined and renamed here to avoid conflicts.\n\nimport type {\n AggregatePaginateOptions,\n Schema,\n} from 'mongoose';\n\ndeclare module 'mongoose' {\n type PrePaginatePipelineStage = '__PREPAGINATE__' | PipelineStage;\n\n interface AggregateCustomLabels<T = boolean | string | undefined> {\n docs?: T;\n hasNextPage?: T;\n hasPrevPage?: T;\n limit?: T;\n meta?: T;\n nextPage?: T;\n page?: T;\n pagingCounter?: T;\n prevPage?: T;\n totalDocs?: T;\n totalPages?: T;\n }\n\n interface AggregatePaginateModel<\n RawDocType,\n QueryHelpers = object,\n InstanceMethodsAndOverrides = object,\n > extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {\n aggregatePaginate: <T>(\n query?: Aggregate<T[]> | PrePaginatePipelineStage[],\n options?: AggregatePaginateOptions,\n callback?: (err: any, result: AggregatePaginateResult<T>) => void,\n ) => Promise<AggregatePaginateResult<T>>;\n }\n\n interface AggregatePaginateOptions {\n allowDiskUse?: boolean;\n countQuery?: object;\n customLabels?: AggregateCustomLabels;\n limit?: number;\n offset?: number;\n page?: number;\n\n /**\n * If pagination is set to `false`, it will return all docs without adding limit condition.\n *\n * @default true\n */\n pagination?: boolean;\n sort?: object | string;\n useFacet?: boolean;\n }\n\n interface AggregatePaginateQueryPopulateOptions {\n /** optional query conditions to match */\n match?: any;\n /** optional model to use for population */\n model?: Model<any> | string;\n /** optional query options like sort, limit, etc */\n options?: any;\n /** space delimited path(s) to populate */\n path: string;\n /** deep populate */\n populate?: AggregatePaginateQueryPopulateOptions | AggregatePaginateQueryPopulateOptions[];\n /** optional fields to select */\n select?: any;\n }\n\n interface AggregatePaginateResult<T> {\n [customLabel: string]: boolean | null | number | T[] | undefined;\n docs: T[];\n hasNextPage: boolean;\n hasPrevPage: boolean;\n limit: number;\n meta?: any;\n nextPage?: null | number;\n page?: number;\n pagingCounter: number;\n prevPage?: null | number;\n totalDocs: number;\n totalPages: number;\n }\n}\n\ndeclare function mongooseAggregatePaginate(schema: Schema): void;\n\n// eslint-disable-next-line ts/no-namespace\ndeclare namespace mongooseAggregatePaginate {\n const PREPAGINATION_PLACEHOLDER: string;\n}\n\n// eslint-disable-next-line ts/no-namespace\ndeclare namespace _ {\n const aggregatePaginate: { options: AggregatePaginateOptions };\n}\n\nexport default mongooseAggregatePaginate;\n"],"names":[],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAiGA,oCAAe,yBAAyB;;;;"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Based on type declarations for mongoose-paginate-v2 1.3.
|
|
3
|
-
//
|
|
4
|
-
// Thanks to knyuwork <https://github.com/knyuwork>
|
|
5
|
-
// and LiRen Tu <https://github.com/tuliren> for their contribution
|
|
6
|
-
// Used with mongoose-paginate, redefined and renamed here to avoid conflicts.
|
|
7
|
-
const mongooseAggregatePaginate$1 = mongooseAggregatePaginate;
|
|
8
|
-
|
|
9
|
-
export { mongooseAggregatePaginate$1 as default };
|
|
10
|
-
//# sourceMappingURL=aggregate-paginate.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate-paginate.mjs","sources":["../../src/types/aggregate-paginate.ts"],"sourcesContent":["//\n// Based on type declarations for mongoose-paginate-v2 1.3.\n//\n// Thanks to knyuwork <https://github.com/knyuwork>\n// and LiRen Tu <https://github.com/tuliren> for their contribution\n// Used with mongoose-paginate, redefined and renamed here to avoid conflicts.\n\nimport type {\n AggregatePaginateOptions,\n Schema,\n} from 'mongoose';\n\ndeclare module 'mongoose' {\n type PrePaginatePipelineStage = '__PREPAGINATE__' | PipelineStage;\n\n interface AggregateCustomLabels<T = boolean | string | undefined> {\n docs?: T;\n hasNextPage?: T;\n hasPrevPage?: T;\n limit?: T;\n meta?: T;\n nextPage?: T;\n page?: T;\n pagingCounter?: T;\n prevPage?: T;\n totalDocs?: T;\n totalPages?: T;\n }\n\n interface AggregatePaginateModel<\n RawDocType,\n QueryHelpers = object,\n InstanceMethodsAndOverrides = object,\n > extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {\n aggregatePaginate: <T>(\n query?: Aggregate<T[]> | PrePaginatePipelineStage[],\n options?: AggregatePaginateOptions,\n callback?: (err: any, result: AggregatePaginateResult<T>) => void,\n ) => Promise<AggregatePaginateResult<T>>;\n }\n\n interface AggregatePaginateOptions {\n allowDiskUse?: boolean;\n countQuery?: object;\n customLabels?: AggregateCustomLabels;\n limit?: number;\n offset?: number;\n page?: number;\n\n /**\n * If pagination is set to `false`, it will return all docs without adding limit condition.\n *\n * @default true\n */\n pagination?: boolean;\n sort?: object | string;\n useFacet?: boolean;\n }\n\n interface AggregatePaginateQueryPopulateOptions {\n /** optional query conditions to match */\n match?: any;\n /** optional model to use for population */\n model?: Model<any> | string;\n /** optional query options like sort, limit, etc */\n options?: any;\n /** space delimited path(s) to populate */\n path: string;\n /** deep populate */\n populate?: AggregatePaginateQueryPopulateOptions | AggregatePaginateQueryPopulateOptions[];\n /** optional fields to select */\n select?: any;\n }\n\n interface AggregatePaginateResult<T> {\n [customLabel: string]: boolean | null | number | T[] | undefined;\n docs: T[];\n hasNextPage: boolean;\n hasPrevPage: boolean;\n limit: number;\n meta?: any;\n nextPage?: null | number;\n page?: number;\n pagingCounter: number;\n prevPage?: null | number;\n totalDocs: number;\n totalPages: number;\n }\n}\n\ndeclare function mongooseAggregatePaginate(schema: Schema): void;\n\n// eslint-disable-next-line ts/no-namespace\ndeclare namespace mongooseAggregatePaginate {\n const PREPAGINATION_PLACEHOLDER: string;\n}\n\n// eslint-disable-next-line ts/no-namespace\ndeclare namespace _ {\n const aggregatePaginate: { options: AggregatePaginateOptions };\n}\n\nexport default mongooseAggregatePaginate;\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AAiGA,oCAAe,yBAAyB;;;;"}
|
package/dist/types/data.cjs
DELETED
package/dist/types/data.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/dist/types/data.mjs
DELETED
package/dist/types/data.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/types/index.cjs
DELETED
package/dist/types/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/dist/types/index.mjs
DELETED
package/dist/types/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/types/options.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/dist/types/options.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/types/paginate.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.cjs","sources":["../../src/types/paginate.ts"],"sourcesContent":["import type {\n FilterQuery,\n mongo,\n PaginateOptions,\n Schema,\n} from 'mongoose';\n\nimport type { IfElse } from './utils';\n\ndeclare module 'mongoose' {\n type PaginateDocument<\n T,\n TMethods,\n TQueryHelpers,\n O extends PaginateOptions = object,\n > = IfElse<\n O['lean'],\n IfElse<\n O['leanWithId'],\n T & { id: string },\n IfElse<\n O['leanWithVirtuals'],\n T & { [key: string]: any },\n T\n >\n >,\n HydratedDocument<T, TMethods, TQueryHelpers>\n >;\n\n interface PaginateCustomLabels<T = boolean | string | undefined> {\n docs?: T;\n hasNextPage?: T;\n hasPrevPage?: T;\n limit?: T;\n meta?: T;\n nextPage?: T;\n page?: T;\n pagingCounter?: T;\n prevPage?: T;\n totalDocs?: T;\n totalPages?: T;\n }\n\n interface PaginateModel<T, TQueryHelpers = object, TMethods = object> extends Model<T, TQueryHelpers, TMethods> {\n paginate: {\n <O extends PaginateOptions>(\n query?: FilterQuery<T>,\n options?: O,\n callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>) => void\n ): Promise<PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>>;\n\n <UserType = T, O extends PaginateOptions = PaginateOptions>(\n query?: FilterQuery<T>,\n options?: O,\n callback?: (\n err: any,\n result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>\n ) => void\n ): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>>;\n\n <UserType = T>(\n query?: FilterQuery<T>,\n options?: PaginateOptions,\n callback?: (\n err: any,\n result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>\n ) => void\n ): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>>;\n };\n }\n\n interface PaginateOptions {\n allowDiskUse?: boolean;\n collation?: mongo.CollationOptions;\n customLabels?: PaginateCustomLabels;\n forceCountFn?: boolean;\n lean?: boolean;\n leanWithId?: boolean;\n leanWithVirtuals?: boolean;\n limit?: number;\n offset?: number;\n options?: QueryOptions;\n page?: number;\n\n /**\n * If pagination is set to `false`, it will return all docs without adding limit condition.\n *\n * @default true\n */\n pagination?: boolean;\n populate?: PopulateOptions | PopulateOptions[] | string | string[];\n projection?: any;\n read?: PaginateReadOptions;\n select?: object | string;\n sort?: object | string;\n useCustomCountFn?: () => Promise<number>;\n useEstimatedCount?: boolean;\n }\n\n interface PaginateReadOptions {\n pref: string;\n tags?: any[];\n }\n\n interface PaginateResult<T> {\n [customLabel: string]: boolean | null | number | T[] | undefined;\n docs: T[];\n hasNextPage: boolean;\n hasPrevPage: boolean;\n limit: number;\n meta?: any;\n nextPage?: null | number;\n offset: number;\n page?: number;\n pagingCounter: number;\n prevPage?: null | number;\n totalDocs: number;\n totalPages: number;\n }\n\n // @ts-expect-error Ignore this error.\n interface Query<\n ResultType,\n DocType,\n THelpers = NonNullable<unknown>,\n RawDocType = DocType,\n _QueryOp = 'find',\n TInstanceMethods = Record<string, never>,\n > {\n paginate: {\n <O extends PaginateOptions>(options?: O): Promise<\n PaginateResult<PaginateDocument<RawDocType, TInstanceMethods, THelpers, O>>\n >;\n\n <UserType = ResultType, O extends PaginateOptions = PaginateOptions>(options?: O): Promise<\n PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, O>>\n >;\n\n <UserType = ResultType>(options?: PaginateOptions): Promise<\n PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, PaginateOptions>>\n >;\n };\n }\n\n interface SubDocumentPagingOptions {\n limit?: number;\n page?: number;\n populate?: PopulateOptions | PopulateOptions[] | string | string[];\n }\n\n interface SubPaginateOptions {\n pagination?: boolean;\n pagingOptions?: SubDocumentPagingOptions;\n populate?: PopulateOptions | PopulateOptions[] | string | string[];\n read?: PaginateReadOptions;\n select?: object | string;\n }\n}\n\ndeclare function _(schema: Schema): void;\n\n// eslint-disable-next-line ts/no-namespace\ndeclare namespace _ {\n const paginate: { options: PaginateOptions };\n const paginateSubDocs: { options: PaginateOptions };\n\n class PaginationParameters<T, O extends PaginateOptions> {\n constructor(request: { query?: Record<string, any> });\n get: () => [FilterQuery<T>, O];\n getOptions: () => O;\n getQuery: () => FilterQuery<T>;\n }\n}\n\nexport default _;\n"],"names":[],"mappings":";;;;AA8KA,YAAe,CAAC;;;;"}
|
package/dist/types/paginate.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.mjs","sources":["../../src/types/paginate.ts"],"sourcesContent":["import type {\n FilterQuery,\n mongo,\n PaginateOptions,\n Schema,\n} from 'mongoose';\n\nimport type { IfElse } from './utils';\n\ndeclare module 'mongoose' {\n type PaginateDocument<\n T,\n TMethods,\n TQueryHelpers,\n O extends PaginateOptions = object,\n > = IfElse<\n O['lean'],\n IfElse<\n O['leanWithId'],\n T & { id: string },\n IfElse<\n O['leanWithVirtuals'],\n T & { [key: string]: any },\n T\n >\n >,\n HydratedDocument<T, TMethods, TQueryHelpers>\n >;\n\n interface PaginateCustomLabels<T = boolean | string | undefined> {\n docs?: T;\n hasNextPage?: T;\n hasPrevPage?: T;\n limit?: T;\n meta?: T;\n nextPage?: T;\n page?: T;\n pagingCounter?: T;\n prevPage?: T;\n totalDocs?: T;\n totalPages?: T;\n }\n\n interface PaginateModel<T, TQueryHelpers = object, TMethods = object> extends Model<T, TQueryHelpers, TMethods> {\n paginate: {\n <O extends PaginateOptions>(\n query?: FilterQuery<T>,\n options?: O,\n callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>) => void\n ): Promise<PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>>;\n\n <UserType = T, O extends PaginateOptions = PaginateOptions>(\n query?: FilterQuery<T>,\n options?: O,\n callback?: (\n err: any,\n result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>\n ) => void\n ): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>>;\n\n <UserType = T>(\n query?: FilterQuery<T>,\n options?: PaginateOptions,\n callback?: (\n err: any,\n result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>\n ) => void\n ): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>>;\n };\n }\n\n interface PaginateOptions {\n allowDiskUse?: boolean;\n collation?: mongo.CollationOptions;\n customLabels?: PaginateCustomLabels;\n forceCountFn?: boolean;\n lean?: boolean;\n leanWithId?: boolean;\n leanWithVirtuals?: boolean;\n limit?: number;\n offset?: number;\n options?: QueryOptions;\n page?: number;\n\n /**\n * If pagination is set to `false`, it will return all docs without adding limit condition.\n *\n * @default true\n */\n pagination?: boolean;\n populate?: PopulateOptions | PopulateOptions[] | string | string[];\n projection?: any;\n read?: PaginateReadOptions;\n select?: object | string;\n sort?: object | string;\n useCustomCountFn?: () => Promise<number>;\n useEstimatedCount?: boolean;\n }\n\n interface PaginateReadOptions {\n pref: string;\n tags?: any[];\n }\n\n interface PaginateResult<T> {\n [customLabel: string]: boolean | null | number | T[] | undefined;\n docs: T[];\n hasNextPage: boolean;\n hasPrevPage: boolean;\n limit: number;\n meta?: any;\n nextPage?: null | number;\n offset: number;\n page?: number;\n pagingCounter: number;\n prevPage?: null | number;\n totalDocs: number;\n totalPages: number;\n }\n\n // @ts-expect-error Ignore this error.\n interface Query<\n ResultType,\n DocType,\n THelpers = NonNullable<unknown>,\n RawDocType = DocType,\n _QueryOp = 'find',\n TInstanceMethods = Record<string, never>,\n > {\n paginate: {\n <O extends PaginateOptions>(options?: O): Promise<\n PaginateResult<PaginateDocument<RawDocType, TInstanceMethods, THelpers, O>>\n >;\n\n <UserType = ResultType, O extends PaginateOptions = PaginateOptions>(options?: O): Promise<\n PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, O>>\n >;\n\n <UserType = ResultType>(options?: PaginateOptions): Promise<\n PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, PaginateOptions>>\n >;\n };\n }\n\n interface SubDocumentPagingOptions {\n limit?: number;\n page?: number;\n populate?: PopulateOptions | PopulateOptions[] | string | string[];\n }\n\n interface SubPaginateOptions {\n pagination?: boolean;\n pagingOptions?: SubDocumentPagingOptions;\n populate?: PopulateOptions | PopulateOptions[] | string | string[];\n read?: PaginateReadOptions;\n select?: object | string;\n }\n}\n\ndeclare function _(schema: Schema): void;\n\n// eslint-disable-next-line ts/no-namespace\ndeclare namespace _ {\n const paginate: { options: PaginateOptions };\n const paginateSubDocs: { options: PaginateOptions };\n\n class PaginationParameters<T, O extends PaginateOptions> {\n constructor(request: { query?: Record<string, any> });\n get: () => [FilterQuery<T>, O];\n getOptions: () => O;\n getQuery: () => FilterQuery<T>;\n }\n}\n\nexport default _;\n"],"names":[],"mappings":"AA8KA,YAAe,CAAC;;;;"}
|
package/dist/types/utils.cjs
DELETED
package/dist/types/utils.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/dist/types/utils.mjs
DELETED
package/dist/types/utils.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/utils.cjs
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const mongoose = require('mongoose');
|
|
4
|
-
const mongooseAggregatePaginate = require('mongoose-aggregate-paginate-v2');
|
|
5
|
-
const mongoosePaginate = require('mongoose-paginate-v2');
|
|
6
|
-
const _internals = require('./_internals.cjs');
|
|
7
|
-
const constants = require('./constants.cjs');
|
|
8
|
-
const normalize = require('./plugins/normalize.cjs');
|
|
9
|
-
|
|
10
|
-
const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
|
|
11
|
-
|
|
12
|
-
const mongoose__default = /*#__PURE__*/_interopDefaultCompat(mongoose);
|
|
13
|
-
const mongooseAggregatePaginate__default = /*#__PURE__*/_interopDefaultCompat(mongooseAggregatePaginate);
|
|
14
|
-
const mongoosePaginate__default = /*#__PURE__*/_interopDefaultCompat(mongoosePaginate);
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Asserts that a Mongoose update operation was successful by checking that it was acknowledged
|
|
18
|
-
* and that at least the expected number of documents were modified.
|
|
19
|
-
*
|
|
20
|
-
* This function is intended for use with `updateOne`, `updateMany`, or any update operation
|
|
21
|
-
* that returns a MongoDB `UpdateResult`.
|
|
22
|
-
*
|
|
23
|
-
* @template T - The shape of the document being updated.
|
|
24
|
-
* @param updatePromise - A promise returned from a Mongoose update operation.
|
|
25
|
-
* @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.
|
|
26
|
-
* @throws Will throw an error if:
|
|
27
|
-
* - The operation was not acknowledged by MongoDB,
|
|
28
|
-
* - Fewer documents were modified than expected.
|
|
29
|
-
*/
|
|
30
|
-
async function assertMongooseUpdateSuccess(updatePromise, expectedModifiedCount = 1) {
|
|
31
|
-
const updateResult = await updatePromise;
|
|
32
|
-
if (!updateResult.acknowledged)
|
|
33
|
-
throw new Error('Update was not acknowledged');
|
|
34
|
-
if (updateResult.modifiedCount < expectedModifiedCount) {
|
|
35
|
-
// eslint-disable-next-line style/max-len
|
|
36
|
-
throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Builds and returns a Mongoose model with specified schema and options.
|
|
41
|
-
*
|
|
42
|
-
* This function sets up a Mongoose model with optional plugins and timestamp settings.
|
|
43
|
-
* It can optionally use a specified connection or the default connection.
|
|
44
|
-
*
|
|
45
|
-
* Determine the connection to use:
|
|
46
|
-
* 1. Use the connection provided in the options, if available.
|
|
47
|
-
* 2. Otherwise, use the default connection stored in `mongooseConnections`.
|
|
48
|
-
* 3. If there's no default connection, create one using the MongoDB URI from the environment variables,
|
|
49
|
-
* or fallback to a local MongoDB instance.
|
|
50
|
-
*
|
|
51
|
-
* You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.
|
|
52
|
-
* However, ensure that this option is configured before calling {@link buildMongooseModel}.
|
|
53
|
-
*
|
|
54
|
-
* @template DocType - The type of the document.
|
|
55
|
-
* @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.
|
|
56
|
-
* @template InstanceMethodsAndOverrides - The type for instance methods and overrides.
|
|
57
|
-
* @template QueryHelpers - The type for additional query helpers.
|
|
58
|
-
*
|
|
59
|
-
* @param collection - The name of the collection.
|
|
60
|
-
* @param name - The name of the model.
|
|
61
|
-
* @param schema - The Mongoose schema to use for the model.
|
|
62
|
-
* @param options - Optional settings for building the model.
|
|
63
|
-
*
|
|
64
|
-
* @returns The created Mongoose model.
|
|
65
|
-
*/
|
|
66
|
-
function buildMongooseModel(collection, name, schema, options) {
|
|
67
|
-
if (options?.enableNormalizePlugin !== false) {
|
|
68
|
-
schema.plugin(normalize.mongooseNormalizePlugin, options?.normalizePluginOptions);
|
|
69
|
-
}
|
|
70
|
-
schema.plugin(mongooseAggregatePaginate__default);
|
|
71
|
-
schema.plugin(mongoosePaginate__default);
|
|
72
|
-
schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);
|
|
73
|
-
_internals.customMongooseOptions.beforeModelBuild?.(schema);
|
|
74
|
-
// eslint-disable-next-line style/max-len
|
|
75
|
-
const connection = options?.connection || (constants.mongooseConnections.default ||= mongoose__default.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));
|
|
76
|
-
return connection.model(name, schema, collection);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Converts a document or ObjectId to a document using the specified model.
|
|
80
|
-
*
|
|
81
|
-
* This function takes a document or ObjectId and returns the corresponding document
|
|
82
|
-
* from the database using the specified model. Optionally, specific fields can be selected.
|
|
83
|
-
*
|
|
84
|
-
* @template D - The type of the hydrated document.
|
|
85
|
-
* @template DocType - The type of the document.
|
|
86
|
-
* @template InstanceMethodsAndOverrides - The type for instance methods and overrides.
|
|
87
|
-
* @template QueryHelpers - The type for additional query helpers.
|
|
88
|
-
*
|
|
89
|
-
* @param documentOrObjectId - The document or ObjectId to convert.
|
|
90
|
-
* @param model - The Mongoose model to use for the conversion.
|
|
91
|
-
* @param selectFields - Optional fields to select from the document.
|
|
92
|
-
*
|
|
93
|
-
* @returns The corresponding document or null if not found.
|
|
94
|
-
*/
|
|
95
|
-
async function mongooseDocumentOrObjectIdToDocument(documentOrObjectId, model, selectFields) {
|
|
96
|
-
if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof mongoose.Types.ObjectId) {
|
|
97
|
-
return (await model.findById(documentOrObjectId).select(selectFields || []));
|
|
98
|
-
}
|
|
99
|
-
return documentOrObjectId;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Converts the input, which can be a MongoDB ObjectId or a string,
|
|
103
|
-
* into a 24-character hexadecimal string representation of the ObjectId.
|
|
104
|
-
*
|
|
105
|
-
* @param {string | Types.ObjectId} id - The ObjectId instance or its string representation
|
|
106
|
-
*
|
|
107
|
-
* @returns {string} The hexadecimal string representation of the ObjectId
|
|
108
|
-
*/
|
|
109
|
-
function toObjectIdHexString(id) {
|
|
110
|
-
return id instanceof mongoose.Types.ObjectId ? id.toHexString() : id;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
exports.assertMongooseUpdateSuccess = assertMongooseUpdateSuccess;
|
|
114
|
-
exports.buildMongooseModel = buildMongooseModel;
|
|
115
|
-
exports.mongooseDocumentOrObjectIdToDocument = mongooseDocumentOrObjectIdToDocument;
|
|
116
|
-
exports.toObjectIdHexString = toObjectIdHexString;
|
|
117
|
-
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sources":["../src/utils.ts"],"sourcesContent":["import mongoose, { Types } from 'mongoose';\nimport type {\n mongo,\n Schema,\n} from 'mongoose';\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';\nimport mongoosePaginate from 'mongoose-paginate-v2';\n\nimport { customMongooseOptions } from './_internals';\nimport { mongooseConnections } from './constants';\nimport type { setCustomMongooseOptions } from './options';\nimport { mongooseNormalizePlugin } from './plugins/normalize';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;\n\n/**\n * Asserts that a Mongoose update operation was successful by checking that it was acknowledged\n * and that at least the expected number of documents were modified.\n *\n * This function is intended for use with `updateOne`, `updateMany`, or any update operation\n * that returns a MongoDB `UpdateResult`.\n *\n * @template T - The shape of the document being updated.\n * @param updatePromise - A promise returned from a Mongoose update operation.\n * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.\n * @throws Will throw an error if:\n * - The operation was not acknowledged by MongoDB,\n * - Fewer documents were modified than expected.\n */\nexport async function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(\n updatePromise: Promise<mongo.UpdateResult<T>>,\n expectedModifiedCount = 1,\n) {\n const updateResult = await updatePromise;\n if (!updateResult.acknowledged) throw new Error('Update was not acknowledged');\n if (updateResult.modifiedCount < expectedModifiedCount) {\n // eslint-disable-next-line style/max-len\n throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}`);\n }\n}\n\n/**\n * Builds and returns a Mongoose model with specified schema and options.\n *\n * This function sets up a Mongoose model with optional plugins and timestamp settings.\n * It can optionally use a specified connection or the default connection.\n *\n * Determine the connection to use:\n * 1. Use the connection provided in the options, if available.\n * 2. Otherwise, use the default connection stored in `mongooseConnections`.\n * 3. If there's no default connection, create one using the MongoDB URI from the environment variables,\n * or fallback to a local MongoDB instance.\n *\n * You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.\n * However, ensure that this option is configured before calling {@link buildMongooseModel}.\n *\n * @template DocType - The type of the document.\n * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param collection - The name of the collection.\n * @param name - The name of the model.\n * @param schema - The Mongoose schema to use for the model.\n * @param options - Optional settings for building the model.\n *\n * @returns The created Mongoose model.\n */\nexport function buildMongooseModel<\n DocType,\n Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n collection: string,\n name: string,\n schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n options?: BuildMongooseModelOptions,\n) {\n if (options?.enableNormalizePlugin !== false) {\n schema.plugin(mongooseNormalizePlugin, options?.normalizePluginOptions);\n }\n\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n // eslint-disable-next-line style/max-len\n const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\n\n/**\n * Converts a document or ObjectId to a document using the specified model.\n *\n * This function takes a document or ObjectId and returns the corresponding document\n * from the database using the specified model. Optionally, specific fields can be selected.\n *\n * @template D - The type of the hydrated document.\n * @template DocType - The type of the document.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param documentOrObjectId - The document or ObjectId to convert.\n * @param model - The Mongoose model to use for the conversion.\n * @param selectFields - Optional fields to select from the document.\n *\n * @returns The corresponding document or null if not found.\n */\nexport async function mongooseDocumentOrObjectIdToDocument<\n D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n DocType,\n InstanceMethodsAndOverrides,\n QueryHelpers,\n>(\n documentOrObjectId: MongooseDocumentOrObjectId<D>,\n model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n selectFields?: string[],\n) {\n if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {\n return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n }\n\n return documentOrObjectId;\n}\n\n/**\n * Converts the input, which can be a MongoDB ObjectId or a string,\n * into a 24-character hexadecimal string representation of the ObjectId.\n *\n * @param {string | Types.ObjectId} id - The ObjectId instance or its string representation\n *\n * @returns {string} The hexadecimal string representation of the ObjectId\n */\nexport function toObjectIdHexString(id: string | Types.ObjectId) {\n return id instanceof Types.ObjectId ? id.toHexString() : id;\n}\n"],"names":["mongooseNormalizePlugin","mongooseAggregatePaginate","mongoosePaginate","customMongooseOptions","mongooseConnections","mongoose","Types"],"mappings":";;;;;;;;;;;;;;;AAgBA;;;;;;;;;;;;;AAaG;AACI,eAAe,2BAA2B,CAC7C,aAA6C,EAC7C,qBAAqB,GAAG,CAAC,EAAA;AAEzB,IAAA,MAAM,YAAY,GAAG,MAAM,aAAa;IACxC,IAAI,CAAC,YAAY,CAAC,YAAY;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC;AAC9E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAqB,EAAE;;QAEpD,MAAM,IAAI,KAAK,CAAC,CAAA,4BAAA,EAA+B,qBAAqB,CAAA,2BAAA,EAA8B,YAAY,CAAC,aAAa,CAAA,CAAE,CAAC;IACnI;AACJ;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,kBAAkB,CAM9B,UAAkB,EAClB,IAAY,EACZ,MAAyE,EACzE,OAAmC,EAAA;AAEnC,IAAA,IAAI,OAAO,EAAE,qBAAqB,KAAK,KAAK,EAAE;QAC1C,MAAM,CAAC,MAAM,CAACA,iCAAuB,EAAE,OAAO,EAAE,sBAAsB,CAAC;IAC3E;AAEA,IAAA,MAAM,CAAC,MAAM,CAACC,kCAAyB,CAAC;AACxC,IAAA,MAAM,CAAC,MAAM,CAACC,yBAAgB,CAAC;AAC/B,IAAA,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,UAAU,IAAI,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC;AACjF,IAAAC,gCAAqB,CAAC,gBAAgB,GAAG,MAAM,CAAC;;IAEhD,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,KAAKC,6BAAmB,CAAC,OAAO,KAAKC,iBAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,2BAA2B,CAAC,CAAC;IAC7J,OAAO,UAAU,CAAC,KAAK,CAA+B,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC;AACnF;AAEA;;;;;;;;;;;;;;;;AAgBG;AACI,eAAe,oCAAoC,CAMtD,kBAAiD,EACjD,KAAoF,EACpF,YAAuB,EAAA;IAEvB,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,YAAYC,cAAK,CAAC,QAAQ,EAAE;AACxF,QAAA,QAAQ,MAAM,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;IAC/E;AAEA,IAAA,OAAO,kBAAkB;AAC7B;AAEA;;;;;;;AAOG;AACG,SAAU,mBAAmB,CAAC,EAA2B,EAAA;AAC3D,IAAA,OAAO,EAAE,YAAYA,cAAK,CAAC,QAAQ,GAAG,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE;AAC/D;;;;;;;"}
|
package/dist/utils.mjs
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import mongoose, { Types } from 'mongoose';
|
|
2
|
-
import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
|
|
3
|
-
import mongoosePaginate from 'mongoose-paginate-v2';
|
|
4
|
-
import { customMongooseOptions } from './_internals.mjs';
|
|
5
|
-
import { mongooseConnections } from './constants.mjs';
|
|
6
|
-
import { mongooseNormalizePlugin } from './plugins/normalize.mjs';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Asserts that a Mongoose update operation was successful by checking that it was acknowledged
|
|
10
|
-
* and that at least the expected number of documents were modified.
|
|
11
|
-
*
|
|
12
|
-
* This function is intended for use with `updateOne`, `updateMany`, or any update operation
|
|
13
|
-
* that returns a MongoDB `UpdateResult`.
|
|
14
|
-
*
|
|
15
|
-
* @template T - The shape of the document being updated.
|
|
16
|
-
* @param updatePromise - A promise returned from a Mongoose update operation.
|
|
17
|
-
* @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.
|
|
18
|
-
* @throws Will throw an error if:
|
|
19
|
-
* - The operation was not acknowledged by MongoDB,
|
|
20
|
-
* - Fewer documents were modified than expected.
|
|
21
|
-
*/
|
|
22
|
-
async function assertMongooseUpdateSuccess(updatePromise, expectedModifiedCount = 1) {
|
|
23
|
-
const updateResult = await updatePromise;
|
|
24
|
-
if (!updateResult.acknowledged)
|
|
25
|
-
throw new Error('Update was not acknowledged');
|
|
26
|
-
if (updateResult.modifiedCount < expectedModifiedCount) {
|
|
27
|
-
// eslint-disable-next-line style/max-len
|
|
28
|
-
throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Builds and returns a Mongoose model with specified schema and options.
|
|
33
|
-
*
|
|
34
|
-
* This function sets up a Mongoose model with optional plugins and timestamp settings.
|
|
35
|
-
* It can optionally use a specified connection or the default connection.
|
|
36
|
-
*
|
|
37
|
-
* Determine the connection to use:
|
|
38
|
-
* 1. Use the connection provided in the options, if available.
|
|
39
|
-
* 2. Otherwise, use the default connection stored in `mongooseConnections`.
|
|
40
|
-
* 3. If there's no default connection, create one using the MongoDB URI from the environment variables,
|
|
41
|
-
* or fallback to a local MongoDB instance.
|
|
42
|
-
*
|
|
43
|
-
* You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.
|
|
44
|
-
* However, ensure that this option is configured before calling {@link buildMongooseModel}.
|
|
45
|
-
*
|
|
46
|
-
* @template DocType - The type of the document.
|
|
47
|
-
* @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.
|
|
48
|
-
* @template InstanceMethodsAndOverrides - The type for instance methods and overrides.
|
|
49
|
-
* @template QueryHelpers - The type for additional query helpers.
|
|
50
|
-
*
|
|
51
|
-
* @param collection - The name of the collection.
|
|
52
|
-
* @param name - The name of the model.
|
|
53
|
-
* @param schema - The Mongoose schema to use for the model.
|
|
54
|
-
* @param options - Optional settings for building the model.
|
|
55
|
-
*
|
|
56
|
-
* @returns The created Mongoose model.
|
|
57
|
-
*/
|
|
58
|
-
function buildMongooseModel(collection, name, schema, options) {
|
|
59
|
-
if (options?.enableNormalizePlugin !== false) {
|
|
60
|
-
schema.plugin(mongooseNormalizePlugin, options?.normalizePluginOptions);
|
|
61
|
-
}
|
|
62
|
-
schema.plugin(mongooseAggregatePaginate);
|
|
63
|
-
schema.plugin(mongoosePaginate);
|
|
64
|
-
schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);
|
|
65
|
-
customMongooseOptions.beforeModelBuild?.(schema);
|
|
66
|
-
// eslint-disable-next-line style/max-len
|
|
67
|
-
const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));
|
|
68
|
-
return connection.model(name, schema, collection);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Converts a document or ObjectId to a document using the specified model.
|
|
72
|
-
*
|
|
73
|
-
* This function takes a document or ObjectId and returns the corresponding document
|
|
74
|
-
* from the database using the specified model. Optionally, specific fields can be selected.
|
|
75
|
-
*
|
|
76
|
-
* @template D - The type of the hydrated document.
|
|
77
|
-
* @template DocType - The type of the document.
|
|
78
|
-
* @template InstanceMethodsAndOverrides - The type for instance methods and overrides.
|
|
79
|
-
* @template QueryHelpers - The type for additional query helpers.
|
|
80
|
-
*
|
|
81
|
-
* @param documentOrObjectId - The document or ObjectId to convert.
|
|
82
|
-
* @param model - The Mongoose model to use for the conversion.
|
|
83
|
-
* @param selectFields - Optional fields to select from the document.
|
|
84
|
-
*
|
|
85
|
-
* @returns The corresponding document or null if not found.
|
|
86
|
-
*/
|
|
87
|
-
async function mongooseDocumentOrObjectIdToDocument(documentOrObjectId, model, selectFields) {
|
|
88
|
-
if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {
|
|
89
|
-
return (await model.findById(documentOrObjectId).select(selectFields || []));
|
|
90
|
-
}
|
|
91
|
-
return documentOrObjectId;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Converts the input, which can be a MongoDB ObjectId or a string,
|
|
95
|
-
* into a 24-character hexadecimal string representation of the ObjectId.
|
|
96
|
-
*
|
|
97
|
-
* @param {string | Types.ObjectId} id - The ObjectId instance or its string representation
|
|
98
|
-
*
|
|
99
|
-
* @returns {string} The hexadecimal string representation of the ObjectId
|
|
100
|
-
*/
|
|
101
|
-
function toObjectIdHexString(id) {
|
|
102
|
-
return id instanceof Types.ObjectId ? id.toHexString() : id;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export { assertMongooseUpdateSuccess, buildMongooseModel, mongooseDocumentOrObjectIdToDocument, toObjectIdHexString };
|
|
106
|
-
//# sourceMappingURL=utils.mjs.map
|
package/dist/utils.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../src/utils.ts"],"sourcesContent":["import mongoose, { Types } from 'mongoose';\nimport type {\n mongo,\n Schema,\n} from 'mongoose';\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';\nimport mongoosePaginate from 'mongoose-paginate-v2';\n\nimport { customMongooseOptions } from './_internals';\nimport { mongooseConnections } from './constants';\nimport type { setCustomMongooseOptions } from './options';\nimport { mongooseNormalizePlugin } from './plugins/normalize';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;\n\n/**\n * Asserts that a Mongoose update operation was successful by checking that it was acknowledged\n * and that at least the expected number of documents were modified.\n *\n * This function is intended for use with `updateOne`, `updateMany`, or any update operation\n * that returns a MongoDB `UpdateResult`.\n *\n * @template T - The shape of the document being updated.\n * @param updatePromise - A promise returned from a Mongoose update operation.\n * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.\n * @throws Will throw an error if:\n * - The operation was not acknowledged by MongoDB,\n * - Fewer documents were modified than expected.\n */\nexport async function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(\n updatePromise: Promise<mongo.UpdateResult<T>>,\n expectedModifiedCount = 1,\n) {\n const updateResult = await updatePromise;\n if (!updateResult.acknowledged) throw new Error('Update was not acknowledged');\n if (updateResult.modifiedCount < expectedModifiedCount) {\n // eslint-disable-next-line style/max-len\n throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}`);\n }\n}\n\n/**\n * Builds and returns a Mongoose model with specified schema and options.\n *\n * This function sets up a Mongoose model with optional plugins and timestamp settings.\n * It can optionally use a specified connection or the default connection.\n *\n * Determine the connection to use:\n * 1. Use the connection provided in the options, if available.\n * 2. Otherwise, use the default connection stored in `mongooseConnections`.\n * 3. If there's no default connection, create one using the MongoDB URI from the environment variables,\n * or fallback to a local MongoDB instance.\n *\n * You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.\n * However, ensure that this option is configured before calling {@link buildMongooseModel}.\n *\n * @template DocType - The type of the document.\n * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param collection - The name of the collection.\n * @param name - The name of the model.\n * @param schema - The Mongoose schema to use for the model.\n * @param options - Optional settings for building the model.\n *\n * @returns The created Mongoose model.\n */\nexport function buildMongooseModel<\n DocType,\n Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n collection: string,\n name: string,\n schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n options?: BuildMongooseModelOptions,\n) {\n if (options?.enableNormalizePlugin !== false) {\n schema.plugin(mongooseNormalizePlugin, options?.normalizePluginOptions);\n }\n\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n // eslint-disable-next-line style/max-len\n const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\n\n/**\n * Converts a document or ObjectId to a document using the specified model.\n *\n * This function takes a document or ObjectId and returns the corresponding document\n * from the database using the specified model. Optionally, specific fields can be selected.\n *\n * @template D - The type of the hydrated document.\n * @template DocType - The type of the document.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param documentOrObjectId - The document or ObjectId to convert.\n * @param model - The Mongoose model to use for the conversion.\n * @param selectFields - Optional fields to select from the document.\n *\n * @returns The corresponding document or null if not found.\n */\nexport async function mongooseDocumentOrObjectIdToDocument<\n D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n DocType,\n InstanceMethodsAndOverrides,\n QueryHelpers,\n>(\n documentOrObjectId: MongooseDocumentOrObjectId<D>,\n model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n selectFields?: string[],\n) {\n if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {\n return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n }\n\n return documentOrObjectId;\n}\n\n/**\n * Converts the input, which can be a MongoDB ObjectId or a string,\n * into a 24-character hexadecimal string representation of the ObjectId.\n *\n * @param {string | Types.ObjectId} id - The ObjectId instance or its string representation\n *\n * @returns {string} The hexadecimal string representation of the ObjectId\n */\nexport function toObjectIdHexString(id: string | Types.ObjectId) {\n return id instanceof Types.ObjectId ? id.toHexString() : id;\n}\n"],"names":[],"mappings":";;;;;;;AAgBA;;;;;;;;;;;;;AAaG;AACI,eAAe,2BAA2B,CAC7C,aAA6C,EAC7C,qBAAqB,GAAG,CAAC,EAAA;AAEzB,IAAA,MAAM,YAAY,GAAG,MAAM,aAAa;IACxC,IAAI,CAAC,YAAY,CAAC,YAAY;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC;AAC9E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAqB,EAAE;;QAEpD,MAAM,IAAI,KAAK,CAAC,CAAA,4BAAA,EAA+B,qBAAqB,CAAA,2BAAA,EAA8B,YAAY,CAAC,aAAa,CAAA,CAAE,CAAC;IACnI;AACJ;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,kBAAkB,CAM9B,UAAkB,EAClB,IAAY,EACZ,MAAyE,EACzE,OAAmC,EAAA;AAEnC,IAAA,IAAI,OAAO,EAAE,qBAAqB,KAAK,KAAK,EAAE;QAC1C,MAAM,CAAC,MAAM,CAAC,uBAAuB,EAAE,OAAO,EAAE,sBAAsB,CAAC;IAC3E;AAEA,IAAA,MAAM,CAAC,MAAM,CAAC,yBAAyB,CAAC;AACxC,IAAA,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;AAC/B,IAAA,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,UAAU,IAAI,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC;AACjF,IAAA,qBAAqB,CAAC,gBAAgB,GAAG,MAAM,CAAC;;IAEhD,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,KAAK,mBAAmB,CAAC,OAAO,KAAK,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,2BAA2B,CAAC,CAAC;IAC7J,OAAO,UAAU,CAAC,KAAK,CAA+B,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC;AACnF;AAEA;;;;;;;;;;;;;;;;AAgBG;AACI,eAAe,oCAAoC,CAMtD,kBAAiD,EACjD,KAAoF,EACpF,YAAuB,EAAA;IAEvB,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,YAAY,KAAK,CAAC,QAAQ,EAAE;AACxF,QAAA,QAAQ,MAAM,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;IAC/E;AAEA,IAAA,OAAO,kBAAkB;AAC7B;AAEA;;;;;;;AAOG;AACG,SAAU,mBAAmB,CAAC,EAA2B,EAAA;AAC3D,IAAA,OAAO,EAAE,YAAY,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE;AAC/D;;;;"}
|