@kikiutils/mongoose 7.0.3 → 7.1.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.
Files changed (55) hide show
  1. package/dist/_internals.d.ts +1 -2
  2. package/dist/_internals.d.ts.map +1 -1
  3. package/dist/assertions.d.ts +1 -2
  4. package/dist/assertions.d.ts.map +1 -1
  5. package/dist/builders.d.ts +3 -4
  6. package/dist/builders.d.ts.map +1 -1
  7. package/dist/constants.d.ts +1 -2
  8. package/dist/constants.d.ts.map +1 -1
  9. package/dist/helpers.d.ts +1 -2
  10. package/dist/helpers.d.ts.map +1 -1
  11. package/dist/options.d.ts +1 -2
  12. package/dist/options.d.ts.map +1 -1
  13. package/dist/plugins/assertions.d.ts +1 -2
  14. package/dist/plugins/assertions.d.ts.map +1 -1
  15. package/dist/plugins/normalize.d.ts +2 -3
  16. package/dist/plugins/normalize.d.ts.map +1 -1
  17. package/dist/plugins/normalize.js +4 -2
  18. package/dist/plugins/normalize.js.map +1 -1
  19. package/dist/schema-builders/base.d.ts +1 -2
  20. package/dist/schema-builders/base.d.ts.map +1 -1
  21. package/dist/schema-builders/base.js.map +1 -1
  22. package/dist/schema-builders/boolean.d.ts +2 -3
  23. package/dist/schema-builders/boolean.d.ts.map +1 -1
  24. package/dist/schema-builders/date.d.ts +2 -3
  25. package/dist/schema-builders/date.d.ts.map +1 -1
  26. package/dist/schema-builders/decimal128.d.ts +17 -3
  27. package/dist/schema-builders/decimal128.d.ts.map +1 -1
  28. package/dist/schema-builders/decimal128.js +23 -0
  29. package/dist/schema-builders/decimal128.js.map +1 -1
  30. package/dist/schema-builders/number.d.ts +2 -3
  31. package/dist/schema-builders/number.d.ts.map +1 -1
  32. package/dist/schema-builders/object-id.d.ts +2 -3
  33. package/dist/schema-builders/object-id.d.ts.map +1 -1
  34. package/dist/schema-builders/ref.d.ts +2 -3
  35. package/dist/schema-builders/ref.d.ts.map +1 -1
  36. package/dist/schema-builders/string.d.ts +32 -5
  37. package/dist/schema-builders/string.d.ts.map +1 -1
  38. package/dist/schema-builders/string.js +13 -1
  39. package/dist/schema-builders/string.js.map +1 -1
  40. package/dist/types/_internals.d.ts +1 -2
  41. package/dist/types/_internals.d.ts.map +1 -1
  42. package/dist/types/aggregate-paginate.d.ts +6 -6
  43. package/dist/types/aggregate-paginate.d.ts.map +1 -1
  44. package/dist/types/data.d.ts +2 -3
  45. package/dist/types/data.d.ts.map +1 -1
  46. package/dist/types/index.d.ts +10 -11
  47. package/dist/types/index.d.ts.map +1 -1
  48. package/dist/types/options.d.ts +2 -3
  49. package/dist/types/options.d.ts.map +1 -1
  50. package/dist/types/paginate.d.ts +9 -9
  51. package/dist/types/paginate.d.ts.map +1 -1
  52. package/package.json +15 -14
  53. package/src/schema-builders/base.ts +2 -0
  54. package/src/schema-builders/decimal128.ts +76 -0
  55. package/src/schema-builders/string.ts +66 -3
@@ -1,6 +1,5 @@
1
1
  import { CustomMongooseOptions } from "./types/options.js";
2
2
  //#region src/_internals.d.ts
3
- declare const customMongooseOptions: CustomMongooseOptions;
3
+ export declare const customMongooseOptions: CustomMongooseOptions;
4
4
  //#endregion
5
- export { customMongooseOptions };
6
5
  //# sourceMappingURL=_internals.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_internals.d.ts","names":[],"sources":["../src/_internals.ts"],"mappings":";;cAEa,uBAAuB"}
1
+ {"version":3,"file":"_internals.d.ts","names":[],"sources":["../src/_internals.ts"],"mappings":";;qBAEa,uBAAuB"}
@@ -1,6 +1,5 @@
1
1
  import { Document, mongo } from "mongoose";
2
2
  //#region src/assertions.d.ts
3
- declare function assertMongooseUpdateSuccess<T extends Document>(updatePromise: Promise<mongo.UpdateResult<T>>, expectedModifiedCount?: number): Promise<void>;
3
+ export declare function assertMongooseUpdateSuccess<T extends Document>(updatePromise: Promise<mongo.UpdateResult<T>>, expectedModifiedCount?: number): Promise<void>;
4
4
  //#endregion
5
- export { assertMongooseUpdateSuccess };
6
5
  //# sourceMappingURL=assertions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assertions.d.ts","names":[],"sources":["../src/assertions.ts"],"mappings":";;iBAKsB,4BAA4B,UAAU,UACxD,eAAe,QAAQ,MAAM,aAAa,KAC1C,iCAAyB"}
1
+ {"version":3,"file":"assertions.d.ts","names":[],"sources":["../src/assertions.ts"],"mappings":";;wBAKsB,4BAA4B,UAAU,UACxD,eAAe,QAAQ,MAAM,aAAa,KAC1C,iCAAyB"}
@@ -4,9 +4,8 @@ import { BuildMongooseModelOptions } from "./types/options.js";
4
4
  import { mongooseAssertionsPlugin } from "./plugins/assertions.js";
5
5
  import { Model, Schema } from "mongoose";
6
6
  //#region src/builders.d.ts
7
- type DoNotRemoveOrUseThisType = typeof mongooseAssertionsPlugin;
8
- declare function buildMongooseModel<DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(collection: string, name: string, schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>, options?: BuildMongooseModelOptions): Model;
9
- declare function registerMongooseNormalizePlugin<DocType, Model$1 extends Model<DocType, QueryHelpers, InstanceMethodsAndOverrides>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(schema: Schema<DocType, Model$1, InstanceMethodsAndOverrides, QueryHelpers>, recursive?: boolean, options?: MongooseNormalizePluginOptions): void;
7
+ export type DoNotRemoveOrUseThisType = typeof mongooseAssertionsPlugin;
8
+ export declare function buildMongooseModel<DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(collection: string, name: string, schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>, options?: BuildMongooseModelOptions): Model;
9
+ export declare function registerMongooseNormalizePlugin<DocType, Model$1 extends Model<DocType, QueryHelpers, InstanceMethodsAndOverrides>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(schema: Schema<DocType, Model$1, InstanceMethodsAndOverrides, QueryHelpers>, recursive?: boolean, options?: MongooseNormalizePluginOptions): void;
10
10
  //#endregion
11
- export { DoNotRemoveOrUseThisType, buildMongooseModel, registerMongooseNormalizePlugin };
12
11
  //# sourceMappingURL=builders.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"builders.d.ts","names":[],"sources":["../src/builders.ts"],"mappings":";;;;;;KAgBY,kCAAkC;iBAE9B,mBACZ,SACA,cAAc,0BAA0B,SAAS,6BAA6B,eAC9E,sCACA,uBAEA,oBACA,cACA,QAAQ,OAAO,SAAS,OAAO,6BAA6B,eAC5D,UAAU,4BACX;iBAoBa,gCACZ,SACA,gBAAc,MAAc,SAAS,cAAc,8BACnD,sCACA,uBAEA,QAAQ,OAAO,SAAS,SAAO,6BAA6B,eAC5D,qBACA,UAAU"}
1
+ {"version":3,"file":"builders.d.ts","names":["MongooseModel","Model"],"sources":["../src/builders.ts"],"mappings":";;;;;;YAgBY,kCAAkC;wBAE9B,mBACZ,SACA,cAAc,0BAA0B,SAAS,6BAA6B,eAC9E,sCACA,uBAEA,oBACA,cACA,QAAQ,OAAO,SAAS,OAAO,6BAA6B,eAC5D,UAAU,4BACX;wBAoBa,gCACZ,SACA,gBAAcA,MAAc,SAAS,cAAc,8BACnD,sCACA,uBAEA,QAAQ,OAAO,SAASC,SAAO,6BAA6B,eAC5D,qBACA,UAAU"}
@@ -1,6 +1,5 @@
1
1
  import { MongooseConnections } from "./types/index.js";
2
2
  //#region src/constants.d.ts
3
- declare const mongooseConnections: MongooseConnections;
3
+ export declare const mongooseConnections: MongooseConnections;
4
4
  //#endregion
5
- export { mongooseConnections };
6
5
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;cAEa,qBAAqB"}
1
+ {"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;qBAEa,qBAAqB"}
package/dist/helpers.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Types } from "mongoose";
2
2
  //#region src/helpers.d.ts
3
- declare function toObjectIdHexString(id: string | Types.ObjectId): string;
3
+ export declare function toObjectIdHexString(id: string | Types.ObjectId): string;
4
4
  //#endregion
5
- export { toObjectIdHexString };
6
5
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","names":[],"sources":["../src/helpers.ts"],"mappings":";;iBAEgB,oBAAoB,aAAa,MAAM"}
1
+ {"version":3,"file":"helpers.d.ts","names":[],"sources":["../src/helpers.ts"],"mappings":";;wBAEgB,oBAAoB,aAAa,MAAM"}
package/dist/options.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { CustomMongooseOptions } from "./types/options.js";
2
2
  //#region src/options.d.ts
3
- declare function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(key: K, value: CustomMongooseOptions[K]): void;
3
+ export declare function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(key: K, value: CustomMongooseOptions[K]): void;
4
4
  //#endregion
5
- export { setCustomMongooseOptions };
6
5
  //# sourceMappingURL=options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","names":[],"sources":["../src/options.ts"],"mappings":";;iBAGgB,yBAAyB,gBAAgB,uBACrD,KAAK,GACL,OAAO,sBAAsB"}
1
+ {"version":3,"file":"options.d.ts","names":[],"sources":["../src/options.ts"],"mappings":";;wBAGgB,yBAAyB,gBAAgB,uBACrD,KAAK,GACL,OAAO,sBAAsB"}
@@ -8,7 +8,6 @@ declare module 'mongoose' {
8
8
  assertUpdateSuccess: (filter: QueryFilter<TRawDocType>, update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline, options?: (mongo.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null, expectedModifiedCount?: number) => Promise<void>;
9
9
  }
10
10
  }
11
- declare function mongooseAssertionsPlugin<S extends Schema>(schema: S): void;
11
+ export declare function mongooseAssertionsPlugin<S extends Schema>(schema: S): void;
12
12
  //#endregion
13
- export { mongooseAssertionsPlugin };
14
13
  //# sourceMappingURL=assertions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assertions.d.ts","names":[],"sources":["../../src/plugins/assertions.ts"],"mappings":";;;YAac,SACN,IAAI,MAAM,UACV,qBACA,eACA,YAAY,qBAEZ;IAEA,sBACI,SACI,YAAY,SAAS,GAAG,eAAe,SAAS,WAAW,mBAC3D,+BACJ,iBAAiB,cACjB,mCACC;;YAGC,MACN,aAEA,oBAEA,uBAEA,gBAEA,wBAAwB,iBAAiB,aAAa,mBAAmB,WAAW,eAAe,YAEnG;IAEA,sBACI,QAAQ,YAAY,cACpB,QAAQ,YAAY,eAAe,+BACnC,WAAW,MAAM,gBAAgB,2BAA2B,sBAC5D,mCACC;;;iBAIG,yBAAyB,UAAU,QAAQ,QAAQ"}
1
+ {"version":3,"file":"assertions.d.ts","names":[],"sources":["../../src/plugins/assertions.ts"],"mappings":";;;YAac,SACN,IAAI,MAAM,UACV,qBACA,eACA,YAAY,qBAEZ;IAEA,sBACI,SACI,YAAY,SAAS,GAAG,eAAe,SAAS,WAAW,mBAC3D,+BACJ,iBAAiB,cACjB,mCACC;;YAGC,MACN,aAEA,oBAEA,uBAEA,gBAEA,wBAAwB,iBAAiB,aAAa,mBAAmB,WAAW,eAAe,YAEnG;IAEA,sBACI,QAAQ,YAAY,cACpB,QAAQ,YAAY,eAAe,+BACnC,WAAW,MAAM,gBAAgB,2BAA2B,sBAC5D,mCACC;;;wBAIG,yBAAyB,UAAU,QAAQ,QAAQ"}
@@ -1,6 +1,6 @@
1
1
  import { Schema } from "mongoose";
2
2
  //#region src/plugins/normalize.d.ts
3
- interface MongooseNormalizePluginOptions {
3
+ export interface MongooseNormalizePluginOptions {
4
4
  /**
5
5
  * Whether to convert `_id` field to `id`.
6
6
  * If true, the `_id` field will be replaced with `id`.
@@ -29,7 +29,6 @@ interface MongooseNormalizePluginOptions {
29
29
  *
30
30
  * @param schema - The Mongoose schema to apply the plugin to.
31
31
  */
32
- declare function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions): void;
32
+ export declare function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions): void;
33
33
  //#endregion
34
- export { MongooseNormalizePluginOptions, mongooseNormalizePlugin };
35
34
  //# sourceMappingURL=normalize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","names":[],"sources":["../../src/plugins/normalize.ts"],"mappings":";;UAQiB;;;;;;;EAOb;;;;;;EAOA;;;;;;;;;;;;;;;;iBAiBY,wBAAwB,UAAU,QAC9C,QAAQ,GACR,gBAAgB"}
1
+ {"version":3,"file":"normalize.d.ts","names":[],"sources":["../../src/plugins/normalize.ts"],"mappings":";;iBAQiB;;;;;;;EAOb;;;;;;EAOA;;;;;;;;;;;;;;;;wBAiBY,wBAAwB,UAAU,QAC9C,QAAQ,GACR,gBAAgB"}
@@ -30,8 +30,10 @@ function mongooseNormalizePlugin(schema, pluginOptions) {
30
30
  let _id = copiedRet._id;
31
31
  delete copiedRet._id;
32
32
  if (pluginOptions?.toHexIdIfObjectId !== false && _id instanceof Types.ObjectId) _id = _id.toHexString();
33
- if (_id !== void 0) if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;
34
- else copiedRet._id = _id;
33
+ if (_id !== void 0) {
34
+ if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;
35
+ else copiedRet._id = _id;
36
+ }
35
37
  for (const path of privatePaths) unset(copiedRet, path);
36
38
  for (const path of decimalPaths) {
37
39
  const value = get(copiedRet, path);
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.js","names":["getProp"],"sources":["../../src/plugins/normalize.ts"],"sourcesContent":["import {\n get as getProp,\n set as setProp,\n unset as unsetProp,\n} from 'es-toolkit/compat';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(\n schema: S,\n pluginOptions?: MongooseNormalizePluginOptions,\n) {\n // Collect special paths (Decimal128 & private)\n const decimalPaths: string[] = [];\n const privatePaths: string[] = [];\n for (const [path, schemaType] of Object.entries(schema.paths)) {\n if (schemaType?.options?.private) privatePaths.push(path);\n else if (schemaType?.instance === 'Decimal128') decimalPaths.push(path);\n }\n\n // Get original toJSON configuration\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n\n // Override toJSON with custom transform\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // Copy object and remove __v\n const copiedRet = { ...ret };\n // @ts-expect-error Ignore this error\n delete copiedRet.__v;\n\n // Normalize _id (convert to hex and/or move to id)\n let _id = copiedRet._id;\n delete copiedRet._id;\n if (pluginOptions?.toHexIdIfObjectId !== false && _id instanceof Types.ObjectId) {\n _id = _id.toHexString();\n }\n\n if (_id !== undefined) {\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _id;\n }\n\n // Remove private fields\n for (const path of privatePaths) unsetProp(copiedRet, path);\n\n // Convert Decimal128 fields to string\n for (const path of decimalPaths) {\n const value = getProp(copiedRet, path) as Types.Decimal128 | undefined;\n if (value) setProp(copiedRet, path, value.toString());\n }\n\n // Run original toJSON transform\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc as any, copiedRet as any, options as any);\n }\n\n // Return normalized object\n return copiedRet;\n },\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuCA,SAAgB,wBACZ,QACA,eACF;CAEE,MAAM,eAAyB,CAAC;CAChC,MAAM,eAAyB,CAAC;CAChC,KAAK,MAAM,CAAC,MAAM,eAAe,OAAO,QAAQ,OAAO,KAAK,GACxD,IAAI,YAAY,SAAS,SAAS,aAAa,KAAK,IAAI;MACnD,IAAI,YAAY,aAAa,cAAc,aAAa,KAAK,IAAI;CAI1E,MAAM,SAAS,OAAO,IAAI,QAAQ;CAClC,MAAM,kBAAkB,QAAQ;CAGhC,OAAO,IACH,UACA;EACI,GAAG;EACH,UAAU,KAAK,KAAK,SAAS;GAEzB,MAAM,YAAY,EAAE,GAAG,IAAI;GAE3B,OAAO,UAAU;GAGjB,IAAI,MAAM,UAAU;GACpB,OAAO,UAAU;GACjB,IAAI,eAAe,sBAAsB,SAAS,eAAe,MAAM,UACnE,MAAM,IAAI,YAAY;GAG1B,IAAI,QAAQ,KAAA,GACR,IAAI,eAAe,mBAAmB,OAAO,UAAU,KAAK;QACvD,UAAU,MAAM;GAIzB,KAAK,MAAM,QAAQ,cAAc,MAAU,WAAW,IAAI;GAG1D,KAAK,MAAM,QAAQ,cAAc;IAC7B,MAAM,QAAQA,IAAQ,WAAW,IAAI;IACrC,IAAI,OAAO,IAAQ,WAAW,MAAM,MAAM,SAAS,CAAC;GACxD;GAGA,IAAI,mBAAmB,OAAO,oBAAoB,WAC9C,OAAO,gBAAgB,KAAY,WAAkB,OAAc;GAIvE,OAAO;EACX;CACJ,CACJ;AACJ"}
1
+ {"version":3,"file":"normalize.js","names":["getProp"],"sources":["../../src/plugins/normalize.ts"],"sourcesContent":["import {\n get as getProp,\n set as setProp,\n unset as unsetProp,\n} from 'es-toolkit/compat';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(\n schema: S,\n pluginOptions?: MongooseNormalizePluginOptions,\n) {\n // Collect special paths (Decimal128 & private)\n const decimalPaths: string[] = [];\n const privatePaths: string[] = [];\n for (const [path, schemaType] of Object.entries(schema.paths)) {\n if (schemaType?.options?.private) privatePaths.push(path);\n else if (schemaType?.instance === 'Decimal128') decimalPaths.push(path);\n }\n\n // Get original toJSON configuration\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n\n // Override toJSON with custom transform\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // Copy object and remove __v\n const copiedRet = { ...ret };\n // @ts-expect-error Ignore this error\n delete copiedRet.__v;\n\n // Normalize _id (convert to hex and/or move to id)\n let _id = copiedRet._id;\n delete copiedRet._id;\n if (pluginOptions?.toHexIdIfObjectId !== false && _id instanceof Types.ObjectId) {\n _id = _id.toHexString();\n }\n\n if (_id !== undefined) {\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _id;\n }\n\n // Remove private fields\n for (const path of privatePaths) unsetProp(copiedRet, path);\n\n // Convert Decimal128 fields to string\n for (const path of decimalPaths) {\n const value = getProp(copiedRet, path) as Types.Decimal128 | undefined;\n if (value) setProp(copiedRet, path, value.toString());\n }\n\n // Run original toJSON transform\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc as any, copiedRet as any, options as any);\n }\n\n // Return normalized object\n return copiedRet;\n },\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuCA,SAAgB,wBACZ,QACA,eACF;CAEE,MAAM,eAAyB,CAAC;CAChC,MAAM,eAAyB,CAAC;CAChC,KAAK,MAAM,CAAC,MAAM,eAAe,OAAO,QAAQ,OAAO,KAAK,GACxD,IAAI,YAAY,SAAS,SAAS,aAAa,KAAK,IAAI;MACnD,IAAI,YAAY,aAAa,cAAc,aAAa,KAAK,IAAI;CAI1E,MAAM,SAAS,OAAO,IAAI,QAAQ;CAClC,MAAM,kBAAkB,QAAQ;CAGhC,OAAO,IACH,UACA;EACI,GAAG;EACH,UAAU,KAAK,KAAK,SAAS;GAEzB,MAAM,YAAY,EAAE,GAAG,IAAI;GAE3B,OAAO,UAAU;GAGjB,IAAI,MAAM,UAAU;GACpB,OAAO,UAAU;GACjB,IAAI,eAAe,sBAAsB,SAAS,eAAe,MAAM,UACnE,MAAM,IAAI,YAAY;GAG1B,IAAI,QAAQ,KAAA,GAAW;IACnB,IAAI,eAAe,mBAAmB,OAAO,UAAU,KAAK;SACvD,UAAU,MAAM;GACzB;GAGA,KAAK,MAAM,QAAQ,cAAc,MAAU,WAAW,IAAI;GAG1D,KAAK,MAAM,QAAQ,cAAc;IAC7B,MAAM,QAAQA,IAAQ,WAAW,IAAI;IACrC,IAAI,OAAO,IAAQ,WAAW,MAAM,MAAM,SAAS,CAAC;GACxD;GAGA,IAAI,mBAAmB,OAAO,oBAAoB,WAC9C,OAAO,gBAAgB,KAAY,WAAkB,OAAc;GAIvE,OAAO;EACX;CACJ,CACJ;AACJ"}
@@ -1,7 +1,6 @@
1
1
  import { Schema } from "mongoose";
2
2
  //#region src/schema-builders/base.d.ts
3
3
  type BaseSchemaType = BooleanConstructor | DateConstructor | NumberConstructor | Schema.Types.ObjectId['constructor'] | StringConstructor;
4
- declare function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType): (schema?: Record<string, any>) => Builder;
4
+ export declare function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType): (schema?: Record<string, any>) => Builder;
5
5
  //#endregion
6
- export { createBaseSchemaBuilderFactory };
7
6
  //# sourceMappingURL=base.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","names":[],"sources":["../../src/schema-builders/base.ts"],"mappings":";;KAEK,iBACD,qBACA,kBACA,oBACA,OAAO,MAAM,0BACb;iBAYY,+BAA+B,UAAU,SAAS,sBAAsB,MAAM,kBAClF,SAAQ,wBA2BP"}
1
+ {"version":3,"file":"base.d.ts","names":[],"sources":["../../src/schema-builders/base.ts"],"mappings":";;KAEK,iBACD,qBACA,kBACA,oBACA,OAAO,MAAM,0BACb;wBAcY,+BAA+B,UAAU,SAAS,sBAAsB,MAAM,kBAClF,SAAQ,wBA2BP"}
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","names":[],"sources":["../../src/schema-builders/base.ts"],"sourcesContent":["import type { Schema } from 'mongoose';\n\ntype BaseSchemaType =\n | BooleanConstructor\n | DateConstructor\n | NumberConstructor\n | Schema.Types.ObjectId['constructor']\n | StringConstructor;\n\nconst isFunctionKeys = new Set([\n 'default',\n 'enum',\n 'index',\n 'max',\n 'maxlength',\n 'min',\n 'minlength',\n]);\n\nexport function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType) {\n return (schema: Record<string, any> = {}) => {\n schema.type = type;\n return new Proxy(\n Object.freeze({}),\n {\n get(_, key, receiver) {\n if (typeof key === 'symbol') throw new Error('Cannot use symbol as a schema attribute');\n if (key in schema) throw new Error(`Duplicate schema attribute: ${key}`);\n if (isFunctionKeys.has(key)) {\n return (value: any) => {\n schema[key] = value;\n return receiver;\n };\n }\n\n if (key === 'nonRequired') return { ...schema };\n if (key === 'required') {\n return {\n ...schema,\n required: true,\n };\n }\n\n schema[key] = true;\n return receiver;\n },\n },\n ) as Builder;\n };\n}\n"],"mappings":";AASA,MAAM,iCAAiB,IAAI,IAAI;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;AACJ,CAAC;AAED,SAAgB,+BAAwE,MAAsB;CAC1G,QAAQ,SAA8B,CAAC,MAAM;EACzC,OAAO,OAAO;EACd,OAAO,IAAI,MACP,OAAO,OAAO,CAAC,CAAC,GAChB,EACI,IAAI,GAAG,KAAK,UAAU;GAClB,IAAI,OAAO,QAAQ,UAAU,MAAM,IAAI,MAAM,yCAAyC;GACtF,IAAI,OAAO,QAAQ,MAAM,IAAI,MAAM,+BAA+B,KAAK;GACvE,IAAI,eAAe,IAAI,GAAG,GACtB,QAAQ,UAAe;IACnB,OAAO,OAAO;IACd,OAAO;GACX;GAGJ,IAAI,QAAQ,eAAe,OAAO,EAAE,GAAG,OAAO;GAC9C,IAAI,QAAQ,YACR,OAAO;IACH,GAAG;IACH,UAAU;GACd;GAGJ,OAAO,OAAO;GACd,OAAO;EACX,EACJ,CACJ;CACJ;AACJ"}
1
+ {"version":3,"file":"base.js","names":[],"sources":["../../src/schema-builders/base.ts"],"sourcesContent":["import type { Schema } from 'mongoose';\n\ntype BaseSchemaType =\n | BooleanConstructor\n | DateConstructor\n | NumberConstructor\n | Schema.Types.ObjectId['constructor']\n | StringConstructor;\n\n// Constants/Variables\nconst isFunctionKeys = new Set([\n 'default',\n 'enum',\n 'index',\n 'max',\n 'maxlength',\n 'min',\n 'minlength',\n]);\n\n// Functions\nexport function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType) {\n return (schema: Record<string, any> = {}) => {\n schema.type = type;\n return new Proxy(\n Object.freeze({}),\n {\n get(_, key, receiver) {\n if (typeof key === 'symbol') throw new Error('Cannot use symbol as a schema attribute');\n if (key in schema) throw new Error(`Duplicate schema attribute: ${key}`);\n if (isFunctionKeys.has(key)) {\n return (value: any) => {\n schema[key] = value;\n return receiver;\n };\n }\n\n if (key === 'nonRequired') return { ...schema };\n if (key === 'required') {\n return {\n ...schema,\n required: true,\n };\n }\n\n schema[key] = true;\n return receiver;\n },\n },\n ) as Builder;\n };\n}\n"],"mappings":";AAUA,MAAM,iCAAiB,IAAI,IAAI;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;AACJ,CAAC;AAGD,SAAgB,+BAAwE,MAAsB;CAC1G,QAAQ,SAA8B,CAAC,MAAM;EACzC,OAAO,OAAO;EACd,OAAO,IAAI,MACP,OAAO,OAAO,CAAC,CAAC,GAChB,EACI,IAAI,GAAG,KAAK,UAAU;GAClB,IAAI,OAAO,QAAQ,UAAU,MAAM,IAAI,MAAM,yCAAyC;GACtF,IAAI,OAAO,QAAQ,MAAM,IAAI,MAAM,+BAA+B,KAAK;GACvE,IAAI,eAAe,IAAI,GAAG,GACtB,QAAQ,UAAe;IACnB,OAAO,OAAO;IACd,OAAO;GACX;GAGJ,IAAI,QAAQ,eAAe,OAAO,EAAE,GAAG,OAAO;GAC9C,IAAI,QAAQ,YACR,OAAO;IACH,GAAG;IACH,UAAU;GACd;GAGJ,OAAO,OAAO;GACd,OAAO;EACX,EACJ,CACJ;CACJ;AACJ"}
@@ -5,7 +5,7 @@ type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string
5
5
  interface BaseProps {
6
6
  type: BooleanSchemaDefinition;
7
7
  }
8
- interface BooleanSchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFields extends string = never> {
8
+ export interface BooleanSchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFields extends string = never> {
9
9
  default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends boolean>(value: T) => ExtendSchemaBuilder<Merge<Props, {
10
10
  default: T;
11
11
  }>, ExtraOmitFields>;
@@ -29,7 +29,6 @@ interface BooleanSchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFie
29
29
  unique: true;
30
30
  }>, ExtraOmitFields>;
31
31
  }
32
- declare const booleanSchemaBuilder: (schema?: Record<string, any>) => BooleanSchemaBuilder<BaseProps, never>;
32
+ export declare const booleanSchemaBuilder: (schema?: Record<string, any>) => BooleanSchemaBuilder<BaseProps, never>;
33
33
  //#endregion
34
- export { BooleanSchemaBuilder, booleanSchemaBuilder };
35
34
  //# sourceMappingURL=boolean.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"boolean.d.ts","names":[],"sources":["../../src/schema-builders/boolean.ts"],"mappings":";;;KAUK,oBACD,cAAc,WACd,kCACA,KACA,qBAAqB,OAAO,kBAC5B,wBAAwB;UAGlB;EACN,MAAM;;UAGO,qBACb,cAAc,YAAY,WAC1B;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,mBACF,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;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;;cAGnD,uBAAoB,SAAA,wBAAA,qBAAA"}
1
+ {"version":3,"file":"boolean.d.ts","names":[],"sources":["../../src/schema-builders/boolean.ts"],"mappings":";;;KAUK,oBACD,cAAc,WACd,kCACA,KACA,qBAAqB,OAAO,kBAC5B,wBAAwB;UAGlB;EACN,MAAM;;iBAGO,qBACb,cAAc,YAAY,WAC1B;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,mBACF,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;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,uBAAoB,SAAA,wBAAA,qBAAA"}
@@ -6,7 +6,7 @@ type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string
6
6
  interface BaseProps {
7
7
  type: DateSchemaDefinition;
8
8
  }
9
- interface DateSchemaBuilder<Props extends {
9
+ export interface DateSchemaBuilder<Props extends {
10
10
  type: DateSchemaDefinition;
11
11
  } = {
12
12
  type: DateSchemaDefinition;
@@ -48,9 +48,8 @@ interface DateSchemaBuilder<Props extends {
48
48
  unique: true;
49
49
  }>, ExtraOmitFields>;
50
50
  }
51
- declare const dateSchemaBuilder: (schema?: Record<string, any>) => DateSchemaBuilder<{
51
+ export declare const dateSchemaBuilder: (schema?: Record<string, any>) => DateSchemaBuilder<{
52
52
  type: DateSchemaDefinition;
53
53
  }, never>;
54
54
  //#endregion
55
- export { DateSchemaBuilder, dateSchemaBuilder };
56
55
  //# sourceMappingURL=date.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"date.d.ts","names":[],"sources":["../../src/schema-builders/date.ts"],"mappings":";;;;KAYK,oBACD,cAAc,WACd,kCACA,KACA,kBAAkB,OAAO,kBACzB,wBAAwB;UAGlB;EACN,MAAM;;UAGO,kBACb;EAAgB,MAAM;;EAA2B,MAAM;GACvD;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,UAAU,YACZ,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,UACE,aAAa,MAAM;KAChB,eAAe;;IAChB,UAAU;IAAG,QAAQ,aAAa,MAAM;KAC5C,UAAU,YACV,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,IAAI,cAAc,GAAG,KAC/B,UAAU,YACV,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,KAAK;MACpB;EAGJ,MACI,UAAU,IAAI,cAAc,GAAG,KAC/B,UAAU,YACV,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;;cAGnD,oBAAiB,SAAA,wBAAA;EAtD6B,MAAA"}
1
+ {"version":3,"file":"date.d.ts","names":[],"sources":["../../src/schema-builders/date.ts"],"mappings":";;;;KAYK,oBACD,cAAc,WACd,kCACA,KACA,kBAAkB,OAAO,kBACzB,wBAAwB;UAGlB;EACN,MAAM;;iBAGO,kBACb;EAAgB,MAAM;;EAA2B,MAAM;GACvD;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,UAAU,YACZ,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,UACE,aAAa,MAAM;KAChB,eAAe;;IAChB,UAAU;IAAG,QAAQ,aAAa,MAAM;KAC5C,UAAU,YACV,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,IAAI,cAAc,GAAG,KAC/B,UAAU,YACV,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,KAAK;MACpB;EAGJ,MACI,UAAU,IAAI,cAAc,GAAG,KAC/B,UAAU,YACV,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,oBAAiB,SAAA,wBAAA;EAtD6B,MAAA"}
@@ -3,11 +3,21 @@ import { DefaultType, IndexDirection, IndexOptions, Schema, Types } from "mongoo
3
3
  import { Decimal } from "decimal.js";
4
4
  import { Merge } from "type-fest";
5
5
  //#region src/schema-builders/decimal128.d.ts
6
+ type Decimal128Limit = Decimal.Value | Types.Decimal128 | {
7
+ toString: () => string;
8
+ };
6
9
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<Decimal128SchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
7
10
  interface BaseProps {
8
11
  type: typeof Schema.Types.Decimal128;
9
12
  }
10
- interface Decimal128SchemaBuilder<Props extends {
13
+ interface Decimal128LimitValidator {
14
+ max?: string;
15
+ message: string;
16
+ min?: string;
17
+ type: 'max' | 'min';
18
+ validator: (value: null | Types.Decimal128 | undefined) => boolean;
19
+ }
20
+ export interface Decimal128SchemaBuilder<Props extends {
11
21
  type: typeof Schema.Types.Decimal128;
12
22
  } = {
13
23
  type: typeof Schema.Types.Decimal128;
@@ -29,6 +39,8 @@ interface Decimal128SchemaBuilder<Props extends {
29
39
  index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<Merge<Props, {
30
40
  index: T;
31
41
  }>, ExtraOmitFields>;
42
+ max: <T extends D | Readonlyable<[D, S]>, D extends Decimal128Limit, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, Decimal128ValidationSchema>, 'max' | ExtraOmitFields>;
43
+ min: <T extends D | Readonlyable<[D, S]>, D extends Decimal128Limit, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, Decimal128ValidationSchema>, 'min' | ExtraOmitFields>;
32
44
  nonRequired: Props;
33
45
  private: ExtendSchemaBuilder<Merge<Props, {
34
46
  private: true;
@@ -64,6 +76,9 @@ interface Decimal128SchemaBuilder<Props extends {
64
76
  unique: true;
65
77
  }>, ExtraOmitFields>;
66
78
  }
79
+ interface Decimal128ValidationSchema {
80
+ validate: Decimal128LimitValidator[];
81
+ }
67
82
  interface ToStringGetterSchema {
68
83
  get: (value?: Types.Decimal128) => string | undefined;
69
84
  }
@@ -72,7 +87,6 @@ interface ToStringSetterSchema {
72
87
  toString: () => string;
73
88
  }) => string | undefined;
74
89
  }
75
- declare function decimal128SchemaBuilder(): Decimal128SchemaBuilder;
90
+ export declare function decimal128SchemaBuilder(): Decimal128SchemaBuilder;
76
91
  //#endregion
77
- export { Decimal128SchemaBuilder, decimal128SchemaBuilder };
78
92
  //# sourceMappingURL=decimal128.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decimal128.d.ts","names":[],"sources":["../../src/schema-builders/decimal128.ts"],"mappings":";;;;;KAcK,oBACD,cAAc,WACd,kCACA,KACA,wBAAwB,OAAO,kBAC/B,wBAAwB;UAGlB;EACN,aAAa,OAAO,MAAM;;UAGb,wBACb;EAAgB,aAAa,OAAO,MAAM;;EAAiB,aAAa,OAAO,MAAM;GACrF;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,UAAU,MAAM,YAClB,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,UACE,aAAa,MAAM;KAChB,eAAe;;IAChB,UAAU;IAAG,QAAQ,aAAa,MAAM;KAC5C,UAAU,MAAM,YAChB,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,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;;;;;;;;;;;EAYzB,2BAA2B,iBAAiB,WAAW,QAAQ,aAAa,oBACxE,MAAM,OAAO,oDACgB;;;;;;;;;;EAYjC,mBAAmB,oBAAoB,MAAM,OAAO,6CAA6C;EACjG,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;;UAGtD;EACN,MAAM,QAAQ,MAAM;;UAGd;EACN,MAAM;IAAU;;;iBAKJ,2BA4BP"}
1
+ {"version":3,"file":"decimal128.d.ts","names":[],"sources":["../../src/schema-builders/decimal128.ts"],"mappings":";;;;;KAcK,kBAAkB,QAAQ,QAAQ,MAAM;EAAe;;KACvD,oBACD,cAAc,WACd,kCACA,KACA,wBAAwB,OAAO,kBAC/B,wBAAwB;UAGlB;EACN,aAAa,OAAO,MAAM;;UAGpB;EACN;EACA;EACA;EACA;EACA,YAAY,cAAc,MAAM;;iBAGnB,wBACb;EAAgB,aAAa,OAAO,MAAM;;EAAiB,aAAa,OAAO,MAAM;GACrF;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,UAAU,MAAM,YAClB,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,UACE,aAAa,MAAM;KAChB,eAAe;;IAChB,UAAU;IAAG,QAAQ,aAAa,MAAM;KAC5C,UAAU,MAAM,YAChB,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,IAAI,cAAc,GAAG,KAC/B,UAAU,iBACV,kBACF,OAAO,MAAM,oBACX,MAAM,OAAO,qCACL;EAGZ,MACI,UAAU,IAAI,cAAc,GAAG,KAC/B,UAAU,iBACV,kBACF,OAAO,MAAM,oBACX,MAAM,OAAO,qCACL;EAGZ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;;;;;;;;;;;EAYzB,2BAA2B,iBAAiB,WAAW,QAAQ,aAAa,oBACxE,MAAM,OAAO,oDACgB;;;;;;;;;;EAYjC,mBAAmB,oBAAoB,MAAM,OAAO,6CAA6C;EACjG,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;;UAGtD;EACN,UAAU;;UAGJ;EACN,MAAM,QAAQ,MAAM;;UAGd;EACN,MAAM;IAAU;;;wBAqCJ,2BAyCP"}
@@ -2,11 +2,34 @@ import { createBaseSchemaBuilderFactory } from "./base.js";
2
2
  import { Schema } from "mongoose";
3
3
  import { Decimal } from "decimal.js";
4
4
  //#region 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}).";
5
7
  const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);
8
+ function createLimitValidator(type, value) {
9
+ const [limit, message] = Array.isArray(value) ? value : [value, void 0];
10
+ const decimalLimit = new Decimal(limit.toString());
11
+ if (!decimalLimit.isFinite()) throw new RangeError(`Decimal128 ${type} limit must be finite`);
12
+ return {
13
+ message: message ?? (type === "min" ? defaultMinValidateMessage : defaultMaxValidateMessage),
14
+ [type]: decimalLimit.toString(),
15
+ type,
16
+ validator: (value) => {
17
+ if (value === null || value === void 0) return true;
18
+ const decimalValue = new Decimal(value.toString());
19
+ return type === "min" ? decimalValue.gte(decimalLimit) : decimalValue.lte(decimalLimit);
20
+ }
21
+ };
22
+ }
6
23
  function decimal128SchemaBuilder() {
7
24
  const schema = {};
8
25
  const baseBuilder = baseBuilderFactory(schema);
9
26
  return new Proxy(baseBuilder, { get(target, key, receiver) {
27
+ if (key === "max" || key === "min") return (value) => {
28
+ const validator = createLimitValidator(key, value);
29
+ const validators = Array.isArray(schema.validate) ? schema.validate : [];
30
+ schema.validate = [...validators.filter(({ type }) => type !== key), validator];
31
+ return receiver;
32
+ };
10
33
  if (key === "setRoundAndToFixedSetter") return (places = 2, rounding = Decimal.ROUND_DOWN) => {
11
34
  schema.set = (value) => {
12
35
  if (value !== void 0 && value !== null) return (Decimal.isDecimal(value) ? value : new Decimal(value.toString())).toFixed(places, rounding);
@@ -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 { Readonlyable } from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\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 { type: typeof Schema.Types.Decimal128 } = { type: typeof Schema.Types.Decimal128 },\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\n | Readonlyable<Array<D | null>>\n | { [path: string]: D | null }\n | { message?: M; values: Readonlyable<Array<D | null>> },\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 nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n\n /**\n * Sets the rounding and toFixed behavior for Decimal128 fields.\n * This method allows specifying the number of decimal places and the rounding strategy to be used when\n * saving the field to the database.\n *\n * @param places - The number of decimal places to round to (default is 2).\n * @param rounding - The rounding strategy from the Decimal.js library (default is Decimal.ROUND_DOWN).\n *\n * @returns A schema builder with the rounding and toFixed behavior applied to the `set` option in Mongoose.\n */\n setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendSchemaBuilder<\n Merge<Props, ToStringSetterSchema>,\n 'setRoundAndToFixedSetter' | ExtraOmitFields\n >;\n\n /**\n * Sets the toString behavior for Decimal128 fields.\n * This method defines how the Decimal128 field should be converted to a string when processing or\n * retrieving the value in the application (e.g., via getters), while still storing the value as Decimal128\n * in the database.\n *\n * @returns A schema builder with the custom `get` behavior applied to convert the Decimal128 field to a string\n * when accessed in the application.\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}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string | undefined;\n}\n\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);\n\nexport function decimal128SchemaBuilder() {\n const schema: Record<string, any> = {};\n const baseBuilder = baseBuilderFactory(schema);\n return new Proxy(\n baseBuilder,\n {\n get(target, key, receiver) {\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 return receiver;\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as Decimal128SchemaBuilder;\n}\n"],"mappings":";;;;AAiGA,MAAM,qBAAqB,+BAA+B,OAAO,MAAM,UAAU;AAEjF,SAAgB,0BAA0B;CACtC,MAAM,SAA8B,CAAC;CACrC,MAAM,cAAc,mBAAmB,MAAM;CAC7C,OAAO,IAAI,MACP,aACA,EACI,IAAI,QAAQ,KAAK,UAAU;EACvB,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;EACX;EAEA,OAAO,QAAQ,IAAI,QAAQ,KAAK,QAAQ;CAC5C,EACJ,CACJ;AACJ"}
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 { Readonlyable } from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype Decimal128Limit = Decimal.Value | Types.Decimal128 | { toString: () => string };\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\ninterface Decimal128LimitValidator {\n max?: string;\n message: string;\n min?: string;\n type: 'max' | 'min';\n validator: (value: null | Types.Decimal128 | undefined) => boolean;\n}\n\nexport interface Decimal128SchemaBuilder<\n Props extends { type: typeof Schema.Types.Decimal128 } = { type: typeof Schema.Types.Decimal128 },\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\n | Readonlyable<Array<D | null>>\n | { [path: string]: D | null }\n | { message?: M; values: Readonlyable<Array<D | null>> },\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 D | Readonlyable<[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 D | Readonlyable<[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 * Sets the rounding and toFixed behavior for Decimal128 fields.\n * This method allows specifying the number of decimal places and the rounding strategy to be used when\n * saving the field to the database.\n *\n * @param places - The number of decimal places to round to (default is 2).\n * @param rounding - The rounding strategy from the Decimal.js library (default is Decimal.ROUND_DOWN).\n *\n * @returns A schema builder with the rounding and toFixed behavior applied to the `set` option in Mongoose.\n */\n setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendSchemaBuilder<\n Merge<Props, ToStringSetterSchema>,\n 'setRoundAndToFixedSetter' | ExtraOmitFields\n >;\n\n /**\n * Sets the toString behavior for Decimal128 fields.\n * This method defines how the Decimal128 field should be converted to a string when processing or\n * retrieving the value in the application (e.g., via getters), while still storing the value as Decimal128\n * in the database.\n *\n * @returns A schema builder with the custom `get` behavior applied to convert the Decimal128 field to a string\n * when accessed in the application.\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 Decimal128ValidationSchema {\n validate: Decimal128LimitValidator[];\n}\n\ninterface ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string | undefined;\n}\n\n// Constants/Variables\nconst defaultMinValidateMessage = 'Path `{PATH}` ({VALUE}) is less than minimum allowed value ({MIN}).';\nconst defaultMaxValidateMessage = 'Path `{PATH}` ({VALUE}) is more than maximum allowed value ({MAX}).';\n\n// Functions\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);\n\nfunction createLimitValidator(\n type: 'max' | 'min',\n value: Decimal128Limit | Readonlyable<[Decimal128Limit, string]>,\n): Decimal128LimitValidator {\n const [limit, message] = Array.isArray(value)\n ? value as Readonly<[Decimal128Limit, string]>\n : [\n value,\n undefined,\n ];\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 ?? (type === 'min' ? defaultMinValidateMessage : defaultMaxValidateMessage),\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: 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: Decimal128Limit | Readonlyable<[Decimal128Limit, string]>) => {\n const validator = createLimitValidator(key, value);\n const validators = Array.isArray(schema.validate) ? schema.validate : [];\n schema.validate = [\n ...validators.filter(({ type }) => type !== key),\n validator,\n ];\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 return receiver;\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as Decimal128SchemaBuilder;\n}\n"],"mappings":";;;;AAiIA,MAAM,4BAA4B;AAClC,MAAM,4BAA4B;AAGlC,MAAM,qBAAqB,+BAA+B,OAAO,MAAM,UAAU;AAEjF,SAAS,qBACL,MACA,OACwB;CACxB,MAAM,CAAC,OAAO,WAAW,MAAM,QAAQ,KAAK,IACtC,QACA,CACE,OACA,KAAA,CACJ;CAEJ,MAAM,eAAe,IAAI,QAAQ,MAAM,SAAS,CAAC;CACjD,IAAI,CAAC,aAAa,SAAS,GAAG,MAAM,IAAI,WAAW,cAAc,KAAK,sBAAsB;CAE5F,OAAO;EACH,SAAS,YAAY,SAAS,QAAQ,4BAA4B;GACjE,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,SAA8B,CAAC;CACrC,MAAM,cAAc,mBAAmB,MAAM;CAC7C,OAAO,IAAI,MACP,aACA,EACI,IAAI,QAAQ,KAAK,UAAU;EACvB,IAAI,QAAQ,SAAS,QAAQ,OACzB,QAAQ,UAAqE;GACzE,MAAM,YAAY,qBAAqB,KAAK,KAAK;GACjD,MAAM,aAAa,MAAM,QAAQ,OAAO,QAAQ,IAAI,OAAO,WAAW,CAAC;GACvE,OAAO,WAAW,CACd,GAAG,WAAW,QAAQ,EAAE,WAAW,SAAS,GAAG,GAC/C,SACJ;GAEA,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;EACX;EAEA,OAAO,QAAQ,IAAI,QAAQ,KAAK,QAAQ;CAC5C,EACJ,CACJ;AACJ"}
@@ -6,7 +6,7 @@ type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string
6
6
  interface BaseProps {
7
7
  type: NumberSchemaDefinition;
8
8
  }
9
- interface NumberSchemaBuilder<Props extends {
9
+ export interface NumberSchemaBuilder<Props extends {
10
10
  type: NumberSchemaDefinition;
11
11
  } = {
12
12
  type: NumberSchemaDefinition;
@@ -48,9 +48,8 @@ interface NumberSchemaBuilder<Props extends {
48
48
  unique: true;
49
49
  }>, ExtraOmitFields>;
50
50
  }
51
- declare const numberSchemaBuilder: (schema?: Record<string, any>) => NumberSchemaBuilder<{
51
+ export declare const numberSchemaBuilder: (schema?: Record<string, any>) => NumberSchemaBuilder<{
52
52
  type: NumberSchemaDefinition;
53
53
  }, never>;
54
54
  //#endregion
55
- export { NumberSchemaBuilder, numberSchemaBuilder };
56
55
  //# sourceMappingURL=number.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"number.d.ts","names":[],"sources":["../../src/schema-builders/number.ts"],"mappings":";;;;KAYK,oBACD,cAAc,WACd,kCACA,KACA,oBAAoB,OAAO,kBAC3B,wBAAwB;UAGlB;EACN,MAAM;;UAGO,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,UACE,aAAa,MAAM;KAChB,eAAe;;IAChB,UAAU;IAAG,QAAQ,aAAa,MAAM;KAC5C,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,IAAI,cAAc,GAAG,KAC/B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,KAAK;MACpB;EAGJ,MACI,UAAU,IAAI,cAAc,GAAG,KAC/B,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;;cAGnD,sBAAmB,SAAA,wBAAA;EAtD6B,MAAA"}
1
+ {"version":3,"file":"number.d.ts","names":[],"sources":["../../src/schema-builders/number.ts"],"mappings":";;;;KAYK,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,UACE,aAAa,MAAM;KAChB,eAAe;;IAChB,UAAU;IAAG,QAAQ,aAAa,MAAM;KAC5C,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,IAAI,cAAc,GAAG,KAC/B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,KAAK;MACpB;EAGJ,MACI,UAAU,IAAI,cAAc,GAAG,KAC/B,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;EAtD6B,MAAA"}
@@ -6,7 +6,7 @@ type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string
6
6
  interface BaseProps {
7
7
  type: typeof Schema.Types.ObjectId;
8
8
  }
9
- interface ObjectIdSchemaBuilder<Props extends {
9
+ export interface ObjectIdSchemaBuilder<Props extends {
10
10
  type: typeof Schema.Types.ObjectId;
11
11
  } = {
12
12
  type: typeof Schema.Types.ObjectId;
@@ -42,9 +42,8 @@ interface ObjectIdSchemaBuilder<Props extends {
42
42
  unique: true;
43
43
  }>, ExtraOmitFields>;
44
44
  }
45
- declare const objectIdSchemaBuilder: (schema?: Record<string, any>) => ObjectIdSchemaBuilder<{
45
+ export declare const objectIdSchemaBuilder: (schema?: Record<string, any>) => ObjectIdSchemaBuilder<{
46
46
  type: typeof Schema.Types.ObjectId;
47
47
  }, never>;
48
48
  //#endregion
49
- export { ObjectIdSchemaBuilder, objectIdSchemaBuilder };
50
49
  //# sourceMappingURL=object-id.d.ts.map
@@ -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;;UAGb,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,UACE,aAAa,aAAa;KACvB,sBAAsB;;IACvB,UAAU;IAAG,QAAQ,aAAa,aAAa;KACnD,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;;cAGnD,wBAAqB,SAAA,wBAAA;EApCiC,aAAO,OAAO,MAAM"}
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,UACE,aAAa,aAAa;KACvB,sBAAsB;;IACvB,UAAU;IAAG,QAAQ,aAAa,aAAa;KACnD,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;EApCiC,aAAO,OAAO,MAAM"}
@@ -6,7 +6,7 @@ type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string
6
6
  interface BaseProps {
7
7
  type: typeof Schema.Types.ObjectId;
8
8
  }
9
- interface RefSchemaBuilder<Props extends {
9
+ export interface RefSchemaBuilder<Props extends {
10
10
  type: typeof Schema.Types.ObjectId;
11
11
  } = {
12
12
  type: typeof Schema.Types.ObjectId;
@@ -42,10 +42,9 @@ interface RefSchemaBuilder<Props extends {
42
42
  unique: true;
43
43
  }>, ExtraOmitFields>;
44
44
  }
45
- declare function refSchemaBuilder<T extends ((this: any, doc: any) => Model<any> | string) | Model<any> | string>(ref: T): RefSchemaBuilder<{
45
+ export declare function refSchemaBuilder<T extends ((this: any, doc: any) => Model<any> | string) | Model<any> | string>(ref: T): RefSchemaBuilder<{
46
46
  ref: T;
47
47
  type: typeof Schema.Types.ObjectId;
48
48
  }>;
49
49
  //#endregion
50
- export { RefSchemaBuilder, refSchemaBuilder };
51
50
  //# sourceMappingURL=ref.d.ts.map
@@ -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;;UAGb,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,UACE,aAAa,aAAa;KACvB,sBAAsB;;IACvB,UAAU;IAAG,QAAQ,aAAa,aAAa;KACnD,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;;iBAKhD,iBAAiB,YAAY,WAAW,aAAa,uBAAuB,qBACxF,KAAK,IAEiC;EAAmB,KAAK;EAAG,aAAa,OAAO,MAAM"}
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,UACE,aAAa,aAAa;KACvB,sBAAsB;;IACvB,UAAU;IAAG,QAAQ,aAAa,aAAa;KACnD,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"}
@@ -13,7 +13,7 @@ interface IpSchema<T extends string> {
13
13
  validator: (value: string) => boolean;
14
14
  };
15
15
  }
16
- interface StringSchemaBuilder<Props extends {
16
+ export interface StringSchemaBuilder<Props extends {
17
17
  type: StringSchemaDefinition;
18
18
  } = {
19
19
  type: StringSchemaDefinition;
@@ -44,7 +44,7 @@ interface StringSchemaBuilder<Props extends {
44
44
  *
45
45
  * @returns A schema builder with IPv4 validation and the `trim` option enabled.
46
46
  */
47
- ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendSchemaBuilder<Merge<Props, IpSchema<T>>, 'ipv4' | 'ipv6' | ExtraOmitFields>;
47
+ ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendSchemaBuilder<Merge<Props, IpSchema<T>>, 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields>;
48
48
  /**
49
49
  * Adds IPv6 validation to the string schema.
50
50
  * Ensures the string is a valid IPv6 address and trims the input. The validation message can be customized.
@@ -54,7 +54,7 @@ interface StringSchemaBuilder<Props extends {
54
54
  *
55
55
  * @returns A schema builder with IPv6 validation and the `trim` option enabled.
56
56
  */
57
- ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendSchemaBuilder<Merge<Props, IpSchema<T>>, 'ipv4' | 'ipv6' | ExtraOmitFields>;
57
+ ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendSchemaBuilder<Merge<Props, IpSchema<T>>, 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields>;
58
58
  /**
59
59
  * Sets both the maximum and minimum length of the string.
60
60
  * This method ensures the string length is exactly or within a specified range.
@@ -70,6 +70,18 @@ interface StringSchemaBuilder<Props extends {
70
70
  lowercase: ExtendSchemaBuilder<Merge<Props, {
71
71
  lowercase: true;
72
72
  }>, ExtraOmitFields>;
73
+ /**
74
+ * Adds regular expression validation to the string schema.
75
+ * The validation message can be customized.
76
+ *
77
+ * @param regex - The regular expression that the string must match.
78
+ * @param message - Optional custom validation message.
79
+ *
80
+ * @returns A schema builder with the Mongoose `match` option configured.
81
+ */
82
+ match: <T extends RegExp, M extends string | undefined = undefined>(regex: T, message?: M) => ExtendSchemaBuilder<Merge<Props, {
83
+ match: M extends string ? Readonly<[T, M]> : T;
84
+ }>, ExtraOmitFields>;
73
85
  maxlength: <T extends L | Readonlyable<[L, S]>, L extends number, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, {
74
86
  maxlength: T;
75
87
  }>, ExtraOmitFields>;
@@ -98,10 +110,25 @@ interface StringSchemaBuilder<Props extends {
98
110
  uppercase: ExtendSchemaBuilder<Merge<Props, {
99
111
  uppercase: true;
100
112
  }>, ExtraOmitFields>;
113
+ /**
114
+ * Adds WHATWG URL validation to the string schema. Credentials and non-HTTP schemes are allowed.
115
+ * The input is parsed only; no DNS lookup or normalization is performed. The validation message can be customized.
116
+ *
117
+ * @param message - Custom validation error message. Defaults to the standard URL validation message.
118
+ *
119
+ * @returns A schema builder with URL validation enabled.
120
+ */
121
+ url: <T extends string = typeof defaultUrlValidateMessage>(message?: T) => ExtendSchemaBuilder<Merge<Props, UrlSchema<T>>, 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields>;
122
+ }
123
+ interface UrlSchema<T extends string> {
124
+ validate: {
125
+ message: T;
126
+ validator: (value: string) => boolean;
127
+ };
101
128
  }
102
129
  declare const defaultIpv4ValidateMessage = "`{VALUE}` is not a valid IPv4 address for path `{PATH}`";
103
130
  declare const defaultIpv6ValidateMessage = "`{VALUE}` is not a valid IPv6 address for path `{PATH}`";
104
- declare function stringSchemaBuilder(): StringSchemaBuilder;
131
+ declare const defaultUrlValidateMessage = "`{VALUE}` is not a valid URL for path `{PATH}`";
132
+ export declare function stringSchemaBuilder(): StringSchemaBuilder;
105
133
  //#endregion
106
- export { StringSchemaBuilder, stringSchemaBuilder };
107
134
  //# sourceMappingURL=string.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"string.d.ts","names":[],"sources":["../../src/schema-builders/string.ts"],"mappings":";;;;KAiBK,oBACD,cAAc,WACd,kCACA,KACA,oBAAoB,OAAO,kBAC3B,wBAAwB;UAGlB;EACN,MAAM;;UAGA,SAAS;EACf;EACA;IAAY,SAAS;IAAG,YAAY;;;UAGvB,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,UACE,aAAa,aAAa;KACvB,sBAAsB;;IACvB,UAAU;IAAG,QAAQ,aAAa,aAAa;KACnD,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;;;;;;;;;;EAYJ,OAAO,0BAA0B,4BAA4B,UAAU,MAAM,oBACzE,MAAM,OAAO,SAAS,uBACJ;;;;;;;;;;EAYtB,OAAO,0BAA0B,4BAA4B,UAAU,MAAM,oBACzE,MAAM,OAAO,SAAS,uBACJ;;;;;;;;;EAWtB,SACI,UAAU,IAAI,cAAc,GAAG,KAC/B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,WAAW;IAAG,WAAW;MACxC;EAGJ,WAAW,oBAAoB,MAAM;IAAS;MAAoB;EAClE,YACI,UAAU,IAAI,cAAc,GAAG,KAC/B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,WAAW;MAC1B;EAGJ,YACI,UAAU,IAAI,cAAc,GAAG,KAC/B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,WAAW;MAC1B;EAGJ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;EACzB,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,MAAM,oBAAoB,MAAM;IAAS;MAAe;EACxD,MAAM,oBAAoB,MAAM;IAAS;MAAe;EACxD,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,WAAW,oBAAoB,MAAM;IAAS;MAAoB;;cAIhE;cACA;iBAEU,uBAyCP"}
1
+ {"version":3,"file":"string.d.ts","names":[],"sources":["../../src/schema-builders/string.ts"],"mappings":";;;;KAiBK,oBACD,cAAc,WACd,kCACA,KACA,oBAAoB,OAAO,kBAC3B,wBAAwB;UAGlB;EACN,MAAM;;UAGA,SAAS;EACf;EACA;IAAY,SAAS;IAAG,YAAY;;;iBAGvB,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,UACE,aAAa,aAAa;KACvB,sBAAsB;;IACvB,UAAU;IAAG,QAAQ,aAAa,aAAa;KACnD,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;;;;;;;;;;EAYJ,OAAO,0BAA0B,4BAA4B,UAAU,MAAM,oBACzE,MAAM,OAAO,SAAS,+BACI;;;;;;;;;;EAY9B,OAAO,0BAA0B,4BAA4B,UAAU,MAAM,oBACzE,MAAM,OAAO,SAAS,+BACI;;;;;;;;;EAW9B,SACI,UAAU,IAAI,cAAc,GAAG,KAC/B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,WAAW;IAAG,WAAW;MACxC;EAGJ,WAAW,oBAAoB,MAAM;IAAS;MAAoB;;;;;;;;;;EAWlE,QACI,UAAU,QACV,0CACF,OAAO,GACL,UAAU,MAAM,oBAChB,MAAM;IAAS,OAAO,mBAAmB,UAAU,GAAG,MAAM;MAC5D;EAEJ,YACI,UAAU,IAAI,cAAc,GAAG,KAC/B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,WAAW;MAC1B;EAGJ,YACI,UAAU,IAAI,cAAc,GAAG,KAC/B,kBACA,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,WAAW;MAC1B;EAGJ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;EACzB,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,MAAM,oBAAoB,MAAM;IAAS;MAAe;EACxD,MAAM,oBAAoB,MAAM;IAAS;MAAe;EACxD,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,WAAW,oBAAoB,MAAM;IAAS;MAAoB;;;;;;;;;EAUlE,MAAM,0BAA0B,2BAA2B,UAAU,MAAM,oBACvE,MAAM,OAAO,UAAU,+BACG;;UAIxB,UAAU;EAChB;IAAY,SAAS;IAAG,YAAY;;;cAIlC;cACA;cACA;wBAKU,uBAiEP"}
@@ -1,9 +1,10 @@
1
1
  import { createBaseSchemaBuilderFactory } from "./base.js";
2
2
  import { isIPv4, isIPv6 } from "node:net";
3
3
  //#region src/schema-builders/string.ts
4
- const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
5
4
  const defaultIpv4ValidateMessage = "`{VALUE}` is not a valid IPv4 address for path `{PATH}`";
6
5
  const defaultIpv6ValidateMessage = "`{VALUE}` is not a valid IPv6 address for path `{PATH}`";
6
+ const defaultUrlValidateMessage = "`{VALUE}` is not a valid URL for path `{PATH}`";
7
+ const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
7
8
  function stringSchemaBuilder() {
8
9
  const schema = {};
9
10
  const baseBuilder = baseBuilderFactory(schema);
@@ -28,6 +29,17 @@ function stringSchemaBuilder() {
28
29
  schema.maxlength = schema.minlength = value;
29
30
  return receiver;
30
31
  };
32
+ if (key === "match") return (regex, message) => {
33
+ schema.match = message === void 0 ? regex : [regex, message];
34
+ return receiver;
35
+ };
36
+ if (key === "url") return (message = defaultUrlValidateMessage) => {
37
+ schema.validate = {
38
+ message,
39
+ validator: (value) => URL.canParse(value)
40
+ };
41
+ return receiver;
42
+ };
31
43
  return Reflect.get(target, key, receiver);
32
44
  } });
33
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"string.js","names":[],"sources":["../../src/schema-builders/string.ts"],"sourcesContent":["import {\n isIPv4,\n isIPv6,\n} from 'node:net';\n\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n StringSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n StringSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: StringSchemaDefinition;\n}\n\ninterface IpSchema<T extends string> {\n trim: true;\n validate: { message: T; validator: (value: string) => boolean };\n}\n\nexport interface StringSchemaBuilder<\n Props extends { type: StringSchemaDefinition } = { type: StringSchemaDefinition },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<null | S>>\n | { [path: string]: null | S }\n | { message?: M; values: Readonlyable<Array<null | S>> },\n M extends string,\n S 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 /**\n * Adds IPv4 validation to the string schema.\n * Ensures the string is a valid IPv4 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv4 validation message.\n *\n * @returns A schema builder with IPv4 validation and the `trim` option enabled.\n */\n ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | ExtraOmitFields\n >;\n\n /**\n * Adds IPv6 validation to the string schema.\n * Ensures the string is a valid IPv6 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv6 validation message.\n *\n * @returns A schema builder with IPv6 validation and the `trim` option enabled.\n */\n ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | ExtraOmitFields\n >;\n\n /**\n * Sets both the maximum and minimum length of the string.\n * This method ensures the string length is exactly or within a specified range.\n *\n * @param value - A number representing the exact length or an array specifying [minimum, maximum] length.\n *\n * @returns A schema builder with both `maxlength` and `minlength` options applied.\n */\n length: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendSchemaBuilder<Merge<Props, { lowercase: true }>, ExtraOmitFields>;\n maxlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { maxlength: T }>,\n ExtraOmitFields\n >;\n\n minlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { minlength: 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 text: ExtendSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendSchemaBuilder<Merge<Props, { uppercase: true }>, ExtraOmitFields>;\n}\n\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(String);\nconst defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`';\nconst defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`';\n\nexport function stringSchemaBuilder() {\n const schema: Record<string, any> = {};\n const baseBuilder = baseBuilderFactory(schema);\n return new Proxy(\n baseBuilder,\n {\n get(target, key, receiver) {\n if (key === 'ipv4') {\n return (message: string = defaultIpv4ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => isIPv4(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'ipv6') {\n return (message: string = defaultIpv6ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => isIPv6(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'length') {\n return (value: any) => {\n schema.maxlength = schema.minlength = value;\n return receiver;\n };\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as StringSchemaBuilder;\n}\n"],"mappings":";;;AA0IA,MAAM,qBAAqB,+BAA+B,MAAM;AAChE,MAAM,6BAA6B;AACnC,MAAM,6BAA6B;AAEnC,SAAgB,sBAAsB;CAClC,MAAM,SAA8B,CAAC;CACrC,MAAM,cAAc,mBAAmB,MAAM;CAC7C,OAAO,IAAI,MACP,aACA,EACI,IAAI,QAAQ,KAAK,UAAU;EACvB,IAAI,QAAQ,QACR,QAAQ,UAAkB,+BAA+B;GACrD,OAAO,OAAO;GACd,OAAO,WAAW;IACd;IACA,YAAY,UAAkB,OAAO,KAAK;GAC9C;GAEA,OAAO;EACX;EAGJ,IAAI,QAAQ,QACR,QAAQ,UAAkB,+BAA+B;GACrD,OAAO,OAAO;GACd,OAAO,WAAW;IACd;IACA,YAAY,UAAkB,OAAO,KAAK;GAC9C;GAEA,OAAO;EACX;EAGJ,IAAI,QAAQ,UACR,QAAQ,UAAe;GACnB,OAAO,YAAY,OAAO,YAAY;GACtC,OAAO;EACX;EAGJ,OAAO,QAAQ,IAAI,QAAQ,KAAK,QAAQ;CAC5C,EACJ,CACJ;AACJ"}
1
+ {"version":3,"file":"string.js","names":[],"sources":["../../src/schema-builders/string.ts"],"sourcesContent":["import {\n isIPv4,\n isIPv6,\n} from 'node:net';\n\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n StringSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n StringSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: StringSchemaDefinition;\n}\n\ninterface IpSchema<T extends string> {\n trim: true;\n validate: { message: T; validator: (value: string) => boolean };\n}\n\nexport interface StringSchemaBuilder<\n Props extends { type: StringSchemaDefinition } = { type: StringSchemaDefinition },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<null | S>>\n | { [path: string]: null | S }\n | { message?: M; values: Readonlyable<Array<null | S>> },\n M extends string,\n S 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 /**\n * Adds IPv4 validation to the string schema.\n * Ensures the string is a valid IPv4 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv4 validation message.\n *\n * @returns A schema builder with IPv4 validation and the `trim` option enabled.\n */\n ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields\n >;\n\n /**\n * Adds IPv6 validation to the string schema.\n * Ensures the string is a valid IPv6 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv6 validation message.\n *\n * @returns A schema builder with IPv6 validation and the `trim` option enabled.\n */\n ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields\n >;\n\n /**\n * Sets both the maximum and minimum length of the string.\n * This method ensures the string length is exactly or within a specified range.\n *\n * @param value - A number representing the exact length or an array specifying [minimum, maximum] length.\n *\n * @returns A schema builder with both `maxlength` and `minlength` options applied.\n */\n length: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendSchemaBuilder<Merge<Props, { lowercase: true }>, ExtraOmitFields>;\n\n /**\n * Adds regular expression validation to the string schema.\n * The validation message can be customized.\n *\n * @param regex - The regular expression that the string must match.\n * @param message - Optional custom validation message.\n *\n * @returns A schema builder with the Mongoose `match` option configured.\n */\n match: <\n T extends RegExp,\n M extends string | undefined = undefined,\n >(regex: T,\n message?: M) => ExtendSchemaBuilder<\n Merge<Props, { match: M extends string ? Readonly<[T, M]> : T }>,\n ExtraOmitFields\n >;\n maxlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { maxlength: T }>,\n ExtraOmitFields\n >;\n\n minlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { minlength: 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 text: ExtendSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendSchemaBuilder<Merge<Props, { uppercase: true }>, ExtraOmitFields>;\n\n /**\n * Adds WHATWG URL validation to the string schema. Credentials and non-HTTP schemes are allowed.\n * The input is parsed only; no DNS lookup or normalization is performed. The validation message can be customized.\n *\n * @param message - Custom validation error message. Defaults to the standard URL validation message.\n *\n * @returns A schema builder with URL validation enabled.\n */\n url: <T extends string = typeof defaultUrlValidateMessage>(message?: T) => ExtendSchemaBuilder<\n Merge<Props, UrlSchema<T>>,\n 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields\n >;\n}\n\ninterface UrlSchema<T extends string> {\n validate: { message: T; validator: (value: string) => boolean };\n}\n\n// Constants/Variables\nconst defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`';\nconst defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`';\nconst defaultUrlValidateMessage = '`{VALUE}` is not a valid URL for path `{PATH}`';\n\n// Functions\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(String);\n\nexport function stringSchemaBuilder() {\n const schema: Record<string, any> = {};\n const baseBuilder = baseBuilderFactory(schema);\n return new Proxy(\n baseBuilder,\n {\n get(target, key, receiver) {\n if (key === 'ipv4') {\n return (message: string = defaultIpv4ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => isIPv4(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'ipv6') {\n return (message: string = defaultIpv6ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => isIPv6(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'length') {\n return (value: any) => {\n schema.maxlength = schema.minlength = value;\n return receiver;\n };\n }\n\n if (key === 'match') {\n return (regex: RegExp, message?: string) => {\n schema.match = message === undefined\n ? regex\n : [\n regex,\n message,\n ];\n\n return receiver;\n };\n }\n\n if (key === 'url') {\n return (message: string = defaultUrlValidateMessage) => {\n schema.validate = {\n message,\n validator: (value: string) => URL.canParse(value),\n };\n\n return receiver;\n };\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as StringSchemaBuilder;\n}\n"],"mappings":";;;AA8KA,MAAM,6BAA6B;AACnC,MAAM,6BAA6B;AACnC,MAAM,4BAA4B;AAGlC,MAAM,qBAAqB,+BAA+B,MAAM;AAEhE,SAAgB,sBAAsB;CAClC,MAAM,SAA8B,CAAC;CACrC,MAAM,cAAc,mBAAmB,MAAM;CAC7C,OAAO,IAAI,MACP,aACA,EACI,IAAI,QAAQ,KAAK,UAAU;EACvB,IAAI,QAAQ,QACR,QAAQ,UAAkB,+BAA+B;GACrD,OAAO,OAAO;GACd,OAAO,WAAW;IACd;IACA,YAAY,UAAkB,OAAO,KAAK;GAC9C;GAEA,OAAO;EACX;EAGJ,IAAI,QAAQ,QACR,QAAQ,UAAkB,+BAA+B;GACrD,OAAO,OAAO;GACd,OAAO,WAAW;IACd;IACA,YAAY,UAAkB,OAAO,KAAK;GAC9C;GAEA,OAAO;EACX;EAGJ,IAAI,QAAQ,UACR,QAAQ,UAAe;GACnB,OAAO,YAAY,OAAO,YAAY;GACtC,OAAO;EACX;EAGJ,IAAI,QAAQ,SACR,QAAQ,OAAe,YAAqB;GACxC,OAAO,QAAQ,YAAY,KAAA,IACrB,QACA,CACE,OACA,OACJ;GAEJ,OAAO;EACX;EAGJ,IAAI,QAAQ,OACR,QAAQ,UAAkB,8BAA8B;GACpD,OAAO,WAAW;IACd;IACA,YAAY,UAAkB,IAAI,SAAS,KAAK;GACpD;GAEA,OAAO;EACX;EAGJ,OAAO,QAAQ,IAAI,QAAQ,KAAK,QAAQ;CAC5C,EACJ,CACJ;AACJ"}
@@ -1,5 +1,4 @@
1
1
  //#region src/types/_internals.d.ts
2
- type Readonlyable<T> = Readonly<T> | T;
2
+ export type Readonlyable<T> = Readonly<T> | T;
3
3
  //#endregion
4
- export { Readonlyable };
5
4
  //# sourceMappingURL=_internals.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_internals.d.ts","names":[],"sources":["../../src/types/_internals.ts"],"mappings":";KAAY,aAAa,KAAK,SAAS,KAAK"}
1
+ {"version":3,"file":"_internals.d.ts","names":[],"sources":["../../src/types/_internals.ts"],"mappings":";YAAY,aAAa,KAAK,SAAS,KAAK"}
@@ -1,7 +1,7 @@
1
1
  import { Aggregate, Model, PipelineStage, Schema } from "mongoose";
2
2
  //#region src/types/aggregate-paginate.d.ts
3
3
  type PrePaginatePipelineStage = '__PREPAGINATE__' | PipelineStage;
4
- interface AggregateCustomLabels<T = boolean | string | undefined> {
4
+ export interface AggregateCustomLabels<T = boolean | string | undefined> {
5
5
  docs?: T;
6
6
  hasNextPage?: T;
7
7
  hasPrevPage?: T;
@@ -14,10 +14,10 @@ interface AggregateCustomLabels<T = boolean | string | undefined> {
14
14
  totalDocs?: T;
15
15
  totalPages?: T;
16
16
  }
17
- interface AggregatePaginateModel<RawDocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
17
+ export interface AggregatePaginateModel<RawDocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
18
18
  aggregatePaginate: <T>(query?: Aggregate<T[]> | PrePaginatePipelineStage[], options?: AggregatePaginateOptions, callback?: (err: any, result: AggregatePaginateResult<T>) => void) => Promise<AggregatePaginateResult<T>>;
19
19
  }
20
- interface AggregatePaginateOptions {
20
+ export interface AggregatePaginateOptions {
21
21
  allowDiskUse?: boolean;
22
22
  countQuery?: object;
23
23
  customLabels?: AggregateCustomLabels;
@@ -33,7 +33,7 @@ interface AggregatePaginateOptions {
33
33
  sort?: object | string;
34
34
  useFacet?: boolean;
35
35
  }
36
- interface AggregatePaginateQueryPopulateOptions {
36
+ export interface AggregatePaginateQueryPopulateOptions {
37
37
  /** optional query conditions to match */
38
38
  match?: any;
39
39
  /** optional model to use for population */
@@ -47,7 +47,7 @@ interface AggregatePaginateQueryPopulateOptions {
47
47
  /** optional fields to select */
48
48
  select?: any;
49
49
  }
50
- interface AggregatePaginateResult<T> {
50
+ export interface AggregatePaginateResult<T> {
51
51
  [customLabel: string]: boolean | null | number | T[] | undefined;
52
52
  docs: T[];
53
53
  hasNextPage: boolean;
@@ -63,5 +63,5 @@ interface AggregatePaginateResult<T> {
63
63
  }
64
64
  declare function _(schema: Schema): void;
65
65
  //#endregion
66
- export { AggregateCustomLabels, AggregatePaginateModel, AggregatePaginateOptions, AggregatePaginateQueryPopulateOptions, AggregatePaginateResult, _ as default };
66
+ export { _ as default };
67
67
  //# sourceMappingURL=aggregate-paginate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"aggregate-paginate.d.ts","names":[],"sources":["../../src/types/aggregate-paginate.ts"],"mappings":";;KAcK,+CAA+C;UAEnC,sBAAsB;EACnC,OAAO;EACP,cAAc;EACd,cAAc;EACd,QAAQ;EACR,OAAO;EACP,WAAW;EACX,OAAO;EACP,gBAAgB;EAChB,WAAW;EACX,YAAY;EACZ,aAAa;;UAGA,uBACb,YACA,uBACA,8CACM,MAAM,YAAY,cAAc;EACtC,oBAAoB,GAChB,QAAQ,UAAU,OAAO,4BACzB,UAAU,0BACV,YAAY,UAAU,QAAQ,wBAAwB,gBACrD,QAAQ,wBAAwB;;UAGxB;EACb;EACA;EACA,eAAe;EACf;EACA;EACA;;;;;;EAOA;EACA;EACA;;UAGa;;EAEb;;EAEA,QAAQ;;EAER;;EAEA;;EAEA,WAAW,wCAAwC;;EAEnD;;UAGa,wBAAwB;GACpC,gDAAgD;EACjD,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGa,EAAE,QAAQ"}
1
+ {"version":3,"file":"aggregate-paginate.d.ts","names":[],"sources":["../../src/types/aggregate-paginate.ts"],"mappings":";;KAcK,+CAA+C;iBAEnC,sBAAsB;EACnC,OAAO;EACP,cAAc;EACd,cAAc;EACd,QAAQ;EACR,OAAO;EACP,WAAW;EACX,OAAO;EACP,gBAAgB;EAChB,WAAW;EACX,YAAY;EACZ,aAAa;;iBAGA,uBACb,YACA,uBACA,8CACM,MAAM,YAAY,cAAc;EACtC,oBAAoB,GAChB,QAAQ,UAAU,OAAO,4BACzB,UAAU,0BACV,YAAY,UAAU,QAAQ,wBAAwB,gBACrD,QAAQ,wBAAwB;;iBAGxB;EACb;EACA;EACA,eAAe;EACf;EACA;EACA;;;;;;EAOA;EACA;EACA;;iBAGa;;EAEb;;EAEA,QAAQ;;EAER;;EAEA;;EAEA,WAAW,wCAAwC;;EAEnD;;iBAGa,wBAAwB;GACpC,gDAAgD;EACjD,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGa,EAAE,QAAQ"}
@@ -1,14 +1,13 @@
1
1
  import { BaseMongooseDocType, SetFieldsToObjectId } from "./index.js";
2
2
  import { SetFieldType } from "type-fest";
3
3
  //#region src/types/data.d.ts
4
- type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = (CreatedAtField extends true ? {
4
+ export type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = (CreatedAtField extends true ? {
5
5
  createdAt: string;
6
6
  } : unknown) & (UpdatedAtField extends true ? {
7
7
  updatedAt: string;
8
8
  } : unknown) & {
9
9
  id: string;
10
10
  };
11
- type DataToBaseMongooseDocType<T, ObjectIdFields extends keyof T = never, DateFields extends Exclude<keyof T, ObjectIdFields> = never, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = BaseMongooseDocType<SetFieldsToObjectId<SetFieldType<T, DateFields, Date>, ObjectIdFields>, CreatedAtField, UpdatedAtField>;
11
+ export type DataToBaseMongooseDocType<T, ObjectIdFields extends keyof T = never, DateFields extends Exclude<keyof T, ObjectIdFields> = never, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = BaseMongooseDocType<SetFieldsToObjectId<SetFieldType<T, DateFields, Date>, ObjectIdFields>, CreatedAtField, UpdatedAtField>;
12
12
  //#endregion
13
- export { BaseMongooseModelData, DataToBaseMongooseDocType };
14
13
  //# sourceMappingURL=data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","names":[],"sources":["../../src/types/data.ts"],"mappings":";;;KAOY,sBAAsB,uCAAuC,0CACpE;EAAgC;gBAChC;EAAgC;;EAC/B;;KAEM,0BACR,GACA,6BAA6B,WAC7B,mBAAmB,cAAc,GAAG,yBACpC,uCACA,yCACA,oBACA,oBAAoB,aAAa,GAAG,YAAY,OAAO,iBACvD,gBACA"}
1
+ {"version":3,"file":"data.d.ts","names":[],"sources":["../../src/types/data.ts"],"mappings":";;;YAOY,sBAAsB,uCAAuC,0CACpE;EAAgC;gBAChC;EAAgC;;EAC/B;;YAEM,0BACR,GACA,6BAA6B,WAC7B,mBAAmB,cAAc,GAAG,yBACpC,uCACA,yCACA,oBACA,oBAAoB,aAAa,GAAG,YAAY,OAAO,iBACvD,gBACA"}
@@ -3,22 +3,21 @@ import { PaginateModel } from "./paginate.js";
3
3
  import { Connection, HydratedDocument, QueryWithHelpers, Types } from "mongoose";
4
4
  import { SetFieldType } from "type-fest";
5
5
  //#region src/types/index.d.ts
6
- type BaseMongooseDocType<T, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = (CreatedAtField extends true ? {
6
+ export type BaseMongooseDocType<T, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = (CreatedAtField extends true ? {
7
7
  createdAt: Date;
8
8
  } : unknown) & Omit<T, 'createdAt' | 'id' | 'updatedAt'> & (UpdatedAtField extends true ? {
9
9
  updatedAt: Date;
10
10
  } : unknown);
11
- type BaseMongoosePaginateModel<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = AggregatePaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> & BaseMongooseModelStatics<RawDocType, InstanceMethodsAndOverrides, QueryHelpers> & PaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides>;
12
- type ExceptMongooseTimestampAndOtherFields<T, K extends keyof T> = Omit<T, 'createdAt' | 'updatedAt' | K>;
13
- type MongooseDocumentOrObjectId<D> = D | string | Types.ObjectId;
14
- type MongooseFindOneReturnType<RawDocType, DocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> = QueryWithHelpers<DocType | null, DocType, QueryHelpers, RawDocType, 'findOne', InstanceMethodsAndOverrides>;
15
- type MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = HydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>;
16
- type OmitMongooseTimestampAndOtherFields<T, K extends number | string | symbol = never> = Omit<T, 'createdAt' | 'updatedAt' | K>;
17
- type SetFieldsToObjectId<T, K extends keyof T> = SetFieldType<T, K, Types.ObjectId>;
18
- interface BaseMongooseModelStatics<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> {}
19
- interface MongooseConnections {
11
+ export type BaseMongoosePaginateModel<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = AggregatePaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> & BaseMongooseModelStatics<RawDocType, InstanceMethodsAndOverrides, QueryHelpers> & PaginateModel<RawDocType, QueryHelpers, InstanceMethodsAndOverrides>;
12
+ export type ExceptMongooseTimestampAndOtherFields<T, K extends keyof T> = Omit<T, 'createdAt' | 'updatedAt' | K>;
13
+ export type MongooseDocumentOrObjectId<D> = D | string | Types.ObjectId;
14
+ export type MongooseFindOneReturnType<RawDocType, DocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> = QueryWithHelpers<DocType | null, DocType, QueryHelpers, RawDocType, 'findOne', InstanceMethodsAndOverrides>;
15
+ export type MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = HydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>;
16
+ export type OmitMongooseTimestampAndOtherFields<T, K extends number | string | symbol = never> = Omit<T, 'createdAt' | 'updatedAt' | K>;
17
+ export type SetFieldsToObjectId<T, K extends keyof T> = SetFieldType<T, K, Types.ObjectId>;
18
+ export interface BaseMongooseModelStatics<RawDocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> {}
19
+ export interface MongooseConnections {
20
20
  default?: Connection;
21
21
  }
22
22
  //#endregion
23
- export { BaseMongooseDocType, BaseMongooseModelStatics, BaseMongoosePaginateModel, ExceptMongooseTimestampAndOtherFields, MongooseConnections, MongooseDocumentOrObjectId, MongooseFindOneReturnType, MongooseHydratedDocument, OmitMongooseTimestampAndOtherFields, SetFieldsToObjectId };
24
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"mappings":";;;;;KAWY,oBAAoB,GAAG,uCAAuC,0CACrE;EAAgC,WAAW;eAC5C,KAAK,wCACJ;EAAgC,WAAW;;KAEpC,0BAA0B,YAAY,sCAAsC,yBACpF,uBAAuB,YAAY,cAAc,+BACjD,yBAAyB,YAAY,6BAA6B,gBAClE,cAAc,YAAY,cAAc;KAEhC,sCAAsC,GAAG,gBAAgB,KAAK,KAAK,+BAA+B;KAClG,2BAA2B,KAAK,aAAa,MAAM;KACnD,0BACR,YACA,SACA,uBACA,wCACA,iBACI,gBACA,SACA,cACA,uBAEA;KAGI,yBACR,SACA,sCACA,yBACA,iBACA,SACA,6BACA;KAGQ,oCAAoC,GAAG,8CAA8C,KAC7F,+BAC4B;KAGpB,oBAAoB,GAAG,gBAAgB,KAAK,aAAa,GAAG,GAAG,MAAM;UAIhE,yBAAyB,YAAY,sCAAsC;UAE3E;EACb,UAAU"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"mappings":";;;;;YAWY,oBAAoB,GAAG,uCAAuC,0CACrE;EAAgC,WAAW;eAC5C,KAAK,wCACJ;EAAgC,WAAW;;YAEpC,0BAA0B,YAAY,sCAAsC,yBACpF,uBAAuB,YAAY,cAAc,+BACjD,yBAAyB,YAAY,6BAA6B,gBAClE,cAAc,YAAY,cAAc;YAEhC,sCAAsC,GAAG,gBAAgB,KAAK,KAAK,+BAA+B;YAClG,2BAA2B,KAAK,aAAa,MAAM;YACnD,0BACR,YACA,SACA,uBACA,wCACA,iBACI,gBACA,SACA,cACA,uBAEA;YAGI,yBACR,SACA,sCACA,yBACA,iBACA,SACA,6BACA;YAGQ,oCAAoC,GAAG,8CAA8C,KAC7F,+BAC4B;YAGpB,oBAAoB,GAAG,gBAAgB,KAAK,aAAa,GAAG,GAAG,MAAM;iBAIhE,yBAAyB,YAAY,sCAAsC;iBAE3E;EACb,UAAU"}
@@ -2,16 +2,15 @@ import { MongooseNormalizePluginOptions } from "../plugins/normalize.js";
2
2
  import { BaseMongoosePaginateModel } from "./index.js";
3
3
  import { Connection, Schema, SchemaTimestampsConfig } from "mongoose";
4
4
  //#region src/types/options.d.ts
5
- interface BuildMongooseModelOptions {
5
+ export interface BuildMongooseModelOptions {
6
6
  connection?: Connection;
7
7
  enableNormalizePlugin?: boolean;
8
8
  normalizePluginOptions?: MongooseNormalizePluginOptions;
9
9
  normalizePluginRecursive?: boolean;
10
10
  timestamps?: boolean | SchemaTimestampsConfig;
11
11
  }
12
- interface CustomMongooseOptions {
12
+ export interface CustomMongooseOptions {
13
13
  beforeModelBuild?: <DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>) => void;
14
14
  }
15
15
  //#endregion
16
- export { BuildMongooseModelOptions, CustomMongooseOptions };
17
16
  //# sourceMappingURL=options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","names":[],"sources":["../../src/types/options.ts"],"mappings":";;;;UAUiB;EACb,aAAa;EACb;EACA,yBAAyB;EACzB;EACA,uBAAuB;;UAGV;EACb,oBACI,SACA,cAAc,0BAA0B,SAAS,6BAA6B,eAC9E,sCACA,uBAEA,QAAQ,OACJ,SACA,OACA,6BACA"}
1
+ {"version":3,"file":"options.d.ts","names":[],"sources":["../../src/types/options.ts"],"mappings":";;;;iBAUiB;EACb,aAAa;EACb;EACA,yBAAyB;EACzB;EACA,uBAAuB;;iBAGV;EACb,oBACI,SACA,cAAc,0BAA0B,SAAS,6BAA6B,eAC9E,sCACA,uBAEA,QAAQ,OACJ,SACA,OACA,6BACA"}
@@ -1,12 +1,12 @@
1
1
  import { HydratedDocument, Model, PopulateOptions, QueryFilter, QueryOptions, Schema, mongo } from "mongoose";
2
2
  //#region src/types/paginate.d.ts
3
- type PaginateDocument<T, TMethods, TQueryHelpers, O extends PaginateOptions = object> = O['lean'] extends true ? PaginateDocumentLeanResult<T, O> : HydratedDocument<T, TMethods, TQueryHelpers>;
3
+ export type PaginateDocument<T, TMethods, TQueryHelpers, O extends PaginateOptions = object> = O['lean'] extends true ? PaginateDocumentLeanResult<T, O> : HydratedDocument<T, TMethods, TQueryHelpers>;
4
4
  type PaginateDocumentLeanResult<T, O extends PaginateOptions> = O['leanWithId'] extends true ? T & {
5
5
  id: string;
6
6
  } : O['leanWithVirtuals'] extends true ? T & {
7
7
  [key: string]: any;
8
8
  } : T;
9
- interface PaginateCustomLabels<T = boolean | string | undefined> {
9
+ export interface PaginateCustomLabels<T = boolean | string | undefined> {
10
10
  docs?: T;
11
11
  hasNextPage?: T;
12
12
  hasPrevPage?: T;
@@ -19,14 +19,14 @@ interface PaginateCustomLabels<T = boolean | string | undefined> {
19
19
  totalDocs?: T;
20
20
  totalPages?: T;
21
21
  }
22
- interface PaginateModel<RawDocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
22
+ export interface PaginateModel<RawDocType, QueryHelpers = object, InstanceMethodsAndOverrides = object> extends Model<RawDocType, QueryHelpers, InstanceMethodsAndOverrides> {
23
23
  paginate: {
24
24
  <O extends PaginateOptions>(query?: QueryFilter<RawDocType>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<RawDocType, InstanceMethodsAndOverrides, QueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<RawDocType, InstanceMethodsAndOverrides, QueryHelpers, O>>>;
25
25
  <UserType = RawDocType, O extends PaginateOptions = PaginateOptions>(query?: QueryFilter<RawDocType>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, InstanceMethodsAndOverrides, QueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<UserType, InstanceMethodsAndOverrides, QueryHelpers, O>>>;
26
26
  <UserType = RawDocType>(query?: QueryFilter<RawDocType>, options?: PaginateOptions, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, InstanceMethodsAndOverrides, QueryHelpers, PaginateOptions>>) => void): Promise<PaginateResult<PaginateDocument<UserType, InstanceMethodsAndOverrides, QueryHelpers, PaginateOptions>>>;
27
27
  };
28
28
  }
29
- interface PaginateOptions {
29
+ export interface PaginateOptions {
30
30
  allowDiskUse?: boolean;
31
31
  collation?: mongo.CollationOptions;
32
32
  customLabels?: PaginateCustomLabels;
@@ -52,11 +52,11 @@ interface PaginateOptions {
52
52
  useCustomCountFn?: () => Promise<number>;
53
53
  useEstimatedCount?: boolean;
54
54
  }
55
- interface PaginateReadOptions {
55
+ export interface PaginateReadOptions {
56
56
  pref: string;
57
57
  tags?: any[];
58
58
  }
59
- interface PaginateResult<T> {
59
+ export interface PaginateResult<T> {
60
60
  [customLabel: string]: boolean | null | number | T[] | undefined;
61
61
  docs: T[];
62
62
  hasNextPage: boolean;
@@ -71,12 +71,12 @@ interface PaginateResult<T> {
71
71
  totalDocs: number;
72
72
  totalPages: number;
73
73
  }
74
- interface SubDocumentPagingOptions {
74
+ export interface SubDocumentPagingOptions {
75
75
  limit?: number;
76
76
  page?: number;
77
77
  populate?: PopulateOptions | PopulateOptions[] | string | string[];
78
78
  }
79
- interface SubPaginateOptions {
79
+ export interface SubPaginateOptions {
80
80
  pagination?: boolean;
81
81
  pagingOptions?: SubDocumentPagingOptions;
82
82
  populate?: PopulateOptions | PopulateOptions[] | string | string[];
@@ -94,5 +94,5 @@ declare module 'mongoose' {
94
94
  }
95
95
  declare function _(schema: Schema): void;
96
96
  //#endregion
97
- export { PaginateCustomLabels, PaginateDocument, PaginateModel, PaginateOptions, PaginateReadOptions, PaginateResult, SubDocumentPagingOptions, SubPaginateOptions, _ as default };
97
+ export { _ as default };
98
98
  //# sourceMappingURL=paginate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"paginate.d.ts","names":[],"sources":["../../src/types/paginate.ts"],"mappings":";;KAUY,iBACR,GACA,UACA,eACA,UAAU,4BACV,yBACE,2BAA2B,GAAG,KAC9B,iBAAiB,GAAG,UAAU;KAE/B,2BAA2B,GAAG,UAAU,mBACzC,+BACM;EAAM;IACN,qCACI;GAAO;IACP;UAEG,qBAAqB;EAClC,OAAO;EACP,cAAc;EACd,cAAc;EACd,QAAQ;EACR,OAAO;EACP,WAAW;EACX,OAAO;EACP,gBAAgB;EAChB,WAAW;EACX,YAAY;EACZ,aAAa;;UAGA,cAAc,YAAY,uBAAuB,8CAA8C,MAC5G,YACA,cACA;EAEA;KACK,UAAU,iBACP,QAAQ,YAAY,aACpB,UAAU,GACV,YACI,UACA,QAAQ,eAAe,iBAAiB,YAAY,6BAA6B,cAAc,eAEpG,QAAQ,eAAe,iBAAiB,YAAY,6BAA6B,cAAc;KAEjG,WAAW,YAAY,UAAU,kBAAkB,iBAChD,QAAQ,YAAY,aACpB,UAAU,GACV,YACI,UACA,QAAQ,eAAe,iBAAiB,UAAU,6BAA6B,cAAc,eAElG,QAAQ,eAAe,iBAAiB,UAAU,6BAA6B,cAAc;KAE/F,WAAW,YACR,QAAQ,YAAY,aACpB,UAAU,iBACV,YACI,UACA,QAAQ,eACJ,iBAAiB,UAAU,6BAA6B,cAAc,6BAG/E,QACC,eAAe,iBAAiB,UAAU,6BAA6B,cAAc;;;UAKhF;EACb;EACA,YAAY,MAAM;EAClB,eAAe;EACf;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV;;;;;;EAOA;EACA,WAAW,kBAAkB;EAC7B;EACA,OAAO;EACP;EACA;EACA,yBAAyB;EACzB;;UAGa;EACb;EACA;;UAGa,eAAe;GAC3B,gDAAgD;EACjD,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGa;EACb;EACA;EACA,WAAW,kBAAkB;;UAGhB;EACb;EACA,gBAAgB;EAChB,WAAW,kBAAkB;EAC7B,OAAO;EACP;;;YAKU,MACN,YACA,SACA,WAAW,sBACX,aAAa,SACb,mBACA,mBAAmB;IAEnB;OACK,UAAU,iBAAiB,UAAU,IAAI,QACtC,eAAe,iBAAiB,YAAY,kBAAkB,UAAU;OAG3E,WAAW,YAAY,UAAU,kBAAkB,iBAAiB,UAAU,IAAI,QAC/E,eAAe,iBAAiB,UAAU,kBAAkB,UAAU;OAGzE,WAAW,YAAY,UAAU,kBAAkB,QAChD,eAAe,iBAAiB,UAAU,kBAAkB,UAAU;;;;iBAMrE,EAAE,QAAQ"}
1
+ {"version":3,"file":"paginate.d.ts","names":[],"sources":["../../src/types/paginate.ts"],"mappings":";;YAUY,iBACR,GACA,UACA,eACA,UAAU,4BACV,yBACE,2BAA2B,GAAG,KAC9B,iBAAiB,GAAG,UAAU;KAE/B,2BAA2B,GAAG,UAAU,mBACzC,+BACM;EAAM;IACN,qCACI;GAAO;IACP;iBAEG,qBAAqB;EAClC,OAAO;EACP,cAAc;EACd,cAAc;EACd,QAAQ;EACR,OAAO;EACP,WAAW;EACX,OAAO;EACP,gBAAgB;EAChB,WAAW;EACX,YAAY;EACZ,aAAa;;iBAGA,cAAc,YAAY,uBAAuB,8CAA8C,MAC5G,YACA,cACA;EAEA;KACK,UAAU,iBACP,QAAQ,YAAY,aACpB,UAAU,GACV,YACI,UACA,QAAQ,eAAe,iBAAiB,YAAY,6BAA6B,cAAc,eAEpG,QAAQ,eAAe,iBAAiB,YAAY,6BAA6B,cAAc;KAEjG,WAAW,YAAY,UAAU,kBAAkB,iBAChD,QAAQ,YAAY,aACpB,UAAU,GACV,YACI,UACA,QAAQ,eAAe,iBAAiB,UAAU,6BAA6B,cAAc,eAElG,QAAQ,eAAe,iBAAiB,UAAU,6BAA6B,cAAc;KAE/F,WAAW,YACR,QAAQ,YAAY,aACpB,UAAU,iBACV,YACI,UACA,QAAQ,eACJ,iBAAiB,UAAU,6BAA6B,cAAc,6BAG/E,QACC,eAAe,iBAAiB,UAAU,6BAA6B,cAAc;;;iBAKhF;EACb;EACA,YAAY,MAAM;EAClB,eAAe;EACf;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV;;;;;;EAOA;EACA,WAAW,kBAAkB;EAC7B;EACA,OAAO;EACP;EACA;EACA,yBAAyB;EACzB;;iBAGa;EACb;EACA;;iBAGa,eAAe;GAC3B,gDAAgD;EACjD,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGa;EACb;EACA;EACA,WAAW,kBAAkB;;iBAGhB;EACb;EACA,gBAAgB;EAChB,WAAW,kBAAkB;EAC7B,OAAO;EACP;;;YAKU,MACN,YACA,SACA,WAAW,sBACX,aAAa,SACb,mBACA,mBAAmB;IAEnB;OACK,UAAU,iBAAiB,UAAU,IAAI,QACtC,eAAe,iBAAiB,YAAY,kBAAkB,UAAU;OAG3E,WAAW,YAAY,UAAU,kBAAkB,iBAAiB,UAAU,IAAI,QAC/E,eAAe,iBAAiB,UAAU,kBAAkB,UAAU;OAGzE,WAAW,YAAY,UAAU,kBAAkB,QAChD,eAAe,iBAAiB,UAAU,kBAAkB,UAAU;;;;iBAMrE,EAAE,QAAQ"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
3
  "type": "module",
4
- "version": "7.0.3",
4
+ "version": "7.1.0",
5
5
  "description": "A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.",
6
6
  "author": "kiki-kanri",
7
7
  "license": "MIT",
@@ -74,27 +74,28 @@
74
74
  "test:watch": "vitest watch --coverage",
75
75
  "typecheck": "tsc -b --noEmit"
76
76
  },
77
+ "peerDependenciesMeta": {},
77
78
  "dependencies": {
78
79
  "decimal.js": "^10.6.0",
79
- "es-toolkit": "^1.50.0",
80
- "mongoose": "^9.9.0",
81
- "mongoose-aggregate-paginate-v2": "^1.1.4",
80
+ "es-toolkit": "^1.52.0",
81
+ "mongoose": "^9.10.2",
82
+ "mongoose-aggregate-paginate-v2": "^1.1.5",
82
83
  "mongoose-paginate-v2": "^1.9.5",
83
- "type-fest": "^5.8.0"
84
+ "type-fest": "^5.10.0"
84
85
  },
85
86
  "devDependencies": {
86
- "@antfu/eslint-config": "^9.2.0",
87
- "@kikiutils/eslint-config": "^9.2.0",
87
+ "@antfu/eslint-config": "^9.5.1",
88
+ "@kikiutils/eslint-config": "^9.2.1",
88
89
  "@kikiutils/tsconfigs": "^7.0.0",
89
- "@types/node": "^26.1.2",
90
- "@vitest/coverage-v8": "^4.1.10",
90
+ "@types/node": "^26.6.3",
91
+ "@vitest/coverage-v8": "^5.0.2",
91
92
  "changelogen": "^0.6.2",
92
- "eslint": "^10.8.0",
93
- "knip": "^6.30.0",
94
- "publint": "^0.3.22",
95
- "tsdown": "^0.22.14",
93
+ "eslint": "^10.11.0",
94
+ "knip": "^6.38.0",
95
+ "publint": "^0.3.24",
96
+ "tsdown": "^0.23.0",
96
97
  "typescript": "^6.0.3",
97
98
  "unplugin-unused": "^0.6.0",
98
- "vitest": "^4.1.10"
99
+ "vitest": "^5.0.2"
99
100
  }
100
101
  }
@@ -7,6 +7,7 @@ type BaseSchemaType =
7
7
  | Schema.Types.ObjectId['constructor']
8
8
  | StringConstructor;
9
9
 
10
+ // Constants/Variables
10
11
  const isFunctionKeys = new Set([
11
12
  'default',
12
13
  'enum',
@@ -17,6 +18,7 @@ const isFunctionKeys = new Set([
17
18
  'minlength',
18
19
  ]);
19
20
 
21
+ // Functions
20
22
  export function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType) {
21
23
  return (schema: Record<string, any> = {}) => {
22
24
  schema.type = type;
@@ -12,6 +12,7 @@ import type { Readonlyable } from '../types/_internals';
12
12
 
13
13
  import { createBaseSchemaBuilderFactory } from './base';
14
14
 
15
+ type Decimal128Limit = Decimal.Value | Types.Decimal128 | { toString: () => string };
15
16
  type ExtendSchemaBuilder<
16
17
  Props extends BaseProps,
17
18
  ExtraOmitFields extends string,
@@ -24,6 +25,14 @@ interface BaseProps {
24
25
  type: typeof Schema.Types.Decimal128;
25
26
  }
26
27
 
28
+ interface Decimal128LimitValidator {
29
+ max?: string;
30
+ message: string;
31
+ min?: string;
32
+ type: 'max' | 'min';
33
+ validator: (value: null | Types.Decimal128 | undefined) => boolean;
34
+ }
35
+
27
36
  export interface Decimal128SchemaBuilder<
28
37
  Props extends { type: typeof Schema.Types.Decimal128 } = { type: typeof Schema.Types.Decimal128 },
29
38
  ExtraOmitFields extends string = never,
@@ -54,6 +63,24 @@ export interface Decimal128SchemaBuilder<
54
63
  ExtraOmitFields
55
64
  >;
56
65
 
66
+ max: <
67
+ T extends D | Readonlyable<[D, S]>,
68
+ D extends Decimal128Limit,
69
+ S extends string,
70
+ >(value: T) => ExtendSchemaBuilder<
71
+ Merge<Props, Decimal128ValidationSchema>,
72
+ 'max' | ExtraOmitFields
73
+ >;
74
+
75
+ min: <
76
+ T extends D | Readonlyable<[D, S]>,
77
+ D extends Decimal128Limit,
78
+ S extends string,
79
+ >(value: T) => ExtendSchemaBuilder<
80
+ Merge<Props, Decimal128ValidationSchema>,
81
+ 'min' | ExtraOmitFields
82
+ >;
83
+
57
84
  nonRequired: Props;
58
85
  private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;
59
86
  required: Merge<Props, { required: true }>;
@@ -87,6 +114,10 @@ export interface Decimal128SchemaBuilder<
87
114
  unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
88
115
  }
89
116
 
117
+ interface Decimal128ValidationSchema {
118
+ validate: Decimal128LimitValidator[];
119
+ }
120
+
90
121
  interface ToStringGetterSchema {
91
122
  get: (value?: Types.Decimal128) => string | undefined;
92
123
  }
@@ -95,8 +126,40 @@ interface ToStringSetterSchema {
95
126
  set: (value?: { toString: () => string }) => string | undefined;
96
127
  }
97
128
 
129
+ // Constants/Variables
130
+ const defaultMinValidateMessage = 'Path `{PATH}` ({VALUE}) is less than minimum allowed value ({MIN}).';
131
+ const defaultMaxValidateMessage = 'Path `{PATH}` ({VALUE}) is more than maximum allowed value ({MAX}).';
132
+
133
+ // Functions
98
134
  const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);
99
135
 
136
+ function createLimitValidator(
137
+ type: 'max' | 'min',
138
+ value: Decimal128Limit | Readonlyable<[Decimal128Limit, string]>,
139
+ ): Decimal128LimitValidator {
140
+ const [limit, message] = Array.isArray(value)
141
+ ? value as Readonly<[Decimal128Limit, string]>
142
+ : [
143
+ value,
144
+ undefined,
145
+ ];
146
+
147
+ const decimalLimit = new Decimal(limit.toString());
148
+ if (!decimalLimit.isFinite()) throw new RangeError(`Decimal128 ${type} limit must be finite`);
149
+
150
+ return {
151
+ message: message ?? (type === 'min' ? defaultMinValidateMessage : defaultMaxValidateMessage),
152
+ [type]: decimalLimit.toString(),
153
+ type,
154
+ validator: (value) => {
155
+ if (value === null || value === undefined) return true;
156
+
157
+ const decimalValue = new Decimal(value.toString());
158
+ return type === 'min' ? decimalValue.gte(decimalLimit) : decimalValue.lte(decimalLimit);
159
+ },
160
+ };
161
+ }
162
+
100
163
  export function decimal128SchemaBuilder() {
101
164
  const schema: Record<string, any> = {};
102
165
  const baseBuilder = baseBuilderFactory(schema);
@@ -104,6 +167,19 @@ export function decimal128SchemaBuilder() {
104
167
  baseBuilder,
105
168
  {
106
169
  get(target, key, receiver) {
170
+ if (key === 'max' || key === 'min') {
171
+ return (value: Decimal128Limit | Readonlyable<[Decimal128Limit, string]>) => {
172
+ const validator = createLimitValidator(key, value);
173
+ const validators = Array.isArray(schema.validate) ? schema.validate : [];
174
+ schema.validate = [
175
+ ...validators.filter(({ type }) => type !== key),
176
+ validator,
177
+ ];
178
+
179
+ return receiver;
180
+ };
181
+ }
182
+
107
183
  if (key === 'setRoundAndToFixedSetter') {
108
184
  return (places: number = 2, rounding: Decimal.Rounding = Decimal.ROUND_DOWN) => {
109
185
  schema.set = (value?: { toString: () => string }) => {
@@ -73,7 +73,7 @@ export interface StringSchemaBuilder<
73
73
  */
74
74
  ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendSchemaBuilder<
75
75
  Merge<Props, IpSchema<T>>,
76
- 'ipv4' | 'ipv6' | ExtraOmitFields
76
+ 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields
77
77
  >;
78
78
 
79
79
  /**
@@ -87,7 +87,7 @@ export interface StringSchemaBuilder<
87
87
  */
88
88
  ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendSchemaBuilder<
89
89
  Merge<Props, IpSchema<T>>,
90
- 'ipv4' | 'ipv6' | ExtraOmitFields
90
+ 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields
91
91
  >;
92
92
 
93
93
  /**
@@ -108,6 +108,24 @@ export interface StringSchemaBuilder<
108
108
  >;
109
109
 
110
110
  lowercase: ExtendSchemaBuilder<Merge<Props, { lowercase: true }>, ExtraOmitFields>;
111
+
112
+ /**
113
+ * Adds regular expression validation to the string schema.
114
+ * The validation message can be customized.
115
+ *
116
+ * @param regex - The regular expression that the string must match.
117
+ * @param message - Optional custom validation message.
118
+ *
119
+ * @returns A schema builder with the Mongoose `match` option configured.
120
+ */
121
+ match: <
122
+ T extends RegExp,
123
+ M extends string | undefined = undefined,
124
+ >(regex: T,
125
+ message?: M) => ExtendSchemaBuilder<
126
+ Merge<Props, { match: M extends string ? Readonly<[T, M]> : T }>,
127
+ ExtraOmitFields
128
+ >;
111
129
  maxlength: <
112
130
  T extends L | Readonlyable<[L, S]>,
113
131
  L extends number,
@@ -134,11 +152,32 @@ export interface StringSchemaBuilder<
134
152
  trim: ExtendSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;
135
153
  unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
136
154
  uppercase: ExtendSchemaBuilder<Merge<Props, { uppercase: true }>, ExtraOmitFields>;
155
+
156
+ /**
157
+ * Adds WHATWG URL validation to the string schema. Credentials and non-HTTP schemes are allowed.
158
+ * The input is parsed only; no DNS lookup or normalization is performed. The validation message can be customized.
159
+ *
160
+ * @param message - Custom validation error message. Defaults to the standard URL validation message.
161
+ *
162
+ * @returns A schema builder with URL validation enabled.
163
+ */
164
+ url: <T extends string = typeof defaultUrlValidateMessage>(message?: T) => ExtendSchemaBuilder<
165
+ Merge<Props, UrlSchema<T>>,
166
+ 'ipv4' | 'ipv6' | 'url' | ExtraOmitFields
167
+ >;
137
168
  }
138
169
 
139
- const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
170
+ interface UrlSchema<T extends string> {
171
+ validate: { message: T; validator: (value: string) => boolean };
172
+ }
173
+
174
+ // Constants/Variables
140
175
  const defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`';
141
176
  const defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`';
177
+ const defaultUrlValidateMessage = '`{VALUE}` is not a valid URL for path `{PATH}`';
178
+
179
+ // Functions
180
+ const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
142
181
 
143
182
  export function stringSchemaBuilder() {
144
183
  const schema: Record<string, any> = {};
@@ -178,6 +217,30 @@ export function stringSchemaBuilder() {
178
217
  };
179
218
  }
180
219
 
220
+ if (key === 'match') {
221
+ return (regex: RegExp, message?: string) => {
222
+ schema.match = message === undefined
223
+ ? regex
224
+ : [
225
+ regex,
226
+ message,
227
+ ];
228
+
229
+ return receiver;
230
+ };
231
+ }
232
+
233
+ if (key === 'url') {
234
+ return (message: string = defaultUrlValidateMessage) => {
235
+ schema.validate = {
236
+ message,
237
+ validator: (value: string) => URL.canParse(value),
238
+ };
239
+
240
+ return receiver;
241
+ };
242
+ }
243
+
181
244
  return Reflect.get(target, key, receiver);
182
245
  },
183
246
  },