@kikiutils/mongoose 1.6.0 → 1.7.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/constants.cjs +2 -0
- package/constants.d.ts +4 -0
- package/constants.mjs +2 -0
- package/package.json +7 -3
- package/schema-builders/base.d.ts +1 -1
- package/schema-builders/boolean.d.ts +13 -11
- package/schema-builders/date.d.ts +13 -11
- package/schema-builders/decimal128.cjs +30 -0
- package/schema-builders/decimal128.d.ts +97 -0
- package/schema-builders/decimal128.mjs +24 -0
- package/schema-builders/index.cjs +5 -0
- package/schema-builders/index.d.ts +9 -15
- package/schema-builders/index.mjs +5 -1
- package/schema-builders/number.d.ts +13 -11
- package/schema-builders/object-id.cjs +8 -0
- package/schema-builders/object-id.d.ts +65 -0
- package/schema-builders/object-id.mjs +6 -0
- package/schema-builders/ref.d.ts +13 -6
- package/schema-builders/string.cjs +4 -2
- package/schema-builders/string.d.ts +37 -8
- package/schema-builders/string.mjs +4 -2
- package/types/options.d.ts +3 -3
- package/types/schema.d.ts +4 -0
- package/utils.cjs +10 -0
- package/utils.d.ts +10 -0
- package/utils.mjs +10 -0
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.
|
|
3
|
+
"version": "1.7.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
|
"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 && pnpm run test && 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.
|
|
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,2 +1,2 @@
|
|
|
1
1
|
import type { Schema } from 'mongoose';
|
|
2
|
-
export declare const createBaseSchemaBuilderFactory: <Builder = Readonly<
|
|
2
|
+
export declare const createBaseSchemaBuilderFactory: <Builder = Readonly<Record<string, any>>>(type: BooleanConstructor | DateConstructor | NumberConstructor | Schema.Types.ObjectId["constructor"] | StringConstructor) => (schema?: Record<string, any>) => Builder;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { BooleanSchemaDefinition, DefaultType } from 'mongoose';
|
|
2
|
-
type ExtendBooleanSchemaBuilder<Props
|
|
3
|
-
export interface BooleanSchemaBuilder<Props = {
|
|
2
|
+
type ExtendBooleanSchemaBuilder<Props extends {
|
|
4
3
|
type: BooleanSchemaDefinition;
|
|
5
|
-
}, ExtraOmitFields extends string =
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
}, ExtraOmitFields extends string> = Omit<BooleanSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
5
|
+
export interface BooleanSchemaBuilder<Props extends {
|
|
6
|
+
type: BooleanSchemaDefinition;
|
|
7
|
+
} = {
|
|
8
|
+
type: BooleanSchemaDefinition;
|
|
9
|
+
}, ExtraOmitFields extends string = never> {
|
|
8
10
|
default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends boolean>(value: T) => ExtendBooleanSchemaBuilder<{
|
|
9
11
|
[key in keyof (Props & {
|
|
10
12
|
default: T;
|
|
@@ -23,7 +25,11 @@ export interface BooleanSchemaBuilder<Props = {
|
|
|
23
25
|
})[key];
|
|
24
26
|
}, ExtraOmitFields>;
|
|
25
27
|
required: {
|
|
26
|
-
[key in keyof
|
|
28
|
+
[key in keyof (Props & {
|
|
29
|
+
required: true;
|
|
30
|
+
})]: (Props & {
|
|
31
|
+
required: true;
|
|
32
|
+
})[key];
|
|
27
33
|
};
|
|
28
34
|
sparse: ExtendBooleanSchemaBuilder<{
|
|
29
35
|
[key in keyof (Props & {
|
|
@@ -42,9 +48,5 @@ export interface BooleanSchemaBuilder<Props = {
|
|
|
42
48
|
}
|
|
43
49
|
export declare const booleanSchemaBuilder: (schema?: Record<string, any>) => BooleanSchemaBuilder<{
|
|
44
50
|
type: BooleanSchemaDefinition;
|
|
45
|
-
}, never
|
|
46
|
-
type: BooleanSchemaDefinition;
|
|
47
|
-
} & {
|
|
48
|
-
required: true;
|
|
49
|
-
}>;
|
|
51
|
+
}, never>;
|
|
50
52
|
export {};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { DefaultType, DateSchemaDefinition } from 'mongoose';
|
|
2
2
|
import type { MaybeReadonly } from '../types/utils';
|
|
3
|
-
type ExtendDateSchemaBuilder<Props
|
|
4
|
-
export interface DateSchemaBuilder<Props = {
|
|
3
|
+
type ExtendDateSchemaBuilder<Props extends {
|
|
5
4
|
type: DateSchemaDefinition;
|
|
6
|
-
}, ExtraOmitFields extends string =
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
}, ExtraOmitFields extends string> = Omit<DateSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
6
|
+
export interface DateSchemaBuilder<Props extends {
|
|
7
|
+
type: DateSchemaDefinition;
|
|
8
|
+
} = {
|
|
9
|
+
type: DateSchemaDefinition;
|
|
10
|
+
}, ExtraOmitFields extends string = never> {
|
|
9
11
|
default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends NativeDate>(value: T) => ExtendDateSchemaBuilder<{
|
|
10
12
|
[key in keyof (Props & {
|
|
11
13
|
default: T;
|
|
@@ -50,7 +52,11 @@ export interface DateSchemaBuilder<Props = {
|
|
|
50
52
|
})[key];
|
|
51
53
|
}, ExtraOmitFields>;
|
|
52
54
|
required: {
|
|
53
|
-
[key in keyof
|
|
55
|
+
[key in keyof (Props & {
|
|
56
|
+
required: true;
|
|
57
|
+
})]: (Props & {
|
|
58
|
+
required: true;
|
|
59
|
+
})[key];
|
|
54
60
|
};
|
|
55
61
|
sparse: ExtendDateSchemaBuilder<{
|
|
56
62
|
[key in keyof (Props & {
|
|
@@ -69,9 +75,5 @@ export interface DateSchemaBuilder<Props = {
|
|
|
69
75
|
}
|
|
70
76
|
export declare const dateSchemaBuilder: (schema?: Record<string, any>) => DateSchemaBuilder<{
|
|
71
77
|
type: DateSchemaDefinition;
|
|
72
|
-
}, never
|
|
73
|
-
type: DateSchemaDefinition;
|
|
74
|
-
} & {
|
|
75
|
-
required: true;
|
|
76
|
-
}>;
|
|
78
|
+
}, never>;
|
|
77
79
|
export {};
|
|
@@ -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,97 @@
|
|
|
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
|
+
/**
|
|
58
|
+
* Sets the rounding and toFixed behavior for Decimal128 fields.
|
|
59
|
+
* This method allows specifying the number of decimal places and the rounding strategy to be used when
|
|
60
|
+
* saving the field to the database.
|
|
61
|
+
*
|
|
62
|
+
* @param places - The number of decimal places to round to (default is 2).
|
|
63
|
+
* @param rounding - The rounding strategy from the Decimal.js library (default is Decimal.ROUND_DOWN).
|
|
64
|
+
* @returns A schema builder with the rounding and toFixed behavior applied to the `set` option in Mongoose.
|
|
65
|
+
*/
|
|
66
|
+
setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendDecimal128SchemaBuilder<{
|
|
67
|
+
[key in keyof (Props & ToStringSetterSchema)]: (Props & ToStringSetterSchema)[key];
|
|
68
|
+
}, ExtraOmitFields | 'setRoundAndToFixedSetter'>;
|
|
69
|
+
/**
|
|
70
|
+
* Sets the toString behavior for Decimal128 fields.
|
|
71
|
+
* This method defines how the Decimal128 field should be converted to a string when processing or
|
|
72
|
+
* retrieving the value in the application (e.g., via getters), while still storing the value as Decimal128
|
|
73
|
+
* in the database.
|
|
74
|
+
*
|
|
75
|
+
* @returns A schema builder with the custom `get` behavior applied to convert the Decimal128 field to a string
|
|
76
|
+
* when accessed in the application.
|
|
77
|
+
*/
|
|
78
|
+
setToStringGetter: ExtendDecimal128SchemaBuilder<{
|
|
79
|
+
[key in keyof (Props & ToStringGetterSchema)]: (Props & ToStringGetterSchema)[key];
|
|
80
|
+
}, ExtraOmitFields | 'setToStringGetter'>;
|
|
81
|
+
sparse: ExtendDecimal128SchemaBuilder<{
|
|
82
|
+
[key in keyof (Props & {
|
|
83
|
+
sparse: true;
|
|
84
|
+
})]: (Props & {
|
|
85
|
+
sparse: true;
|
|
86
|
+
})[key];
|
|
87
|
+
}, ExtraOmitFields>;
|
|
88
|
+
unique: ExtendDecimal128SchemaBuilder<{
|
|
89
|
+
[key in keyof (Props & {
|
|
90
|
+
unique: true;
|
|
91
|
+
})]: (Props & {
|
|
92
|
+
unique: true;
|
|
93
|
+
})[key];
|
|
94
|
+
}, ExtraOmitFields>;
|
|
95
|
+
}
|
|
96
|
+
export declare const decimal128SchemaBuilder: () => Decimal128SchemaBuilder;
|
|
97
|
+
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';
|
|
@@ -6,27 +7,20 @@ export * from './string';
|
|
|
6
7
|
export declare const schemaBuilders: {
|
|
7
8
|
date: (schema?: Record<string, any>) => import("./date").DateSchemaBuilder<{
|
|
8
9
|
type: import("mongoose").DateSchemaDefinition;
|
|
9
|
-
}, never
|
|
10
|
-
|
|
11
|
-
} & {
|
|
12
|
-
required: true;
|
|
13
|
-
}>;
|
|
10
|
+
}, never>;
|
|
11
|
+
decimal128: () => import("./decimal128").Decimal128SchemaBuilder;
|
|
14
12
|
boolean: (schema?: Record<string, any>) => import("./boolean").BooleanSchemaBuilder<{
|
|
15
13
|
type: import("mongoose").BooleanSchemaDefinition;
|
|
16
|
-
}, never
|
|
17
|
-
type: import("mongoose").BooleanSchemaDefinition;
|
|
18
|
-
} & {
|
|
19
|
-
required: true;
|
|
20
|
-
}>;
|
|
14
|
+
}, never>;
|
|
21
15
|
number: (schema?: Record<string, any>) => import("./number").NumberSchemaBuilder<{
|
|
22
16
|
type: import("mongoose").NumberSchemaDefinition;
|
|
23
|
-
}, never
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}>;
|
|
17
|
+
}, never>;
|
|
18
|
+
objectId: (schema?: Record<string, any>) => import("./object-id").ObjectIdSchemaBuilder<{
|
|
19
|
+
type: import("mongoose").ObjectIdSchemaDefinition;
|
|
20
|
+
}, never>;
|
|
28
21
|
ref: <T extends string | import("mongoose").Model<any> | ((this: any, doc: any) => string | import("mongoose").Model<any>)>(ref: T) => import("./ref").RefSchemaBuilder<{
|
|
29
22
|
ref: T;
|
|
23
|
+
type: import("mongoose").ObjectIdSchemaDefinition;
|
|
30
24
|
}>;
|
|
31
25
|
string: () => import("./string").StringSchemaBuilder;
|
|
32
26
|
};
|
|
@@ -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,11 +1,13 @@
|
|
|
1
1
|
import type { DefaultType, NumberSchemaDefinition } from 'mongoose';
|
|
2
2
|
import type { MaybeReadonly } from '../types/utils';
|
|
3
|
-
type ExtendNumberSchemaBuilder<Props
|
|
4
|
-
export interface NumberSchemaBuilder<Props = {
|
|
3
|
+
type ExtendNumberSchemaBuilder<Props extends {
|
|
5
4
|
type: NumberSchemaDefinition;
|
|
6
|
-
}, ExtraOmitFields extends string =
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
}, ExtraOmitFields extends string> = Omit<NumberSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
6
|
+
export interface NumberSchemaBuilder<Props extends {
|
|
7
|
+
type: NumberSchemaDefinition;
|
|
8
|
+
} = {
|
|
9
|
+
type: NumberSchemaDefinition;
|
|
10
|
+
}, ExtraOmitFields extends string = never> {
|
|
9
11
|
default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends number>(value: T) => ExtendNumberSchemaBuilder<{
|
|
10
12
|
[key in keyof (Props & {
|
|
11
13
|
default: T;
|
|
@@ -50,7 +52,11 @@ export interface NumberSchemaBuilder<Props = {
|
|
|
50
52
|
})[key];
|
|
51
53
|
}, ExtraOmitFields>;
|
|
52
54
|
required: {
|
|
53
|
-
[key in keyof
|
|
55
|
+
[key in keyof (Props & {
|
|
56
|
+
required: true;
|
|
57
|
+
})]: (Props & {
|
|
58
|
+
required: true;
|
|
59
|
+
})[key];
|
|
54
60
|
};
|
|
55
61
|
sparse: ExtendNumberSchemaBuilder<{
|
|
56
62
|
[key in keyof (Props & {
|
|
@@ -69,9 +75,5 @@ export interface NumberSchemaBuilder<Props = {
|
|
|
69
75
|
}
|
|
70
76
|
export declare const numberSchemaBuilder: (schema?: Record<string, any>) => NumberSchemaBuilder<{
|
|
71
77
|
type: NumberSchemaDefinition;
|
|
72
|
-
}, never
|
|
73
|
-
type: NumberSchemaDefinition;
|
|
74
|
-
} & {
|
|
75
|
-
required: true;
|
|
76
|
-
}>;
|
|
78
|
+
}, never>;
|
|
77
79
|
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
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> {
|
|
11
|
+
default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends Types.ObjectId>(value: T) => ExtendObjectIdSchemaBuilder<{
|
|
12
|
+
[key in keyof (Props & {
|
|
13
|
+
default: T;
|
|
14
|
+
})]: (Props & {
|
|
15
|
+
default: T;
|
|
16
|
+
})[key];
|
|
17
|
+
}, ExtraOmitFields>;
|
|
18
|
+
enum: <T extends MaybeReadonly<Array<O | null>> | {
|
|
19
|
+
message?: M;
|
|
20
|
+
values: MaybeReadonly<Array<O | null>>;
|
|
21
|
+
} | {
|
|
22
|
+
[path: string]: O | null;
|
|
23
|
+
}, M extends string, O extends Types.ObjectId>(value: T) => ExtendObjectIdSchemaBuilder<{
|
|
24
|
+
[key in keyof (Props & {
|
|
25
|
+
enum: T;
|
|
26
|
+
})]: (Props & {
|
|
27
|
+
enum: T;
|
|
28
|
+
})[key];
|
|
29
|
+
}, ExtraOmitFields>;
|
|
30
|
+
nonRequired: {
|
|
31
|
+
[key in keyof Props]: Props[key];
|
|
32
|
+
};
|
|
33
|
+
private: ExtendObjectIdSchemaBuilder<{
|
|
34
|
+
[key in keyof (Props & {
|
|
35
|
+
private: true;
|
|
36
|
+
})]: (Props & {
|
|
37
|
+
private: true;
|
|
38
|
+
})[key];
|
|
39
|
+
}, ExtraOmitFields>;
|
|
40
|
+
required: {
|
|
41
|
+
[key in keyof (Props & {
|
|
42
|
+
required: true;
|
|
43
|
+
})]: (Props & {
|
|
44
|
+
required: true;
|
|
45
|
+
})[key];
|
|
46
|
+
};
|
|
47
|
+
sparse: ExtendObjectIdSchemaBuilder<{
|
|
48
|
+
[key in keyof (Props & {
|
|
49
|
+
sparse: true;
|
|
50
|
+
})]: (Props & {
|
|
51
|
+
sparse: true;
|
|
52
|
+
})[key];
|
|
53
|
+
}, ExtraOmitFields>;
|
|
54
|
+
unique: ExtendObjectIdSchemaBuilder<{
|
|
55
|
+
[key in keyof (Props & {
|
|
56
|
+
unique: true;
|
|
57
|
+
})]: (Props & {
|
|
58
|
+
unique: true;
|
|
59
|
+
})[key];
|
|
60
|
+
}, ExtraOmitFields>;
|
|
61
|
+
}
|
|
62
|
+
export declare const objectIdSchemaBuilder: (schema?: Record<string, any>) => ObjectIdSchemaBuilder<{
|
|
63
|
+
type: ObjectIdSchemaDefinition;
|
|
64
|
+
}, never>;
|
|
65
|
+
export {};
|
package/schema-builders/ref.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { DefaultType, Model, ObjectIdSchemaDefinition, Types } from 'mongoose';
|
|
2
2
|
import type { MaybeReadonly } from '../types/utils';
|
|
3
|
-
type ExtendRefSchemaBuilder<Props
|
|
4
|
-
export interface RefSchemaBuilder<Props = {
|
|
3
|
+
type ExtendRefSchemaBuilder<Props extends {
|
|
5
4
|
type: ObjectIdSchemaDefinition;
|
|
6
|
-
}, ExtraOmitFields extends string =
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
}, ExtraOmitFields extends string> = Omit<RefSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
6
|
+
export interface RefSchemaBuilder<Props extends {
|
|
7
|
+
type: ObjectIdSchemaDefinition;
|
|
8
|
+
} = {
|
|
9
|
+
type: ObjectIdSchemaDefinition;
|
|
10
|
+
}, ExtraOmitFields extends string = never> {
|
|
9
11
|
default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends Types.ObjectId>(value: T) => ExtendRefSchemaBuilder<{
|
|
10
12
|
[key in keyof (Props & {
|
|
11
13
|
default: T;
|
|
@@ -36,7 +38,11 @@ export interface RefSchemaBuilder<Props = {
|
|
|
36
38
|
})[key];
|
|
37
39
|
}, ExtraOmitFields>;
|
|
38
40
|
required: {
|
|
39
|
-
[key in keyof
|
|
41
|
+
[key in keyof (Props & {
|
|
42
|
+
required: true;
|
|
43
|
+
})]: (Props & {
|
|
44
|
+
required: true;
|
|
45
|
+
})[key];
|
|
40
46
|
};
|
|
41
47
|
sparse: ExtendRefSchemaBuilder<{
|
|
42
48
|
[key in keyof (Props & {
|
|
@@ -55,5 +61,6 @@ export interface RefSchemaBuilder<Props = {
|
|
|
55
61
|
}
|
|
56
62
|
export declare const refSchemaBuilder: <T extends string | Model<any> | ((this: any, doc: any) => string | Model<any>)>(ref: T) => RefSchemaBuilder<{
|
|
57
63
|
ref: T;
|
|
64
|
+
type: ObjectIdSchemaDefinition;
|
|
58
65
|
}>;
|
|
59
66
|
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 =
|
|
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 =
|
|
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
|
|
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,11 +10,11 @@ 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
|
-
}, ExtraOmitFields extends string = never
|
|
14
|
-
required: true;
|
|
15
|
-
}> {
|
|
17
|
+
}, ExtraOmitFields extends string = never> {
|
|
16
18
|
default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends string>(value: T) => ExtendStringSchemaBuilder<{
|
|
17
19
|
[key in keyof (Props & {
|
|
18
20
|
default: T;
|
|
@@ -32,12 +34,33 @@ export interface StringSchemaBuilder<Props = {
|
|
|
32
34
|
enum: T;
|
|
33
35
|
})[key];
|
|
34
36
|
}, ExtraOmitFields>;
|
|
35
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Adds IPv4 validation to the string schema.
|
|
39
|
+
* Ensures the string is a valid IPv4 address and trims the input. The validation message can be customized.
|
|
40
|
+
*
|
|
41
|
+
* @param message - The custom error message to return if validation fails. Defaults to a standard IPv4 validation message.
|
|
42
|
+
* @returns A schema builder with IPv4 validation and the `trim` option enabled.
|
|
43
|
+
*/
|
|
44
|
+
ipv4: <T extends string = typeof defaultIPv4ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<{
|
|
36
45
|
[key in keyof (Props & IPSchema<T>)]: (Props & IPSchema<T>)[key];
|
|
37
46
|
}, ExtraOmitFields | 'ipv4' | 'ipv6'>;
|
|
38
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Adds IPv6 validation to the string schema.
|
|
49
|
+
* Ensures the string is a valid IPv6 address and trims the input. The validation message can be customized.
|
|
50
|
+
*
|
|
51
|
+
* @param message - The custom error message to return if validation fails. Defaults to a standard IPv6 validation message.
|
|
52
|
+
* @returns A schema builder with IPv6 validation and the `trim` option enabled.
|
|
53
|
+
*/
|
|
54
|
+
ipv6: <T extends string = typeof defaultIPv6ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<{
|
|
39
55
|
[key in keyof (Props & IPSchema<T>)]: (Props & IPSchema<T>)[key];
|
|
40
56
|
}, ExtraOmitFields | 'ipv4' | 'ipv6'>;
|
|
57
|
+
/**
|
|
58
|
+
* Sets both the maximum and minimum length of the string.
|
|
59
|
+
* This method ensures the string length is exactly or within a specified range.
|
|
60
|
+
*
|
|
61
|
+
* @param value - A number representing the exact length or an array specifying [minimum, maximum] length.
|
|
62
|
+
* @returns A schema builder with both `maxlength` and `minlength` options applied.
|
|
63
|
+
*/
|
|
41
64
|
length: <T extends L | MaybeReadonly<[L, S]>, L extends number, S extends string>(value: T) => ExtendStringSchemaBuilder<{
|
|
42
65
|
[key in keyof (Props & {
|
|
43
66
|
maxlength: T;
|
|
@@ -79,7 +102,11 @@ export interface StringSchemaBuilder<Props = {
|
|
|
79
102
|
})[key];
|
|
80
103
|
}, ExtraOmitFields>;
|
|
81
104
|
required: {
|
|
82
|
-
[key in keyof
|
|
105
|
+
[key in keyof (Props & {
|
|
106
|
+
required: true;
|
|
107
|
+
})]: (Props & {
|
|
108
|
+
required: true;
|
|
109
|
+
})[key];
|
|
83
110
|
};
|
|
84
111
|
sparse: ExtendStringSchemaBuilder<{
|
|
85
112
|
[key in keyof (Props & {
|
|
@@ -117,5 +144,7 @@ export interface StringSchemaBuilder<Props = {
|
|
|
117
144
|
})[key];
|
|
118
145
|
}, ExtraOmitFields>;
|
|
119
146
|
}
|
|
147
|
+
declare const defaultIPv4ValidateMessage = "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
148
|
+
declare const defaultIPv6ValidateMessage = "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
120
149
|
export declare const stringSchemaBuilder: () => StringSchemaBuilder;
|
|
121
150
|
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 =
|
|
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 =
|
|
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/options.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type { Connection, Schema, SchemaTimestampsConfig } from 'mongoose';
|
|
2
|
-
export interface CustomMongooseOptions {
|
|
3
|
-
beforeModelBuild?: <DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = {}, QueryHelpers = {}>(schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>) => void;
|
|
4
|
-
}
|
|
5
2
|
/**
|
|
6
3
|
* Interface for options used when building a Mongoose model.
|
|
7
4
|
*
|
|
@@ -37,3 +34,6 @@ export interface BuildMongooseModelOptions {
|
|
|
37
34
|
*/
|
|
38
35
|
timestamps?: boolean | SchemaTimestampsConfig;
|
|
39
36
|
}
|
|
37
|
+
export interface CustomMongooseOptions {
|
|
38
|
+
beforeModelBuild?: <DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = {}, QueryHelpers = {}>(schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>) => void;
|
|
39
|
+
}
|
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.
|