@kikiutils/mongoose 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
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
  "license": "MIT",
6
6
  "author": "kiki-kanri",
@@ -9,24 +9,25 @@
9
9
  "url": "git+https://github.com/kiki-kanri/kikiutils-node-mongoose.git"
10
10
  },
11
11
  "scripts": {
12
- "build": "ts-project-builder ./src/constants.ts ./src/utils.ts --clean --preserve-modules",
13
- "bumplog": "changelogen --bump"
12
+ "build": "ts-project-builder ./src/constants.ts ./src/schema-builders/index.ts ./src/utils.ts --clean --preserve-modules",
13
+ "bumplog": "changelogen --bump",
14
+ "release": "pnpm run build && changelogen --push --release && sh ./build-and-publish.sh"
14
15
  },
15
16
  "dependencies": {
16
17
  "decimal.js": "^10.4.3",
17
18
  "lodash": "^4.17.21",
18
- "mongoose": "^8.7.0",
19
+ "mongoose": "^8.7.2",
19
20
  "mongoose-aggregate-paginate-v2": "^1.1.2",
20
21
  "mongoose-paginate-v2": "^1.8.5"
21
22
  },
22
23
  "devDependencies": {
24
+ "@kikiutils/changelogen": "^0.7.0",
23
25
  "@kikiutils/prettierrc": "^1.3.2",
24
26
  "@kikiutils/tsconfigs": "^3.0.1",
25
- "@types/lodash": "^4.17.9",
26
- "@types/node": "^22.7.4",
27
- "changelogen": "^0.5.7",
28
- "ts-project-builder": "^3.0.1",
29
- "tslib": "^2.7.0"
27
+ "@types/lodash": "^4.17.12",
28
+ "@types/node": "^22.7.8",
29
+ "ts-project-builder": "^3.3.0",
30
+ "tslib": "^2.8.0"
30
31
  },
31
32
  "keywords": [
32
33
  "Decimal128",
@@ -39,7 +40,7 @@
39
40
  "schema"
40
41
  ],
41
42
  "engines": {
42
- "node": ">=18"
43
+ "node": ">=18.12.1"
43
44
  },
44
45
  "exports": {
45
46
  "./*": {
@@ -52,10 +53,10 @@
52
53
  "require": null,
53
54
  "types": null
54
55
  },
55
- "./plugins/*": {
56
- "import": "./plugins/*.mjs",
57
- "require": "./plugins/*.cjs",
58
- "types": "./plugins/*.d.ts"
56
+ "./schema-builders": {
57
+ "import": "./schema-builders/index.mjs",
58
+ "require": "./schema-builders/index.cjs",
59
+ "types": "./schema-builders/index.d.ts"
59
60
  },
60
61
  "./types": {
61
62
  "types": "./types/index.d.ts"
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ const createSchemaBuilder = (type) => {
4
+ return () => {
5
+ const schema = { type };
6
+ return new Proxy(Object.freeze({}), {
7
+ get(_, key, receiver) {
8
+ if (typeof key === 'symbol')
9
+ throw new Error('Cannot use symbol as a schema attribute');
10
+ if (key in schema)
11
+ throw new Error(`Duplicate schema attribute: ${key}`);
12
+ if (isFunctionKeys.has(key))
13
+ return (value) => ((schema[key] = value), receiver);
14
+ if (key === 'length')
15
+ return (value) => ((schema['maxlength'] = schema['minlength'] = value), receiver);
16
+ if (key === 'nonRequired')
17
+ return schema;
18
+ if (key === 'required')
19
+ return { ...schema, required: true };
20
+ schema[key] = true;
21
+ return receiver;
22
+ }
23
+ });
24
+ };
25
+ };
26
+ const isFunctionKeys = new Set([
27
+ 'default',
28
+ 'enum',
29
+ 'max',
30
+ 'maxlength',
31
+ 'min',
32
+ 'minlength'
33
+ ]);
34
+
35
+ exports.createSchemaBuilder = createSchemaBuilder;
@@ -0,0 +1 @@
1
+ export declare const createSchemaBuilder: <Builder>(type: BooleanConstructor | DateConstructor | NumberConstructor | StringConstructor) => () => Builder;
@@ -0,0 +1,33 @@
1
+ const createSchemaBuilder = (type) => {
2
+ return () => {
3
+ const schema = { type };
4
+ return new Proxy(Object.freeze({}), {
5
+ get(_, key, receiver) {
6
+ if (typeof key === 'symbol')
7
+ throw new Error('Cannot use symbol as a schema attribute');
8
+ if (key in schema)
9
+ throw new Error(`Duplicate schema attribute: ${key}`);
10
+ if (isFunctionKeys.has(key))
11
+ return (value) => ((schema[key] = value), receiver);
12
+ if (key === 'length')
13
+ return (value) => ((schema['maxlength'] = schema['minlength'] = value), receiver);
14
+ if (key === 'nonRequired')
15
+ return schema;
16
+ if (key === 'required')
17
+ return { ...schema, required: true };
18
+ schema[key] = true;
19
+ return receiver;
20
+ }
21
+ });
22
+ };
23
+ };
24
+ const isFunctionKeys = new Set([
25
+ 'default',
26
+ 'enum',
27
+ 'max',
28
+ 'maxlength',
29
+ 'min',
30
+ 'minlength'
31
+ ]);
32
+
33
+ export { createSchemaBuilder };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ const base = require('./base.cjs');
4
+
5
+ const booleanSchemaBuilder = base.createSchemaBuilder(Boolean);
6
+
7
+ exports.booleanSchemaBuilder = booleanSchemaBuilder;
@@ -0,0 +1,50 @@
1
+ import type { BooleanSchemaDefinition, DefaultType } from 'mongoose';
2
+ type ExtendBooleanSchemaBuilder<Props> = Omit<BooleanSchemaBuilder<Props>, keyof Props>;
3
+ export interface BooleanSchemaBuilder<Props = {
4
+ type: BooleanSchemaDefinition;
5
+ }, PropsWithRequired = Props & {
6
+ required: true;
7
+ }> {
8
+ default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends boolean>(value: T) => ExtendBooleanSchemaBuilder<{
9
+ [key in keyof (Props & {
10
+ default: T;
11
+ })]: (Props & {
12
+ default: T;
13
+ })[key];
14
+ }>;
15
+ nonRequired: {
16
+ [key in keyof Props]: Props[key];
17
+ };
18
+ private: ExtendBooleanSchemaBuilder<{
19
+ [key in keyof (Props & {
20
+ private: true;
21
+ })]: (Props & {
22
+ private: true;
23
+ })[key];
24
+ }>;
25
+ required: {
26
+ [key in keyof PropsWithRequired]: PropsWithRequired[key];
27
+ };
28
+ sparse: ExtendBooleanSchemaBuilder<{
29
+ [key in keyof (Props & {
30
+ sparse: true;
31
+ })]: (Props & {
32
+ sparse: true;
33
+ })[key];
34
+ }>;
35
+ unique: ExtendBooleanSchemaBuilder<{
36
+ [key in keyof (Props & {
37
+ unique: true;
38
+ })]: (Props & {
39
+ unique: true;
40
+ })[key];
41
+ }>;
42
+ }
43
+ export declare const booleanSchemaBuilder: () => BooleanSchemaBuilder<{
44
+ type: BooleanSchemaDefinition;
45
+ }, {
46
+ type: BooleanSchemaDefinition;
47
+ } & {
48
+ required: true;
49
+ }>;
50
+ export {};
@@ -0,0 +1,5 @@
1
+ import { createSchemaBuilder } from './base.mjs';
2
+
3
+ const booleanSchemaBuilder = createSchemaBuilder(Boolean);
4
+
5
+ export { booleanSchemaBuilder };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ const base = require('./base.cjs');
4
+
5
+ const dateSchemaBuilder = base.createSchemaBuilder(Date);
6
+
7
+ exports.dateSchemaBuilder = dateSchemaBuilder;
@@ -0,0 +1,77 @@
1
+ import type { DefaultType, DateSchemaDefinition } from 'mongoose';
2
+ import type { MaybeReadonly } from '../types/utils';
3
+ type ExtendDateSchemaBuilder<Props> = Omit<DateSchemaBuilder<Props>, keyof Props>;
4
+ export interface DateSchemaBuilder<Props = {
5
+ type: DateSchemaDefinition;
6
+ }, PropsWithRequired = Props & {
7
+ required: true;
8
+ }> {
9
+ default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends NativeDate>(value: T) => ExtendDateSchemaBuilder<{
10
+ [key in keyof (Props & {
11
+ default: T;
12
+ })]: (Props & {
13
+ default: T;
14
+ })[key];
15
+ }>;
16
+ enum: <T extends MaybeReadonly<Array<D | null>> | {
17
+ message?: M;
18
+ values: MaybeReadonly<Array<D | null>>;
19
+ } | {
20
+ [path: string]: D | null;
21
+ }, D extends NativeDate, M extends string>(value: T) => ExtendDateSchemaBuilder<{
22
+ [key in keyof (Props & {
23
+ enum: T;
24
+ })]: (Props & {
25
+ enum: T;
26
+ })[key];
27
+ }>;
28
+ max: <T extends D | MaybeReadonly<[D, S]>, D extends NativeDate, S extends string>(value: T) => ExtendDateSchemaBuilder<{
29
+ [key in keyof (Props & {
30
+ max: T;
31
+ })]: (Props & {
32
+ max: T;
33
+ })[key];
34
+ }>;
35
+ min: <T extends D | MaybeReadonly<[D, S]>, D extends NativeDate, S extends string>(value: T) => ExtendDateSchemaBuilder<{
36
+ [key in keyof (Props & {
37
+ min: T;
38
+ })]: (Props & {
39
+ min: T;
40
+ })[key];
41
+ }>;
42
+ nonRequired: {
43
+ [key in keyof Props]: Props[key];
44
+ };
45
+ private: ExtendDateSchemaBuilder<{
46
+ [key in keyof (Props & {
47
+ private: true;
48
+ })]: (Props & {
49
+ private: true;
50
+ })[key];
51
+ }>;
52
+ required: {
53
+ [key in keyof PropsWithRequired]: PropsWithRequired[key];
54
+ };
55
+ sparse: ExtendDateSchemaBuilder<{
56
+ [key in keyof (Props & {
57
+ sparse: true;
58
+ })]: (Props & {
59
+ sparse: true;
60
+ })[key];
61
+ }>;
62
+ unique: ExtendDateSchemaBuilder<{
63
+ [key in keyof (Props & {
64
+ unique: true;
65
+ })]: (Props & {
66
+ unique: true;
67
+ })[key];
68
+ }>;
69
+ }
70
+ export declare const dateSchemaBuilder: () => DateSchemaBuilder<{
71
+ type: DateSchemaDefinition;
72
+ }, {
73
+ type: DateSchemaDefinition;
74
+ } & {
75
+ required: true;
76
+ }>;
77
+ export {};
@@ -0,0 +1,5 @@
1
+ import { createSchemaBuilder } from './base.mjs';
2
+
3
+ const dateSchemaBuilder = createSchemaBuilder(Date);
4
+
5
+ export { dateSchemaBuilder };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const date = require('./date.cjs');
6
+ const boolean = require('./boolean.cjs');
7
+ const number = require('./number.cjs');
8
+ const string = require('./string.cjs');
9
+
10
+ const schemaBuilders = {
11
+ date: date.dateSchemaBuilder,
12
+ boolean: boolean.booleanSchemaBuilder,
13
+ number: number.numberSchemaBuilder,
14
+ string: string.stringSchemaBuilder
15
+ };
16
+
17
+ exports.dateSchemaBuilder = date.dateSchemaBuilder;
18
+ exports.booleanSchemaBuilder = boolean.booleanSchemaBuilder;
19
+ exports.numberSchemaBuilder = number.numberSchemaBuilder;
20
+ exports.stringSchemaBuilder = string.stringSchemaBuilder;
21
+ exports.default = schemaBuilders;
22
+ exports.schemaBuilders = schemaBuilders;
@@ -0,0 +1,35 @@
1
+ export * from './date';
2
+ export * from './boolean';
3
+ export * from './number';
4
+ export * from './string';
5
+ export declare const schemaBuilders: {
6
+ date: () => import("./date").DateSchemaBuilder<{
7
+ type: import("mongoose").DateSchemaDefinition;
8
+ }, {
9
+ type: import("mongoose").DateSchemaDefinition;
10
+ } & {
11
+ required: true;
12
+ }>;
13
+ boolean: () => import("./boolean").BooleanSchemaBuilder<{
14
+ type: import("mongoose").BooleanSchemaDefinition;
15
+ }, {
16
+ type: import("mongoose").BooleanSchemaDefinition;
17
+ } & {
18
+ required: true;
19
+ }>;
20
+ number: () => import("./number").NumberSchemaBuilder<{
21
+ type: import("mongoose").NumberSchemaDefinition;
22
+ }, {
23
+ type: import("mongoose").NumberSchemaDefinition;
24
+ } & {
25
+ required: true;
26
+ }>;
27
+ string: () => import("./string").StringSchemaBuilder<{
28
+ type: import("mongoose").StringSchemaDefinition;
29
+ }, {
30
+ type: import("mongoose").StringSchemaDefinition;
31
+ } & {
32
+ required: true;
33
+ }>;
34
+ };
35
+ export default schemaBuilders;
@@ -0,0 +1,13 @@
1
+ import { dateSchemaBuilder } from './date.mjs';
2
+ import { booleanSchemaBuilder } from './boolean.mjs';
3
+ import { numberSchemaBuilder } from './number.mjs';
4
+ import { stringSchemaBuilder } from './string.mjs';
5
+
6
+ const schemaBuilders = {
7
+ date: dateSchemaBuilder,
8
+ boolean: booleanSchemaBuilder,
9
+ number: numberSchemaBuilder,
10
+ string: stringSchemaBuilder
11
+ };
12
+
13
+ export { booleanSchemaBuilder, dateSchemaBuilder, schemaBuilders as default, numberSchemaBuilder, schemaBuilders, stringSchemaBuilder };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ const base = require('./base.cjs');
4
+
5
+ const numberSchemaBuilder = base.createSchemaBuilder(Number);
6
+
7
+ exports.numberSchemaBuilder = numberSchemaBuilder;
@@ -0,0 +1,77 @@
1
+ import type { DefaultType, NumberSchemaDefinition } from 'mongoose';
2
+ import type { MaybeReadonly } from '../types/utils';
3
+ type ExtendNumberSchemaBuilder<Props> = Omit<NumberSchemaBuilder<Props>, keyof Props>;
4
+ export interface NumberSchemaBuilder<Props = {
5
+ type: NumberSchemaDefinition;
6
+ }, PropsWithRequired = Props & {
7
+ required: true;
8
+ }> {
9
+ default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends number>(value: T) => ExtendNumberSchemaBuilder<{
10
+ [key in keyof (Props & {
11
+ default: T;
12
+ })]: (Props & {
13
+ default: T;
14
+ })[key];
15
+ }>;
16
+ enum: <T extends MaybeReadonly<Array<N | null>> | {
17
+ message?: M;
18
+ values: MaybeReadonly<Array<N | null>>;
19
+ } | {
20
+ [path: string]: N | null;
21
+ }, M extends string, N extends number>(value: T) => ExtendNumberSchemaBuilder<{
22
+ [key in keyof (Props & {
23
+ enum: T;
24
+ })]: (Props & {
25
+ enum: T;
26
+ })[key];
27
+ }>;
28
+ max: <T extends N | MaybeReadonly<[N, S]>, N extends number, S extends string>(value: T) => ExtendNumberSchemaBuilder<{
29
+ [key in keyof (Props & {
30
+ max: T;
31
+ })]: (Props & {
32
+ max: T;
33
+ })[key];
34
+ }>;
35
+ min: <T extends N | MaybeReadonly<[N, S]>, N extends number, S extends string>(value: T) => ExtendNumberSchemaBuilder<{
36
+ [key in keyof (Props & {
37
+ min: T;
38
+ })]: (Props & {
39
+ min: T;
40
+ })[key];
41
+ }>;
42
+ nonRequired: {
43
+ [key in keyof Props]: Props[key];
44
+ };
45
+ private: ExtendNumberSchemaBuilder<{
46
+ [key in keyof (Props & {
47
+ private: true;
48
+ })]: (Props & {
49
+ private: true;
50
+ })[key];
51
+ }>;
52
+ required: {
53
+ [key in keyof PropsWithRequired]: PropsWithRequired[key];
54
+ };
55
+ sparse: ExtendNumberSchemaBuilder<{
56
+ [key in keyof (Props & {
57
+ sparse: true;
58
+ })]: (Props & {
59
+ sparse: true;
60
+ })[key];
61
+ }>;
62
+ unique: ExtendNumberSchemaBuilder<{
63
+ [key in keyof (Props & {
64
+ unique: true;
65
+ })]: (Props & {
66
+ unique: true;
67
+ })[key];
68
+ }>;
69
+ }
70
+ export declare const numberSchemaBuilder: () => NumberSchemaBuilder<{
71
+ type: NumberSchemaDefinition;
72
+ }, {
73
+ type: NumberSchemaDefinition;
74
+ } & {
75
+ required: true;
76
+ }>;
77
+ export {};
@@ -0,0 +1,5 @@
1
+ import { createSchemaBuilder } from './base.mjs';
2
+
3
+ const numberSchemaBuilder = createSchemaBuilder(Number);
4
+
5
+ export { numberSchemaBuilder };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ const base = require('./base.cjs');
4
+
5
+ const stringSchemaBuilder = base.createSchemaBuilder(String);
6
+
7
+ exports.stringSchemaBuilder = stringSchemaBuilder;
@@ -0,0 +1,114 @@
1
+ import type { DefaultType, StringSchemaDefinition } from 'mongoose';
2
+ import type { MaybeReadonly } from '../types/utils';
3
+ type ExtendStringSchemaBuilder<Props> = Omit<StringSchemaBuilder<Props>, keyof Props>;
4
+ export interface StringSchemaBuilder<Props = {
5
+ type: StringSchemaDefinition;
6
+ }, PropsWithRequired = Props & {
7
+ required: true;
8
+ }> {
9
+ default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends string>(value: T) => ExtendStringSchemaBuilder<{
10
+ [key in keyof (Props & {
11
+ default: T;
12
+ })]: (Props & {
13
+ default: T;
14
+ })[key];
15
+ }>;
16
+ enum: <T extends MaybeReadonly<Array<S | null>> | {
17
+ message?: M;
18
+ values: MaybeReadonly<Array<S | null>>;
19
+ } | {
20
+ [path: string]: S | null;
21
+ }, M extends string, S extends string>(value: T) => ExtendStringSchemaBuilder<{
22
+ [key in keyof (Props & {
23
+ enum: T;
24
+ })]: (Props & {
25
+ enum: T;
26
+ })[key];
27
+ }>;
28
+ length: <T extends L | MaybeReadonly<[L, S]>, L extends number, S extends string>(value: T) => ExtendStringSchemaBuilder<{
29
+ [key in keyof (Props & {
30
+ maxlength: T;
31
+ minlength: T;
32
+ })]: (Props & {
33
+ maxlength: T;
34
+ minlength: T;
35
+ })[key];
36
+ }>;
37
+ lowercase: ExtendStringSchemaBuilder<{
38
+ [key in keyof (Props & {
39
+ lowercase: true;
40
+ })]: (Props & {
41
+ lowercase: true;
42
+ })[key];
43
+ }>;
44
+ maxlength: <T extends L | MaybeReadonly<[L, S]>, L extends number, S extends string>(value: T) => ExtendStringSchemaBuilder<{
45
+ [key in keyof (Props & {
46
+ maxlength: T;
47
+ })]: (Props & {
48
+ maxlength: T;
49
+ })[key];
50
+ }>;
51
+ minlength: <T extends L | MaybeReadonly<[L, S]>, L extends number, S extends string>(value: T) => ExtendStringSchemaBuilder<{
52
+ [key in keyof (Props & {
53
+ minlength: T;
54
+ })]: (Props & {
55
+ minlength: T;
56
+ })[key];
57
+ }>;
58
+ nonRequired: {
59
+ [key in keyof Props]: Props[key];
60
+ };
61
+ private: ExtendStringSchemaBuilder<{
62
+ [key in keyof (Props & {
63
+ private: true;
64
+ })]: (Props & {
65
+ private: true;
66
+ })[key];
67
+ }>;
68
+ required: {
69
+ [key in keyof PropsWithRequired]: PropsWithRequired[key];
70
+ };
71
+ sparse: ExtendStringSchemaBuilder<{
72
+ [key in keyof (Props & {
73
+ sparse: true;
74
+ })]: (Props & {
75
+ sparse: true;
76
+ })[key];
77
+ }>;
78
+ text: ExtendStringSchemaBuilder<{
79
+ [key in keyof (Props & {
80
+ text: true;
81
+ })]: (Props & {
82
+ text: true;
83
+ })[key];
84
+ }>;
85
+ trim: ExtendStringSchemaBuilder<{
86
+ [key in keyof (Props & {
87
+ trim: true;
88
+ })]: (Props & {
89
+ trim: true;
90
+ })[key];
91
+ }>;
92
+ unique: ExtendStringSchemaBuilder<{
93
+ [key in keyof (Props & {
94
+ unique: true;
95
+ })]: (Props & {
96
+ unique: true;
97
+ })[key];
98
+ }>;
99
+ uppercase: ExtendStringSchemaBuilder<{
100
+ [key in keyof (Props & {
101
+ uppercase: true;
102
+ })]: (Props & {
103
+ uppercase: true;
104
+ })[key];
105
+ }>;
106
+ }
107
+ export declare const stringSchemaBuilder: () => StringSchemaBuilder<{
108
+ type: StringSchemaDefinition;
109
+ }, {
110
+ type: StringSchemaDefinition;
111
+ } & {
112
+ required: true;
113
+ }>;
114
+ export {};
@@ -0,0 +1,5 @@
1
+ import { createSchemaBuilder } from './base.mjs';
2
+
3
+ const stringSchemaBuilder = createSchemaBuilder(String);
4
+
5
+ export { stringSchemaBuilder };
@@ -32,7 +32,7 @@ declare module 'mongoose' {
32
32
  /** optional query conditions to match */
33
33
  match?: any;
34
34
  /** optional model to use for population */
35
- model?: string | Model<any> | undefined;
35
+ model?: string | Model<any>;
36
36
  /** optional query options like sort, limit, etc */
37
37
  options?: any;
38
38
  /** deep populate */
package/types/data.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * Interface for the base data of a Mongoose model, optionally including timestamp fields.
3
3
  *
4
- * This interface extends `_WithTimestampFieldsData` to optionally include `createdAt`
4
+ * This interface extends `LocalWithTimestampFieldsData` to optionally include `createdAt`
5
5
  * and `updatedAt` fields based on the `CreatedAtField` and `UpdatedAtField` flags.
6
6
  * It also includes a mandatory `id` field.
7
7
  *
8
8
  * @template CreatedAtField - A boolean flag indicating whether the `createdAt` field should be included.
9
9
  * @template UpdatedAtField - A boolean flag indicating whether the `updatedAt` field should be included.
10
10
  */
11
- interface _BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> extends _WithTimestampFieldsData<CreatedAtField, UpdatedAtField> {
11
+ interface LocalBaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> extends LocalWithTimestampFieldsData<CreatedAtField, UpdatedAtField> {
12
12
  id: string;
13
13
  }
14
14
  /**
@@ -21,7 +21,7 @@ interface _BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedA
21
21
  * @template CreatedAt - A boolean flag indicating whether the `createdAt` field should be included.
22
22
  * @template UpdatedAt - A boolean flag indicating whether the `updatedAt` field should be included.
23
23
  */
24
- interface _WithTimestampFieldsData<CreatedAt extends boolean = true, UpdatedAt extends boolean = true> {
24
+ interface LocalWithTimestampFieldsData<CreatedAt extends boolean = true, UpdatedAt extends boolean = true> {
25
25
  createdAt: CreatedAt extends true ? string : never;
26
26
  updatedAt: UpdatedAt extends true ? string : never;
27
27
  }
@@ -40,13 +40,13 @@ declare global {
40
40
  /**
41
41
  * Type definition for the base data of a Mongoose model, optionally including timestamp fields.
42
42
  *
43
- * This type alias uses `OmitNever` to remove any `never` properties from `_BaseMongooseModelData`
43
+ * This type alias uses `OmitNever` to remove any `never` properties from `LocalBaseMongooseModelData`
44
44
  * based on the presence of the `CreatedAtField` and `UpdatedAtField` flags.
45
45
  *
46
46
  * @template CreatedAtField - A boolean flag indicating whether the `createdAt` field should be included.
47
47
  * @template UpdatedAtField - A boolean flag indicating whether the `updatedAt` field should be included.
48
48
  */
49
- type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = OmitNever<_BaseMongooseModelData<CreatedAtField, UpdatedAtField>>;
49
+ type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = OmitNever<LocalBaseMongooseModelData<CreatedAtField, UpdatedAtField>>;
50
50
  /**
51
51
  * Type definition to omit timestamp fields and other specified fields from a given type.
52
52
  *
@@ -60,12 +60,12 @@ declare global {
60
60
  /**
61
61
  * Type definition for including timestamp fields conditionally based on the provided flags.
62
62
  *
63
- * This type alias uses `OmitNever` to remove any `never` properties from `_WithTimestampFieldsData`
63
+ * This type alias uses `OmitNever` to remove any `never` properties from `LocalWithTimestampFieldsData`
64
64
  * based on the presence of the `CreatedAt` and `UpdatedAt` flags.
65
65
  *
66
66
  * @template CreatedAt - A boolean flag indicating whether the `createdAt` field should be included.
67
67
  * @template UpdatedAt - A boolean flag indicating whether the `updatedAt` field should be included.
68
68
  */
69
- type WithMongooseTimestampFieldsData<CreatedAt extends boolean = true, UpdatedAt extends boolean = true> = OmitNever<_WithTimestampFieldsData<CreatedAt, UpdatedAt>>;
69
+ type WithMongooseTimestampFieldsData<CreatedAt extends boolean = true, UpdatedAt extends boolean = true> = OmitNever<LocalWithTimestampFieldsData<CreatedAt, UpdatedAt>>;
70
70
  }
71
71
  export {};
@@ -21,7 +21,7 @@ declare module 'mongoose' {
21
21
  select?: object | string;
22
22
  collation?: mongo.CollationOptions;
23
23
  sort?: object | string;
24
- populate?: PopulateOptions[] | string[] | PopulateOptions | string | PopulateOptions;
24
+ populate?: PopulateOptions[] | string[] | PopulateOptions | string;
25
25
  projection?: any;
26
26
  lean?: boolean;
27
27
  leanWithId?: boolean;
@@ -39,13 +39,13 @@ declare module 'mongoose' {
39
39
  }
40
40
  interface SubPaginateOptions {
41
41
  select?: object | string;
42
- populate?: PopulateOptions[] | string[] | PopulateOptions | string | PopulateOptions;
42
+ populate?: PopulateOptions[] | string[] | PopulateOptions | string;
43
43
  pagination?: boolean;
44
44
  read?: PaginateReadOptions;
45
45
  pagingOptions: SubDocumentPagingOptions | undefined;
46
46
  }
47
47
  interface SubDocumentPagingOptions {
48
- populate?: PopulateOptions[] | string[] | PopulateOptions | string | PopulateOptions;
48
+ populate?: PopulateOptions[] | string[] | PopulateOptions | string;
49
49
  page?: number;
50
50
  limit?: number;
51
51
  }
@@ -0,0 +1 @@
1
+ export type MaybeReadonly<T> = T | Readonly<T>;
package/utils.cjs CHANGED
@@ -93,6 +93,9 @@ function createCommonMongooseSchemas(customSchemas, options) {
93
93
  const baseRequiredNumber = { required: true, type: Number };
94
94
  const baseRequiredObjectId = { required: true, type: mongoose__default.Schema.Types.ObjectId };
95
95
  return merge({
96
+ /**
97
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.boolean} instead.
98
+ */
96
99
  boolean: {
97
100
  defaultFalse: {
98
101
  nonRequired: { default: false, type: Boolean },
@@ -113,6 +116,9 @@ function createCommonMongooseSchemas(customSchemas, options) {
113
116
  nonRequired: { type: mongoose__default.Schema.Types.Decimal128 },
114
117
  required: { required: true, type: mongoose__default.Schema.Types.Decimal128 }
115
118
  },
119
+ /**
120
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.number} instead.
121
+ */
116
122
  number: {
117
123
  nonRequired: { type: Number },
118
124
  required: baseRequiredNumber,
@@ -129,6 +135,9 @@ function createCommonMongooseSchemas(customSchemas, options) {
129
135
  required: { ...baseRequiredObjectId, unique: true }
130
136
  }
131
137
  },
138
+ /**
139
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.string} instead.
140
+ */
132
141
  string: {
133
142
  ipv4: {
134
143
  nonRequired: baseIPv4,
@@ -287,6 +296,8 @@ function createMongooseObjectIdRefSchema(refModelName, ...attributes) {
287
296
  * such as 'private', 'required', 'short', 'trim', and 'unique'. If the 'short' attribute
288
297
  * is included, the `maxlength` is set to 16.
289
298
  *
299
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.string} instead.
300
+ *
290
301
  * @template T - An array of attributes to apply to the schema field.
291
302
  *
292
303
  * @param attributes - The attributes to apply to the schema field.
@@ -297,8 +308,9 @@ function createMongooseStringSchema(...attributes) {
297
308
  const schema = { type: String };
298
309
  new Set(attributes).forEach((attribute) => {
299
310
  if (attribute === 'short')
300
- return (schema.maxlength = 16);
301
- schema[attribute] = true;
311
+ schema.maxlength = 16;
312
+ else
313
+ schema[attribute] = true;
302
314
  });
303
315
  return schema;
304
316
  }
package/utils.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import mongoose from 'mongoose';
2
+ import type { schemaBuilders } from './schema-builders';
2
3
  import type { BuildMongooseModelOptions } from './types/options';
3
4
  import type { BaseSchemaAttribute, CreateCommonMongooseSchemasOptions, MongooseObjectIdRefSchema, MongooseStringSchema, MongooseStringSchemaAttribute } from './types/schema';
5
+ export type DoNotUseOrRemoveThisType = typeof schemaBuilders;
4
6
  /**
5
7
  * Builds and returns a Mongoose model with specified schema and options.
6
8
  *
@@ -41,6 +43,9 @@ export declare function buildMongooseModel<DocType, Model extends BaseMongoosePa
41
43
  * @returns The merged common and custom schemas.
42
44
  */
43
45
  export declare function createCommonMongooseSchemas<T extends {}>(customSchemas?: T, options?: CreateCommonMongooseSchemasOptions): {
46
+ /**
47
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.boolean} instead.
48
+ */
44
49
  readonly boolean: {
45
50
  readonly defaultFalse: {
46
51
  readonly nonRequired: {
@@ -96,6 +101,9 @@ export declare function createCommonMongooseSchemas<T extends {}>(customSchemas?
96
101
  readonly type: typeof mongoose.Schema.Types.Decimal128;
97
102
  };
98
103
  };
104
+ /**
105
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.number} instead.
106
+ */
99
107
  readonly number: {
100
108
  readonly nonRequired: {
101
109
  readonly type: NumberConstructor;
@@ -136,6 +144,9 @@ export declare function createCommonMongooseSchemas<T extends {}>(customSchemas?
136
144
  };
137
145
  };
138
146
  };
147
+ /**
148
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.string} instead.
149
+ */
139
150
  readonly string: {
140
151
  readonly ipv4: {
141
152
  readonly nonRequired: {
@@ -391,6 +402,8 @@ export declare function createMongooseObjectIdRefSchema<R extends string, T exte
391
402
  * such as 'private', 'required', 'short', 'trim', and 'unique'. If the 'short' attribute
392
403
  * is included, the `maxlength` is set to 16.
393
404
  *
405
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.string} instead.
406
+ *
394
407
  * @template T - An array of attributes to apply to the schema field.
395
408
  *
396
409
  * @param attributes - The attributes to apply to the schema field.
package/utils.mjs CHANGED
@@ -82,6 +82,9 @@ function createCommonMongooseSchemas(customSchemas, options) {
82
82
  const baseRequiredNumber = { required: true, type: Number };
83
83
  const baseRequiredObjectId = { required: true, type: mongoose.Schema.Types.ObjectId };
84
84
  return merge({
85
+ /**
86
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.boolean} instead.
87
+ */
85
88
  boolean: {
86
89
  defaultFalse: {
87
90
  nonRequired: { default: false, type: Boolean },
@@ -102,6 +105,9 @@ function createCommonMongooseSchemas(customSchemas, options) {
102
105
  nonRequired: { type: mongoose.Schema.Types.Decimal128 },
103
106
  required: { required: true, type: mongoose.Schema.Types.Decimal128 }
104
107
  },
108
+ /**
109
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.number} instead.
110
+ */
105
111
  number: {
106
112
  nonRequired: { type: Number },
107
113
  required: baseRequiredNumber,
@@ -118,6 +124,9 @@ function createCommonMongooseSchemas(customSchemas, options) {
118
124
  required: { ...baseRequiredObjectId, unique: true }
119
125
  }
120
126
  },
127
+ /**
128
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.string} instead.
129
+ */
121
130
  string: {
122
131
  ipv4: {
123
132
  nonRequired: baseIPv4,
@@ -276,6 +285,8 @@ function createMongooseObjectIdRefSchema(refModelName, ...attributes) {
276
285
  * such as 'private', 'required', 'short', 'trim', and 'unique'. If the 'short' attribute
277
286
  * is included, the `maxlength` is set to 16.
278
287
  *
288
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.string} instead.
289
+ *
279
290
  * @template T - An array of attributes to apply to the schema field.
280
291
  *
281
292
  * @param attributes - The attributes to apply to the schema field.
@@ -286,8 +297,9 @@ function createMongooseStringSchema(...attributes) {
286
297
  const schema = { type: String };
287
298
  new Set(attributes).forEach((attribute) => {
288
299
  if (attribute === 'short')
289
- return (schema.maxlength = 16);
290
- schema[attribute] = true;
300
+ schema.maxlength = 16;
301
+ else
302
+ schema[attribute] = true;
291
303
  });
292
304
  return schema;
293
305
  }