@kikiutils/mongoose 3.0.4 → 3.1.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 +14 -13
- package/dist/plugins/normalize.cjs +9 -3
- package/dist/plugins/normalize.cjs.map +1 -1
- package/dist/plugins/normalize.d.ts +16 -1
- package/dist/plugins/normalize.d.ts.map +1 -1
- package/dist/plugins/normalize.mjs +9 -3
- package/dist/plugins/normalize.mjs.map +1 -1
- package/dist/schema-builders/decimal128.cjs.map +1 -1
- package/dist/schema-builders/decimal128.d.ts +8 -8
- package/dist/schema-builders/decimal128.d.ts.map +1 -1
- package/dist/schema-builders/decimal128.mjs.map +1 -1
- package/dist/types/aggregate-paginate.cjs +14 -0
- package/dist/types/aggregate-paginate.cjs.map +1 -0
- package/dist/types/aggregate-paginate.d.ts +3 -3
- package/dist/types/aggregate-paginate.d.ts.map +1 -1
- package/dist/types/aggregate-paginate.mjs +10 -0
- package/dist/types/aggregate-paginate.mjs.map +1 -0
- package/dist/types/data.cjs +3 -0
- package/dist/types/data.cjs.map +1 -0
- package/dist/types/data.mjs +2 -0
- package/dist/types/data.mjs.map +1 -0
- package/dist/types/index.cjs +3 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.mjs +2 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/options.cjs +3 -0
- package/dist/types/options.cjs.map +1 -0
- package/dist/types/options.d.ts +2 -0
- package/dist/types/options.d.ts.map +1 -1
- package/dist/types/options.mjs +2 -0
- package/dist/types/options.mjs.map +1 -0
- package/dist/types/paginate.cjs +8 -0
- package/dist/types/paginate.cjs.map +1 -0
- package/dist/types/paginate.d.ts +26 -26
- package/dist/types/paginate.d.ts.map +1 -1
- package/dist/types/paginate.mjs +4 -0
- package/dist/types/paginate.mjs.map +1 -0
- package/dist/types/utils.cjs +3 -0
- package/dist/types/utils.cjs.map +1 -0
- package/dist/types/utils.mjs +2 -0
- package/dist/types/utils.mjs.map +1 -0
- package/dist/utils.cjs +3 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.mjs +3 -2
- package/dist/utils.mjs.map +1 -1
- package/package.json +23 -19
- package/src/plugins/normalize.ts +26 -4
- package/src/schema-builders/decimal128.ts +8 -8
- package/src/types/aggregate-paginate.ts +12 -12
- package/src/types/options.ts +2 -0
- package/src/types/paginate.ts +62 -62
- package/src/utils.ts +4 -1
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<!-- TODO: Update -->
|
|
2
|
+
|
|
1
3
|
# @kikiutils/mongoose
|
|
2
4
|
|
|
3
5
|
[![npm version][npm-version-src]][npm-version-href]
|
|
@@ -19,26 +21,25 @@ A Mongoose plugin for enhanced JSON normalization and common schema creation, wi
|
|
|
19
21
|
- 🔄 Reference Management: Enables easy conversion of ObjectId references to fully populated documents with field selection and population options
|
|
20
22
|
- 🔧 Utility Functions: Includes helper functions for converting and normalizing documents, handling ObjectId transformations, and processing schema fields
|
|
21
23
|
|
|
22
|
-
##
|
|
24
|
+
## Requirements
|
|
23
25
|
|
|
24
|
-
- Mongoose
|
|
25
|
-
- Node.js
|
|
26
|
+
- **Mongoose** `>= 8`
|
|
27
|
+
- **Node.js** `>= 18.12.1`
|
|
26
28
|
|
|
27
29
|
## Installation
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
Using [pnpm](https://pnpm.io):
|
|
30
32
|
|
|
31
33
|
```bash
|
|
32
34
|
pnpm add @kikiutils/mongoose mongoose
|
|
33
35
|
```
|
|
34
36
|
|
|
35
|
-
You can also use yarn
|
|
36
|
-
|
|
37
|
-
That's it! You're ready to use this package in your project. Check out the [usage instructions](#usage) below ✨.
|
|
37
|
+
You can also use `yarn`, `npm`, or `bun`.
|
|
38
38
|
|
|
39
39
|
## Usage
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
<!-- TODO: Full doc. -->
|
|
42
|
+
To be completed.
|
|
42
43
|
|
|
43
44
|
## License
|
|
44
45
|
|
|
@@ -46,13 +47,13 @@ Please refer to the [examples](./examples/README.md) folder for usage instructio
|
|
|
46
47
|
|
|
47
48
|
<!-- Badges -->
|
|
48
49
|
[npm-version-href]: https://npmjs.com/package/@kikiutils/mongoose
|
|
49
|
-
[npm-version-src]: https://img.shields.io/npm/v/@kikiutils/mongoose/latest.svg?
|
|
50
|
+
[npm-version-src]: https://img.shields.io/npm/v/@kikiutils/mongoose/latest.svg?colorA=18181b&colorB=28cf8d&style=flat
|
|
50
51
|
|
|
51
52
|
[npm-downloads-href]: https://npmjs.com/package/@kikiutils/mongoose
|
|
52
|
-
[npm-downloads-src]: https://img.shields.io/npm/dm/@kikiutils/mongoose.svg?
|
|
53
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@kikiutils/mongoose.svg?colorA=18181b&colorB=28cf8d&style=flat
|
|
53
54
|
|
|
54
|
-
[codecov-href]: https://codecov.io/
|
|
55
|
-
[codecov-src]: https://codecov.io/
|
|
55
|
+
[codecov-href]: https://codecov.io/gh/kikiutils/node-mongoose
|
|
56
|
+
[codecov-src]: https://codecov.io/gh/kikiutils/node-mongoose/graph/badge.svg?token=DM89MM6FPK
|
|
56
57
|
|
|
57
58
|
[license-href]: https://github.com/kikiutils/node-mongoose/blob/main/LICENSE
|
|
58
|
-
[license-src]: https://img.shields.io/
|
|
59
|
+
[license-src]: https://img.shields.io/github/license/kikiutils/node-mongoose?colorA=18181b&colorB=28cf8d&style=flat
|
|
@@ -26,15 +26,21 @@ const lodashUnset__default = /*#__PURE__*/_interopDefaultCompat(lodashUnset);
|
|
|
26
26
|
*
|
|
27
27
|
* @param schema - The Mongoose schema to apply the plugin to.
|
|
28
28
|
*/
|
|
29
|
-
function mongooseNormalizePlugin(schema) {
|
|
29
|
+
function mongooseNormalizePlugin(schema, pluginOptions) {
|
|
30
30
|
const toJson = schema.get('toJSON');
|
|
31
31
|
const toJsonTransform = toJson?.transform;
|
|
32
32
|
schema.set('toJSON', {
|
|
33
33
|
...toJson,
|
|
34
34
|
transform(doc, ret, options) {
|
|
35
35
|
// eslint-disable-next-line style/object-curly-newline
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
let { __v, _id, ...copiedRet } = ret;
|
|
37
|
+
if (pluginOptions?.toHexIdIfObjectId !== false) {
|
|
38
|
+
_id = _id instanceof mongoose.Types.ObjectId ? _id.toHexString() : _id;
|
|
39
|
+
}
|
|
40
|
+
if (pluginOptions?.convertIdField !== false)
|
|
41
|
+
copiedRet.id = _id;
|
|
42
|
+
else
|
|
43
|
+
copiedRet._id = _id;
|
|
38
44
|
for (const path in schema.paths) {
|
|
39
45
|
if (schema.paths[path]?.options?.private)
|
|
40
46
|
lodashUnset__default(copiedRet, path);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.cjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["// @ts-expect-error Ignore this error.\nimport lodashGet from 'lodash/get.js';\n// @ts-expect-error Ignore this error.\nimport lodashSet from 'lodash/set.js';\n// @ts-expect-error Ignore this error.\nimport lodashUnset from 'lodash/unset.js';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(schema: S) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc
|
|
1
|
+
{"version":3,"file":"normalize.cjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["// @ts-expect-error Ignore this error.\nimport lodashGet from 'lodash/get.js';\n// @ts-expect-error Ignore this error.\nimport lodashSet from 'lodash/set.js';\n// @ts-expect-error Ignore this error.\nimport lodashUnset from 'lodash/unset.js';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // eslint-disable-next-line style/object-curly-newline\n let { __v, _id, ...copiedRet } = ret;\n if (pluginOptions?.toHexIdIfObjectId !== false) {\n _id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;\n }\n\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _id;\n for (const path in schema.paths) {\n if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);\n if (schema.paths[path]?.instance === 'Decimal128') {\n const value: Types.Decimal128 | undefined = lodashGet(copiedRet, path);\n if (value) lodashSet(copiedRet, path, value.toString());\n }\n }\n\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc, copiedRet, options);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":["Types","lodashUnset","lodashGet","lodashSet"],"mappings":";;;;;;;;;;;;;AAAA;AA0BA;;;;;;;;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AC;;AAGnD,YAAA,OAAO,SAAS;SACnB;AACJ,KAAA,CACJ;AACL;;;;"}
|
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import type { Schema } from 'mongoose';
|
|
2
|
+
export interface MongooseNormalizePluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Whether to convert `_id` field to `id`.
|
|
5
|
+
* If true, the `_id` field will be replaced with `id`.
|
|
6
|
+
*
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
9
|
+
convertIdField?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to convert the `_id` field to a hex string if it's an ObjectId.
|
|
12
|
+
*
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
toHexIdIfObjectId?: boolean;
|
|
16
|
+
}
|
|
2
17
|
/**
|
|
3
18
|
* Mongoose plugin to normalize the JSON output of documents.
|
|
4
19
|
*
|
|
@@ -13,5 +28,5 @@ import type { Schema } from 'mongoose';
|
|
|
13
28
|
*
|
|
14
29
|
* @param schema - The Mongoose schema to apply the plugin to.
|
|
15
30
|
*/
|
|
16
|
-
export declare function mongooseNormalizePlugin<S extends Schema>(schema: S): void;
|
|
31
|
+
export declare function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions): void;
|
|
17
32
|
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/plugins/normalize.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/plugins/normalize.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,WAAW,8BAA8B;IAC3C;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa,CAAC,EAAE,8BAA8B,QAgClH"}
|
|
@@ -18,15 +18,21 @@ import { Types } from 'mongoose';
|
|
|
18
18
|
*
|
|
19
19
|
* @param schema - The Mongoose schema to apply the plugin to.
|
|
20
20
|
*/
|
|
21
|
-
function mongooseNormalizePlugin(schema) {
|
|
21
|
+
function mongooseNormalizePlugin(schema, pluginOptions) {
|
|
22
22
|
const toJson = schema.get('toJSON');
|
|
23
23
|
const toJsonTransform = toJson?.transform;
|
|
24
24
|
schema.set('toJSON', {
|
|
25
25
|
...toJson,
|
|
26
26
|
transform(doc, ret, options) {
|
|
27
27
|
// eslint-disable-next-line style/object-curly-newline
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
let { __v, _id, ...copiedRet } = ret;
|
|
29
|
+
if (pluginOptions?.toHexIdIfObjectId !== false) {
|
|
30
|
+
_id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;
|
|
31
|
+
}
|
|
32
|
+
if (pluginOptions?.convertIdField !== false)
|
|
33
|
+
copiedRet.id = _id;
|
|
34
|
+
else
|
|
35
|
+
copiedRet._id = _id;
|
|
30
36
|
for (const path in schema.paths) {
|
|
31
37
|
if (schema.paths[path]?.options?.private)
|
|
32
38
|
lodashUnset(copiedRet, path);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.mjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["// @ts-expect-error Ignore this error.\nimport lodashGet from 'lodash/get.js';\n// @ts-expect-error Ignore this error.\nimport lodashSet from 'lodash/set.js';\n// @ts-expect-error Ignore this error.\nimport lodashUnset from 'lodash/unset.js';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(schema: S) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc
|
|
1
|
+
{"version":3,"file":"normalize.mjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["// @ts-expect-error Ignore this error.\nimport lodashGet from 'lodash/get.js';\n// @ts-expect-error Ignore this error.\nimport lodashSet from 'lodash/set.js';\n// @ts-expect-error Ignore this error.\nimport lodashUnset from 'lodash/unset.js';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // eslint-disable-next-line style/object-curly-newline\n let { __v, _id, ...copiedRet } = ret;\n if (pluginOptions?.toHexIdIfObjectId !== false) {\n _id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;\n }\n\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _id;\n for (const path in schema.paths) {\n if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);\n if (schema.paths[path]?.instance === 'Decimal128') {\n const value: Types.Decimal128 | undefined = lodashGet(copiedRet, path);\n if (value) lodashSet(copiedRet, path, value.toString());\n }\n }\n\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc, copiedRet, options);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":[],"mappings":";;;;;AAAA;AA0BA;;;;;;;;;;;;;AAaG;AACa,SAAA,uBAAuB,CAAmB,MAAS,EAAE,aAA8C,EAAA;IAC/G,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;AACnC,IAAA,MAAM,eAAe,GAAG,MAAM,EAAE,SAAS;AACzC,IAAA,MAAM,CAAC,GAAG,CACN,QAAQ,EACR;AACI,QAAA,GAAG,MAAM;AACT,QAAA,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAA;;YAEvB,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,GAAG;AACpC,YAAA,IAAI,aAAa,EAAE,iBAAiB,KAAK,KAAK,EAAE;AAC5C,gBAAA,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,GAAG,GAAG;;AAGjE,YAAA,IAAI,aAAa,EAAE,cAAc,KAAK,KAAK;AAAE,gBAAA,SAAS,CAAC,EAAE,GAAG,GAAG;;AAC1D,gBAAA,SAAS,CAAC,GAAG,GAAG,GAAG;AACxB,YAAA,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;gBAC7B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO;AAAE,oBAAA,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC;gBACtE,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,KAAK,YAAY,EAAE;oBAC/C,MAAM,KAAK,GAAiC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC;AACtE,oBAAA,IAAI,KAAK;wBAAE,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;;;AAI/D,YAAA,IAAI,eAAe,IAAI,OAAO,eAAe,KAAK,SAAS,EAAE;gBACzD,OAAO,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC;;AAGnD,YAAA,OAAO,SAAS;SACnB;AACJ,KAAA,CACJ;AACL;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decimal128.cjs","sources":["../../src/schema-builders/decimal128.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\nimport { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendDecimal128SchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n Decimal128SchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: typeof Schema.Types.Decimal128;\n}\n\
|
|
1
|
+
{"version":3,"file":"decimal128.cjs","sources":["../../src/schema-builders/decimal128.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\nimport { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendDecimal128SchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n Decimal128SchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: typeof Schema.Types.Decimal128;\n}\n\nexport interface Decimal128SchemaBuilder<\n Props extends { type: typeof Schema.Types.Decimal128 } = { type: typeof Schema.Types.Decimal128 },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends Types.Decimal128,\n >(value: T) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<D | null>>\n | { [path: string]: D | null }\n | { message?: M; values: Readonlyable<Array<D | null>> },\n D extends Types.Decimal128,\n M extends string,\n >(value: T) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendDecimal128SchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n\n /**\n * Sets the rounding and toFixed behavior for Decimal128 fields.\n * This method allows specifying the number of decimal places and the rounding strategy to be used when\n * saving the field to the database.\n *\n * @param places - The number of decimal places to round to (default is 2).\n * @param rounding - The rounding strategy from the Decimal.js library (default is Decimal.ROUND_DOWN).\n *\n * @returns A schema builder with the rounding and toFixed behavior applied to the `set` option in Mongoose.\n */\n setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendDecimal128SchemaBuilder<\n Merge<Props, ToStringSetterSchema>,\n 'setRoundAndToFixedSetter' | ExtraOmitFields\n >;\n\n /**\n * Sets the toString behavior for Decimal128 fields.\n * This method defines how the Decimal128 field should be converted to a string when processing or\n * retrieving the value in the application (e.g., via getters), while still storing the value as Decimal128\n * in the database.\n *\n * @returns A schema builder with the custom `get` behavior applied to convert the Decimal128 field to a string\n * when accessed in the application.\n */\n setToStringGetter: ExtendDecimal128SchemaBuilder<\n Merge<Props, ToStringGetterSchema>,\n 'setToStringGetter' | ExtraOmitFields\n >;\n\n sparse: ExtendDecimal128SchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendDecimal128SchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\ninterface ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string;\n}\n\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);\n\nexport function decimal128SchemaBuilder() {\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 === 'setRoundAndToFixedSetter') {\n return (places: number = 2, rounding: Decimal.Rounding = Decimal.ROUND_DOWN) => {\n schema.set = (value?: { toString: () => string }) => {\n if (value) return new Decimal(value.toString()).toFixed(places, rounding);\n };\n\n return receiver;\n };\n }\n\n if (key === 'setToStringGetter') {\n schema.get = (value?: Types.Decimal128) => value?.toString();\n return receiver;\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as Decimal128SchemaBuilder;\n}\n"],"names":["createBaseSchemaBuilderFactory","Schema","Decimal"],"mappings":";;;;;;AAoGA,MAAM,kBAAkB,GAAGA,mCAA8B,CAACC,eAAM,CAAC,KAAK,CAAC,UAAU,CAAC;SAElE,uBAAuB,GAAA;IACnC,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,0BAA0B,EAAE;gBACpC,OAAO,CAAC,SAAiB,CAAC,EAAE,WAA6BC,kBAAO,CAAC,UAAU,KAAI;AAC3E,oBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAkC,KAAI;AAChD,wBAAA,IAAI,KAAK;AAAE,4BAAA,OAAO,IAAIA,kBAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;AAC7E,qBAAC;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,mBAAmB,EAAE;AAC7B,gBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAwB,KAAK,KAAK,EAAE,QAAQ,EAAE;AAC5D,gBAAA,OAAO,QAAQ;;YAGnB,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC5C;AACJ,KAAA,CACuB;AAChC;;;;"}
|
|
@@ -7,14 +7,6 @@ export type ExtendDecimal128SchemaBuilder<Props extends BaseProps, ExtraOmitFiel
|
|
|
7
7
|
interface BaseProps {
|
|
8
8
|
type: typeof Schema.Types.Decimal128;
|
|
9
9
|
}
|
|
10
|
-
interface ToStringGetterSchema {
|
|
11
|
-
get: (value?: Types.Decimal128) => string | undefined;
|
|
12
|
-
}
|
|
13
|
-
interface ToStringSetterSchema {
|
|
14
|
-
set: (value?: {
|
|
15
|
-
toString: () => string;
|
|
16
|
-
}) => string;
|
|
17
|
-
}
|
|
18
10
|
export interface Decimal128SchemaBuilder<Props extends {
|
|
19
11
|
type: typeof Schema.Types.Decimal128;
|
|
20
12
|
} = {
|
|
@@ -69,6 +61,14 @@ export interface Decimal128SchemaBuilder<Props extends {
|
|
|
69
61
|
unique: true;
|
|
70
62
|
}>, ExtraOmitFields>;
|
|
71
63
|
}
|
|
64
|
+
interface ToStringGetterSchema {
|
|
65
|
+
get: (value?: Types.Decimal128) => string | undefined;
|
|
66
|
+
}
|
|
67
|
+
interface ToStringSetterSchema {
|
|
68
|
+
set: (value?: {
|
|
69
|
+
toString: () => string;
|
|
70
|
+
}) => string;
|
|
71
|
+
}
|
|
72
72
|
export declare function decimal128SchemaBuilder(): Decimal128SchemaBuilder;
|
|
73
73
|
export {};
|
|
74
74
|
//# sourceMappingURL=decimal128.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decimal128.d.ts","sourceRoot":"","sources":["../../src/schema-builders/decimal128.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,EACR,WAAW,EACX,cAAc,EACd,YAAY,EACZ,KAAK,EACR,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAInD,MAAM,MAAM,6BAA6B,CACrC,KAAK,SAAS,SAAS,EACvB,eAAe,SAAS,MAAM,IAC9B,IAAI,CACJ,uBAAuB,CAAC,KAAK,EAAE,eAAe,CAAC,EAC/C,eAAe,GAAG,MAAM,KAAK,CAChC,CAAC;AAEF,UAAU,SAAS;IACf,IAAI,EAAE,OAAO,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;CACxC;AAED,
|
|
1
|
+
{"version":3,"file":"decimal128.d.ts","sourceRoot":"","sources":["../../src/schema-builders/decimal128.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,EACR,WAAW,EACX,cAAc,EACd,YAAY,EACZ,KAAK,EACR,MAAM,UAAU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AC1F;AAED,UAAU,oBAAoB;IAC1B,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,MAAM,GAAG,SAAS,CAAC;CACzD;AAED,UAAU,oBAAoB;IAC1B,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;CACvD;AAID,wBAAgB,uBAAuB,IAyB9B,uBAAuB,CAC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decimal128.mjs","sources":["../../src/schema-builders/decimal128.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\nimport { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendDecimal128SchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n Decimal128SchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: typeof Schema.Types.Decimal128;\n}\n\
|
|
1
|
+
{"version":3,"file":"decimal128.mjs","sources":["../../src/schema-builders/decimal128.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\nimport { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendDecimal128SchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n Decimal128SchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: typeof Schema.Types.Decimal128;\n}\n\nexport interface Decimal128SchemaBuilder<\n Props extends { type: typeof Schema.Types.Decimal128 } = { type: typeof Schema.Types.Decimal128 },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends Types.Decimal128,\n >(value: T) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<D | null>>\n | { [path: string]: D | null }\n | { message?: M; values: Readonlyable<Array<D | null>> },\n D extends Types.Decimal128,\n M extends string,\n >(value: T) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendDecimal128SchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n\n /**\n * Sets the rounding and toFixed behavior for Decimal128 fields.\n * This method allows specifying the number of decimal places and the rounding strategy to be used when\n * saving the field to the database.\n *\n * @param places - The number of decimal places to round to (default is 2).\n * @param rounding - The rounding strategy from the Decimal.js library (default is Decimal.ROUND_DOWN).\n *\n * @returns A schema builder with the rounding and toFixed behavior applied to the `set` option in Mongoose.\n */\n setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendDecimal128SchemaBuilder<\n Merge<Props, ToStringSetterSchema>,\n 'setRoundAndToFixedSetter' | ExtraOmitFields\n >;\n\n /**\n * Sets the toString behavior for Decimal128 fields.\n * This method defines how the Decimal128 field should be converted to a string when processing or\n * retrieving the value in the application (e.g., via getters), while still storing the value as Decimal128\n * in the database.\n *\n * @returns A schema builder with the custom `get` behavior applied to convert the Decimal128 field to a string\n * when accessed in the application.\n */\n setToStringGetter: ExtendDecimal128SchemaBuilder<\n Merge<Props, ToStringGetterSchema>,\n 'setToStringGetter' | ExtraOmitFields\n >;\n\n sparse: ExtendDecimal128SchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendDecimal128SchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\ninterface ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string;\n}\n\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);\n\nexport function decimal128SchemaBuilder() {\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 === 'setRoundAndToFixedSetter') {\n return (places: number = 2, rounding: Decimal.Rounding = Decimal.ROUND_DOWN) => {\n schema.set = (value?: { toString: () => string }) => {\n if (value) return new Decimal(value.toString()).toFixed(places, rounding);\n };\n\n return receiver;\n };\n }\n\n if (key === 'setToStringGetter') {\n schema.get = (value?: Types.Decimal128) => value?.toString();\n return receiver;\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as Decimal128SchemaBuilder;\n}\n"],"names":[],"mappings":";;;;AAoGA,MAAM,kBAAkB,GAAG,8BAA8B,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;SAElE,uBAAuB,GAAA;IACnC,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,0BAA0B,EAAE;gBACpC,OAAO,CAAC,SAAiB,CAAC,EAAE,WAA6B,OAAO,CAAC,UAAU,KAAI;AAC3E,oBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAkC,KAAI;AAChD,wBAAA,IAAI,KAAK;AAAE,4BAAA,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;AAC7E,qBAAC;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,mBAAmB,EAAE;AAC7B,gBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAwB,KAAK,KAAK,EAAE,QAAQ,EAAE;AAC5D,gBAAA,OAAO,QAAQ;;YAGnB,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC5C;AACJ,KAAA,CACuB;AAChC;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;"}
|
|
@@ -14,6 +14,9 @@ declare module 'mongoose' {
|
|
|
14
14
|
totalDocs?: T;
|
|
15
15
|
totalPages?: T;
|
|
16
16
|
}
|
|
17
|
+
interface AggregatePaginateModel<RawDocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
|
|
18
|
+
aggregatePaginate: <T>(query?: Aggregate<T[]> | PrePaginatePipelineStage[], options?: AggregatePaginateOptions, callback?: (err: any, result: AggregatePaginateResult<T>) => void) => Promise<AggregatePaginateResult<T>>;
|
|
19
|
+
}
|
|
17
20
|
interface AggregatePaginateOptions {
|
|
18
21
|
allowDiskUse?: boolean;
|
|
19
22
|
countQuery?: object;
|
|
@@ -58,9 +61,6 @@ declare module 'mongoose' {
|
|
|
58
61
|
totalDocs: number;
|
|
59
62
|
totalPages: number;
|
|
60
63
|
}
|
|
61
|
-
interface AggregatePaginateModel<RawDocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
|
|
62
|
-
aggregatePaginate: <T>(query?: Aggregate<T[]> | PrePaginatePipelineStage[], options?: AggregatePaginateOptions, callback?: (err: any, result: AggregatePaginateResult<T>) => void) => Promise<AggregatePaginateResult<T>>;
|
|
63
|
-
}
|
|
64
64
|
}
|
|
65
65
|
declare function mongooseAggregatePaginate(schema: Schema): void;
|
|
66
66
|
declare namespace mongooseAggregatePaginate {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate-paginate.d.ts","sourceRoot":"","sources":["../../src/types/aggregate-paginate.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAER,MAAM,EACT,MAAM,UAAU,CAAC;AAElB,OAAO,QAAQ,UAAU,CAAC;IACtB,KAAK,wBAAwB,GAAG,iBAAiB,GAAG,a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C,CAAC;QAC/B,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,SAAS,CAAC;QACjE,IAAI,EAAE,CAAC,EAAE,CAAC;QACV,WAAW,EAAE,OAAO,CAAC;QACrB,WAAW,EAAE,OAAO,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;QACzB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,aAAa,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;QACzB,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;KACtB;CACJ;AAED,OAAO,UAAU,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;AAGjE,OAAO,WAAW,yBAAyB,CAAC;IACxC,MAAM,yBAAyB,EAAE,MAAM,CAAC;CAC3C;AAOD,eAAe,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/dist/types/options.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Connection, Schema, SchemaTimestampsConfig } from 'mongoose';
|
|
2
|
+
import type { MongooseNormalizePluginOptions } from '../plugins/normalize';
|
|
2
3
|
import type { buildMongooseModel } from '../utils';
|
|
3
4
|
export type DoNotRemoveOrUseThisType = typeof buildMongooseModel;
|
|
4
5
|
/**
|
|
@@ -25,6 +26,7 @@ export interface BuildMongooseModelOptions {
|
|
|
25
26
|
* @default true
|
|
26
27
|
*/
|
|
27
28
|
enableNormalizePlugin?: boolean;
|
|
29
|
+
normalizePluginOptions?: MongooseNormalizePluginOptions;
|
|
28
30
|
/**
|
|
29
31
|
* Configures Mongoose timestamps.
|
|
30
32
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,MAAM,EACN,sBAAsB,EACzB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,MAAM,MAAM,wBAAwB,GAAG,OAAO,kBAAkB,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB;;;;;;;OAOG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,MAAM,EACN,sBAAsB,EACzB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,MAAM,MAAM,wBAAwB,GAAG,OAAO,kBAAkB,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB;;;;;;;OAOG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,sBAAsB,CAAC,EAAE,8BAA8B,CAAC;IAExD;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,sBAAsB,CAAC;CACjD;AAED,MAAM,WAAW,qBAAqB;IAClC;;OAEG;IACH,gBAAgB,CAAC,EAAE,CACf,OAAO,EACP,KAAK,SAAS,yBAAyB,CAAC,OAAO,EAAE,2BAA2B,EAAE,YAAY,CAAC,EAC3F,2BAA2B,GAAG,MAAM,EACpC,YAAY,GAAG,MAAM,EAErB,MAAM,EAAE,MAAM,CACV,OAAO,EACP,KAAK,EACL,2BAA2B,EAC3B,YAAY,CACf,KACA,IAAI,CAAC;CACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
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.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { FilterQuery, mongo, PaginateOptions, Schema } from 'mongoose';
|
|
2
2
|
import type { IfElse } from './utils';
|
|
3
3
|
declare module 'mongoose' {
|
|
4
|
+
type PaginateDocument<T, TMethods, TQueryHelpers, O extends PaginateOptions = object> = IfElse<O['lean'], IfElse<O['leanWithId'], T & {
|
|
5
|
+
id: string;
|
|
6
|
+
}, IfElse<O['leanWithVirtuals'], T & {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}, T>>, HydratedDocument<T, TMethods, TQueryHelpers>>;
|
|
4
9
|
interface PaginateCustomLabels<T = boolean | string | undefined> {
|
|
5
10
|
docs?: T;
|
|
6
11
|
hasNextPage?: T;
|
|
@@ -14,9 +19,12 @@ declare module 'mongoose' {
|
|
|
14
19
|
totalDocs?: T;
|
|
15
20
|
totalPages?: T;
|
|
16
21
|
}
|
|
17
|
-
interface
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
interface PaginateModel<T, TQueryHelpers = object, TMethods = object> extends Model<T, TQueryHelpers, TMethods> {
|
|
23
|
+
paginate: {
|
|
24
|
+
<O extends PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>>;
|
|
25
|
+
<UserType = T, O extends PaginateOptions = PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>>;
|
|
26
|
+
<UserType = T>(query?: FilterQuery<T>, options?: PaginateOptions, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>>;
|
|
27
|
+
};
|
|
20
28
|
}
|
|
21
29
|
interface PaginateOptions {
|
|
22
30
|
allowDiskUse?: boolean;
|
|
@@ -44,17 +52,9 @@ declare module 'mongoose' {
|
|
|
44
52
|
useCustomCountFn?: () => Promise<number>;
|
|
45
53
|
useEstimatedCount?: boolean;
|
|
46
54
|
}
|
|
47
|
-
interface
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
51
|
-
read?: PaginateReadOptions;
|
|
52
|
-
select?: object | string;
|
|
53
|
-
}
|
|
54
|
-
interface SubDocumentPagingOptions {
|
|
55
|
-
limit?: number;
|
|
56
|
-
page?: number;
|
|
57
|
-
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
55
|
+
interface PaginateReadOptions {
|
|
56
|
+
pref: string;
|
|
57
|
+
tags?: any[];
|
|
58
58
|
}
|
|
59
59
|
interface PaginateResult<T> {
|
|
60
60
|
[customLabel: string]: boolean | null | number | T[] | undefined;
|
|
@@ -71,18 +71,6 @@ declare module 'mongoose' {
|
|
|
71
71
|
totalDocs: number;
|
|
72
72
|
totalPages: number;
|
|
73
73
|
}
|
|
74
|
-
type PaginateDocument<T, TMethods, TQueryHelpers, O extends PaginateOptions = object> = IfElse<O['lean'], IfElse<O['leanWithId'], T & {
|
|
75
|
-
id: string;
|
|
76
|
-
}, IfElse<O['leanWithVirtuals'], T & {
|
|
77
|
-
[key: string]: any;
|
|
78
|
-
}, T>>, HydratedDocument<T, TMethods, TQueryHelpers>>;
|
|
79
|
-
interface PaginateModel<T, TQueryHelpers = object, TMethods = object> extends Model<T, TQueryHelpers, TMethods> {
|
|
80
|
-
paginate: {
|
|
81
|
-
<O extends PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>>;
|
|
82
|
-
<UserType = T, O extends PaginateOptions = PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>>;
|
|
83
|
-
<UserType = T>(query?: FilterQuery<T>, options?: PaginateOptions, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>>;
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
74
|
interface Query<ResultType, DocType, THelpers = NonNullable<unknown>, RawDocType = DocType, _QueryOp = 'find', TInstanceMethods = Record<string, never>> {
|
|
87
75
|
paginate: {
|
|
88
76
|
<O extends PaginateOptions>(options?: O): Promise<PaginateResult<PaginateDocument<RawDocType, TInstanceMethods, THelpers, O>>>;
|
|
@@ -90,6 +78,18 @@ declare module 'mongoose' {
|
|
|
90
78
|
<UserType = ResultType>(options?: PaginateOptions): Promise<PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, PaginateOptions>>>;
|
|
91
79
|
};
|
|
92
80
|
}
|
|
81
|
+
interface SubDocumentPagingOptions {
|
|
82
|
+
limit?: number;
|
|
83
|
+
page?: number;
|
|
84
|
+
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
85
|
+
}
|
|
86
|
+
interface SubPaginateOptions {
|
|
87
|
+
pagination?: boolean;
|
|
88
|
+
pagingOptions?: SubDocumentPagingOptions;
|
|
89
|
+
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
90
|
+
read?: PaginateReadOptions;
|
|
91
|
+
select?: object | string;
|
|
92
|
+
}
|
|
93
93
|
}
|
|
94
94
|
declare function _(schema: Schema): void;
|
|
95
95
|
declare namespace _ {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.d.ts","sourceRoot":"","sources":["../../src/types/paginate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,WAAW,EACX,KAAK,EACL,eAAe,EACf,MAAM,EACT,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,QAAQ,UAAU,CAAC;IACtB,
|
|
1
|
+
{"version":3,"file":"paginate.d.ts","sourceRoot":"","sources":["../../src/types/paginate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,WAAW,EACX,KAAK,EACL,eAAe,EACf,MAAM,EACT,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,QAAQ,UAAU,CAAC;IACtB,KAAK,gBAAgB,CACjB,CAAC,EACD,QAAQ,EACR,aAAa,EACb,CAAC,SAAS,eAAe,GAAG,MAAM,IAClC,MAAM,CACN,CAAC,CAAC,MAAM,CAAC,EACT,MAAM,CACF,CAAC,CAAC,YAAY,CAAC,EACf,CAAC,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EAClB,MAAM,CACF,CAAC,CAAC,kBAAkB,CAAC,EACrB,CAAC,GAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAC1B,CA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CAAC,SAAS,eAAe;oBACvC,OAAO,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;SAAE;QACpD,GAAG,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC,CAAC;QACpB,QAAQ,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,CAAC;KAClC;CACJ;AAED,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/utils.cjs
CHANGED
|
@@ -64,8 +64,9 @@ async function assertMongooseUpdateSuccess(updatePromise, expectedModifiedCount
|
|
|
64
64
|
* @returns The created Mongoose model.
|
|
65
65
|
*/
|
|
66
66
|
function buildMongooseModel(collection, name, schema, options) {
|
|
67
|
-
if (options?.enableNormalizePlugin !== false)
|
|
68
|
-
schema.plugin(normalize.mongooseNormalizePlugin);
|
|
67
|
+
if (options?.enableNormalizePlugin !== false) {
|
|
68
|
+
schema.plugin(normalize.mongooseNormalizePlugin, options?.normalizePluginOptions);
|
|
69
|
+
}
|
|
69
70
|
schema.plugin(mongooseAggregatePaginate__default);
|
|
70
71
|
schema.plugin(mongoosePaginate__default);
|
|
71
72
|
schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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) schema.plugin(mongooseNormalizePlugin);\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"],"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,8BAA8B,CAAC;AAC/E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAqB,EAAE;;QAEpD,MAAM,IAAI,KAAK,CAAC,CAA+B,4BAAA,EAAA,qBAAqB,CAA8B,2BAAA,EAAA,YAAY,CAAC,aAAa,CAAG,CAAA,CAAA,CAAC;;AAExI;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,kBAAkB,CAM9B,UAAkB,EAClB,IAAY,EACZ,MAAyE,EACzE,OAAmC,EAAA;AAEnC,IAAA,IAAI,OAAO,EAAE,qBAAqB,KAAK,KAAK;
|
|
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"],"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,8BAA8B,CAAC;AAC/E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAqB,EAAE;;QAEpD,MAAM,IAAI,KAAK,CAAC,CAA+B,4BAAA,EAAA,qBAAqB,CAA8B,2BAAA,EAAA,YAAY,CAAC,aAAa,CAAG,CAAA,CAAA,CAAC;;AAExI;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;;AAG3E,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,CAA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B,CAAC,CAAC,CAAC,EACjD,KAAK,EAAE,yBAAyB,CAAC,OAAO,EAAE,2BAA2B,EAAE,YAAY,CAAC,EACpF,YAAY,CAAC,EAAE,MAAM,EAAE,qBAO1B"}
|
package/dist/utils.mjs
CHANGED
|
@@ -56,8 +56,9 @@ async function assertMongooseUpdateSuccess(updatePromise, expectedModifiedCount
|
|
|
56
56
|
* @returns The created Mongoose model.
|
|
57
57
|
*/
|
|
58
58
|
function buildMongooseModel(collection, name, schema, options) {
|
|
59
|
-
if (options?.enableNormalizePlugin !== false)
|
|
60
|
-
schema.plugin(mongooseNormalizePlugin);
|
|
59
|
+
if (options?.enableNormalizePlugin !== false) {
|
|
60
|
+
schema.plugin(mongooseNormalizePlugin, options?.normalizePluginOptions);
|
|
61
|
+
}
|
|
61
62
|
schema.plugin(mongooseAggregatePaginate);
|
|
62
63
|
schema.plugin(mongoosePaginate);
|
|
63
64
|
schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);
|
package/dist/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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) schema.plugin(mongooseNormalizePlugin);\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"],"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,8BAA8B,CAAC;AAC/E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAqB,EAAE;;QAEpD,MAAM,IAAI,KAAK,CAAC,CAA+B,4BAAA,EAAA,qBAAqB,CAA8B,2BAAA,EAAA,YAAY,CAAC,aAAa,CAAG,CAAA,CAAA,CAAC;;AAExI;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,kBAAkB,CAM9B,UAAkB,EAClB,IAAY,EACZ,MAAyE,EACzE,OAAmC,EAAA;AAEnC,IAAA,IAAI,OAAO,EAAE,qBAAqB,KAAK,KAAK;
|
|
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"],"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,8BAA8B,CAAC;AAC/E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAqB,EAAE;;QAEpD,MAAM,IAAI,KAAK,CAAC,CAA+B,4BAAA,EAAA,qBAAqB,CAA8B,2BAAA,EAAA,YAAY,CAAC,aAAa,CAAG,CAAA,CAAA,CAAC;;AAExI;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;;AAG3E,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;;AAG/E,IAAA,OAAO,kBAAkB;AAC7B;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/mongoose",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.",
|
|
5
5
|
"author": "kiki-kanri",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,35 +50,39 @@
|
|
|
50
50
|
"node": ">=18.12.1"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"build": "ts-project-builder ./src
|
|
54
|
-
"bumplog": "changelogen --bump",
|
|
55
|
-
"lint": "eslint",
|
|
56
|
-
"lint:fix": "eslint --fix",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
53
|
+
"build": "ts-project-builder './src/**/*.ts' --clean --preserve-modules --sourcemaps",
|
|
54
|
+
"bumplog": "changelogen --bump --hideAuthorEmail",
|
|
55
|
+
"lint": "eslint --max-warnings 0",
|
|
56
|
+
"lint:fix": "eslint --fix --max-warnings 0",
|
|
57
|
+
"prepack": "pnpm run build",
|
|
58
|
+
"release": "pnpm run lint && pnpm run typecheck && pnpm run test && pnpm run build && changelogen --hideAuthorEmail --push --release && npm publish",
|
|
59
|
+
"test": "vitest run --coverage",
|
|
60
|
+
"test:watch": "vitest watch --coverage",
|
|
61
|
+
"typecheck": "tsc --noEmit"
|
|
59
62
|
},
|
|
60
63
|
"dependencies": {
|
|
61
64
|
"decimal.js": "^10.5.0",
|
|
62
65
|
"lodash": "^4.17.21",
|
|
63
|
-
"mongoose": "^8.
|
|
66
|
+
"mongoose": "^8.15.1",
|
|
64
67
|
"mongoose-aggregate-paginate-v2": "^1.1.4",
|
|
65
|
-
"mongoose-paginate-v2": "^1.9.
|
|
66
|
-
"type-fest": "^4.
|
|
68
|
+
"mongoose-paginate-v2": "^1.9.1",
|
|
69
|
+
"type-fest": "^4.41.0"
|
|
67
70
|
},
|
|
68
71
|
"devDependencies": {
|
|
69
72
|
"@kikiutils/changelogen": "^0.8.0",
|
|
70
|
-
"@kikiutils/eslint-config": "^
|
|
71
|
-
"@kikiutils/tsconfigs": "^
|
|
72
|
-
"@types/
|
|
73
|
-
"@types/
|
|
74
|
-
"@
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
73
|
+
"@kikiutils/eslint-config": "^1.2.3",
|
|
74
|
+
"@kikiutils/tsconfigs": "^5.0.4",
|
|
75
|
+
"@types/lodash": "^4.17.17",
|
|
76
|
+
"@types/node": "^22.15.30",
|
|
77
|
+
"@vitest/coverage-v8": "^3.2.2",
|
|
78
|
+
"ts-project-builder": "^5.0.2",
|
|
79
|
+
"typescript": "^5.8.3",
|
|
80
|
+
"vitest": "^3.2.2"
|
|
78
81
|
},
|
|
79
82
|
"pnpm": {
|
|
80
83
|
"onlyBuiltDependencies": [
|
|
81
|
-
"esbuild"
|
|
84
|
+
"esbuild",
|
|
85
|
+
"unrs-resolver"
|
|
82
86
|
]
|
|
83
87
|
}
|
|
84
88
|
}
|
package/src/plugins/normalize.ts
CHANGED
|
@@ -7,6 +7,23 @@ import lodashUnset from 'lodash/unset.js';
|
|
|
7
7
|
import { Types } from 'mongoose';
|
|
8
8
|
import type { Schema } from 'mongoose';
|
|
9
9
|
|
|
10
|
+
export interface MongooseNormalizePluginOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Whether to convert `_id` field to `id`.
|
|
13
|
+
* If true, the `_id` field will be replaced with `id`.
|
|
14
|
+
*
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
convertIdField?: boolean;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Whether to convert the `_id` field to a hex string if it's an ObjectId.
|
|
21
|
+
*
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
toHexIdIfObjectId?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
10
27
|
/**
|
|
11
28
|
* Mongoose plugin to normalize the JSON output of documents.
|
|
12
29
|
*
|
|
@@ -21,17 +38,22 @@ import type { Schema } from 'mongoose';
|
|
|
21
38
|
*
|
|
22
39
|
* @param schema - The Mongoose schema to apply the plugin to.
|
|
23
40
|
*/
|
|
24
|
-
export function mongooseNormalizePlugin<S extends Schema>(schema: S) {
|
|
41
|
+
export function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions) {
|
|
25
42
|
const toJson = schema.get('toJSON');
|
|
26
43
|
const toJsonTransform = toJson?.transform;
|
|
27
44
|
schema.set(
|
|
28
45
|
'toJSON',
|
|
29
46
|
{
|
|
30
47
|
...toJson,
|
|
31
|
-
transform(doc
|
|
48
|
+
transform(doc, ret, options) {
|
|
32
49
|
// eslint-disable-next-line style/object-curly-newline
|
|
33
|
-
|
|
34
|
-
|
|
50
|
+
let { __v, _id, ...copiedRet } = ret;
|
|
51
|
+
if (pluginOptions?.toHexIdIfObjectId !== false) {
|
|
52
|
+
_id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;
|
|
56
|
+
else copiedRet._id = _id;
|
|
35
57
|
for (const path in schema.paths) {
|
|
36
58
|
if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);
|
|
37
59
|
if (schema.paths[path]?.instance === 'Decimal128') {
|
|
@@ -24,14 +24,6 @@ interface BaseProps {
|
|
|
24
24
|
type: typeof Schema.Types.Decimal128;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
interface ToStringGetterSchema {
|
|
28
|
-
get: (value?: Types.Decimal128) => string | undefined;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface ToStringSetterSchema {
|
|
32
|
-
set: (value?: { toString: () => string }) => string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
27
|
export interface Decimal128SchemaBuilder<
|
|
36
28
|
Props extends { type: typeof Schema.Types.Decimal128 } = { type: typeof Schema.Types.Decimal128 },
|
|
37
29
|
ExtraOmitFields extends string = never,
|
|
@@ -98,6 +90,14 @@ export interface Decimal128SchemaBuilder<
|
|
|
98
90
|
unique: ExtendDecimal128SchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
99
91
|
}
|
|
100
92
|
|
|
93
|
+
interface ToStringGetterSchema {
|
|
94
|
+
get: (value?: Types.Decimal128) => string | undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface ToStringSetterSchema {
|
|
98
|
+
set: (value?: { toString: () => string }) => string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
101
|
const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);
|
|
102
102
|
|
|
103
103
|
export function decimal128SchemaBuilder() {
|
|
@@ -27,6 +27,18 @@ declare module 'mongoose' {
|
|
|
27
27
|
totalPages?: T;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
interface AggregatePaginateModel<
|
|
31
|
+
RawDocType,
|
|
32
|
+
QueryHelpers = object,
|
|
33
|
+
InstanceMethodsAndOverrides = object,
|
|
34
|
+
> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
|
|
35
|
+
aggregatePaginate: <T>(
|
|
36
|
+
query?: Aggregate<T[]> | PrePaginatePipelineStage[],
|
|
37
|
+
options?: AggregatePaginateOptions,
|
|
38
|
+
callback?: (err: any, result: AggregatePaginateResult<T>) => void,
|
|
39
|
+
) => Promise<AggregatePaginateResult<T>>;
|
|
40
|
+
}
|
|
41
|
+
|
|
30
42
|
interface AggregatePaginateOptions {
|
|
31
43
|
allowDiskUse?: boolean;
|
|
32
44
|
countQuery?: object;
|
|
@@ -74,18 +86,6 @@ declare module 'mongoose' {
|
|
|
74
86
|
totalDocs: number;
|
|
75
87
|
totalPages: number;
|
|
76
88
|
}
|
|
77
|
-
|
|
78
|
-
interface AggregatePaginateModel<
|
|
79
|
-
RawDocType,
|
|
80
|
-
QueryHelpers = object,
|
|
81
|
-
InstanceMethodsAndOverrides = object,
|
|
82
|
-
> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
|
|
83
|
-
aggregatePaginate: <T>(
|
|
84
|
-
query?: Aggregate<T[]> | PrePaginatePipelineStage[],
|
|
85
|
-
options?: AggregatePaginateOptions,
|
|
86
|
-
callback?: (err: any, result: AggregatePaginateResult<T>) => void,
|
|
87
|
-
) => Promise<AggregatePaginateResult<T>>;
|
|
88
|
-
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
declare function mongooseAggregatePaginate(schema: Schema): void;
|
package/src/types/options.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
SchemaTimestampsConfig,
|
|
5
5
|
} from 'mongoose';
|
|
6
6
|
|
|
7
|
+
import type { MongooseNormalizePluginOptions } from '../plugins/normalize';
|
|
7
8
|
import type { buildMongooseModel } from '../utils';
|
|
8
9
|
|
|
9
10
|
export type DoNotRemoveOrUseThisType = typeof buildMongooseModel;
|
|
@@ -33,6 +34,7 @@ export interface BuildMongooseModelOptions {
|
|
|
33
34
|
* @default true
|
|
34
35
|
*/
|
|
35
36
|
enableNormalizePlugin?: boolean;
|
|
37
|
+
normalizePluginOptions?: MongooseNormalizePluginOptions;
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
40
|
* Configures Mongoose timestamps.
|
package/src/types/paginate.ts
CHANGED
|
@@ -8,6 +8,25 @@ import type {
|
|
|
8
8
|
import type { IfElse } from './utils';
|
|
9
9
|
|
|
10
10
|
declare module 'mongoose' {
|
|
11
|
+
type PaginateDocument<
|
|
12
|
+
T,
|
|
13
|
+
TMethods,
|
|
14
|
+
TQueryHelpers,
|
|
15
|
+
O extends PaginateOptions = object,
|
|
16
|
+
> = IfElse<
|
|
17
|
+
O['lean'],
|
|
18
|
+
IfElse<
|
|
19
|
+
O['leanWithId'],
|
|
20
|
+
T & { id: string },
|
|
21
|
+
IfElse<
|
|
22
|
+
O['leanWithVirtuals'],
|
|
23
|
+
T & { [key: string]: any },
|
|
24
|
+
T
|
|
25
|
+
>
|
|
26
|
+
>,
|
|
27
|
+
HydratedDocument<T, TMethods, TQueryHelpers>
|
|
28
|
+
>;
|
|
29
|
+
|
|
11
30
|
interface PaginateCustomLabels<T = boolean | string | undefined> {
|
|
12
31
|
docs?: T;
|
|
13
32
|
hasNextPage?: T;
|
|
@@ -22,9 +41,32 @@ declare module 'mongoose' {
|
|
|
22
41
|
totalPages?: T;
|
|
23
42
|
}
|
|
24
43
|
|
|
25
|
-
interface
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
interface PaginateModel<T, TQueryHelpers = object, TMethods = object> extends Model<T, TQueryHelpers, TMethods> {
|
|
45
|
+
paginate: {
|
|
46
|
+
<O extends PaginateOptions>(
|
|
47
|
+
query?: FilterQuery<T>,
|
|
48
|
+
options?: O,
|
|
49
|
+
callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>) => void
|
|
50
|
+
): Promise<PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>>;
|
|
51
|
+
|
|
52
|
+
<UserType = T, O extends PaginateOptions = PaginateOptions>(
|
|
53
|
+
query?: FilterQuery<T>,
|
|
54
|
+
options?: O,
|
|
55
|
+
callback?: (
|
|
56
|
+
err: any,
|
|
57
|
+
result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>
|
|
58
|
+
) => void
|
|
59
|
+
): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>>;
|
|
60
|
+
|
|
61
|
+
<UserType = T>(
|
|
62
|
+
query?: FilterQuery<T>,
|
|
63
|
+
options?: PaginateOptions,
|
|
64
|
+
callback?: (
|
|
65
|
+
err: any,
|
|
66
|
+
result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>
|
|
67
|
+
) => void
|
|
68
|
+
): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>>;
|
|
69
|
+
};
|
|
28
70
|
}
|
|
29
71
|
|
|
30
72
|
interface PaginateOptions {
|
|
@@ -55,18 +97,9 @@ declare module 'mongoose' {
|
|
|
55
97
|
useEstimatedCount?: boolean;
|
|
56
98
|
}
|
|
57
99
|
|
|
58
|
-
interface
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
62
|
-
read?: PaginateReadOptions;
|
|
63
|
-
select?: object | string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
interface SubDocumentPagingOptions {
|
|
67
|
-
limit?: number;
|
|
68
|
-
page?: number;
|
|
69
|
-
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
100
|
+
interface PaginateReadOptions {
|
|
101
|
+
pref: string;
|
|
102
|
+
tags?: any[];
|
|
70
103
|
}
|
|
71
104
|
|
|
72
105
|
interface PaginateResult<T> {
|
|
@@ -85,53 +118,6 @@ declare module 'mongoose' {
|
|
|
85
118
|
totalPages: number;
|
|
86
119
|
}
|
|
87
120
|
|
|
88
|
-
type PaginateDocument<
|
|
89
|
-
T,
|
|
90
|
-
TMethods,
|
|
91
|
-
TQueryHelpers,
|
|
92
|
-
O extends PaginateOptions = object,
|
|
93
|
-
> = IfElse<
|
|
94
|
-
O['lean'],
|
|
95
|
-
IfElse<
|
|
96
|
-
O['leanWithId'],
|
|
97
|
-
T & { id: string },
|
|
98
|
-
IfElse<
|
|
99
|
-
O['leanWithVirtuals'],
|
|
100
|
-
T & { [key: string]: any },
|
|
101
|
-
T
|
|
102
|
-
>
|
|
103
|
-
>,
|
|
104
|
-
HydratedDocument<T, TMethods, TQueryHelpers>
|
|
105
|
-
>;
|
|
106
|
-
|
|
107
|
-
interface PaginateModel<T, TQueryHelpers = object, TMethods = object> extends Model<T, TQueryHelpers, TMethods> {
|
|
108
|
-
paginate: {
|
|
109
|
-
<O extends PaginateOptions>(
|
|
110
|
-
query?: FilterQuery<T>,
|
|
111
|
-
options?: O,
|
|
112
|
-
callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>) => void
|
|
113
|
-
): Promise<PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>>;
|
|
114
|
-
|
|
115
|
-
<UserType = T, O extends PaginateOptions = PaginateOptions>(
|
|
116
|
-
query?: FilterQuery<T>,
|
|
117
|
-
options?: O,
|
|
118
|
-
callback?: (
|
|
119
|
-
err: any,
|
|
120
|
-
result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>
|
|
121
|
-
) => void
|
|
122
|
-
): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>>;
|
|
123
|
-
|
|
124
|
-
<UserType = T>(
|
|
125
|
-
query?: FilterQuery<T>,
|
|
126
|
-
options?: PaginateOptions,
|
|
127
|
-
callback?: (
|
|
128
|
-
err: any,
|
|
129
|
-
result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>
|
|
130
|
-
) => void
|
|
131
|
-
): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>>;
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
121
|
// @ts-expect-error Ignore this error.
|
|
136
122
|
interface Query<
|
|
137
123
|
ResultType,
|
|
@@ -155,6 +141,20 @@ declare module 'mongoose' {
|
|
|
155
141
|
>;
|
|
156
142
|
};
|
|
157
143
|
}
|
|
144
|
+
|
|
145
|
+
interface SubDocumentPagingOptions {
|
|
146
|
+
limit?: number;
|
|
147
|
+
page?: number;
|
|
148
|
+
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
interface SubPaginateOptions {
|
|
152
|
+
pagination?: boolean;
|
|
153
|
+
pagingOptions?: SubDocumentPagingOptions;
|
|
154
|
+
populate?: PopulateOptions | PopulateOptions[] | string | string[];
|
|
155
|
+
read?: PaginateReadOptions;
|
|
156
|
+
select?: object | string;
|
|
157
|
+
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
declare function _(schema: Schema): void;
|
package/src/utils.ts
CHANGED
|
@@ -78,7 +78,10 @@ export function buildMongooseModel<
|
|
|
78
78
|
schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,
|
|
79
79
|
options?: BuildMongooseModelOptions,
|
|
80
80
|
) {
|
|
81
|
-
if (options?.enableNormalizePlugin !== false)
|
|
81
|
+
if (options?.enableNormalizePlugin !== false) {
|
|
82
|
+
schema.plugin(mongooseNormalizePlugin, options?.normalizePluginOptions);
|
|
83
|
+
}
|
|
84
|
+
|
|
82
85
|
schema.plugin(mongooseAggregatePaginate);
|
|
83
86
|
schema.plugin(mongoosePaginate);
|
|
84
87
|
schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);
|