@kikiutils/mongoose 9.0.2 → 9.0.4
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/dist/assertions.js.map +1 -1
- package/dist/plugins/assertions.js +4 -4
- package/dist/plugins/assertions.js.map +1 -1
- package/dist/plugins/lean-decimal128-to-string.d.ts +6 -2
- package/dist/plugins/lean-decimal128-to-string.d.ts.map +1 -1
- package/dist/plugins/lean-decimal128-to-string.js +5 -4
- package/dist/plugins/lean-decimal128-to-string.js.map +1 -1
- package/dist/plugins/normalize.d.ts +3 -1
- package/dist/plugins/normalize.d.ts.map +1 -1
- package/dist/plugins/normalize.js +2 -1
- package/dist/plugins/normalize.js.map +1 -1
- package/dist/schema-builders/_internals.d.ts +18 -0
- package/dist/schema-builders/_internals.d.ts.map +1 -0
- package/dist/schema-builders/_internals.js +36 -0
- package/dist/schema-builders/_internals.js.map +1 -0
- package/dist/schema-builders/bigint.d.ts +5 -25
- package/dist/schema-builders/bigint.d.ts.map +1 -1
- package/dist/schema-builders/bigint.js +9 -19
- package/dist/schema-builders/bigint.js.map +1 -1
- package/dist/schema-builders/date.d.ts +4 -9
- package/dist/schema-builders/date.d.ts.map +1 -1
- package/dist/schema-builders/date.js.map +1 -1
- package/dist/schema-builders/decimal128.d.ts +6 -24
- package/dist/schema-builders/decimal128.d.ts.map +1 -1
- package/dist/schema-builders/decimal128.js +4 -6
- package/dist/schema-builders/decimal128.js.map +1 -1
- package/dist/schema-builders/double.d.ts +5 -25
- package/dist/schema-builders/double.d.ts.map +1 -1
- package/dist/schema-builders/double.js +9 -19
- package/dist/schema-builders/double.js.map +1 -1
- package/dist/schema-builders/int32.d.ts +5 -25
- package/dist/schema-builders/int32.d.ts.map +1 -1
- package/dist/schema-builders/int32.js +9 -19
- package/dist/schema-builders/int32.js.map +1 -1
- package/dist/schema-builders/number.d.ts +4 -9
- package/dist/schema-builders/number.d.ts.map +1 -1
- package/dist/schema-builders/number.js.map +1 -1
- package/dist/schema-builders/object-id.d.ts +2 -7
- package/dist/schema-builders/object-id.d.ts.map +1 -1
- package/dist/schema-builders/object-id.js.map +1 -1
- package/dist/schema-builders/ref.d.ts +2 -7
- package/dist/schema-builders/ref.d.ts.map +1 -1
- package/dist/schema-builders/ref.js.map +1 -1
- package/dist/schema-builders/string.d.ts +5 -10
- package/dist/schema-builders/string.d.ts.map +1 -1
- package/dist/schema-builders/string.js.map +1 -1
- package/dist/types/_internals.d.ts +22 -0
- package/dist/types/_internals.d.ts.map +1 -1
- package/dist/types/aggregate-paginate.d.ts +2 -1
- package/dist/types/aggregate-paginate.d.ts.map +1 -1
- package/dist/types/data.d.ts +3 -1
- package/dist/types/data.d.ts.map +1 -1
- package/dist/types/options.d.ts +6 -2
- package/dist/types/options.d.ts.map +1 -1
- package/package.json +23 -29
- package/src/assertions.ts +0 -1
- package/src/plugins/assertions.ts +4 -4
- package/src/plugins/lean-decimal128-to-string.ts +18 -7
- package/src/plugins/normalize.ts +5 -2
- package/src/schema-builders/_internals.ts +64 -0
- package/src/schema-builders/bigint.ts +33 -67
- package/src/schema-builders/date.ts +7 -7
- package/src/schema-builders/decimal128.ts +25 -41
- package/src/schema-builders/double.ts +35 -67
- package/src/schema-builders/int32.ts +33 -67
- package/src/schema-builders/number.ts +7 -7
- package/src/schema-builders/object-id.ts +2 -5
- package/src/schema-builders/ref.ts +2 -5
- package/src/schema-builders/string.ts +8 -8
- package/src/types/_internals.ts +26 -0
- package/src/types/aggregate-paginate.ts +2 -1
- package/src/types/data.ts +3 -1
- package/src/types/options.ts +6 -2
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
import { defaultLimitValidateMessages, normalizeValueWithMessage, setSchemaValidator } from "./_internals.js";
|
|
1
2
|
import { createBaseSchemaBuilderFactory } from "./base.js";
|
|
2
3
|
import { Schema } from "mongoose";
|
|
3
4
|
import { Decimal } from "decimal.js";
|
|
4
5
|
// src/schema-builders/decimal128.ts
|
|
5
|
-
const defaultMinValidateMessage = "Path `{PATH}` ({VALUE}) is less than minimum allowed value ({MIN}).";
|
|
6
|
-
const defaultMaxValidateMessage = "Path `{PATH}` ({VALUE}) is more than maximum allowed value ({MAX}).";
|
|
7
6
|
const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);
|
|
8
7
|
function createLimitValidator(type, value) {
|
|
9
|
-
const [limit, message] =
|
|
8
|
+
const [limit, message] = normalizeValueWithMessage(value);
|
|
10
9
|
const decimalLimit = new Decimal(limit.toString());
|
|
11
10
|
if (!decimalLimit.isFinite()) throw new RangeError(`Decimal128 ${type} limit must be finite`);
|
|
12
11
|
return {
|
|
13
|
-
message: message ??
|
|
12
|
+
message: message ?? defaultLimitValidateMessages[type],
|
|
14
13
|
[type]: decimalLimit.toString(),
|
|
15
14
|
type,
|
|
16
15
|
validator: (value) => {
|
|
@@ -26,8 +25,7 @@ function decimal128SchemaBuilder() {
|
|
|
26
25
|
return new Proxy(baseBuilder, { get(target, key, receiver) {
|
|
27
26
|
if (key === "max" || key === "min") return (value) => {
|
|
28
27
|
const validator = createLimitValidator(key, value);
|
|
29
|
-
|
|
30
|
-
schema.validate = [...validators.filter(({ type }) => type !== key), validator];
|
|
28
|
+
setSchemaValidator(schema, validator);
|
|
31
29
|
return receiver;
|
|
32
30
|
};
|
|
33
31
|
if (key === "setRoundAndToFixedSetter") return (places = 2, rounding = Decimal.ROUND_DOWN) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decimal128.js","names":[],"sources":["../../src/schema-builders/decimal128.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\nimport { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"decimal128.js","names":[],"sources":["../../src/schema-builders/decimal128.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\nimport { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type {\n EnumInput,\n LimitValidator,\n ValidationSchema,\n ValueWithMessage,\n} from '../types/_internals';\n\nimport {\n defaultLimitValidateMessages,\n normalizeValueWithMessage,\n setSchemaValidator,\n} from './_internals';\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype Decimal128Limit = Decimal.Value | Types.Decimal128 | { toString: () => string };\ntype Decimal128ValidationSchema = ValidationSchema<LimitValidator<string, Types.Decimal128>>;\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n Decimal128SchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: typeof Schema.Types.Decimal128;\n}\n\nexport interface Decimal128SchemaBuilder<\n Props extends BaseProps = BaseProps,\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends Types.Decimal128,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends EnumInput<D | null, M>,\n D extends Types.Decimal128,\n M extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n max: <\n T extends ValueWithMessage<D, S>,\n D extends Decimal128Limit,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, Decimal128ValidationSchema>,\n 'max' | ExtraOmitFields\n >;\n\n min: <\n T extends ValueWithMessage<D, S>,\n D extends Decimal128Limit,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, Decimal128ValidationSchema>,\n 'min' | ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n\n /**\n * Configures a setter that rounds decimal values and formats them with a fixed number of decimal places.\n *\n * @remarks\n * Replaces the configured setter on this builder. The setter converts non-nullish values through Decimal.js\n * and returns a decimal string for Mongoose to cast to `Decimal128`. It returns `undefined` for `null` or\n * `undefined`. Decimal.js validates conversion and formatting when the setter processes a value,\n * not when the setter is configured.\n *\n * @param places - The non-negative integer number of decimal places. Defaults to `2`.\n * @param rounding - The Decimal.js rounding mode. Defaults to `Decimal.ROUND_DOWN`, which rounds toward zero.\n *\n * @returns This instance for chaining.\n */\n setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendSchemaBuilder<\n Merge<Props, ToStringSetterSchema>,\n 'setRoundAndToFixedSetter' | ExtraOmitFields\n >;\n\n /**\n * Configures a getter that converts decimal values to strings.\n *\n * @remarks\n * Replaces the configured getter on this builder. The getter returns the value's string representation,\n * or `undefined` for `null` or `undefined`. It changes the read representation, not the stored BSON type.\n * Marks this path for the lean Decimal128-to-string plugin; the plugin does not invoke this getter.\n *\n * @returns This instance for chaining.\n */\n setToStringGetter: ExtendSchemaBuilder<Merge<Props, ToStringGetterSchema>, 'setToStringGetter' | ExtraOmitFields>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\ninterface ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n leanDecimal128ToString: true;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string | undefined;\n}\n\n// Functions\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);\n\nfunction createLimitValidator(\n type: 'max' | 'min',\n value: ValueWithMessage<Decimal128Limit>,\n): LimitValidator<string, Types.Decimal128> {\n const [limit, message] = normalizeValueWithMessage(value);\n\n const decimalLimit = new Decimal(limit.toString());\n if (!decimalLimit.isFinite()) throw new RangeError(`Decimal128 ${type} limit must be finite`);\n\n return {\n message: message ?? defaultLimitValidateMessages[type],\n [type]: decimalLimit.toString(),\n type,\n validator: (value) => {\n if (value === null || value === undefined) return true;\n\n const decimalValue = new Decimal(value.toString());\n return type === 'min' ? decimalValue.gte(decimalLimit) : decimalValue.lte(decimalLimit);\n },\n };\n}\n\nexport function decimal128SchemaBuilder() {\n const schema: Partial<Decimal128ValidationSchema> & Record<string, any> = {};\n const baseBuilder = baseBuilderFactory(schema);\n return new Proxy(\n baseBuilder,\n {\n get(target, key, receiver) {\n if (key === 'max' || key === 'min') {\n return (value: ValueWithMessage<Decimal128Limit>) => {\n const validator = createLimitValidator(key, value);\n setSchemaValidator(schema, validator);\n\n return receiver;\n };\n }\n\n if (key === 'setRoundAndToFixedSetter') {\n return (places: number = 2, rounding: Decimal.Rounding = Decimal.ROUND_DOWN) => {\n schema.set = (value?: { toString: () => string }) => {\n if (value !== undefined && value !== null) {\n const decimal = Decimal.isDecimal(value) ? value : new Decimal(value.toString());\n return decimal.toFixed(places, rounding);\n }\n };\n\n return receiver;\n };\n }\n\n if (key === 'setToStringGetter') {\n schema.get = (value?: Types.Decimal128) => value?.toString();\n schema.leanDecimal128ToString = true;\n return receiver;\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as Decimal128SchemaBuilder;\n}\n"],"mappings":";;;;;AAoIA,MAAM,qBAAqB,+BAA+B,OAAO,MAAM,UAAU;AAEjF,SAAS,qBACL,MACA,OACwC;CACxC,MAAM,CAAC,OAAO,WAAW,0BAA0B,KAAK;CAExD,MAAM,eAAe,IAAI,QAAQ,MAAM,SAAS,CAAC;CACjD,IAAI,CAAC,aAAa,SAAS,GAAG,MAAM,IAAI,WAAW,cAAc,KAAK,sBAAsB;CAE5F,OAAO;EACH,SAAS,WAAW,6BAA6B;GAChD,OAAO,aAAa,SAAS;EAC9B;EACA,YAAY,UAAU;GAClB,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;GAElD,MAAM,eAAe,IAAI,QAAQ,MAAM,SAAS,CAAC;GACjD,OAAO,SAAS,QAAQ,aAAa,IAAI,YAAY,IAAI,aAAa,IAAI,YAAY;EAC1F;CACJ;AACJ;AAEA,SAAgB,0BAA0B;CACtC,MAAM,SAAoE,CAAC;CAC3E,MAAM,cAAc,mBAAmB,MAAM;CAC7C,OAAO,IAAI,MACP,aACA,EACI,IAAI,QAAQ,KAAK,UAAU;EACvB,IAAI,QAAQ,SAAS,QAAQ,OACzB,QAAQ,UAA6C;GACjD,MAAM,YAAY,qBAAqB,KAAK,KAAK;GACjD,mBAAmB,QAAQ,SAAS;GAEpC,OAAO;EACX;EAGJ,IAAI,QAAQ,4BACR,QAAQ,SAAiB,GAAG,WAA6B,QAAQ,eAAe;GAC5E,OAAO,OAAO,UAAuC;IACjD,IAAI,UAAU,KAAA,KAAa,UAAU,MAEjC,QADgB,QAAQ,UAAU,KAAK,IAAI,QAAQ,IAAI,QAAQ,MAAM,SAAS,CAAC,EAAA,CAChE,QAAQ,QAAQ,QAAQ;GAE/C;GAEA,OAAO;EACX;EAGJ,IAAI,QAAQ,qBAAqB;GAC7B,OAAO,OAAO,UAA6B,OAAO,SAAS;GAC3D,OAAO,yBAAyB;GAChC,OAAO;EACX;EAEA,OAAO,QAAQ,IAAI,QAAQ,KAAK,QAAQ;CAC5C,EACJ,CACJ;AACJ"}
|
|
@@ -1,42 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EnumInput, EnumValidator, LimitValidator, ValidationSchema, ValueWithMessage } from "../types/_internals.js";
|
|
2
2
|
import { IndexDirection, IndexOptions, Schema, Types } from "mongoose";
|
|
3
3
|
import { Merge } from "type-fest";
|
|
4
4
|
type DoubleLimit = number | Types.Double;
|
|
5
|
+
type DoubleValidationSchema = ValidationSchema<EnumValidator<number | Types.Double, Types.Double> | LimitValidator<number, Types.Double>>;
|
|
5
6
|
type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<DoubleSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
6
7
|
interface BaseProps {
|
|
7
8
|
type: typeof Schema.Types.Double;
|
|
8
9
|
}
|
|
9
|
-
interface DoubleEnumValidator {
|
|
10
|
-
enumValues: (null | number | Types.Double)[];
|
|
11
|
-
message: string;
|
|
12
|
-
type: 'enum';
|
|
13
|
-
validator: (value: null | Types.Double | undefined) => boolean;
|
|
14
|
-
}
|
|
15
|
-
interface DoubleLimitValidator {
|
|
16
|
-
max?: number;
|
|
17
|
-
message: string;
|
|
18
|
-
min?: number;
|
|
19
|
-
type: 'max' | 'min';
|
|
20
|
-
validator: (value: null | Types.Double | undefined) => boolean;
|
|
21
|
-
}
|
|
22
10
|
export interface DoubleSchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFields extends string = never> {
|
|
23
11
|
default: <T extends ((this: any, doc: any) => D | null | undefined) | D | null | undefined, D extends Types.Double>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
24
12
|
default: T;
|
|
25
13
|
}>, ExtraOmitFields>;
|
|
26
|
-
enum: <T extends
|
|
27
|
-
[path: string]: N | null;
|
|
28
|
-
} | {
|
|
29
|
-
message?: M;
|
|
30
|
-
values: Readonlyable<(N | null)[]>;
|
|
31
|
-
}, M extends string, N extends number | Types.Double>(value: T) => ExtendSchemaBuilder<Merge<Props, DoubleValidationSchema>, 'enum' | ExtraOmitFields>;
|
|
14
|
+
enum: <T extends EnumInput<N | null, M>, M extends string, N extends number | Types.Double>(value: T) => ExtendSchemaBuilder<Merge<Props, DoubleValidationSchema>, 'enum' | ExtraOmitFields>;
|
|
32
15
|
immutable: ExtendSchemaBuilder<Merge<Props, {
|
|
33
16
|
immutable: true;
|
|
34
17
|
}>, ExtraOmitFields>;
|
|
35
18
|
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
36
19
|
index: T;
|
|
37
20
|
}>, ExtraOmitFields>;
|
|
38
|
-
max: <T extends
|
|
39
|
-
min: <T extends
|
|
21
|
+
max: <T extends ValueWithMessage<L, S>, L extends DoubleLimit, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, DoubleValidationSchema>, 'max' | ExtraOmitFields>;
|
|
22
|
+
min: <T extends ValueWithMessage<L, S>, L extends DoubleLimit, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, DoubleValidationSchema>, 'min' | ExtraOmitFields>;
|
|
40
23
|
nonRequired: Props;
|
|
41
24
|
private: ExtendSchemaBuilder<Merge<Props, {
|
|
42
25
|
private: true;
|
|
@@ -51,9 +34,6 @@ export interface DoubleSchemaBuilder<Props extends BaseProps = BaseProps, ExtraO
|
|
|
51
34
|
unique: true;
|
|
52
35
|
}>, ExtraOmitFields>;
|
|
53
36
|
}
|
|
54
|
-
interface DoubleValidationSchema {
|
|
55
|
-
validate: (DoubleEnumValidator | DoubleLimitValidator)[];
|
|
56
|
-
}
|
|
57
37
|
export declare function doubleSchemaBuilder(): DoubleSchemaBuilder;
|
|
58
38
|
export {};
|
|
59
39
|
//# sourceMappingURL=double.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"double.d.ts","names":[],"sources":["../../src/schema-builders/double.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"double.d.ts","names":[],"sources":["../../src/schema-builders/double.ts"],"mappings":";;;KA0BK,uBAAuB,MAAM;KAC7B,yBAAyB,iBAC1B,uBAAuB,MAAM,QAAQ,MAAM,UAAU,uBAAuB,MAAM;KAGjF,oBACD,cAAc,WACd,kCACA,KACA,oBAAoB,OAAO,kBAC3B,wBAAwB;UAGlB;EACN,aAAa,OAAO,MAAM;;iBAGb,oBAAoB,cAAc,YAAY,WAAW;EACtE,UACI,YAAY,WAAW,aAAa,wBAAwB,sBAC5D,UAAU,MAAM,QAClB,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,UAAU,UAAU,UAAU,IAC9B,kBACA,mBAAmB,MAAM,QAC3B,OAAO,MAAM,oBACX,MAAM,OAAO,kCACJ;EAGb,WAAW,oBAAoB,MAAM;IAAS;MAAoB;EAClE,QAAQ,oBAAoB,iBAAiB,cAAc,OAAO,MAAM,oBACpE,MAAM;IAAS,OAAO;MACtB;EAGJ,MACI,UAAU,iBAAiB,GAAG,IAC9B,UAAU,aACV,kBACF,OAAO,MAAM,oBACX,MAAM,OAAO,iCACL;EAGZ,MACI,UAAU,iBAAiB,GAAG,IAC9B,UAAU,aACV,kBACF,OAAO,MAAM,oBACX,MAAM,OAAO,iCACL;EAGZ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;EACzB,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;;wBA2BhD,uBAgDP"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
+
import { defaultLimitValidateMessages, hasSchemaValidator, normalizeEnumValues, normalizeValueWithMessage, setSchemaValidator } from "./_internals.js";
|
|
1
2
|
import { createBaseSchemaBuilderFactory } from "./base.js";
|
|
2
3
|
import { Schema } from "mongoose";
|
|
3
4
|
// src/schema-builders/double.ts
|
|
4
|
-
const defaultEnumValidateMessage = "Path `{PATH}` ({VALUE}) is not a valid enum value.";
|
|
5
|
-
const defaultMinValidateMessage = "Path `{PATH}` ({VALUE}) is less than minimum allowed value ({MIN}).";
|
|
6
|
-
const defaultMaxValidateMessage = "Path `{PATH}` ({VALUE}) is more than maximum allowed value ({MAX}).";
|
|
7
5
|
const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Double);
|
|
8
6
|
function createLimitValidator(type, value) {
|
|
9
|
-
const [limit, message] =
|
|
7
|
+
const [limit, message] = normalizeValueWithMessage(value);
|
|
10
8
|
const numericLimit = typeof limit === "number" ? limit : limit.valueOf();
|
|
11
9
|
if (!Number.isFinite(numericLimit)) throw new RangeError(`Double ${type} limit must be finite`);
|
|
12
10
|
return {
|
|
13
|
-
message: message ??
|
|
11
|
+
message: message ?? defaultLimitValidateMessages[type],
|
|
14
12
|
[type]: numericLimit,
|
|
15
13
|
type,
|
|
16
14
|
validator: (value) => {
|
|
@@ -24,33 +22,25 @@ function doubleSchemaBuilder() {
|
|
|
24
22
|
const baseBuilder = baseBuilderFactory(schema);
|
|
25
23
|
return new Proxy(baseBuilder, { get(target, key, receiver) {
|
|
26
24
|
if (key === "enum") {
|
|
27
|
-
if (schema
|
|
25
|
+
if (hasSchemaValidator(schema, "enum")) throw new Error("Duplicate schema attribute: enum");
|
|
28
26
|
return (value) => {
|
|
29
|
-
|
|
30
|
-
let message;
|
|
31
|
-
if (Array.isArray(value)) enumValues = [...value];
|
|
32
|
-
else if ("values" in value && Array.isArray(value.values)) {
|
|
33
|
-
enumValues = [...value.values];
|
|
34
|
-
if ("message" in value && typeof value.message === "string") message = value.message;
|
|
35
|
-
} else enumValues = Object.values(value);
|
|
27
|
+
const { enumValues, message } = normalizeEnumValues(value);
|
|
36
28
|
const allowedValues = new Set(enumValues.map((value) => value === null ? null : value.valueOf()));
|
|
37
|
-
|
|
29
|
+
setSchemaValidator(schema, {
|
|
38
30
|
enumValues,
|
|
39
|
-
message: message ??
|
|
31
|
+
message: message ?? "Path `{PATH}` ({VALUE}) is not a valid enum value.",
|
|
40
32
|
type: "enum",
|
|
41
33
|
validator: (value) => {
|
|
42
34
|
if (value === null || value === void 0) return true;
|
|
43
35
|
return allowedValues.has(value.valueOf());
|
|
44
36
|
}
|
|
45
|
-
};
|
|
46
|
-
schema.validate = [...schema.validate ?? [], validator];
|
|
37
|
+
});
|
|
47
38
|
return receiver;
|
|
48
39
|
};
|
|
49
40
|
}
|
|
50
41
|
if (key === "max" || key === "min") return (value) => {
|
|
51
42
|
const validator = createLimitValidator(key, value);
|
|
52
|
-
|
|
53
|
-
schema.validate = [...validators.filter(({ type }) => type !== key), validator];
|
|
43
|
+
setSchemaValidator(schema, validator);
|
|
54
44
|
return receiver;
|
|
55
45
|
};
|
|
56
46
|
return Reflect.get(target, key, receiver);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"double.js","names":[],"sources":["../../src/schema-builders/double.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type {\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"double.js","names":[],"sources":["../../src/schema-builders/double.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type {\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type {\n EnumInput,\n EnumValidator,\n LimitValidator,\n ValidationSchema,\n ValueWithMessage,\n} from '../types/_internals';\n\nimport {\n defaultEnumValidateMessage,\n defaultLimitValidateMessages,\n hasSchemaValidator,\n normalizeEnumValues,\n normalizeValueWithMessage,\n setSchemaValidator,\n} from './_internals';\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype DoubleLimit = number | Types.Double;\ntype DoubleValidationSchema = ValidationSchema<\n EnumValidator<number | Types.Double, Types.Double> | LimitValidator<number, Types.Double>\n>;\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n DoubleSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: typeof Schema.Types.Double;\n}\n\nexport interface DoubleSchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFields extends string = never> {\n default: <\n T extends ((this: any, doc: any) => D | null | undefined) | D | null | undefined,\n D extends Types.Double,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends EnumInput<N | null, M>,\n M extends string,\n N extends number | Types.Double,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, DoubleValidationSchema>,\n 'enum' | ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n max: <\n T extends ValueWithMessage<L, S>,\n L extends DoubleLimit,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, DoubleValidationSchema>,\n 'max' | ExtraOmitFields\n >;\n\n min: <\n T extends ValueWithMessage<L, S>,\n L extends DoubleLimit,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, DoubleValidationSchema>,\n 'min' | ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\n// Functions\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Double);\n\nfunction createLimitValidator(\n type: 'max' | 'min',\n value: ValueWithMessage<DoubleLimit>,\n): LimitValidator<number, Types.Double> {\n const [limit, message] = normalizeValueWithMessage(value);\n\n const numericLimit = typeof limit === 'number' ? limit : limit.valueOf();\n if (!Number.isFinite(numericLimit)) throw new RangeError(`Double ${type} limit must be finite`);\n\n return {\n message: message ?? defaultLimitValidateMessages[type],\n [type]: numericLimit,\n type,\n validator: (value) => {\n if (value === null || value === undefined) return true;\n\n return type === 'min' ? value.valueOf() >= numericLimit : value.valueOf() <= numericLimit;\n },\n };\n}\n\nexport function doubleSchemaBuilder() {\n const schema: Partial<DoubleValidationSchema> & Record<string, any> = {};\n const baseBuilder = baseBuilderFactory(schema);\n return new Proxy(\n baseBuilder,\n {\n get(target, key, receiver) {\n if (key === 'enum') {\n if (hasSchemaValidator(schema, 'enum')) {\n throw new Error('Duplicate schema attribute: enum');\n }\n\n return (value: EnumInput<null | number | Types.Double>) => {\n const { enumValues, message } = normalizeEnumValues(value);\n\n const allowedValues = new Set(\n enumValues.map((value) => value === null ? null : value.valueOf()),\n );\n\n const validator: EnumValidator<number | Types.Double, Types.Double> = {\n enumValues,\n message: message ?? defaultEnumValidateMessage,\n type: 'enum',\n validator: (value) => {\n if (value === null || value === undefined) return true;\n\n return allowedValues.has(value.valueOf());\n },\n };\n\n setSchemaValidator(schema, validator);\n\n return receiver;\n };\n }\n\n if (key === 'max' || key === 'min') {\n return (value: ValueWithMessage<DoubleLimit>) => {\n const validator = createLimitValidator(key, value);\n setSchemaValidator(schema, validator);\n\n return receiver;\n };\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as DoubleSchemaBuilder;\n}\n"],"mappings":";;;;AA6FA,MAAM,qBAAqB,+BAA+B,OAAO,MAAM,MAAM;AAE7E,SAAS,qBACL,MACA,OACoC;CACpC,MAAM,CAAC,OAAO,WAAW,0BAA0B,KAAK;CAExD,MAAM,eAAe,OAAO,UAAU,WAAW,QAAQ,MAAM,QAAQ;CACvE,IAAI,CAAC,OAAO,SAAS,YAAY,GAAG,MAAM,IAAI,WAAW,UAAU,KAAK,sBAAsB;CAE9F,OAAO;EACH,SAAS,WAAW,6BAA6B;GAChD,OAAO;EACR;EACA,YAAY,UAAU;GAClB,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;GAElD,OAAO,SAAS,QAAQ,MAAM,QAAQ,KAAK,eAAe,MAAM,QAAQ,KAAK;EACjF;CACJ;AACJ;AAEA,SAAgB,sBAAsB;CAClC,MAAM,SAAgE,CAAC;CACvE,MAAM,cAAc,mBAAmB,MAAM;CAC7C,OAAO,IAAI,MACP,aACA,EACI,IAAI,QAAQ,KAAK,UAAU;EACvB,IAAI,QAAQ,QAAQ;GAChB,IAAI,mBAAmB,QAAQ,MAAM,GACjC,MAAM,IAAI,MAAM,kCAAkC;GAGtD,QAAQ,UAAmD;IACvD,MAAM,EAAE,YAAY,YAAY,oBAAoB,KAAK;IAEzD,MAAM,gBAAgB,IAAI,IACtB,WAAW,KAAK,UAAU,UAAU,OAAO,OAAO,MAAM,QAAQ,CAAC,CACrE;IAaA,mBAAmB,QAAQ;KAVvB;KACA,SAAS,WAAA;KACT,MAAM;KACN,YAAY,UAAU;MAClB,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;MAElD,OAAO,cAAc,IAAI,MAAM,QAAQ,CAAC;KAC5C;IAG+B,CAAC;IAEpC,OAAO;GACX;EACJ;EAEA,IAAI,QAAQ,SAAS,QAAQ,OACzB,QAAQ,UAAyC;GAC7C,MAAM,YAAY,qBAAqB,KAAK,KAAK;GACjD,mBAAmB,QAAQ,SAAS;GAEpC,OAAO;EACX;EAGJ,OAAO,QAAQ,IAAI,QAAQ,KAAK,QAAQ;CAC5C,EACJ,CACJ;AACJ"}
|
|
@@ -1,42 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EnumInput, EnumValidator, LimitValidator, ValidationSchema, ValueWithMessage } from "../types/_internals.js";
|
|
2
2
|
import { DefaultType, IndexDirection, IndexOptions, Schema } from "mongoose";
|
|
3
3
|
import { Merge } from "type-fest";
|
|
4
4
|
type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<Int32SchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
5
5
|
type Int32Limit = number;
|
|
6
|
+
type Int32ValidationSchema = ValidationSchema<EnumValidator<number> | LimitValidator<number>>;
|
|
6
7
|
interface BaseProps {
|
|
7
8
|
type: typeof Schema.Types.Int32;
|
|
8
9
|
}
|
|
9
|
-
interface Int32EnumValidator {
|
|
10
|
-
enumValues: (null | number)[];
|
|
11
|
-
message: string;
|
|
12
|
-
type: 'enum';
|
|
13
|
-
validator: (value: null | number | undefined) => boolean;
|
|
14
|
-
}
|
|
15
|
-
interface Int32LimitValidator {
|
|
16
|
-
max?: number;
|
|
17
|
-
message: string;
|
|
18
|
-
min?: number;
|
|
19
|
-
type: 'max' | 'min';
|
|
20
|
-
validator: (value: null | number | undefined) => boolean;
|
|
21
|
-
}
|
|
22
10
|
export interface Int32SchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFields extends string = never> {
|
|
23
11
|
default: <T extends ((this: any, doc: any) => DefaultType<D> | null | undefined) | DefaultType<D> | null | undefined, D extends number>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
24
12
|
default: T;
|
|
25
13
|
}>, ExtraOmitFields>;
|
|
26
|
-
enum: <T extends
|
|
27
|
-
[path: string]: N | null;
|
|
28
|
-
} | {
|
|
29
|
-
message?: M;
|
|
30
|
-
values: Readonlyable<(N | null)[]>;
|
|
31
|
-
}, M extends string, N extends number>(value: T) => ExtendSchemaBuilder<Merge<Props, Int32ValidationSchema>, 'enum' | ExtraOmitFields>;
|
|
14
|
+
enum: <T extends EnumInput<N | null, M>, M extends string, N extends number>(value: T) => ExtendSchemaBuilder<Merge<Props, Int32ValidationSchema>, 'enum' | ExtraOmitFields>;
|
|
32
15
|
immutable: ExtendSchemaBuilder<Merge<Props, {
|
|
33
16
|
immutable: true;
|
|
34
17
|
}>, ExtraOmitFields>;
|
|
35
18
|
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
36
19
|
index: T;
|
|
37
20
|
}>, ExtraOmitFields>;
|
|
38
|
-
max: <T extends
|
|
39
|
-
min: <T extends
|
|
21
|
+
max: <T extends ValueWithMessage<L, S>, L extends Int32Limit, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, Int32ValidationSchema>, 'max' | ExtraOmitFields>;
|
|
22
|
+
min: <T extends ValueWithMessage<L, S>, L extends Int32Limit, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, Int32ValidationSchema>, 'min' | ExtraOmitFields>;
|
|
40
23
|
nonRequired: Props;
|
|
41
24
|
private: ExtendSchemaBuilder<Merge<Props, {
|
|
42
25
|
private: true;
|
|
@@ -51,9 +34,6 @@ export interface Int32SchemaBuilder<Props extends BaseProps = BaseProps, ExtraOm
|
|
|
51
34
|
unique: true;
|
|
52
35
|
}>, ExtraOmitFields>;
|
|
53
36
|
}
|
|
54
|
-
interface Int32ValidationSchema {
|
|
55
|
-
validate: (Int32EnumValidator | Int32LimitValidator)[];
|
|
56
|
-
}
|
|
57
37
|
export declare function int32SchemaBuilder(): Int32SchemaBuilder;
|
|
58
38
|
export {};
|
|
59
39
|
//# sourceMappingURL=int32.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int32.d.ts","names":[],"sources":["../../src/schema-builders/int32.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"int32.d.ts","names":[],"sources":["../../src/schema-builders/int32.ts"],"mappings":";;;KA0BK,oBACD,cAAc,WACd,kCACA,KACA,mBAAmB,OAAO,kBAC1B,wBAAwB;KAGvB;KAEA,wBAAwB,iBAAiB,wBAAwB;UAE5D;EACN,aAAa,OAAO,MAAM;;iBAGb,mBAAmB,cAAc,YAAY,WAAW;EACrE,UACI,YAAY,WAAW,aAAa,YAAY,yBAAyB,YAAY,uBACrF,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,UAAU,UAAU,UAAU,IAC9B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM,OAAO,iCACJ;EAGb,WAAW,oBAAoB,MAAM;IAAS;MAAoB;EAClE,QAAQ,oBAAoB,iBAAiB,cAAc,OAAO,MAAM,oBACpE,MAAM;IAAS,OAAO;MACtB;EAGJ,MACI,UAAU,iBAAiB,GAAG,IAC9B,UAAU,YACV,kBACF,OAAO,MAAM,oBACX,MAAM,OAAO,gCACL;EAGZ,MACI,UAAU,iBAAiB,GAAG,IAC9B,UAAU,YACV,kBACF,OAAO,MAAM,oBACX,MAAM,OAAO,gCACL;EAGZ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;EACzB,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;;wBA0BhD,sBAyCP"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
+
import { defaultLimitValidateMessages, hasSchemaValidator, normalizeEnumValues, normalizeValueWithMessage, setSchemaValidator } from "./_internals.js";
|
|
1
2
|
import { createBaseSchemaBuilderFactory } from "./base.js";
|
|
2
3
|
import { Schema } from "mongoose";
|
|
3
4
|
// src/schema-builders/int32.ts
|
|
4
|
-
const defaultEnumValidateMessage = "Path `{PATH}` ({VALUE}) is not a valid enum value.";
|
|
5
|
-
const defaultMinValidateMessage = "Path `{PATH}` ({VALUE}) is less than minimum allowed value ({MIN}).";
|
|
6
|
-
const defaultMaxValidateMessage = "Path `{PATH}` ({VALUE}) is more than maximum allowed value ({MAX}).";
|
|
7
5
|
const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Int32);
|
|
8
6
|
function createLimitValidator(type, value) {
|
|
9
|
-
const [numericLimit, message] =
|
|
7
|
+
const [numericLimit, message] = normalizeValueWithMessage(value);
|
|
10
8
|
if (!Number.isFinite(numericLimit)) throw new RangeError(`Int32 ${type} limit must be finite`);
|
|
11
9
|
return {
|
|
12
|
-
message: message ??
|
|
10
|
+
message: message ?? defaultLimitValidateMessages[type],
|
|
13
11
|
[type]: numericLimit,
|
|
14
12
|
type,
|
|
15
13
|
validator: (value) => {
|
|
@@ -23,30 +21,22 @@ function int32SchemaBuilder() {
|
|
|
23
21
|
const baseBuilder = baseBuilderFactory(schema);
|
|
24
22
|
return new Proxy(baseBuilder, { get(target, key, receiver) {
|
|
25
23
|
if (key === "enum") {
|
|
26
|
-
if (schema
|
|
24
|
+
if (hasSchemaValidator(schema, "enum")) throw new Error("Duplicate schema attribute: enum");
|
|
27
25
|
return (value) => {
|
|
28
|
-
|
|
29
|
-
let message;
|
|
30
|
-
if (Array.isArray(value)) enumValues = [...value];
|
|
31
|
-
else if ("values" in value && Array.isArray(value.values)) {
|
|
32
|
-
enumValues = [...value.values];
|
|
33
|
-
if ("message" in value && typeof value.message === "string") message = value.message;
|
|
34
|
-
} else enumValues = Object.values(value);
|
|
26
|
+
const { enumValues, message } = normalizeEnumValues(value);
|
|
35
27
|
const allowedValues = new Set(enumValues);
|
|
36
|
-
|
|
28
|
+
setSchemaValidator(schema, {
|
|
37
29
|
enumValues,
|
|
38
|
-
message: message ??
|
|
30
|
+
message: message ?? "Path `{PATH}` ({VALUE}) is not a valid enum value.",
|
|
39
31
|
type: "enum",
|
|
40
32
|
validator: (value) => value === null || value === void 0 || allowedValues.has(value)
|
|
41
|
-
};
|
|
42
|
-
schema.validate = [...schema.validate ?? [], validator];
|
|
33
|
+
});
|
|
43
34
|
return receiver;
|
|
44
35
|
};
|
|
45
36
|
}
|
|
46
37
|
if (key === "max" || key === "min") return (value) => {
|
|
47
38
|
const validator = createLimitValidator(key, value);
|
|
48
|
-
|
|
49
|
-
schema.validate = [...validators.filter(({ type }) => type !== key), validator];
|
|
39
|
+
setSchemaValidator(schema, validator);
|
|
50
40
|
return receiver;
|
|
51
41
|
};
|
|
52
42
|
return Reflect.get(target, key, receiver);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int32.js","names":[],"sources":["../../src/schema-builders/int32.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"int32.js","names":[],"sources":["../../src/schema-builders/int32.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type {\n EnumInput,\n EnumValidator,\n LimitValidator,\n ValidationSchema,\n ValueWithMessage,\n} from '../types/_internals';\n\nimport {\n defaultEnumValidateMessage,\n defaultLimitValidateMessages,\n hasSchemaValidator,\n normalizeEnumValues,\n normalizeValueWithMessage,\n setSchemaValidator,\n} from './_internals';\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n Int32SchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ntype Int32Limit = number;\n\ntype Int32ValidationSchema = ValidationSchema<EnumValidator<number> | LimitValidator<number>>;\n\ninterface BaseProps {\n type: typeof Schema.Types.Int32;\n}\n\nexport interface Int32SchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFields extends string = never> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D> | null | undefined) | DefaultType<D> | null | undefined,\n D extends number,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends EnumInput<N | null, M>,\n M extends string,\n N extends number,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, Int32ValidationSchema>,\n 'enum' | ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n max: <\n T extends ValueWithMessage<L, S>,\n L extends Int32Limit,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, Int32ValidationSchema>,\n 'max' | ExtraOmitFields\n >;\n\n min: <\n T extends ValueWithMessage<L, S>,\n L extends Int32Limit,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, Int32ValidationSchema>,\n 'min' | ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\n// Functions\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Int32);\n\nfunction createLimitValidator(\n type: 'max' | 'min',\n value: ValueWithMessage<Int32Limit>,\n): LimitValidator<number> {\n const [numericLimit, message] = normalizeValueWithMessage(value);\n\n if (!Number.isFinite(numericLimit)) throw new RangeError(`Int32 ${type} limit must be finite`);\n\n return {\n message: message ?? defaultLimitValidateMessages[type],\n [type]: numericLimit,\n type,\n validator: (value) => {\n if (value === null || value === undefined) return true;\n\n return type === 'min' ? value >= numericLimit : value <= numericLimit;\n },\n };\n}\n\nexport function int32SchemaBuilder() {\n const schema: Partial<Int32ValidationSchema> & Record<string, any> = {};\n const baseBuilder = baseBuilderFactory(schema);\n return new Proxy(\n baseBuilder,\n {\n get(target, key, receiver) {\n if (key === 'enum') {\n if (hasSchemaValidator(schema, 'enum')) {\n throw new Error('Duplicate schema attribute: enum');\n }\n\n return (value: EnumInput<null | number>) => {\n const { enumValues, message } = normalizeEnumValues(value);\n\n const allowedValues = new Set(enumValues);\n const validator: EnumValidator<number> = {\n enumValues,\n message: message ?? defaultEnumValidateMessage,\n type: 'enum',\n validator: (value) => value === null || value === undefined || allowedValues.has(value),\n };\n\n setSchemaValidator(schema, validator);\n\n return receiver;\n };\n }\n\n if (key === 'max' || key === 'min') {\n return (value: ValueWithMessage<Int32Limit>) => {\n const validator = createLimitValidator(key, value);\n setSchemaValidator(schema, validator);\n\n return receiver;\n };\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as Int32SchemaBuilder;\n}\n"],"mappings":";;;;AA4FA,MAAM,qBAAqB,+BAA+B,OAAO,MAAM,KAAK;AAE5E,SAAS,qBACL,MACA,OACsB;CACtB,MAAM,CAAC,cAAc,WAAW,0BAA0B,KAAK;CAE/D,IAAI,CAAC,OAAO,SAAS,YAAY,GAAG,MAAM,IAAI,WAAW,SAAS,KAAK,sBAAsB;CAE7F,OAAO;EACH,SAAS,WAAW,6BAA6B;GAChD,OAAO;EACR;EACA,YAAY,UAAU;GAClB,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;GAElD,OAAO,SAAS,QAAQ,SAAS,eAAe,SAAS;EAC7D;CACJ;AACJ;AAEA,SAAgB,qBAAqB;CACjC,MAAM,SAA+D,CAAC;CACtE,MAAM,cAAc,mBAAmB,MAAM;CAC7C,OAAO,IAAI,MACP,aACA,EACI,IAAI,QAAQ,KAAK,UAAU;EACvB,IAAI,QAAQ,QAAQ;GAChB,IAAI,mBAAmB,QAAQ,MAAM,GACjC,MAAM,IAAI,MAAM,kCAAkC;GAGtD,QAAQ,UAAoC;IACxC,MAAM,EAAE,YAAY,YAAY,oBAAoB,KAAK;IAEzD,MAAM,gBAAgB,IAAI,IAAI,UAAU;IAQxC,mBAAmB,QAAQ;KANvB;KACA,SAAS,WAAA;KACT,MAAM;KACN,YAAY,UAAU,UAAU,QAAQ,UAAU,KAAA,KAAa,cAAc,IAAI,KAAK;IAGvD,CAAC;IAEpC,OAAO;GACX;EACJ;EAEA,IAAI,QAAQ,SAAS,QAAQ,OACzB,QAAQ,UAAwC;GAC5C,MAAM,YAAY,qBAAqB,KAAK,KAAK;GACjD,mBAAmB,QAAQ,SAAS;GAEpC,OAAO;EACX;EAGJ,OAAO,QAAQ,IAAI,QAAQ,KAAK,QAAQ;CAC5C,EACJ,CACJ;AACJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EnumInput, ValueWithMessage } from "../types/_internals.js";
|
|
2
2
|
import { DefaultType, IndexDirection, IndexOptions, NumberSchemaDefinition } from "mongoose";
|
|
3
3
|
import { Merge } from "type-fest";
|
|
4
4
|
type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<NumberSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
@@ -13,12 +13,7 @@ export interface NumberSchemaBuilder<Props extends {
|
|
|
13
13
|
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends number>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
14
14
|
default: T;
|
|
15
15
|
}>, ExtraOmitFields>;
|
|
16
|
-
enum: <T extends
|
|
17
|
-
[path: string]: N | null;
|
|
18
|
-
} | {
|
|
19
|
-
message?: M;
|
|
20
|
-
values: Readonlyable<(N | null)[]>;
|
|
21
|
-
}, M extends string, N extends number>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
16
|
+
enum: <T extends EnumInput<N | null, M>, M extends string, N extends number>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
22
17
|
enum: T;
|
|
23
18
|
}>, ExtraOmitFields>;
|
|
24
19
|
immutable: ExtendSchemaBuilder<Merge<Props, {
|
|
@@ -27,10 +22,10 @@ export interface NumberSchemaBuilder<Props extends {
|
|
|
27
22
|
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
28
23
|
index: T;
|
|
29
24
|
}>, ExtraOmitFields>;
|
|
30
|
-
max: <T extends
|
|
25
|
+
max: <T extends ValueWithMessage<N, S>, N extends number, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
31
26
|
max: T;
|
|
32
27
|
}>, ExtraOmitFields>;
|
|
33
|
-
min: <T extends
|
|
28
|
+
min: <T extends ValueWithMessage<N, S>, N extends number, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
34
29
|
min: T;
|
|
35
30
|
}>, ExtraOmitFields>;
|
|
36
31
|
nonRequired: Props;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.d.ts","names":[],"sources":["../../src/schema-builders/number.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"number.d.ts","names":[],"sources":["../../src/schema-builders/number.ts"],"mappings":";;;KAeK,oBACD,cAAc,WACd,kCACA,KACA,oBAAoB,OAAO,kBAC3B,wBAAwB;UAGlB;EACN,MAAM;;iBAGO,oBACb;EAAgB,MAAM;;EAA6B,MAAM;GACzD;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,UAAU,UAAU,UAAU,IAC9B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,MAAM;MACrB;EAGJ,WAAW,oBAAoB,MAAM;IAAS;MAAoB;EAClE,QAAQ,oBAAoB,iBAAiB,cAAc,OAAO,MAAM,oBACpE,MAAM;IAAS,OAAO;MACtB;EAGJ,MACI,UAAU,iBAAiB,GAAG,IAC9B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,KAAK;MACpB;EAGJ,MACI,UAAU,iBAAiB,GAAG,IAC9B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,KAAK;MACpB;EAGJ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;EACzB,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;;qBAGnD,sBAAmB,SAAA,wBAAA;EAnD6B,MAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","names":[],"sources":["../../src/schema-builders/number.ts"],"sourcesContent":["import type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n NumberSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"number.js","names":[],"sources":["../../src/schema-builders/number.ts"],"sourcesContent":["import type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n NumberSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type {\n EnumInput,\n ValueWithMessage,\n} from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n NumberSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: NumberSchemaDefinition;\n}\n\nexport interface NumberSchemaBuilder<\n Props extends { type: NumberSchemaDefinition } = { type: NumberSchemaDefinition },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends number,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends EnumInput<N | null, M>,\n M extends string,\n N extends number,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n max: <\n T extends ValueWithMessage<N, S>,\n N extends number,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { max: T }>,\n ExtraOmitFields\n >;\n\n min: <\n T extends ValueWithMessage<N, S>,\n N extends number,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { min: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\nexport const numberSchemaBuilder = createBaseSchemaBuilderFactory<NumberSchemaBuilder>(Number);\n"],"mappings":";;AA+EA,MAAa,sBAAsB,+BAAoD,MAAM"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EnumInput } from "../types/_internals.js";
|
|
2
2
|
import { DefaultType, IndexDirection, IndexOptions, Schema, Types } from "mongoose";
|
|
3
3
|
import { Merge } from "type-fest";
|
|
4
4
|
type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<ObjectIdSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
@@ -13,12 +13,7 @@ export interface ObjectIdSchemaBuilder<Props extends {
|
|
|
13
13
|
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends Types.ObjectId>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
14
14
|
default: T;
|
|
15
15
|
}>, ExtraOmitFields>;
|
|
16
|
-
enum: <T extends
|
|
17
|
-
[path: string]: null | O;
|
|
18
|
-
} | {
|
|
19
|
-
message?: M;
|
|
20
|
-
values: Readonlyable<(null | O)[]>;
|
|
21
|
-
}, M extends string, O extends Types.ObjectId>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
16
|
+
enum: <T extends EnumInput<null | O, M>, M extends string, O extends Types.ObjectId>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
22
17
|
enum: T;
|
|
23
18
|
}>, ExtraOmitFields>;
|
|
24
19
|
immutable: ExtendSchemaBuilder<Merge<Props, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-id.d.ts","names":[],"sources":["../../src/schema-builders/object-id.ts"],"mappings":";;;KAaK,oBACD,cAAc,WACd,kCACA,KACA,sBAAsB,OAAO,kBAC7B,wBAAwB;UAGlB;EACN,aAAa,OAAO,MAAM;;iBAGb,sBACb;EAAgB,aAAa,OAAO,MAAM;;EAAe,aAAa,OAAO,MAAM;GACnF;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,UAAU,MAAM,UAClB,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,
|
|
1
|
+
{"version":3,"file":"object-id.d.ts","names":[],"sources":["../../src/schema-builders/object-id.ts"],"mappings":";;;KAaK,oBACD,cAAc,WACd,kCACA,KACA,sBAAsB,OAAO,kBAC7B,wBAAwB;UAGlB;EACN,aAAa,OAAO,MAAM;;iBAGb,sBACb;EAAgB,aAAa,OAAO,MAAM;;EAAe,aAAa,OAAO,MAAM;GACnF;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,UAAU,MAAM,UAClB,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,UAAU,iBAAiB,GAAG,IAC9B,kBACA,UAAU,MAAM,UAClB,OAAO,MAAM,oBACX,MAAM;IAAS,MAAM;MACrB;EAGJ,WAAW,oBAAoB,MAAM;IAAS;MAAoB;EAClE,QAAQ,oBAAoB,iBAAiB,cAAc,OAAO,MAAM,oBACpE,MAAM;IAAS,OAAO;MACtB;EAGJ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;EACzB,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;;qBAGnD,wBAAqB,SAAA,wBAAA;EAjCiC,aAAO,OAAO,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-id.js","names":[],"sources":["../../src/schema-builders/object-id.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"object-id.js","names":[],"sources":["../../src/schema-builders/object-id.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { EnumInput } from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n ObjectIdSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: typeof Schema.Types.ObjectId;\n}\n\nexport interface ObjectIdSchemaBuilder<\n Props extends { type: typeof Schema.Types.ObjectId } = { type: typeof Schema.Types.ObjectId },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends Types.ObjectId,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends EnumInput<null | O, M>,\n M extends string,\n O extends Types.ObjectId,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\nexport const objectIdSchemaBuilder = createBaseSchemaBuilderFactory<ObjectIdSchemaBuilder>(Schema.Types.ObjectId);\n"],"mappings":";;;AA2DA,MAAa,wBAAwB,+BAAsD,OAAO,MAAM,QAAQ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EnumInput } from "../types/_internals.js";
|
|
2
2
|
import { DefaultType, IndexDirection, IndexOptions, Model, Schema, Types } from "mongoose";
|
|
3
3
|
import { Merge } from "type-fest";
|
|
4
4
|
type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<RefSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
@@ -13,12 +13,7 @@ export interface RefSchemaBuilder<Props extends {
|
|
|
13
13
|
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends Types.ObjectId>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
14
14
|
default: T;
|
|
15
15
|
}>, ExtraOmitFields>;
|
|
16
|
-
enum: <T extends
|
|
17
|
-
[path: string]: null | O;
|
|
18
|
-
} | {
|
|
19
|
-
message?: M;
|
|
20
|
-
values: Readonlyable<(null | O)[]>;
|
|
21
|
-
}, M extends string, O extends Types.ObjectId>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
16
|
+
enum: <T extends EnumInput<null | O, M>, M extends string, O extends Types.ObjectId>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
22
17
|
enum: T;
|
|
23
18
|
}>, ExtraOmitFields>;
|
|
24
19
|
immutable: ExtendSchemaBuilder<Merge<Props, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.d.ts","names":[],"sources":["../../src/schema-builders/ref.ts"],"mappings":";;;KAcK,oBACD,cAAc,WACd,kCACA,KACA,iBAAiB,OAAO,kBACxB,wBAAwB;UAGlB;EACN,aAAa,OAAO,MAAM;;iBAGb,iBACb;EAAgB,aAAa,OAAO,MAAM;;EAAe,aAAa,OAAO,MAAM;GACnF;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,UAAU,MAAM,UAClB,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,
|
|
1
|
+
{"version":3,"file":"ref.d.ts","names":[],"sources":["../../src/schema-builders/ref.ts"],"mappings":";;;KAcK,oBACD,cAAc,WACd,kCACA,KACA,iBAAiB,OAAO,kBACxB,wBAAwB;UAGlB;EACN,aAAa,OAAO,MAAM;;iBAGb,iBACb;EAAgB,aAAa,OAAO,MAAM;;EAAe,aAAa,OAAO,MAAM;GACnF;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,UAAU,MAAM,UAClB,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,UAAU,iBAAiB,GAAG,IAC9B,kBACA,UAAU,MAAM,UAClB,OAAO,MAAM,oBACX,MAAM;IAAS,MAAM;MACrB;EAGJ,WAAW,oBAAoB,MAAM;IAAS;MAAoB;EAClE,QAAQ,oBAAoB,iBAAiB,cAAc,OAAO,MAAM,oBACpE,MAAM;IAAS,OAAO;MACtB;EAGJ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;EACzB,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;;wBAKhD,iBAAiB,YAAY,WAAW,aAAa,uBAAuB,qBACxF,KAAK,IAEiC;EAAmB,KAAK;EAAG,aAAa,OAAO,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.js","names":[],"sources":["../../src/schema-builders/ref.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n Model,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"ref.js","names":[],"sources":["../../src/schema-builders/ref.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n Model,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { EnumInput } from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n RefSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: typeof Schema.Types.ObjectId;\n}\n\nexport interface RefSchemaBuilder<\n Props extends { type: typeof Schema.Types.ObjectId } = { type: typeof Schema.Types.ObjectId },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends Types.ObjectId,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends EnumInput<null | O, M>,\n M extends string,\n O extends Types.ObjectId,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.ObjectId);\n\nexport function refSchemaBuilder<T extends ((this: any, doc: any) => Model<any> | string) | Model<any> | string>(\n ref: T,\n) {\n return baseBuilderFactory({ ref }) as RefSchemaBuilder<{ ref: T; type: typeof Schema.Types.ObjectId }>;\n}\n"],"mappings":";;;AA4DA,MAAM,qBAAqB,+BAA+B,OAAO,MAAM,QAAQ;AAE/E,SAAgB,iBACZ,KACF;CACE,OAAO,mBAAmB,EAAE,IAAI,CAAC;AACrC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EnumInput, ValueWithMessage } from "../types/_internals.js";
|
|
2
2
|
import { DefaultType, IndexDirection, IndexOptions, StringSchemaDefinition } from "mongoose";
|
|
3
3
|
import { Merge } from "type-fest";
|
|
4
4
|
type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<StringSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
@@ -20,12 +20,7 @@ export interface StringSchemaBuilder<Props extends {
|
|
|
20
20
|
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
21
21
|
default: T;
|
|
22
22
|
}>, ExtraOmitFields>;
|
|
23
|
-
enum: <T extends
|
|
24
|
-
[path: string]: null | S;
|
|
25
|
-
} | {
|
|
26
|
-
message?: M;
|
|
27
|
-
values: Readonlyable<(null | S)[]>;
|
|
28
|
-
}, M extends string, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
23
|
+
enum: <T extends EnumInput<null | S, M>, M extends string, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
29
24
|
enum: T;
|
|
30
25
|
}>, ExtraOmitFields>;
|
|
31
26
|
immutable: ExtendSchemaBuilder<Merge<Props, {
|
|
@@ -67,7 +62,7 @@ export interface StringSchemaBuilder<Props extends {
|
|
|
67
62
|
*
|
|
68
63
|
* @returns This instance for chaining.
|
|
69
64
|
*/
|
|
70
|
-
length: <T extends
|
|
65
|
+
length: <T extends ValueWithMessage<L, S>, L extends number, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
71
66
|
maxlength: T;
|
|
72
67
|
minlength: T;
|
|
73
68
|
}>, ExtraOmitFields>;
|
|
@@ -88,10 +83,10 @@ export interface StringSchemaBuilder<Props extends {
|
|
|
88
83
|
match: <T extends RegExp, M extends string | undefined = undefined>(regex: T, message?: M) => ExtendSchemaBuilder<Merge<Props, {
|
|
89
84
|
match: M extends string ? Readonly<[T, M]> : T;
|
|
90
85
|
}>, ExtraOmitFields>;
|
|
91
|
-
maxlength: <T extends
|
|
86
|
+
maxlength: <T extends ValueWithMessage<L, S>, L extends number, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
92
87
|
maxlength: T;
|
|
93
88
|
}>, ExtraOmitFields>;
|
|
94
|
-
minlength: <T extends
|
|
89
|
+
minlength: <T extends ValueWithMessage<L, S>, L extends number, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
|
|
95
90
|
minlength: T;
|
|
96
91
|
}>, ExtraOmitFields>;
|
|
97
92
|
nonRequired: Props;
|