@kikiutils/mongoose 1.4.1 → 1.6.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 +13 -12
- package/schema-builders/base.cjs +33 -0
- package/schema-builders/base.d.ts +2 -0
- package/schema-builders/base.mjs +31 -0
- package/schema-builders/boolean.cjs +7 -0
- package/schema-builders/boolean.d.ts +50 -0
- package/schema-builders/boolean.mjs +5 -0
- package/schema-builders/date.cjs +7 -0
- package/schema-builders/date.d.ts +77 -0
- package/schema-builders/date.mjs +5 -0
- package/schema-builders/index.cjs +25 -0
- package/schema-builders/index.d.ts +33 -0
- package/schema-builders/index.mjs +15 -0
- package/schema-builders/number.cjs +7 -0
- package/schema-builders/number.d.ts +77 -0
- package/schema-builders/number.mjs +5 -0
- package/schema-builders/ref.cjs +9 -0
- package/schema-builders/ref.d.ts +59 -0
- package/schema-builders/ref.mjs +7 -0
- package/schema-builders/string.cjs +37 -0
- package/schema-builders/string.d.ts +121 -0
- package/schema-builders/string.mjs +31 -0
- package/types/paginate.d.ts +1 -1
- package/types/utils.d.ts +1 -0
- package/utils.cjs +13 -0
- package/utils.d.ts +15 -0
- package/utils.mjs +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/mongoose",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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,9 +9,9 @@
|
|
|
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",
|
|
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 --release && sh ./build-and-publish.sh"
|
|
14
|
+
"release": "pnpm run build && changelogen --push --release && sh ./build-and-publish.sh"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"decimal.js": "^10.4.3",
|
|
@@ -21,12 +21,13 @@
|
|
|
21
21
|
"mongoose-paginate-v2": "^1.8.5"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@kikiutils/changelogen": "^0.
|
|
24
|
+
"@kikiutils/changelogen": "^0.7.0",
|
|
25
25
|
"@kikiutils/prettierrc": "^1.3.2",
|
|
26
26
|
"@kikiutils/tsconfigs": "^3.0.1",
|
|
27
|
-
"@types/lodash": "^4.17.
|
|
28
|
-
"@types/node": "^22.7.
|
|
29
|
-
"ts-project-builder": "^3.
|
|
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
|
-
"./
|
|
56
|
-
"import": "./
|
|
57
|
-
"require": "./
|
|
58
|
-
"types": "./
|
|
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,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const createBaseSchemaBuilderFactory = (type) => {
|
|
4
|
+
return (schema = {}) => {
|
|
5
|
+
schema.type = 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 === '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
|
+
exports.createBaseSchemaBuilderFactory = createBaseSchemaBuilderFactory;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { Schema } from 'mongoose';
|
|
2
|
+
export declare const createBaseSchemaBuilderFactory: <Builder = Readonly<{}>>(type: BooleanConstructor | DateConstructor | NumberConstructor | Schema.Types.ObjectId["constructor"] | StringConstructor) => (schema?: Record<string, any>) => Builder;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const createBaseSchemaBuilderFactory = (type) => {
|
|
2
|
+
return (schema = {}) => {
|
|
3
|
+
schema.type = 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 === 'nonRequired')
|
|
13
|
+
return { ...schema };
|
|
14
|
+
if (key === 'required')
|
|
15
|
+
return { ...schema, required: true };
|
|
16
|
+
schema[key] = true;
|
|
17
|
+
return receiver;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const isFunctionKeys = new Set([
|
|
23
|
+
'default',
|
|
24
|
+
'enum',
|
|
25
|
+
'max',
|
|
26
|
+
'maxlength',
|
|
27
|
+
'min',
|
|
28
|
+
'minlength'
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
export { createBaseSchemaBuilderFactory };
|
|
@@ -0,0 +1,50 @@
|
|
|
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 = {
|
|
4
|
+
type: BooleanSchemaDefinition;
|
|
5
|
+
}, ExtraOmitFields extends string = never, 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
|
+
}, ExtraOmitFields>;
|
|
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
|
+
}, ExtraOmitFields>;
|
|
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
|
+
}, ExtraOmitFields>;
|
|
35
|
+
unique: ExtendBooleanSchemaBuilder<{
|
|
36
|
+
[key in keyof (Props & {
|
|
37
|
+
unique: true;
|
|
38
|
+
})]: (Props & {
|
|
39
|
+
unique: true;
|
|
40
|
+
})[key];
|
|
41
|
+
}, ExtraOmitFields>;
|
|
42
|
+
}
|
|
43
|
+
export declare const booleanSchemaBuilder: (schema?: Record<string, any>) => BooleanSchemaBuilder<{
|
|
44
|
+
type: BooleanSchemaDefinition;
|
|
45
|
+
}, never, {
|
|
46
|
+
type: BooleanSchemaDefinition;
|
|
47
|
+
} & {
|
|
48
|
+
required: true;
|
|
49
|
+
}>;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { DefaultType, DateSchemaDefinition } from 'mongoose';
|
|
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 = {
|
|
5
|
+
type: DateSchemaDefinition;
|
|
6
|
+
}, ExtraOmitFields extends string = never, 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
|
+
}, ExtraOmitFields>;
|
|
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
|
+
}, ExtraOmitFields>;
|
|
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
|
+
}, ExtraOmitFields>;
|
|
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
|
+
}, ExtraOmitFields>;
|
|
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
|
+
}, ExtraOmitFields>;
|
|
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
|
+
}, ExtraOmitFields>;
|
|
62
|
+
unique: ExtendDateSchemaBuilder<{
|
|
63
|
+
[key in keyof (Props & {
|
|
64
|
+
unique: true;
|
|
65
|
+
})]: (Props & {
|
|
66
|
+
unique: true;
|
|
67
|
+
})[key];
|
|
68
|
+
}, ExtraOmitFields>;
|
|
69
|
+
}
|
|
70
|
+
export declare const dateSchemaBuilder: (schema?: Record<string, any>) => DateSchemaBuilder<{
|
|
71
|
+
type: DateSchemaDefinition;
|
|
72
|
+
}, never, {
|
|
73
|
+
type: DateSchemaDefinition;
|
|
74
|
+
} & {
|
|
75
|
+
required: true;
|
|
76
|
+
}>;
|
|
77
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
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 ref = require('./ref.cjs');
|
|
9
|
+
const string = require('./string.cjs');
|
|
10
|
+
|
|
11
|
+
const schemaBuilders = {
|
|
12
|
+
date: date.dateSchemaBuilder,
|
|
13
|
+
boolean: boolean.booleanSchemaBuilder,
|
|
14
|
+
number: number.numberSchemaBuilder,
|
|
15
|
+
ref: ref.refSchemaBuilder,
|
|
16
|
+
string: string.stringSchemaBuilder
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.dateSchemaBuilder = date.dateSchemaBuilder;
|
|
20
|
+
exports.booleanSchemaBuilder = boolean.booleanSchemaBuilder;
|
|
21
|
+
exports.numberSchemaBuilder = number.numberSchemaBuilder;
|
|
22
|
+
exports.refSchemaBuilder = ref.refSchemaBuilder;
|
|
23
|
+
exports.stringSchemaBuilder = string.stringSchemaBuilder;
|
|
24
|
+
exports.default = schemaBuilders;
|
|
25
|
+
exports.schemaBuilders = schemaBuilders;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export * from './date';
|
|
2
|
+
export * from './boolean';
|
|
3
|
+
export * from './number';
|
|
4
|
+
export * from './ref';
|
|
5
|
+
export * from './string';
|
|
6
|
+
export declare const schemaBuilders: {
|
|
7
|
+
date: (schema?: Record<string, any>) => import("./date").DateSchemaBuilder<{
|
|
8
|
+
type: import("mongoose").DateSchemaDefinition;
|
|
9
|
+
}, never, {
|
|
10
|
+
type: import("mongoose").DateSchemaDefinition;
|
|
11
|
+
} & {
|
|
12
|
+
required: true;
|
|
13
|
+
}>;
|
|
14
|
+
boolean: (schema?: Record<string, any>) => import("./boolean").BooleanSchemaBuilder<{
|
|
15
|
+
type: import("mongoose").BooleanSchemaDefinition;
|
|
16
|
+
}, never, {
|
|
17
|
+
type: import("mongoose").BooleanSchemaDefinition;
|
|
18
|
+
} & {
|
|
19
|
+
required: true;
|
|
20
|
+
}>;
|
|
21
|
+
number: (schema?: Record<string, any>) => import("./number").NumberSchemaBuilder<{
|
|
22
|
+
type: import("mongoose").NumberSchemaDefinition;
|
|
23
|
+
}, never, {
|
|
24
|
+
type: import("mongoose").NumberSchemaDefinition;
|
|
25
|
+
} & {
|
|
26
|
+
required: true;
|
|
27
|
+
}>;
|
|
28
|
+
ref: <T extends string | import("mongoose").Model<any> | ((this: any, doc: any) => string | import("mongoose").Model<any>)>(ref: T) => import("./ref").RefSchemaBuilder<{
|
|
29
|
+
ref: T;
|
|
30
|
+
}>;
|
|
31
|
+
string: () => import("./string").StringSchemaBuilder;
|
|
32
|
+
};
|
|
33
|
+
export default schemaBuilders;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { dateSchemaBuilder } from './date.mjs';
|
|
2
|
+
import { booleanSchemaBuilder } from './boolean.mjs';
|
|
3
|
+
import { numberSchemaBuilder } from './number.mjs';
|
|
4
|
+
import { refSchemaBuilder } from './ref.mjs';
|
|
5
|
+
import { stringSchemaBuilder } from './string.mjs';
|
|
6
|
+
|
|
7
|
+
const schemaBuilders = {
|
|
8
|
+
date: dateSchemaBuilder,
|
|
9
|
+
boolean: booleanSchemaBuilder,
|
|
10
|
+
number: numberSchemaBuilder,
|
|
11
|
+
ref: refSchemaBuilder,
|
|
12
|
+
string: stringSchemaBuilder
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { booleanSchemaBuilder, dateSchemaBuilder, schemaBuilders as default, numberSchemaBuilder, refSchemaBuilder, schemaBuilders, stringSchemaBuilder };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { DefaultType, NumberSchemaDefinition } from 'mongoose';
|
|
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 = {
|
|
5
|
+
type: NumberSchemaDefinition;
|
|
6
|
+
}, ExtraOmitFields extends string = never, 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
|
+
}, ExtraOmitFields>;
|
|
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
|
+
}, ExtraOmitFields>;
|
|
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
|
+
}, ExtraOmitFields>;
|
|
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
|
+
}, ExtraOmitFields>;
|
|
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
|
+
}, ExtraOmitFields>;
|
|
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
|
+
}, ExtraOmitFields>;
|
|
62
|
+
unique: ExtendNumberSchemaBuilder<{
|
|
63
|
+
[key in keyof (Props & {
|
|
64
|
+
unique: true;
|
|
65
|
+
})]: (Props & {
|
|
66
|
+
unique: true;
|
|
67
|
+
})[key];
|
|
68
|
+
}, ExtraOmitFields>;
|
|
69
|
+
}
|
|
70
|
+
export declare const numberSchemaBuilder: (schema?: Record<string, any>) => NumberSchemaBuilder<{
|
|
71
|
+
type: NumberSchemaDefinition;
|
|
72
|
+
}, never, {
|
|
73
|
+
type: NumberSchemaDefinition;
|
|
74
|
+
} & {
|
|
75
|
+
required: true;
|
|
76
|
+
}>;
|
|
77
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const mongoose = require('mongoose');
|
|
4
|
+
const base = require('./base.cjs');
|
|
5
|
+
|
|
6
|
+
const baseBuilderFactory = base.createBaseSchemaBuilderFactory(mongoose.Schema.Types.ObjectId);
|
|
7
|
+
const refSchemaBuilder = (ref) => baseBuilderFactory({ ref });
|
|
8
|
+
|
|
9
|
+
exports.refSchemaBuilder = refSchemaBuilder;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { DefaultType, Model, ObjectIdSchemaDefinition, Types } from 'mongoose';
|
|
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 = {
|
|
5
|
+
type: ObjectIdSchemaDefinition;
|
|
6
|
+
}, ExtraOmitFields extends string = never, PropsWithRequired = Props & {
|
|
7
|
+
required: true;
|
|
8
|
+
}> {
|
|
9
|
+
default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends Types.ObjectId>(value: T) => ExtendRefSchemaBuilder<{
|
|
10
|
+
[key in keyof (Props & {
|
|
11
|
+
default: T;
|
|
12
|
+
})]: (Props & {
|
|
13
|
+
default: T;
|
|
14
|
+
})[key];
|
|
15
|
+
}, ExtraOmitFields>;
|
|
16
|
+
enum: <T extends MaybeReadonly<Array<O | null>> | {
|
|
17
|
+
message?: M;
|
|
18
|
+
values: MaybeReadonly<Array<O | null>>;
|
|
19
|
+
} | {
|
|
20
|
+
[path: string]: O | null;
|
|
21
|
+
}, M extends string, O extends Types.ObjectId>(value: T) => ExtendRefSchemaBuilder<{
|
|
22
|
+
[key in keyof (Props & {
|
|
23
|
+
enum: T;
|
|
24
|
+
})]: (Props & {
|
|
25
|
+
enum: T;
|
|
26
|
+
})[key];
|
|
27
|
+
}, ExtraOmitFields>;
|
|
28
|
+
nonRequired: {
|
|
29
|
+
[key in keyof Props]: Props[key];
|
|
30
|
+
};
|
|
31
|
+
private: ExtendRefSchemaBuilder<{
|
|
32
|
+
[key in keyof (Props & {
|
|
33
|
+
private: true;
|
|
34
|
+
})]: (Props & {
|
|
35
|
+
private: true;
|
|
36
|
+
})[key];
|
|
37
|
+
}, ExtraOmitFields>;
|
|
38
|
+
required: {
|
|
39
|
+
[key in keyof PropsWithRequired]: PropsWithRequired[key];
|
|
40
|
+
};
|
|
41
|
+
sparse: ExtendRefSchemaBuilder<{
|
|
42
|
+
[key in keyof (Props & {
|
|
43
|
+
sparse: true;
|
|
44
|
+
})]: (Props & {
|
|
45
|
+
sparse: true;
|
|
46
|
+
})[key];
|
|
47
|
+
}, ExtraOmitFields>;
|
|
48
|
+
unique: ExtendRefSchemaBuilder<{
|
|
49
|
+
[key in keyof (Props & {
|
|
50
|
+
unique: true;
|
|
51
|
+
})]: (Props & {
|
|
52
|
+
unique: true;
|
|
53
|
+
})[key];
|
|
54
|
+
}, ExtraOmitFields>;
|
|
55
|
+
}
|
|
56
|
+
export declare const refSchemaBuilder: <T extends string | Model<any> | ((this: any, doc: any) => string | Model<any>)>(ref: T) => RefSchemaBuilder<{
|
|
57
|
+
ref: T;
|
|
58
|
+
}>;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
import { createBaseSchemaBuilderFactory } from './base.mjs';
|
|
3
|
+
|
|
4
|
+
const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.ObjectId);
|
|
5
|
+
const refSchemaBuilder = (ref) => baseBuilderFactory({ ref });
|
|
6
|
+
|
|
7
|
+
export { refSchemaBuilder };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const net = require('node:net');
|
|
4
|
+
const base = require('./base.cjs');
|
|
5
|
+
|
|
6
|
+
const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
|
|
7
|
+
|
|
8
|
+
const net__default = /*#__PURE__*/_interopDefaultCompat(net);
|
|
9
|
+
|
|
10
|
+
const baseBuilderFactory = base.createBaseSchemaBuilderFactory(String);
|
|
11
|
+
const stringSchemaBuilder = () => {
|
|
12
|
+
const schema = {};
|
|
13
|
+
const baseBuilder = baseBuilderFactory(schema);
|
|
14
|
+
return new Proxy(baseBuilder, {
|
|
15
|
+
get(target, key, receiver) {
|
|
16
|
+
if (key === 'ipv4') {
|
|
17
|
+
return (message = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.') => {
|
|
18
|
+
schema.trim = true;
|
|
19
|
+
schema.validate = { message, validator: (value) => net__default.isIPv4(value) };
|
|
20
|
+
return receiver;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (key === 'ipv6') {
|
|
24
|
+
return (message = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.') => {
|
|
25
|
+
schema.trim = true;
|
|
26
|
+
schema.validate = { message, validator: (value) => net__default.isIPv6(value) };
|
|
27
|
+
return receiver;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (key === 'length')
|
|
31
|
+
return (value) => ((schema['maxlength'] = schema['minlength'] = value), receiver);
|
|
32
|
+
return Reflect.get(target, key, receiver);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.stringSchemaBuilder = stringSchemaBuilder;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { DefaultType, StringSchemaDefinition } from 'mongoose';
|
|
2
|
+
import type { MaybeReadonly } from '../types/utils';
|
|
3
|
+
type ExtendStringSchemaBuilder<Props, ExtraOmitFields extends string> = Omit<StringSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
4
|
+
type IPSchema<T extends string> = {
|
|
5
|
+
trim: true;
|
|
6
|
+
validate: {
|
|
7
|
+
message: T;
|
|
8
|
+
validator: (value: string) => boolean;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export interface StringSchemaBuilder<Props = {
|
|
12
|
+
type: StringSchemaDefinition;
|
|
13
|
+
}, ExtraOmitFields extends string = never, PropsWithRequired = Props & {
|
|
14
|
+
required: true;
|
|
15
|
+
}> {
|
|
16
|
+
default: <T extends DefaultType<D> | ((this: any, doc: any) => DefaultType<D>) | null, D extends string>(value: T) => ExtendStringSchemaBuilder<{
|
|
17
|
+
[key in keyof (Props & {
|
|
18
|
+
default: T;
|
|
19
|
+
})]: (Props & {
|
|
20
|
+
default: T;
|
|
21
|
+
})[key];
|
|
22
|
+
}, ExtraOmitFields>;
|
|
23
|
+
enum: <T extends MaybeReadonly<Array<S | null>> | {
|
|
24
|
+
message?: M;
|
|
25
|
+
values: MaybeReadonly<Array<S | null>>;
|
|
26
|
+
} | {
|
|
27
|
+
[path: string]: S | null;
|
|
28
|
+
}, M extends string, S extends string>(value: T) => ExtendStringSchemaBuilder<{
|
|
29
|
+
[key in keyof (Props & {
|
|
30
|
+
enum: T;
|
|
31
|
+
})]: (Props & {
|
|
32
|
+
enum: T;
|
|
33
|
+
})[key];
|
|
34
|
+
}, ExtraOmitFields>;
|
|
35
|
+
ipv4: <T extends string = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.'>(message?: T) => ExtendStringSchemaBuilder<{
|
|
36
|
+
[key in keyof (Props & IPSchema<T>)]: (Props & IPSchema<T>)[key];
|
|
37
|
+
}, ExtraOmitFields | 'ipv4' | 'ipv6'>;
|
|
38
|
+
ipv6: <T extends string = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.'>(message?: T) => ExtendStringSchemaBuilder<{
|
|
39
|
+
[key in keyof (Props & IPSchema<T>)]: (Props & IPSchema<T>)[key];
|
|
40
|
+
}, ExtraOmitFields | 'ipv4' | 'ipv6'>;
|
|
41
|
+
length: <T extends L | MaybeReadonly<[L, S]>, L extends number, S extends string>(value: T) => ExtendStringSchemaBuilder<{
|
|
42
|
+
[key in keyof (Props & {
|
|
43
|
+
maxlength: T;
|
|
44
|
+
minlength: T;
|
|
45
|
+
})]: (Props & {
|
|
46
|
+
maxlength: T;
|
|
47
|
+
minlength: T;
|
|
48
|
+
})[key];
|
|
49
|
+
}, ExtraOmitFields>;
|
|
50
|
+
lowercase: ExtendStringSchemaBuilder<{
|
|
51
|
+
[key in keyof (Props & {
|
|
52
|
+
lowercase: true;
|
|
53
|
+
})]: (Props & {
|
|
54
|
+
lowercase: true;
|
|
55
|
+
})[key];
|
|
56
|
+
}, ExtraOmitFields>;
|
|
57
|
+
maxlength: <T extends L | MaybeReadonly<[L, S]>, L extends number, S extends string>(value: T) => ExtendStringSchemaBuilder<{
|
|
58
|
+
[key in keyof (Props & {
|
|
59
|
+
maxlength: T;
|
|
60
|
+
})]: (Props & {
|
|
61
|
+
maxlength: T;
|
|
62
|
+
})[key];
|
|
63
|
+
}, ExtraOmitFields>;
|
|
64
|
+
minlength: <T extends L | MaybeReadonly<[L, S]>, L extends number, S extends string>(value: T) => ExtendStringSchemaBuilder<{
|
|
65
|
+
[key in keyof (Props & {
|
|
66
|
+
minlength: T;
|
|
67
|
+
})]: (Props & {
|
|
68
|
+
minlength: T;
|
|
69
|
+
})[key];
|
|
70
|
+
}, ExtraOmitFields>;
|
|
71
|
+
nonRequired: {
|
|
72
|
+
[key in keyof Props]: Props[key];
|
|
73
|
+
};
|
|
74
|
+
private: ExtendStringSchemaBuilder<{
|
|
75
|
+
[key in keyof (Props & {
|
|
76
|
+
private: true;
|
|
77
|
+
})]: (Props & {
|
|
78
|
+
private: true;
|
|
79
|
+
})[key];
|
|
80
|
+
}, ExtraOmitFields>;
|
|
81
|
+
required: {
|
|
82
|
+
[key in keyof PropsWithRequired]: PropsWithRequired[key];
|
|
83
|
+
};
|
|
84
|
+
sparse: ExtendStringSchemaBuilder<{
|
|
85
|
+
[key in keyof (Props & {
|
|
86
|
+
sparse: true;
|
|
87
|
+
})]: (Props & {
|
|
88
|
+
sparse: true;
|
|
89
|
+
})[key];
|
|
90
|
+
}, ExtraOmitFields>;
|
|
91
|
+
text: ExtendStringSchemaBuilder<{
|
|
92
|
+
[key in keyof (Props & {
|
|
93
|
+
text: true;
|
|
94
|
+
})]: (Props & {
|
|
95
|
+
text: true;
|
|
96
|
+
})[key];
|
|
97
|
+
}, ExtraOmitFields>;
|
|
98
|
+
trim: ExtendStringSchemaBuilder<{
|
|
99
|
+
[key in keyof (Props & {
|
|
100
|
+
trim: true;
|
|
101
|
+
})]: (Props & {
|
|
102
|
+
trim: true;
|
|
103
|
+
})[key];
|
|
104
|
+
}, ExtraOmitFields>;
|
|
105
|
+
unique: ExtendStringSchemaBuilder<{
|
|
106
|
+
[key in keyof (Props & {
|
|
107
|
+
unique: true;
|
|
108
|
+
})]: (Props & {
|
|
109
|
+
unique: true;
|
|
110
|
+
})[key];
|
|
111
|
+
}, ExtraOmitFields>;
|
|
112
|
+
uppercase: ExtendStringSchemaBuilder<{
|
|
113
|
+
[key in keyof (Props & {
|
|
114
|
+
uppercase: true;
|
|
115
|
+
})]: (Props & {
|
|
116
|
+
uppercase: true;
|
|
117
|
+
})[key];
|
|
118
|
+
}, ExtraOmitFields>;
|
|
119
|
+
}
|
|
120
|
+
export declare const stringSchemaBuilder: () => StringSchemaBuilder;
|
|
121
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import net from 'node:net';
|
|
2
|
+
import { createBaseSchemaBuilderFactory } from './base.mjs';
|
|
3
|
+
|
|
4
|
+
const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
|
|
5
|
+
const stringSchemaBuilder = () => {
|
|
6
|
+
const schema = {};
|
|
7
|
+
const baseBuilder = baseBuilderFactory(schema);
|
|
8
|
+
return new Proxy(baseBuilder, {
|
|
9
|
+
get(target, key, receiver) {
|
|
10
|
+
if (key === 'ipv4') {
|
|
11
|
+
return (message = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.') => {
|
|
12
|
+
schema.trim = true;
|
|
13
|
+
schema.validate = { message, validator: (value) => net.isIPv4(value) };
|
|
14
|
+
return receiver;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (key === 'ipv6') {
|
|
18
|
+
return (message = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.') => {
|
|
19
|
+
schema.trim = true;
|
|
20
|
+
schema.validate = { message, validator: (value) => net.isIPv6(value) };
|
|
21
|
+
return receiver;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (key === 'length')
|
|
25
|
+
return (value) => ((schema['maxlength'] = schema['minlength'] = value), receiver);
|
|
26
|
+
return Reflect.get(target, key, receiver);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { stringSchemaBuilder };
|
package/types/paginate.d.ts
CHANGED
|
@@ -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
|
|
24
|
+
populate?: PopulateOptions[] | string[] | PopulateOptions | string;
|
|
25
25
|
projection?: any;
|
|
26
26
|
lean?: boolean;
|
|
27
27
|
leanWithId?: boolean;
|
package/types/utils.d.ts
ADDED
|
@@ -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,
|
|
@@ -267,6 +276,8 @@ function createCommonMongooseSchemas(customSchemas, options) {
|
|
|
267
276
|
* This function generates a schema definition for an ObjectId reference field, including
|
|
268
277
|
* attributes such as 'private', 'required', and 'unique'.
|
|
269
278
|
*
|
|
279
|
+
* @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.ref} instead.
|
|
280
|
+
*
|
|
270
281
|
* @template R - The type of the reference model name.
|
|
271
282
|
* @template T - An array of attributes to apply to the schema field.
|
|
272
283
|
*
|
|
@@ -287,6 +298,8 @@ function createMongooseObjectIdRefSchema(refModelName, ...attributes) {
|
|
|
287
298
|
* such as 'private', 'required', 'short', 'trim', and 'unique'. If the 'short' attribute
|
|
288
299
|
* is included, the `maxlength` is set to 16.
|
|
289
300
|
*
|
|
301
|
+
* @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.string} instead.
|
|
302
|
+
*
|
|
290
303
|
* @template T - An array of attributes to apply to the schema field.
|
|
291
304
|
*
|
|
292
305
|
* @param attributes - The attributes to apply to the schema field.
|
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: {
|
|
@@ -375,6 +386,8 @@ export declare function createCommonMongooseSchemas<T extends {}>(customSchemas?
|
|
|
375
386
|
* This function generates a schema definition for an ObjectId reference field, including
|
|
376
387
|
* attributes such as 'private', 'required', and 'unique'.
|
|
377
388
|
*
|
|
389
|
+
* @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.ref} instead.
|
|
390
|
+
*
|
|
378
391
|
* @template R - The type of the reference model name.
|
|
379
392
|
* @template T - An array of attributes to apply to the schema field.
|
|
380
393
|
*
|
|
@@ -391,6 +404,8 @@ export declare function createMongooseObjectIdRefSchema<R extends string, T exte
|
|
|
391
404
|
* such as 'private', 'required', 'short', 'trim', and 'unique'. If the 'short' attribute
|
|
392
405
|
* is included, the `maxlength` is set to 16.
|
|
393
406
|
*
|
|
407
|
+
* @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.string} instead.
|
|
408
|
+
*
|
|
394
409
|
* @template T - An array of attributes to apply to the schema field.
|
|
395
410
|
*
|
|
396
411
|
* @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,
|
|
@@ -256,6 +265,8 @@ function createCommonMongooseSchemas(customSchemas, options) {
|
|
|
256
265
|
* This function generates a schema definition for an ObjectId reference field, including
|
|
257
266
|
* attributes such as 'private', 'required', and 'unique'.
|
|
258
267
|
*
|
|
268
|
+
* @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.ref} instead.
|
|
269
|
+
*
|
|
259
270
|
* @template R - The type of the reference model name.
|
|
260
271
|
* @template T - An array of attributes to apply to the schema field.
|
|
261
272
|
*
|
|
@@ -276,6 +287,8 @@ function createMongooseObjectIdRefSchema(refModelName, ...attributes) {
|
|
|
276
287
|
* such as 'private', 'required', 'short', 'trim', and 'unique'. If the 'short' attribute
|
|
277
288
|
* is included, the `maxlength` is set to 16.
|
|
278
289
|
*
|
|
290
|
+
* @deprecated - Will be removed in the next major version. Use {@link schemaBuilders.string} instead.
|
|
291
|
+
*
|
|
279
292
|
* @template T - An array of attributes to apply to the schema field.
|
|
280
293
|
*
|
|
281
294
|
* @param attributes - The attributes to apply to the schema field.
|