@kikiutils/mongoose 1.6.0 → 1.7.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/constants.cjs CHANGED
@@ -9,6 +9,8 @@ const _connections = require('./_connections.cjs');
9
9
  * This constant holds a set of commonly used Mongoose schema definitions, generated
10
10
  * by the `createCommonMongooseSchemas` utility function. These schemas include common
11
11
  * field types and configurations used across multiple models.
12
+ *
13
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders} instead.
12
14
  */
13
15
  const commonMongooseSchemas = utils.createCommonMongooseSchemas();
14
16
 
package/constants.d.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  export { mongooseConnections } from './_connections';
2
+ import type { schemaBuilders } from './schema-builders';
3
+ export type DoNotUseOrRemoveThisType = typeof schemaBuilders;
2
4
  /**
3
5
  * Common Mongoose schemas.
4
6
  *
5
7
  * This constant holds a set of commonly used Mongoose schema definitions, generated
6
8
  * by the `createCommonMongooseSchemas` utility function. These schemas include common
7
9
  * field types and configurations used across multiple models.
10
+ *
11
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders} instead.
8
12
  */
9
13
  export declare const commonMongooseSchemas: {
10
14
  readonly boolean: {
package/constants.mjs CHANGED
@@ -7,6 +7,8 @@ export { mongooseConnections } from './_connections.mjs';
7
7
  * This constant holds a set of commonly used Mongoose schema definitions, generated
8
8
  * by the `createCommonMongooseSchemas` utility function. These schemas include common
9
9
  * field types and configurations used across multiple models.
10
+ *
11
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders} instead.
10
12
  */
11
13
  const commonMongooseSchemas = createCommonMongooseSchemas();
12
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
- "version": "1.6.0",
3
+ "version": "1.7.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",
@@ -11,7 +11,8 @@
11
11
  "scripts": {
12
12
  "build": "ts-project-builder ./src/constants.ts ./src/schema-builders/index.ts ./src/utils.ts --clean --preserve-modules",
13
13
  "bumplog": "changelogen --bump",
14
- "release": "pnpm run build && changelogen --push --release && sh ./build-and-publish.sh"
14
+ "release": "pnpm run build && changelogen --push --release && sh ./build-and-publish.sh",
15
+ "test": "jest --coverage"
15
16
  },
16
17
  "dependencies": {
17
18
  "decimal.js": "^10.4.3",
@@ -24,8 +25,11 @@
24
25
  "@kikiutils/changelogen": "^0.7.0",
25
26
  "@kikiutils/prettierrc": "^1.3.2",
26
27
  "@kikiutils/tsconfigs": "^3.0.1",
28
+ "@types/jest": "^29.5.14",
27
29
  "@types/lodash": "^4.17.12",
28
- "@types/node": "^22.7.8",
30
+ "@types/node": "^22.7.9",
31
+ "jest": "^29.7.0",
32
+ "ts-jest": "^29.2.5",
29
33
  "ts-project-builder": "^3.3.0",
30
34
  "tslib": "^2.8.0"
31
35
  },
@@ -1,6 +1,10 @@
1
1
  import type { BooleanSchemaDefinition, DefaultType } from 'mongoose';
2
- type ExtendBooleanSchemaBuilder<Props, ExtraOmitFields extends string> = Omit<BooleanSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
3
- export interface BooleanSchemaBuilder<Props = {
2
+ type ExtendBooleanSchemaBuilder<Props extends {
3
+ type: BooleanSchemaDefinition;
4
+ }, ExtraOmitFields extends string> = Omit<BooleanSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
5
+ export interface BooleanSchemaBuilder<Props extends {
6
+ type: BooleanSchemaDefinition;
7
+ } = {
4
8
  type: BooleanSchemaDefinition;
5
9
  }, ExtraOmitFields extends string = never, PropsWithRequired = Props & {
6
10
  required: true;
@@ -1,7 +1,11 @@
1
1
  import type { DefaultType, DateSchemaDefinition } from 'mongoose';
2
2
  import type { MaybeReadonly } from '../types/utils';
3
- type ExtendDateSchemaBuilder<Props, ExtraOmitFields extends string> = Omit<DateSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
4
- export interface DateSchemaBuilder<Props = {
3
+ type ExtendDateSchemaBuilder<Props extends {
4
+ type: DateSchemaDefinition;
5
+ }, ExtraOmitFields extends string> = Omit<DateSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
6
+ export interface DateSchemaBuilder<Props extends {
7
+ type: DateSchemaDefinition;
8
+ } = {
5
9
  type: DateSchemaDefinition;
6
10
  }, ExtraOmitFields extends string = never, PropsWithRequired = Props & {
7
11
  required: true;
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ const Decimal = require('decimal.js');
4
+ const mongoose = require('mongoose');
5
+ const base = require('./base.cjs');
6
+
7
+ const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
8
+
9
+ const Decimal__default = /*#__PURE__*/_interopDefaultCompat(Decimal);
10
+
11
+ const baseBuilderFactory = base.createBaseSchemaBuilderFactory(mongoose.Schema.Types.Decimal128);
12
+ const decimal128SchemaBuilder = () => {
13
+ const schema = {};
14
+ const baseBuilder = baseBuilderFactory(schema);
15
+ return new Proxy(baseBuilder, {
16
+ get(target, key, receiver) {
17
+ if (key === 'setRoundAndToFixedSetter') {
18
+ return (places = 2, rounding = Decimal__default.ROUND_DOWN) => {
19
+ schema['set'] = (value) => new Decimal__default(value.toString()).toFixed(places, rounding);
20
+ return receiver;
21
+ };
22
+ }
23
+ if (key === 'setToStringGetter')
24
+ return (schema['get'] = (value) => value.toString()), receiver;
25
+ return Reflect.get(target, key, receiver);
26
+ }
27
+ });
28
+ };
29
+
30
+ exports.decimal128SchemaBuilder = decimal128SchemaBuilder;
@@ -0,0 +1,79 @@
1
+ import Decimal from 'decimal.js';
2
+ import { Schema } from 'mongoose';
3
+ import type { DefaultType, Types } from 'mongoose';
4
+ import type { MaybeReadonly } from '../types/utils';
5
+ type ExtendDecimal128SchemaBuilder<Props extends {
6
+ type: Schema.Types.Decimal128;
7
+ }, ExtraOmitFields extends string> = Omit<Decimal128SchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
8
+ type ToStringGetterSchema = {
9
+ get: (value: Types.Decimal128) => string;
10
+ };
11
+ type ToStringSetterSchema = {
12
+ set: (value: {
13
+ toString(): string;
14
+ }) => string;
15
+ };
16
+ export interface Decimal128SchemaBuilder<Props extends {
17
+ type: Schema.Types.Decimal128;
18
+ } = {
19
+ type: Schema.Types.Decimal128;
20
+ }, ExtraOmitFields extends string = never> {
21
+ default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends Types.Decimal128>(value: T) => ExtendDecimal128SchemaBuilder<{
22
+ [key in keyof (Props & {
23
+ default: T;
24
+ })]: (Props & {
25
+ default: T;
26
+ })[key];
27
+ }, ExtraOmitFields>;
28
+ enum: <T extends MaybeReadonly<Array<D | null>> | {
29
+ message?: M;
30
+ values: MaybeReadonly<Array<D | null>>;
31
+ } | {
32
+ [path: string]: D | null;
33
+ }, D extends Types.Decimal128, M extends string>(value: T) => ExtendDecimal128SchemaBuilder<{
34
+ [key in keyof (Props & {
35
+ enum: T;
36
+ })]: (Props & {
37
+ enum: T;
38
+ })[key];
39
+ }, ExtraOmitFields>;
40
+ nonRequired: {
41
+ [key in keyof Props]: Props[key];
42
+ };
43
+ private: ExtendDecimal128SchemaBuilder<{
44
+ [key in keyof (Props & {
45
+ private: true;
46
+ })]: (Props & {
47
+ private: true;
48
+ })[key];
49
+ }, ExtraOmitFields>;
50
+ required: {
51
+ [key in keyof (Props & {
52
+ required: true;
53
+ })]: (Props & {
54
+ required: true;
55
+ })[key];
56
+ };
57
+ setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendDecimal128SchemaBuilder<{
58
+ [key in keyof (Props & ToStringSetterSchema)]: (Props & ToStringSetterSchema)[key];
59
+ }, ExtraOmitFields | 'setRoundAndToFixedSetter'>;
60
+ setToStringGetter: ExtendDecimal128SchemaBuilder<{
61
+ [key in keyof (Props & ToStringGetterSchema)]: (Props & ToStringGetterSchema)[key];
62
+ }, ExtraOmitFields | 'setToStringGetter'>;
63
+ sparse: ExtendDecimal128SchemaBuilder<{
64
+ [key in keyof (Props & {
65
+ sparse: true;
66
+ })]: (Props & {
67
+ sparse: true;
68
+ })[key];
69
+ }, ExtraOmitFields>;
70
+ unique: ExtendDecimal128SchemaBuilder<{
71
+ [key in keyof (Props & {
72
+ unique: true;
73
+ })]: (Props & {
74
+ unique: true;
75
+ })[key];
76
+ }, ExtraOmitFields>;
77
+ }
78
+ export declare const decimal128SchemaBuilder: () => Decimal128SchemaBuilder;
79
+ export {};
@@ -0,0 +1,24 @@
1
+ import Decimal from 'decimal.js';
2
+ import { Schema } from 'mongoose';
3
+ import { createBaseSchemaBuilderFactory } from './base.mjs';
4
+
5
+ const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);
6
+ const decimal128SchemaBuilder = () => {
7
+ const schema = {};
8
+ const baseBuilder = baseBuilderFactory(schema);
9
+ return new Proxy(baseBuilder, {
10
+ get(target, key, receiver) {
11
+ if (key === 'setRoundAndToFixedSetter') {
12
+ return (places = 2, rounding = Decimal.ROUND_DOWN) => {
13
+ schema['set'] = (value) => new Decimal(value.toString()).toFixed(places, rounding);
14
+ return receiver;
15
+ };
16
+ }
17
+ if (key === 'setToStringGetter')
18
+ return (schema['get'] = (value) => value.toString()), receiver;
19
+ return Reflect.get(target, key, receiver);
20
+ }
21
+ });
22
+ };
23
+
24
+ export { decimal128SchemaBuilder };
@@ -3,20 +3,25 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const date = require('./date.cjs');
6
+ const decimal128 = require('./decimal128.cjs');
6
7
  const boolean = require('./boolean.cjs');
7
8
  const number = require('./number.cjs');
9
+ const objectId = require('./object-id.cjs');
8
10
  const ref = require('./ref.cjs');
9
11
  const string = require('./string.cjs');
10
12
 
11
13
  const schemaBuilders = {
12
14
  date: date.dateSchemaBuilder,
15
+ decimal128: decimal128.decimal128SchemaBuilder,
13
16
  boolean: boolean.booleanSchemaBuilder,
14
17
  number: number.numberSchemaBuilder,
18
+ objectId: objectId.objectIdSchemaBuilder,
15
19
  ref: ref.refSchemaBuilder,
16
20
  string: string.stringSchemaBuilder
17
21
  };
18
22
 
19
23
  exports.dateSchemaBuilder = date.dateSchemaBuilder;
24
+ exports.decimal128SchemaBuilder = decimal128.decimal128SchemaBuilder;
20
25
  exports.booleanSchemaBuilder = boolean.booleanSchemaBuilder;
21
26
  exports.numberSchemaBuilder = number.numberSchemaBuilder;
22
27
  exports.refSchemaBuilder = ref.refSchemaBuilder;
@@ -1,4 +1,5 @@
1
1
  export * from './date';
2
+ export * from './decimal128';
2
3
  export * from './boolean';
3
4
  export * from './number';
4
5
  export * from './ref';
@@ -11,6 +12,7 @@ export declare const schemaBuilders: {
11
12
  } & {
12
13
  required: true;
13
14
  }>;
15
+ decimal128: () => import("./decimal128").Decimal128SchemaBuilder;
14
16
  boolean: (schema?: Record<string, any>) => import("./boolean").BooleanSchemaBuilder<{
15
17
  type: import("mongoose").BooleanSchemaDefinition;
16
18
  }, never, {
@@ -25,8 +27,16 @@ export declare const schemaBuilders: {
25
27
  } & {
26
28
  required: true;
27
29
  }>;
30
+ objectId: (schema?: Record<string, any>) => import("./object-id").ObjectIdSchemaBuilder<{
31
+ type: import("mongoose").ObjectIdSchemaDefinition;
32
+ }, never, {
33
+ type: import("mongoose").ObjectIdSchemaDefinition;
34
+ } & {
35
+ required: true;
36
+ }>;
28
37
  ref: <T extends string | import("mongoose").Model<any> | ((this: any, doc: any) => string | import("mongoose").Model<any>)>(ref: T) => import("./ref").RefSchemaBuilder<{
29
38
  ref: T;
39
+ type: import("mongoose").ObjectIdSchemaDefinition;
30
40
  }>;
31
41
  string: () => import("./string").StringSchemaBuilder;
32
42
  };
@@ -1,15 +1,19 @@
1
1
  import { dateSchemaBuilder } from './date.mjs';
2
+ import { decimal128SchemaBuilder } from './decimal128.mjs';
2
3
  import { booleanSchemaBuilder } from './boolean.mjs';
3
4
  import { numberSchemaBuilder } from './number.mjs';
5
+ import { objectIdSchemaBuilder } from './object-id.mjs';
4
6
  import { refSchemaBuilder } from './ref.mjs';
5
7
  import { stringSchemaBuilder } from './string.mjs';
6
8
 
7
9
  const schemaBuilders = {
8
10
  date: dateSchemaBuilder,
11
+ decimal128: decimal128SchemaBuilder,
9
12
  boolean: booleanSchemaBuilder,
10
13
  number: numberSchemaBuilder,
14
+ objectId: objectIdSchemaBuilder,
11
15
  ref: refSchemaBuilder,
12
16
  string: stringSchemaBuilder
13
17
  };
14
18
 
15
- export { booleanSchemaBuilder, dateSchemaBuilder, schemaBuilders as default, numberSchemaBuilder, refSchemaBuilder, schemaBuilders, stringSchemaBuilder };
19
+ export { booleanSchemaBuilder, dateSchemaBuilder, decimal128SchemaBuilder, schemaBuilders as default, numberSchemaBuilder, refSchemaBuilder, schemaBuilders, stringSchemaBuilder };
@@ -1,7 +1,11 @@
1
1
  import type { DefaultType, NumberSchemaDefinition } from 'mongoose';
2
2
  import type { MaybeReadonly } from '../types/utils';
3
- type ExtendNumberSchemaBuilder<Props, ExtraOmitFields extends string> = Omit<NumberSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
4
- export interface NumberSchemaBuilder<Props = {
3
+ type ExtendNumberSchemaBuilder<Props extends {
4
+ type: NumberSchemaDefinition;
5
+ }, ExtraOmitFields extends string> = Omit<NumberSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
6
+ export interface NumberSchemaBuilder<Props extends {
7
+ type: NumberSchemaDefinition;
8
+ } = {
5
9
  type: NumberSchemaDefinition;
6
10
  }, ExtraOmitFields extends string = never, PropsWithRequired = Props & {
7
11
  required: true;
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ const mongoose = require('mongoose');
4
+ const base = require('./base.cjs');
5
+
6
+ const objectIdSchemaBuilder = base.createBaseSchemaBuilderFactory(mongoose.Schema.Types.ObjectId);
7
+
8
+ exports.objectIdSchemaBuilder = objectIdSchemaBuilder;
@@ -0,0 +1,67 @@
1
+ import type { DefaultType, ObjectIdSchemaDefinition, Types } from 'mongoose';
2
+ import type { MaybeReadonly } from '../types/utils';
3
+ type ExtendObjectIdSchemaBuilder<Props extends {
4
+ type: ObjectIdSchemaDefinition;
5
+ }, ExtraOmitFields extends string> = Omit<ObjectIdSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
6
+ export interface ObjectIdSchemaBuilder<Props extends {
7
+ type: ObjectIdSchemaDefinition;
8
+ } = {
9
+ type: ObjectIdSchemaDefinition;
10
+ }, ExtraOmitFields extends string = never, PropsWithRequired = Props & {
11
+ required: true;
12
+ }> {
13
+ default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends Types.ObjectId>(value: T) => ExtendObjectIdSchemaBuilder<{
14
+ [key in keyof (Props & {
15
+ default: T;
16
+ })]: (Props & {
17
+ default: T;
18
+ })[key];
19
+ }, ExtraOmitFields>;
20
+ enum: <T extends MaybeReadonly<Array<O | null>> | {
21
+ message?: M;
22
+ values: MaybeReadonly<Array<O | null>>;
23
+ } | {
24
+ [path: string]: O | null;
25
+ }, M extends string, O extends Types.ObjectId>(value: T) => ExtendObjectIdSchemaBuilder<{
26
+ [key in keyof (Props & {
27
+ enum: T;
28
+ })]: (Props & {
29
+ enum: T;
30
+ })[key];
31
+ }, ExtraOmitFields>;
32
+ nonRequired: {
33
+ [key in keyof Props]: Props[key];
34
+ };
35
+ private: ExtendObjectIdSchemaBuilder<{
36
+ [key in keyof (Props & {
37
+ private: true;
38
+ })]: (Props & {
39
+ private: true;
40
+ })[key];
41
+ }, ExtraOmitFields>;
42
+ required: {
43
+ [key in keyof PropsWithRequired]: PropsWithRequired[key];
44
+ };
45
+ sparse: ExtendObjectIdSchemaBuilder<{
46
+ [key in keyof (Props & {
47
+ sparse: true;
48
+ })]: (Props & {
49
+ sparse: true;
50
+ })[key];
51
+ }, ExtraOmitFields>;
52
+ unique: ExtendObjectIdSchemaBuilder<{
53
+ [key in keyof (Props & {
54
+ unique: true;
55
+ })]: (Props & {
56
+ unique: true;
57
+ })[key];
58
+ }, ExtraOmitFields>;
59
+ }
60
+ export declare const objectIdSchemaBuilder: (schema?: Record<string, any>) => ObjectIdSchemaBuilder<{
61
+ type: ObjectIdSchemaDefinition;
62
+ }, never, {
63
+ type: ObjectIdSchemaDefinition;
64
+ } & {
65
+ required: true;
66
+ }>;
67
+ export {};
@@ -0,0 +1,6 @@
1
+ import { Schema } from 'mongoose';
2
+ import { createBaseSchemaBuilderFactory } from './base.mjs';
3
+
4
+ const objectIdSchemaBuilder = createBaseSchemaBuilderFactory(Schema.Types.ObjectId);
5
+
6
+ export { objectIdSchemaBuilder };
@@ -1,7 +1,11 @@
1
1
  import type { DefaultType, Model, ObjectIdSchemaDefinition, Types } from 'mongoose';
2
2
  import type { MaybeReadonly } from '../types/utils';
3
- type ExtendRefSchemaBuilder<Props, ExtraOmitFields extends string> = Omit<RefSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
4
- export interface RefSchemaBuilder<Props = {
3
+ type ExtendRefSchemaBuilder<Props extends {
4
+ type: ObjectIdSchemaDefinition;
5
+ }, ExtraOmitFields extends string> = Omit<RefSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
6
+ export interface RefSchemaBuilder<Props extends {
7
+ type: ObjectIdSchemaDefinition;
8
+ } = {
5
9
  type: ObjectIdSchemaDefinition;
6
10
  }, ExtraOmitFields extends string = never, PropsWithRequired = Props & {
7
11
  required: true;
@@ -55,5 +59,6 @@ export interface RefSchemaBuilder<Props = {
55
59
  }
56
60
  export declare const refSchemaBuilder: <T extends string | Model<any> | ((this: any, doc: any) => string | Model<any>)>(ref: T) => RefSchemaBuilder<{
57
61
  ref: T;
62
+ type: ObjectIdSchemaDefinition;
58
63
  }>;
59
64
  export {};
@@ -8,20 +8,22 @@ const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e
8
8
  const net__default = /*#__PURE__*/_interopDefaultCompat(net);
9
9
 
10
10
  const baseBuilderFactory = base.createBaseSchemaBuilderFactory(String);
11
+ const defaultIPv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.';
12
+ const defaultIPv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.';
11
13
  const stringSchemaBuilder = () => {
12
14
  const schema = {};
13
15
  const baseBuilder = baseBuilderFactory(schema);
14
16
  return new Proxy(baseBuilder, {
15
17
  get(target, key, receiver) {
16
18
  if (key === 'ipv4') {
17
- return (message = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.') => {
19
+ return (message = defaultIPv4ValidateMessage) => {
18
20
  schema.trim = true;
19
21
  schema.validate = { message, validator: (value) => net__default.isIPv4(value) };
20
22
  return receiver;
21
23
  };
22
24
  }
23
25
  if (key === 'ipv6') {
24
- return (message = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.') => {
26
+ return (message = defaultIPv6ValidateMessage) => {
25
27
  schema.trim = true;
26
28
  schema.validate = { message, validator: (value) => net__default.isIPv6(value) };
27
29
  return receiver;
@@ -1,6 +1,8 @@
1
1
  import type { DefaultType, StringSchemaDefinition } from 'mongoose';
2
2
  import type { MaybeReadonly } from '../types/utils';
3
- type ExtendStringSchemaBuilder<Props, ExtraOmitFields extends string> = Omit<StringSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
3
+ type ExtendStringSchemaBuilder<Props extends {
4
+ type: StringSchemaDefinition;
5
+ }, ExtraOmitFields extends string> = Omit<StringSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
4
6
  type IPSchema<T extends string> = {
5
7
  trim: true;
6
8
  validate: {
@@ -8,7 +10,9 @@ type IPSchema<T extends string> = {
8
10
  validator: (value: string) => boolean;
9
11
  };
10
12
  };
11
- export interface StringSchemaBuilder<Props = {
13
+ export interface StringSchemaBuilder<Props extends {
14
+ type: StringSchemaDefinition;
15
+ } = {
12
16
  type: StringSchemaDefinition;
13
17
  }, ExtraOmitFields extends string = never, PropsWithRequired = Props & {
14
18
  required: true;
@@ -32,10 +36,10 @@ export interface StringSchemaBuilder<Props = {
32
36
  enum: T;
33
37
  })[key];
34
38
  }, ExtraOmitFields>;
35
- ipv4: <T extends string = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.'>(message?: T) => ExtendStringSchemaBuilder<{
39
+ ipv4: <T extends string = typeof defaultIPv4ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<{
36
40
  [key in keyof (Props & IPSchema<T>)]: (Props & IPSchema<T>)[key];
37
41
  }, ExtraOmitFields | 'ipv4' | 'ipv6'>;
38
- ipv6: <T extends string = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.'>(message?: T) => ExtendStringSchemaBuilder<{
42
+ ipv6: <T extends string = typeof defaultIPv6ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<{
39
43
  [key in keyof (Props & IPSchema<T>)]: (Props & IPSchema<T>)[key];
40
44
  }, ExtraOmitFields | 'ipv4' | 'ipv6'>;
41
45
  length: <T extends L | MaybeReadonly<[L, S]>, L extends number, S extends string>(value: T) => ExtendStringSchemaBuilder<{
@@ -117,5 +121,7 @@ export interface StringSchemaBuilder<Props = {
117
121
  })[key];
118
122
  }, ExtraOmitFields>;
119
123
  }
124
+ declare const defaultIPv4ValidateMessage = "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
125
+ declare const defaultIPv6ValidateMessage = "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
120
126
  export declare const stringSchemaBuilder: () => StringSchemaBuilder;
121
127
  export {};
@@ -2,20 +2,22 @@ import net from 'node:net';
2
2
  import { createBaseSchemaBuilderFactory } from './base.mjs';
3
3
 
4
4
  const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
5
+ const defaultIPv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.';
6
+ const defaultIPv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.';
5
7
  const stringSchemaBuilder = () => {
6
8
  const schema = {};
7
9
  const baseBuilder = baseBuilderFactory(schema);
8
10
  return new Proxy(baseBuilder, {
9
11
  get(target, key, receiver) {
10
12
  if (key === 'ipv4') {
11
- return (message = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.') => {
13
+ return (message = defaultIPv4ValidateMessage) => {
12
14
  schema.trim = true;
13
15
  schema.validate = { message, validator: (value) => net.isIPv4(value) };
14
16
  return receiver;
15
17
  };
16
18
  }
17
19
  if (key === 'ipv6') {
18
- return (message = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.') => {
20
+ return (message = defaultIPv6ValidateMessage) => {
19
21
  schema.trim = true;
20
22
  schema.validate = { message, validator: (value) => net.isIPv6(value) };
21
23
  return receiver;
package/types/schema.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type Decimal from 'decimal.js';
2
2
  import type { ObjectIdSchemaDefinition, SchemaTypeOptions, StringSchemaDefinition, Types } from 'mongoose';
3
+ import type { schemaBuilders } from '../schema-builders';
4
+ export type DoNotUseOrRemoveThisType = typeof schemaBuilders;
3
5
  /**
4
6
  * Base attributes for Mongoose schemas.
5
7
  *
@@ -18,6 +20,8 @@ export type MongooseStringSchemaAttribute = BaseSchemaAttribute | 'lowercase' |
18
20
  *
19
21
  * This interface defines options for creating common Mongoose schemas, including
20
22
  * settings for automatic rounding and fixed decimal places for Decimal128 fields.
23
+ *
24
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders} instead.
21
25
  */
22
26
  export interface CreateCommonMongooseSchemasOptions {
23
27
  /**
package/utils.cjs CHANGED
@@ -60,6 +60,8 @@ function buildMongooseModel(collection, name, schema, options$1) {
60
60
  * number, objectId, and string schemas, with optional custom configurations and rounding
61
61
  * options for Decimal128 fields.
62
62
  *
63
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders} instead.
64
+ *
63
65
  * @template T - The type for custom schemas.
64
66
  *
65
67
  * @param customSchemas - Optional custom schemas to merge with the common schemas.
@@ -108,6 +110,9 @@ function createCommonMongooseSchemas(customSchemas, options) {
108
110
  nonRequired: { type: Boolean },
109
111
  required: baseRequiredBoolean
110
112
  },
113
+ /**
114
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.decimal128} instead.
115
+ */
111
116
  decimal128: {
112
117
  autoRoundAndToFixed: {
113
118
  nonRequired: baseAutoRoundAndToFixedDecimal128,
@@ -127,6 +132,9 @@ function createCommonMongooseSchemas(customSchemas, options) {
127
132
  required: { ...baseRequiredNumber, unique: true }
128
133
  }
129
134
  },
135
+ /**
136
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.objectId} instead.
137
+ */
130
138
  objectId: {
131
139
  nonRequired: { type: mongoose__default.Schema.Types.ObjectId },
132
140
  required: baseRequiredObjectId,
@@ -344,6 +352,8 @@ async function mongooseDocumentOrObjectIdToDocument(documentOrObjectId, model, s
344
352
  * This function adds a getter to the specified Decimal128 fields in the schema,
345
353
  * converting the values to strings for easier use.
346
354
  *
355
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.decimal128} instead.
356
+ *
347
357
  * @template DocType - The type of the document.
348
358
  * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.
349
359
  * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.
package/utils.d.ts CHANGED
@@ -35,6 +35,8 @@ export declare function buildMongooseModel<DocType, Model extends BaseMongoosePa
35
35
  * number, objectId, and string schemas, with optional custom configurations and rounding
36
36
  * options for Decimal128 fields.
37
37
  *
38
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders} instead.
39
+ *
38
40
  * @template T - The type for custom schemas.
39
41
  *
40
42
  * @param customSchemas - Optional custom schemas to merge with the common schemas.
@@ -77,6 +79,9 @@ export declare function createCommonMongooseSchemas<T extends {}>(customSchemas?
77
79
  readonly type: BooleanConstructor;
78
80
  };
79
81
  };
82
+ /**
83
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.decimal128} instead.
84
+ */
80
85
  readonly decimal128: {
81
86
  readonly autoRoundAndToFixed: {
82
87
  readonly nonRequired: {
@@ -124,6 +129,9 @@ export declare function createCommonMongooseSchemas<T extends {}>(customSchemas?
124
129
  };
125
130
  };
126
131
  };
132
+ /**
133
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.objectId} instead.
134
+ */
127
135
  readonly objectId: {
128
136
  readonly nonRequired: {
129
137
  readonly type: typeof mongoose.Schema.Types.ObjectId;
@@ -437,6 +445,8 @@ export declare function mongooseDocumentOrObjectIdToDocument<D extends MongooseH
437
445
  * This function adds a getter to the specified Decimal128 fields in the schema,
438
446
  * converting the values to strings for easier use.
439
447
  *
448
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.decimal128} instead.
449
+ *
440
450
  * @template DocType - The type of the document.
441
451
  * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.
442
452
  * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.
package/utils.mjs CHANGED
@@ -49,6 +49,8 @@ function buildMongooseModel(collection, name, schema, options) {
49
49
  * number, objectId, and string schemas, with optional custom configurations and rounding
50
50
  * options for Decimal128 fields.
51
51
  *
52
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders} instead.
53
+ *
52
54
  * @template T - The type for custom schemas.
53
55
  *
54
56
  * @param customSchemas - Optional custom schemas to merge with the common schemas.
@@ -97,6 +99,9 @@ function createCommonMongooseSchemas(customSchemas, options) {
97
99
  nonRequired: { type: Boolean },
98
100
  required: baseRequiredBoolean
99
101
  },
102
+ /**
103
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.decimal128} instead.
104
+ */
100
105
  decimal128: {
101
106
  autoRoundAndToFixed: {
102
107
  nonRequired: baseAutoRoundAndToFixedDecimal128,
@@ -116,6 +121,9 @@ function createCommonMongooseSchemas(customSchemas, options) {
116
121
  required: { ...baseRequiredNumber, unique: true }
117
122
  }
118
123
  },
124
+ /**
125
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.objectId} instead.
126
+ */
119
127
  objectId: {
120
128
  nonRequired: { type: mongoose.Schema.Types.ObjectId },
121
129
  required: baseRequiredObjectId,
@@ -333,6 +341,8 @@ async function mongooseDocumentOrObjectIdToDocument(documentOrObjectId, model, s
333
341
  * This function adds a getter to the specified Decimal128 fields in the schema,
334
342
  * converting the values to strings for easier use.
335
343
  *
344
+ * @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.decimal128} instead.
345
+ *
336
346
  * @template DocType - The type of the document.
337
347
  * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.
338
348
  * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.