@kikiutils/mongoose 0.6.0 → 1.0.0-rc.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 CHANGED
@@ -1,5 +1,49 @@
1
1
  # @kikiutils/mongoose
2
2
 
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![License][license-src]][license-href]
6
+
3
7
  For mongoose v8 types and utils.
4
8
 
9
+ - [✨ Release Notes](/CHANGELOG.md)
10
+
11
+ ## Features
12
+
13
+ - Enhanced `toJSON` method with normalization functions, auto-converts `_id` to `id`, and more.
14
+ - Commonly used schema settings for fast schema creation.
15
+ - Automatic timestamp field settings.
16
+ - Pre-registered `mongoose-paginate-v2` and `mongoose-aggregate-paginate-v2` plugins.
17
+ - Automatic Decimal128 field conversion and processing.
18
+ - TypeScript support.
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ # Using pnpm
24
+ pnpm add @kikiutils/mongoose
25
+
26
+ # Using yarn
27
+ yarn add @kikiutils/mongoose
28
+
29
+ # Using npm
30
+ npm install @kikiutils/mongoose
31
+ ```
32
+
33
+ ## Environmental Requirements
34
+
35
+ - ESM only
36
+ - Mongoose v8
37
+ - NodeJS 18 or higher
38
+
5
39
  **Detailed documentation will be added in future releases.**
40
+
41
+ <!-- Badges -->
42
+ [npm-version-src]: https://img.shields.io/npm/v/@kikiutils/mongoose/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
43
+ [npm-version-href]: https://npmjs.com/package/@kikiutils/mongoose
44
+
45
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@kikiutils/mongoose.svg?style=flat&colorA=18181B&colorB=28CF8D
46
+ [npm-downloads-href]: https://npmjs.com/package/@kikiutils/mongoose
47
+
48
+ [license-src]: https://img.shields.io/npm/l/@kikiutils/mongoose.svg?style=flat&colorA=18181B&colorB=28CF8D
49
+ [license-href]: https://npmjs.com/package/@kikiutils/mongoose
package/constants.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /// <reference path="types/paginate/aggregate.d.ts" />
2
+ /// <reference path="types/paginate/index.d.ts" />
1
3
  /// <reference types="mongoose/types/aggregate" />
2
4
  /// <reference types="mongoose/types/callback" />
3
5
  /// <reference types="mongoose/types/collection" />
@@ -22,7 +24,7 @@
22
24
  /// <reference types="mongoose/types/validation" />
23
25
  /// <reference types="mongoose/types/virtuals" />
24
26
  /// <reference types="mongoose/types/inferschematype" />
25
- /// <reference types="mongoose-paginate-v2" />
27
+ /// <reference types="mongoose/types/inferrawdoctype" />
26
28
  import type { Connection } from 'mongoose';
27
29
  export declare const commonMongooseSchemas: {
28
30
  readonly boolean: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
- "version": "0.6.0",
3
+ "version": "1.0.0-rc.1",
4
4
  "license": "MIT",
5
5
  "author": "kiki-kanri",
6
6
  "repository": {
@@ -15,8 +15,9 @@
15
15
  "dependencies": {
16
16
  "decimal.js": "^10.4.3",
17
17
  "lodash-es": "^4.17.21",
18
- "mongoose": "^8.3.5",
19
- "mongoose-paginate-v2": "^1.8.0"
18
+ "mongoose": "^8.4.0",
19
+ "mongoose-aggregate-paginate-v2": "^1.0.7",
20
+ "mongoose-paginate-v2": "^1.8.1"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@kikiutils/prettierrc": "^1.3.1",
@@ -1,3 +1,5 @@
1
+ /// <reference path="../types/paginate/aggregate.d.ts" />
2
+ /// <reference path="../types/paginate/index.d.ts" />
1
3
  /// <reference types="mongoose/types/aggregate" />
2
4
  /// <reference types="mongoose/types/callback" />
3
5
  /// <reference types="mongoose/types/collection" />
@@ -22,7 +24,7 @@
22
24
  /// <reference types="mongoose/types/validation" />
23
25
  /// <reference types="mongoose/types/virtuals" />
24
26
  /// <reference types="mongoose/types/inferschematype" />
25
- /// <reference types="mongoose-paginate-v2" />
27
+ /// <reference types="mongoose/types/inferrawdoctype" />
26
28
  import type { Schema } from 'mongoose';
27
29
  export declare const mongooseNormalizePlugin: <S extends Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, {
28
30
  [x: string]: unknown;
package/types/data.d.ts CHANGED
@@ -9,8 +9,61 @@ type OmitNever<T> = {
9
9
  [P in keyof T as T[P] extends never ? never : P]: T[P];
10
10
  };
11
11
  declare global {
12
+ /**
13
+ * Global type for base mongoose model data.
14
+ *
15
+ * @example
16
+ * interface UserData extends BaseMongooseModelData {
17
+ * account: string;
18
+ * name: string;
19
+ * }
20
+ *
21
+ * // Resulting type:
22
+ * // {
23
+ * // account: string;
24
+ * // createdAt: string;
25
+ * // id: string;
26
+ * // name: string;
27
+ * // updatedAt: string;
28
+ * // }
29
+ */
12
30
  type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = OmitNever<_BaseMongooseModelData<CreatedAtField, UpdatedAtField>>;
31
+ /**
32
+ * Global type to omit timestamp fields and optionally other fields from a given type.
33
+ *
34
+ * @example
35
+ * interface UserData extends BaseMongooseModelData {
36
+ * account: string;
37
+ * name: string;
38
+ * }
39
+ *
40
+ * type UserDataWithoutTimestamps = OmitMongooseTimestampAndOtherFields<UserData>;
41
+ *
42
+ * // Resulting type:
43
+ * // {
44
+ * // account: string;
45
+ * // id: string;
46
+ * // name: string;
47
+ * // }
48
+ */
13
49
  type OmitMongooseTimestampAndOtherFields<T, OT extends number | symbol | string = ''> = Omit<T, 'createdAt' | 'updatedAt' | OT>;
50
+ /**
51
+ * Global type for handling optional timestamp fields.
52
+ *
53
+ * @example
54
+ * interface UserLogData extends WithMongooseTimestampFieldsData<true, false> {
55
+ * content: string;
56
+ * type: number;
57
+ * }
58
+ *
59
+ * // Resulting type:
60
+ * // {
61
+ * // content: string;
62
+ * // createdAt: string;
63
+ * // type: number;
64
+ * // }
65
+ * }
66
+ */
14
67
  type WithMongooseTimestampFieldsData<CreatedAt extends boolean = true, UpdatedAt extends boolean = true> = OmitNever<_WithTimestampFieldsData<CreatedAt, UpdatedAt>>;
15
68
  }
16
69
  export {};
package/types/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /// <reference path="paginate/aggregate.d.ts" />
2
+ /// <reference path="paginate/index.d.ts" />
1
3
  /// <reference types="mongoose/types/aggregate" />
2
4
  /// <reference types="mongoose/types/callback" />
3
5
  /// <reference types="mongoose/types/collection" />
@@ -22,8 +24,8 @@
22
24
  /// <reference types="mongoose/types/validation" />
23
25
  /// <reference types="mongoose/types/virtuals" />
24
26
  /// <reference types="mongoose/types/inferschematype" />
25
- import type { HydratedDocument, PaginateModel, QueryWithHelpers, Types } from 'mongoose';
26
- export {} from 'mongoose-paginate-v2';
27
+ /// <reference types="mongoose/types/inferrawdoctype" />
28
+ import type { AggregatePaginateModel, HydratedDocument, PaginateModel, QueryWithHelpers, Types } from 'mongoose';
27
29
  export interface BaseModelStatics<RawDocType, InstanceMethodsAndOverrides = {}, QueryHelpers = {}> {
28
30
  }
29
31
  declare global {
@@ -32,7 +34,7 @@ declare global {
32
34
  } : {}) & (UpdatedAtField extends true ? {
33
35
  updatedAt: Date;
34
36
  } : {});
35
- type BaseMongoosePaginateModel<RawDocType, InstanceMethodsAndOverrides = {}, QueryHelpers = {}> = PaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> & BaseModelStatics<RawDocType, InstanceMethodsAndOverrides, QueryHelpers>;
37
+ type BaseMongoosePaginateModel<RawDocType, InstanceMethodsAndOverrides = {}, QueryHelpers = {}> = AggregatePaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> & PaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> & BaseModelStatics<RawDocType, InstanceMethodsAndOverrides, QueryHelpers>;
36
38
  type MongooseDocumentOrObjectId<D> = D | string | Types.ObjectId;
37
39
  type MongooseFindOneReturnType<RawDocType, DocType, QueryHelpers = {}> = QueryWithHelpers<DocType | null, DocType, QueryHelpers, RawDocType, 'findOne'>;
38
40
  type MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides = {}, QueryHelpers = {}> = HydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>;
package/types/index.mjs CHANGED
@@ -1 +1 @@
1
- export {} from 'mongoose-paginate-v2';
1
+ export {};
@@ -1,3 +1,5 @@
1
+ /// <reference path="paginate/aggregate.d.ts" />
2
+ /// <reference path="paginate/index.d.ts" />
1
3
  /// <reference types="mongoose/types/aggregate" />
2
4
  /// <reference types="mongoose/types/callback" />
3
5
  /// <reference types="mongoose/types/collection" />
@@ -22,7 +24,7 @@
22
24
  /// <reference types="mongoose/types/validation" />
23
25
  /// <reference types="mongoose/types/virtuals" />
24
26
  /// <reference types="mongoose/types/inferschematype" />
25
- /// <reference types="mongoose-paginate-v2" />
27
+ /// <reference types="mongoose/types/inferrawdoctype" />
26
28
  import type { Connection, SchemaTimestampsConfig } from 'mongoose';
27
29
  export interface BuildMongooseModelOptions {
28
30
  connection?: Connection;
@@ -0,0 +1,91 @@
1
+ /// <reference path="index.d.ts" />
2
+ /// <reference types="mongoose/types/aggregate" />
3
+ /// <reference types="mongoose/types/callback" />
4
+ /// <reference types="mongoose/types/collection" />
5
+ /// <reference types="mongoose/types/connection" />
6
+ /// <reference types="mongoose/types/cursor" />
7
+ /// <reference types="mongoose/types/document" />
8
+ /// <reference types="mongoose/types/error" />
9
+ /// <reference types="mongoose/types/expressions" />
10
+ /// <reference types="mongoose/types/helpers" />
11
+ /// <reference types="mongoose/types/middlewares" />
12
+ /// <reference types="mongoose/types/indexes" />
13
+ /// <reference types="mongoose/types/models" />
14
+ /// <reference types="mongoose/types/mongooseoptions" />
15
+ /// <reference types="mongoose/types/pipelinestage" />
16
+ /// <reference types="mongoose/types/populate" />
17
+ /// <reference types="mongoose/types/query" />
18
+ /// <reference types="mongoose/types/schemaoptions" />
19
+ /// <reference types="mongoose/types/schematypes" />
20
+ /// <reference types="mongoose/types/session" />
21
+ /// <reference types="mongoose/types/types" />
22
+ /// <reference types="mongoose/types/utility" />
23
+ /// <reference types="mongoose/types/validation" />
24
+ /// <reference types="mongoose/types/virtuals" />
25
+ /// <reference types="mongoose/types/inferschematype" />
26
+ /// <reference types="mongoose/types/inferrawdoctype" />
27
+ import type { AggregatePaginateOptions, Schema } from 'mongoose';
28
+ declare module 'mongoose' {
29
+ interface AggregateCustomLabels<T = string | undefined | boolean> {
30
+ totalDocs?: T;
31
+ docs?: T;
32
+ limit?: T;
33
+ page?: T;
34
+ nextPage?: T;
35
+ prevPage?: T;
36
+ hasNextPage?: T;
37
+ hasPrevPage?: T;
38
+ totalPages?: T;
39
+ pagingCounter?: T;
40
+ meta?: T;
41
+ }
42
+ interface AggregatePaginateOptions {
43
+ sort?: object | string;
44
+ offset?: number;
45
+ page?: number;
46
+ limit?: number;
47
+ customLabels?: AggregateCustomLabels;
48
+ pagination?: boolean;
49
+ allowDiskUse?: boolean;
50
+ countQuery?: object;
51
+ useFacet?: boolean;
52
+ }
53
+ interface AggregatePaginateQueryPopulateOptions {
54
+ /** space delimited path(s) to populate */
55
+ path: string;
56
+ /** optional fields to select */
57
+ select?: any;
58
+ /** optional query conditions to match */
59
+ match?: any;
60
+ /** optional model to use for population */
61
+ model?: string | Model<any> | undefined;
62
+ /** optional query options like sort, limit, etc */
63
+ options?: any;
64
+ /** deep populate */
65
+ populate?: AggregatePaginateQueryPopulateOptions | AggregatePaginateQueryPopulateOptions[] | undefined;
66
+ }
67
+ interface AggregatePaginateResult<T> {
68
+ docs: T[];
69
+ totalDocs: number;
70
+ limit: number;
71
+ page?: number;
72
+ totalPages: number;
73
+ nextPage?: number | null;
74
+ prevPage?: number | null;
75
+ pagingCounter: number;
76
+ hasPrevPage: boolean;
77
+ hasNextPage: boolean;
78
+ meta?: any;
79
+ [customLabel: string]: T[] | number | boolean | null | undefined;
80
+ }
81
+ interface AggregatePaginateModel<RawDocType, QueryHelpers = {}, InstanceMethodsAndOverrides = {}> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
82
+ aggregatePaginate<T>(query?: Aggregate<T[]>, options?: AggregatePaginateOptions, callback?: (err: any, result: AggregatePaginateResult<T>) => void): Promise<AggregatePaginateResult<T>>;
83
+ }
84
+ }
85
+ declare function mongooseAggregatePaginate(schema: Schema): void;
86
+ declare namespace mongooseAggregatePaginate {
87
+ const aggregatePaginate: {
88
+ options: AggregatePaginateOptions;
89
+ };
90
+ }
91
+ export default mongooseAggregatePaginate;
@@ -0,0 +1,7 @@
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
+ export default mongooseAggregatePaginate;
@@ -0,0 +1,123 @@
1
+ /// <reference path="aggregate.d.ts" />
2
+ /// <reference types="mongoose/types/aggregate" />
3
+ /// <reference types="mongoose/types/callback" />
4
+ /// <reference types="mongoose/types/collection" />
5
+ /// <reference types="mongoose/types/connection" />
6
+ /// <reference types="mongoose/types/cursor" />
7
+ /// <reference types="mongoose/types/document" />
8
+ /// <reference types="mongoose/types/error" />
9
+ /// <reference types="mongoose/types/expressions" />
10
+ /// <reference types="mongoose/types/helpers" />
11
+ /// <reference types="mongoose/types/middlewares" />
12
+ /// <reference types="mongoose/types/indexes" />
13
+ /// <reference types="mongoose/types/models" />
14
+ /// <reference types="mongoose/types/mongooseoptions" />
15
+ /// <reference types="mongoose/types/pipelinestage" />
16
+ /// <reference types="mongoose/types/populate" />
17
+ /// <reference types="mongoose/types/query" />
18
+ /// <reference types="mongoose/types/schemaoptions" />
19
+ /// <reference types="mongoose/types/schematypes" />
20
+ /// <reference types="mongoose/types/session" />
21
+ /// <reference types="mongoose/types/types" />
22
+ /// <reference types="mongoose/types/utility" />
23
+ /// <reference types="mongoose/types/validation" />
24
+ /// <reference types="mongoose/types/virtuals" />
25
+ /// <reference types="mongoose/types/inferschematype" />
26
+ /// <reference types="mongoose/types/inferrawdoctype" />
27
+ import type { FilterQuery, mongo, PaginateOptions, Schema } from 'mongoose';
28
+ declare module 'mongoose' {
29
+ interface PaginateCustomLabels<T = string | undefined | boolean> {
30
+ totalDocs?: T;
31
+ docs?: T;
32
+ limit?: T;
33
+ page?: T;
34
+ nextPage?: T;
35
+ prevPage?: T;
36
+ hasNextPage?: T;
37
+ hasPrevPage?: T;
38
+ totalPages?: T;
39
+ pagingCounter?: T;
40
+ meta?: T;
41
+ }
42
+ interface PaginateReadOptions {
43
+ pref: string;
44
+ tags?: any[];
45
+ }
46
+ interface PaginateOptions {
47
+ select?: object | string;
48
+ collation?: mongo.CollationOptions;
49
+ sort?: object | string;
50
+ populate?: PopulateOptions[] | string[] | PopulateOptions | string | PopulateOptions;
51
+ projection?: any;
52
+ lean?: boolean;
53
+ leanWithId?: boolean;
54
+ offset?: number;
55
+ page?: number;
56
+ limit?: number;
57
+ customLabels?: PaginateCustomLabels;
58
+ pagination?: boolean;
59
+ useEstimatedCount?: boolean;
60
+ useCustomCountFn?: () => Promise<number>;
61
+ forceCountFn?: boolean;
62
+ allowDiskUse?: boolean;
63
+ read?: PaginateReadOptions;
64
+ options?: QueryOptions;
65
+ }
66
+ interface SubPaginateOptions {
67
+ select?: object | string;
68
+ populate?: PopulateOptions[] | string[] | PopulateOptions | string | PopulateOptions;
69
+ pagination?: boolean;
70
+ read?: PaginateReadOptions;
71
+ pagingOptions: SubDocumentPagingOptions | undefined;
72
+ }
73
+ interface SubDocumentPagingOptions {
74
+ populate?: PopulateOptions[] | string[] | PopulateOptions | string | PopulateOptions;
75
+ page?: number;
76
+ limit?: number;
77
+ }
78
+ interface PaginateResult<T> {
79
+ docs: T[];
80
+ totalDocs: number;
81
+ limit: number;
82
+ hasPrevPage: boolean;
83
+ hasNextPage: boolean;
84
+ page?: number;
85
+ totalPages: number;
86
+ offset: number;
87
+ prevPage?: number | null;
88
+ nextPage?: number | null;
89
+ pagingCounter: number;
90
+ meta?: any;
91
+ [customLabel: string]: T[] | number | boolean | null | undefined;
92
+ }
93
+ type PaginateDocument<T, TMethods, TVirtuals, O extends PaginateOptions = {}> = O['lean'] extends true ? (O['leanWithId'] extends true ? T & {
94
+ id: string;
95
+ } : T) : HydratedDocument<T, TMethods, TVirtuals>;
96
+ interface PaginateModel<T, TQueryHelpers = {}, TMethods = {}> extends Model<T, TQueryHelpers, TMethods> {
97
+ paginate<O extends PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, O>>) => void): Promise<PaginateResult<PaginateDocument<T, TMethods, O>>>;
98
+ }
99
+ interface PaginateModel<T, TQueryHelpers = {}, TMethods = {}> extends Model<T, TQueryHelpers, TMethods> {
100
+ paginate<UserType = T, O extends PaginateOptions = PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, O>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, O>>>;
101
+ }
102
+ interface PaginateModel<T, TQueryHelpers = {}, TMethods = {}> extends Model<T, TQueryHelpers, TMethods> {
103
+ paginate<UserType = T>(query?: FilterQuery<T>, options?: PaginateOptions, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, PaginateOptions>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, PaginateOptions>>>;
104
+ }
105
+ }
106
+ declare function _(schema: Schema): void;
107
+ declare namespace _ {
108
+ const paginate: {
109
+ options: PaginateOptions;
110
+ };
111
+ const paginateSubDocs: {
112
+ options: PaginateOptions;
113
+ };
114
+ class PaginationParameters<T, O extends PaginateOptions> {
115
+ constructor(request: {
116
+ query?: Record<string, any>;
117
+ });
118
+ get: () => [FilterQuery<T>, O];
119
+ getOptions: () => O;
120
+ getQuery: () => FilterQuery<T>;
121
+ }
122
+ }
123
+ export default _;
@@ -0,0 +1 @@
1
+ export default _;
package/types/schema.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /// <reference path="paginate/aggregate.d.ts" />
2
+ /// <reference path="paginate/index.d.ts" />
1
3
  /// <reference types="mongoose/types/aggregate" />
2
4
  /// <reference types="mongoose/types/callback" />
3
5
  /// <reference types="mongoose/types/collection" />
@@ -22,18 +24,25 @@
22
24
  /// <reference types="mongoose/types/validation" />
23
25
  /// <reference types="mongoose/types/virtuals" />
24
26
  /// <reference types="mongoose/types/inferschematype" />
25
- /// <reference types="mongoose-paginate-v2" />
27
+ /// <reference types="mongoose/types/inferrawdoctype" />
26
28
  import type Decimal from 'decimal.js';
27
29
  import type { ObjectIdSchemaDefinition, SchemaTypeOptions, StringSchemaDefinition, Types } from 'mongoose';
28
30
  export type BaseSchemaAttribute = 'private' | 'required' | 'unique';
29
31
  export type MongooseStringSchemaAttribute = BaseSchemaAttribute | 'lowercase' | 'short' | 'trim' | 'uppercase';
30
32
  export interface CreateCommonMongooseSchemasOptions {
33
+ /**
34
+ * Options for auto-rounding and fixing decimal places for Decimal128 fields.
35
+ */
31
36
  autoRoundAndToFixedDecimal128?: {
32
37
  /**
38
+ * Number of decimal places to round to.
39
+ *
33
40
  * @default 2
34
41
  */
35
42
  places?: number;
36
43
  /**
44
+ * Rounding strategy to use.
45
+ *
37
46
  * @default Decimal.ROUND_DOWN
38
47
  */
39
48
  rounding?: Decimal.Rounding;
package/utils.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /// <reference path="types/paginate/aggregate.d.ts" />
2
+ /// <reference path="types/paginate/index.d.ts" />
1
3
  /// <reference types="mongoose/types/aggregate" />
2
4
  /// <reference types="mongoose/types/callback" />
3
5
  /// <reference types="mongoose/types/collection" />
@@ -22,7 +24,7 @@
22
24
  /// <reference types="mongoose/types/validation" />
23
25
  /// <reference types="mongoose/types/virtuals" />
24
26
  /// <reference types="mongoose/types/inferschematype" />
25
- /// <reference types="mongoose-paginate-v2" />
27
+ /// <reference types="mongoose/types/inferrawdoctype" />
26
28
  import mongoose from 'mongoose';
27
29
  import type { BuildMongooseModelOptions } from './types/options';
28
30
  import type { BaseSchemaAttribute, CreateCommonMongooseSchemasOptions, MongooseObjectIdRefSchema, MongooseStringSchema, MongooseStringSchemaAttribute } from './types/schema';
package/utils.mjs CHANGED
@@ -2,12 +2,14 @@ import Decimal from 'decimal.js';
2
2
  import { merge } from 'lodash-es';
3
3
  import mongoose from 'mongoose';
4
4
  import { Types } from 'mongoose';
5
+ import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
5
6
  import mongoosePaginate from 'mongoose-paginate-v2';
6
7
  import { mongooseConnections } from "./constants.mjs";
7
8
  import mongooseNormalizePlugin from "./plugins/normalize.mjs";
8
9
  export const buildMongooseModel = (collection, name, schema, options) => {
9
10
  if (options?.enableNormalizePlugin !== false)
10
11
  schema.plugin(mongooseNormalizePlugin);
12
+ schema.plugin(mongooseAggregatePaginate);
11
13
  schema.plugin(mongoosePaginate);
12
14
  schema.set('timestamps', options?.timestamps === undefined ? true : options.timestamps);
13
15
  return (options?.connection || mongooseConnections.default || (mongooseConnections.default = mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://localhost:27017'))).model(name, schema, collection);