@kikiutils/mongoose 3.0.0 → 3.0.2

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.
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const lodashGet = require('lodash/get');
4
- const lodashSet = require('lodash/set');
5
- const lodashUnset = require('lodash/unset');
3
+ const lodashGet = require('lodash/get.js');
4
+ const lodashSet = require('lodash/set.js');
5
+ const lodashUnset = require('lodash/unset.js');
6
6
 
7
7
  const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
8
8
 
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.cjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["import lodashGet from 'lodash/get';\nimport lodashSet from 'lodash/set';\nimport lodashUnset from 'lodash/unset';\nimport type {\n Schema,\n Types,\n} from 'mongoose';\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>(schema: S) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc: any, ret: any, options: any) {\n const copiedRet = { ...ret };\n copiedRet.id = copiedRet._id?.toHexString();\n delete copiedRet._id;\n for (const path in schema.paths) {\n if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);\n if (schema.paths[path]?.instance === 'Decimal128') {\n const value: Types.Decimal128 | undefined = lodashGet(copiedRet, path);\n if (value) lodashSet(copiedRet, path, value.toString());\n }\n }\n\n delete copiedRet.__v;\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc, copied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ources":["../../src/plugins/normalize.ts"],"sourcesContent":["import lodashGet from 'lodash/get.js';\nimport lodashSet from 'lodash/set.js';\nimport lodashUnset from 'lodash/unset.js';\nimport type {\n Schema,\n Types,\n} from 'mongoose';\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>(schema: S) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc: any, ret: any, options: any) {\n const copiedRet = { ...ret };\n copiedRet.id = copiedRet._id?.toHexString();\n delete copiedRet._id;\n for (const path in schema.paths) {\n if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);\n if (schema.paths[path]?.instance === 'Decimal128') {\n const value: Types.Decimal128 | undefined = lodashGet(copiedRet, path);\n if (value) lodashSet(copiedRet, path, value.toString());\n }\n }\n\n delete copiedRet.__v;\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc, copiedRet, options);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":["lodashUnset","lodashGet","lodashSet"],"mappings":";;;;;;;;;;;;AAQA;;;;;;;;;;;;;AAaG;AACG,SAAU,uBAAuB,CAAmB,MAAS,EAAA;IAC/D,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;AACnC,IAAA,MAAM,eAAe,GAAG,MAAM,EAAE,SAAS;AACzC,IAAA,MAAM,CAAC,GAAG,CACN,QAAQ,EACR;AACI,QAAA,GAAG,MAAM;AACT,QAAA,SAAS,CAAC,GAAQ,EAAE,GAAQ,EAAE,OAAY,EAAA;AACtC,YAAA,MAAM,SAAS,GAAG,EAAE,GAAG,GAAG,EAAE;YAC5B,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE;YAC3C,OAAO,SAAS,CAAC,GAAG;AACpB,YAAA,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;gBAC7B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO;AAAE,oBAAAA,oBAAW,CAAC,SAAS,EAAE,IAAI,CAAC;gBACtE,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,KAAK,YAAY,EAAE;oBAC/C,MAAM,KAAK,GAAiCC,kBAAS,CAAC,SAAS,EAAE,IAAI,CAAC;AACtE,oBAAA,IAAI,KAAK;wBAAEC,kBAAS,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;;;YAI/D,OAAO,SAAS,CAAC,GAAG;AACpB,YAAA,IAAI,eAAe,IAAI,OAAO,eAAe,KAAK,SAAS,EAAE;gBACzD,OAAO,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC;;AAGnD,YAAA,OAAO,SAAS;SACnB;AACJ,KAAA,CACJ;AACL;;;;"}
@@ -1,6 +1,6 @@
1
- import lodashGet from 'lodash/get';
2
- import lodashSet from 'lodash/set';
3
- import lodashUnset from 'lodash/unset';
1
+ import lodashGet from 'lodash/get.js';
2
+ import lodashSet from 'lodash/set.js';
3
+ import lodashUnset from 'lodash/unset.js';
4
4
 
5
5
  /**
6
6
  * Mongoose plugin to normalize the JSON output of documents.
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.mjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["import lodashGet from 'lodash/get';\nimport lodashSet from 'lodash/set';\nimport lodashUnset from 'lodash/unset';\nimport type {\n Schema,\n Types,\n} from 'mongoose';\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>(schema: S) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc: any, ret: any, options: any) {\n const copiedRet = { ...ret };\n copiedRet.id = copiedRet._id?.toHexString();\n delete copiedRet._id;\n for (const path in schema.paths) {\n if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);\n if (schema.paths[path]?.instance === 'Decimal128') {\n const value: Types.Decimal128 | undefined = lodashGet(copiedRet, path);\n if (value) lodashSet(copiedRet, path, value.toString());\n }\n }\n\n delete copiedRet.__v;\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc, copiedRet, options);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":[],"mappings":";;;;AAQA;;;;;;;;;;;;;AAaG;AACG,SAAU,uBAAuB,CAAmB,MAAS,EAAA;IAC/D,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;AACnC,IAAA,MAAM,eAAe,GAAG,MAAM,EAAE,SAAS;AACzC,IAAA,MAAM,CAAC,GAAG,CACN,QAAQ,EACR;AACI,QAAA,GAAG,MAAM;AACT,QAAA,SAAS,CAAC,GAAQ,EAAE,GAAQ,EAAE,OAAY,EAAA;AACtC,YAAA,MAAM,SAAS,GAAG,EAAE,GAAG,GAAG,EAAE;YAC5B,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE;YAC3C,OAAO,SAAS,CAAC,GAAG;AACpB,YAAA,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;gBAC7B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO;AAAE,oBAAA,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC;gBACtE,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,KAAK,YAAY,EAAE;oBAC/C,MAAM,KAAK,GAAiC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC;AACtE,oBAAA,IAAI,KAAK;wBAAE,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;;;YAI/D,OAAO,SAAS,CAAC,GAAG;AACpB,YAAA,IAAI,eAAe,IAAI,OAAO,eAAe,KAAK,SAAS,EAAE;gBACzD,OAAO,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC;;AAGnD,YAAA,OAAO,SAAS;SACnB;AACJ,KAAA,CACJ;AACL;;;;"}
1
+ {"version":3,"file":"normalize.mjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["import lodashGet from 'lodash/get.js';\nimport lodashSet from 'lodash/set.js';\nimport lodashUnset from 'lodash/unset.js';\nimport type {\n Schema,\n Types,\n} from 'mongoose';\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>(schema: S) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc: any, ret: any, options: any) {\n const copiedRet = { ...ret };\n copiedRet.id = copiedRet._id?.toHexString();\n delete copiedRet._id;\n for (const path in schema.paths) {\n if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);\n if (schema.paths[path]?.instance === 'Decimal128') {\n const value: Types.Decimal128 | undefined = lodashGet(copiedRet, path);\n if (value) lodashSet(copiedRet, path, value.toString());\n }\n }\n\n delete copiedRet.__v;\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc, copiedRet, options);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":[],"mappings":";;;;AAQA;;;;;;;;;;;;;AAaG;AACG,SAAU,uBAAuB,CAAmB,MAAS,EAAA;IAC/D,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;AACnC,IAAA,MAAM,eAAe,GAAG,MAAM,EAAE,SAAS;AACzC,IAAA,MAAM,CAAC,GAAG,CACN,QAAQ,EACR;AACI,QAAA,GAAG,MAAM;AACT,QAAA,SAAS,CAAC,GAAQ,EAAE,GAAQ,EAAE,OAAY,EAAA;AACtC,YAAA,MAAM,SAAS,GAAG,EAAE,GAAG,GAAG,EAAE;YAC5B,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE;YAC3C,OAAO,SAAS,CAAC,GAAG;AACpB,YAAA,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;gBAC7B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO;AAAE,oBAAA,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC;gBACtE,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,KAAK,YAAY,EAAE;oBAC/C,MAAM,KAAK,GAAiC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC;AACtE,oBAAA,IAAI,KAAK;wBAAE,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;;;YAI/D,OAAO,SAAS,CAAC,GAAG;AACpB,YAAA,IAAI,eAAe,IAAI,OAAO,eAAe,KAAK,SAAS,EAAE;gBACzD,OAAO,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC;;AAGnD,YAAA,OAAO,SAAS;SACnB;AACJ,KAAA,CACJ;AACL;;;;"}
@@ -1,13 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const Decimal = require('decimal.js');
3
+ const decimal_js = require('decimal.js');
4
4
  const mongoose = require('mongoose');
5
5
  const base = require('./base.cjs');
6
6
 
7
- const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
8
-
9
- const Decimal__default = /*#__PURE__*/_interopDefaultCompat(Decimal);
10
-
11
7
  const baseBuilderFactory = base.createBaseSchemaBuilderFactory(mongoose.Schema.Types.Decimal128);
12
8
  function decimal128SchemaBuilder() {
13
9
  const schema = {};
@@ -15,10 +11,10 @@ function decimal128SchemaBuilder() {
15
11
  return new Proxy(baseBuilder, {
16
12
  get(target, key, receiver) {
17
13
  if (key === 'setRoundAndToFixedSetter') {
18
- return (places = 2, rounding = Decimal__default.ROUND_DOWN) => {
14
+ return (places = 2, rounding = decimal_js.Decimal.ROUND_DOWN) => {
19
15
  schema.set = (value) => {
20
16
  if (value)
21
- return new Decimal__default(value.toString()).toFixed(places, rounding);
17
+ return new decimal_js.Decimal(value.toString()).toFixed(places, rounding);
22
18
  };
23
19
  return receiver;
24
20
  };
@@ -1 +1 @@
1
- {"version":3,"file":"decimal128.cjs","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/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendDecimal128SchemaBuilder<\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 ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string;\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) => ExtendDecimal128SchemaBuilder<\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) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendDecimal128SchemaBuilder<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) => ExtendDecimal128SchemaBuilder<\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: ExtendDecimal128SchemaBuilder<\n Merge<Props, ToStringGetterSchema>,\n 'setToStringGetter' | ExtraOmitFields\n >;\n\n sparse: ExtendDecimal128SchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendDecimal128SchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\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) return new Decimal(value.toString()).toFixed(places, rounding);\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"],"names":["createBaseSchemaBuilderFactory","Schema","Decimal"],"mappings":";;;;;;;;;;AAoGA,MAAM,kBAAkB,GAAGA,mCAA8B,CAACC,eAAM,CAAC,KAAK,CAAC,UAAU,CAAC;SAElE,uBAAuB,GAAA;IACnC,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,OAAO,IAAI,KAAK,CACZ,WAAW,EACX;AACI,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACrB,YAAA,IAAI,GAAG,KAAK,0BAA0B,EAAE;gBACpC,OAAO,CAAC,SAAiB,CAAC,EAAE,WAA6BC,gBAAO,CAAC,UAAU,KAAI;AAC3E,oBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAkC,KAAI;AAChD,wBAAA,IAAI,KAAK;AAAE,4BAAA,OAAO,IAAIA,gBAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;AAC7E,qBAAC;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,mBAAmB,EAAE;AAC7B,gBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAwB,KAAK,KAAK,EAAE,QAAQ,EAAE;AAC5D,gBAAA,OAAO,QAAQ;;YAGnB,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC5C;AACJ,KAAA,CACuB;AAChC;;;;"}
1
+ {"version":3,"file":"decimal128.cjs","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/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendDecimal128SchemaBuilder<\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 ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string;\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) => ExtendDecimal128SchemaBuilder<\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) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendDecimal128SchemaBuilder<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) => ExtendDecimal128SchemaBuilder<\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: ExtendDecimal128SchemaBuilder<\n Merge<Props, ToStringGetterSchema>,\n 'setToStringGetter' | ExtraOmitFields\n >;\n\n sparse: ExtendDecimal128SchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendDecimal128SchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\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) return new Decimal(value.toString()).toFixed(places, rounding);\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"],"names":["createBaseSchemaBuilderFactory","Schema","Decimal"],"mappings":";;;;;;AAoGA,MAAM,kBAAkB,GAAGA,mCAA8B,CAACC,eAAM,CAAC,KAAK,CAAC,UAAU,CAAC;SAElE,uBAAuB,GAAA;IACnC,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,OAAO,IAAI,KAAK,CACZ,WAAW,EACX;AACI,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACrB,YAAA,IAAI,GAAG,KAAK,0BAA0B,EAAE;gBACpC,OAAO,CAAC,SAAiB,CAAC,EAAE,WAA6BC,kBAAO,CAAC,UAAU,KAAI;AAC3E,oBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAkC,KAAI;AAChD,wBAAA,IAAI,KAAK;AAAE,4BAAA,OAAO,IAAIA,kBAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;AAC7E,qBAAC;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,mBAAmB,EAAE;AAC7B,gBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAwB,KAAK,KAAK,EAAE,QAAQ,EAAE;AAC5D,gBAAA,OAAO,QAAQ;;YAGnB,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC5C;AACJ,KAAA,CACuB;AAChC;;;;"}
@@ -1,4 +1,4 @@
1
- import Decimal from 'decimal.js';
1
+ import { Decimal } from 'decimal.js';
2
2
  import { Schema } from 'mongoose';
3
3
  import type { DefaultType, IndexDirection, IndexOptions, Types } from 'mongoose';
4
4
  import type { Merge } from 'type-fest';
@@ -1 +1 @@
1
- {"version":3,"file":"decimal128.d.ts","sourceRoot":"","sources":["../../src/schema-builders/decimal128.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,EACR,WAAW,EACX,cAAc,EACd,YAAY,EACZ,KAAK,EACR,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAInD,MAAM,MAAM,6BAA6B,CACrC,KAAK,SAAS,SAAS,EACvB,eAAe,SAAS,MAAM,IAC9B,IAAI,CACJ,uBAAuB,CAAC,KAAK,EAAE,eAAe,CAAC,EAC/C,eAAe,GAAG,MAAM,KAAK,CAChC,CAAC;AAEF,UAAU,SAAS;IACf,IAAI,EAAE,OAAO,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;CACxC;AAED,UAAU,oBAAoB;IAC1B,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,MAAM,GAAG,SAAS,CAAC;CACzD;AAED,UAAU,oBAAoB;IAC1B,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;CACvD;AAED,MAAM,WAAW,uBAAuB,CACpC,KAAK,SAAS;IAAE,IAAI,EAA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,MAAM,EAAE,6BAA6B,CAAC,KAAK,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,IAAI,CAAA;KAAE,CAAC,EAAE,eAAe,CAAC,CAAC;CAC1F;AAID,wBAAgB,uBAAuB,IAyB9B,uBAAuB,CAC/B"}
@@ -1,4 +1,4 @@
1
- import Decimal from 'decimal.js';
1
+ import { Decimal } from 'decimal.js';
2
2
  import { Schema } from 'mongoose';
3
3
  import { createBaseSchemaBuilderFactory } from './base.mjs';
4
4
 
@@ -1 +1 @@
1
- {"version":3,"file":"decimal128.mjs","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/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendDecimal128SchemaBuilder<\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 ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string;\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) => ExtendDecimal128SchemaBuilder<\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) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendDecimal128SchemaBuilder<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) => ExtendDecimal128SchemaBuilder<\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: ExtendDecimal128SchemaBuilder<\n Merge<Props, ToStringGetterSchema>,\n 'setToStringGetter' | ExtraOmitFields\n >;\n\n sparse: ExtendDecimal128SchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendDecimal128SchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\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) return new Decimal(value.toString()).toFixed(places, rounding);\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"],"names":[],"mappings":";;;;AAoGA,MAAM,kBAAkB,GAAG,8BAA8B,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;SAElE,uBAAuB,GAAA;IACnC,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,OAAO,IAAI,KAAK,CACZ,WAAW,EACX;AACI,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACrB,YAAA,IAAI,GAAG,KAAK,0BAA0B,EAAE;gBACpC,OAAO,CAAC,SAAiB,CAAC,EAAE,WAA6B,OAAO,CAAC,UAAU,KAAI;AAC3E,oBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAkC,KAAI;AAChD,wBAAA,IAAI,KAAK;AAAE,4BAAA,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;AAC7E,qBAAC;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,mBAAmB,EAAE;AAC7B,gBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAwB,KAAK,KAAK,EAAE,QAAQ,EAAE;AAC5D,gBAAA,OAAO,QAAQ;;YAGnB,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC5C;AACJ,KAAA,CACuB;AAChC;;;;"}
1
+ {"version":3,"file":"decimal128.mjs","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/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendDecimal128SchemaBuilder<\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 ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string;\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) => ExtendDecimal128SchemaBuilder<\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) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendDecimal128SchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendDecimal128SchemaBuilder<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) => ExtendDecimal128SchemaBuilder<\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: ExtendDecimal128SchemaBuilder<\n Merge<Props, ToStringGetterSchema>,\n 'setToStringGetter' | ExtraOmitFields\n >;\n\n sparse: ExtendDecimal128SchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendDecimal128SchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\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) return new Decimal(value.toString()).toFixed(places, rounding);\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"],"names":[],"mappings":";;;;AAoGA,MAAM,kBAAkB,GAAG,8BAA8B,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;SAElE,uBAAuB,GAAA;IACnC,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,OAAO,IAAI,KAAK,CACZ,WAAW,EACX;AACI,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACrB,YAAA,IAAI,GAAG,KAAK,0BAA0B,EAAE;gBACpC,OAAO,CAAC,SAAiB,CAAC,EAAE,WAA6B,OAAO,CAAC,UAAU,KAAI;AAC3E,oBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAkC,KAAI;AAChD,wBAAA,IAAI,KAAK;AAAE,4BAAA,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;AAC7E,qBAAC;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,mBAAmB,EAAE;AAC7B,gBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAwB,KAAK,KAAK,EAAE,QAAQ,EAAE;AAC5D,gBAAA,OAAO,QAAQ;;YAGnB,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC5C;AACJ,KAAA,CACuB;AAChC;;;;"}
@@ -1,12 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const net = require('node:net');
3
+ const node_net = require('node:net');
4
4
  const base = require('./base.cjs');
5
5
 
6
- const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
7
-
8
- const net__default = /*#__PURE__*/_interopDefaultCompat(net);
9
-
10
6
  const baseBuilderFactory = base.createBaseSchemaBuilderFactory(String);
11
7
  const defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.';
12
8
  const defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.';
@@ -20,7 +16,7 @@ function stringSchemaBuilder() {
20
16
  schema.trim = true;
21
17
  schema.validate = {
22
18
  message,
23
- validator: (value) => net__default.isIPv4(value),
19
+ validator: (value) => node_net.isIPv4(value),
24
20
  };
25
21
  return receiver;
26
22
  };
@@ -30,7 +26,7 @@ function stringSchemaBuilder() {
30
26
  schema.trim = true;
31
27
  schema.validate = {
32
28
  message,
33
- validator: (value) => net__default.isIPv6(value),
29
+ validator: (value) => node_net.isIPv6(value),
34
30
  };
35
31
  return receiver;
36
32
  };
@@ -1 +1 @@
1
- {"version":3,"file":"string.cjs","sources":["../../src/schema-builders/string.ts"],"sourcesContent":["import net 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/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendStringSchemaBuilder<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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { minlength: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendStringSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendStringSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n text: ExtendStringSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendStringSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendStringSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendStringSchemaBuilder<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) => net.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) => net.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"],"names":["createBaseSchemaBuilderFactory","net"],"mappings":";;;;;;;;;AAsIA,MAAM,kBAAkB,GAAGA,mCAA8B,CAAC,MAAM,CAAC;AACjE,MAAM,0BAA0B,GAAG,0DAA0D;AAC7F,MAAM,0BAA0B,GAAG,0DAA0D;SAE7E,mBAAmB,GAAA;IAC/B,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,OAAO,IAAI,KAAK,CACZ,WAAW,EACX;AACI,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACrB,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAKC,YAAG,CAAC,MAAM,CAAC,KAAK,CAAC;qBAClD;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAKA,YAAG,CAAC,MAAM,CAAC,KAAK,CAAC;qBAClD;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,QAAQ,EAAE;gBAClB,OAAO,CAAC,KAAU,KAAI;oBAClB,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,GAAG,KAAK;AAC3C,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;YAGL,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC5C;AACJ,KAAA,CACmB;AAC5B;;;;"}
1
+ {"version":3,"file":"string.cjs","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/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendStringSchemaBuilder<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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { minlength: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendStringSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendStringSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n text: ExtendStringSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendStringSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendStringSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendStringSchemaBuilder<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"],"names":["createBaseSchemaBuilderFactory","isIPv4","isIPv6"],"mappings":";;;;;AAyIA,MAAM,kBAAkB,GAAGA,mCAA8B,CAAC,MAAM,CAAC;AACjE,MAAM,0BAA0B,GAAG,0DAA0D;AAC7F,MAAM,0BAA0B,GAAG,0DAA0D;SAE7E,mBAAmB,GAAA;IAC/B,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,OAAO,IAAI,KAAK,CACZ,WAAW,EACX;AACI,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACrB,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAKC,eAAM,CAAC,KAAK,CAAC;qBAC9C;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,G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C,CAAC;IAC/E,IAAI,EAAE,yBAAyB,CAAC,KAAK,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC,EAAE,eAAe,CAAC,CAAC;IAC/E,MAAM,EAAE,yBAAyB,CAAC,KAAK,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,IAAI,CAAA;KAAE,CAAC,EAAE,eAAe,CAAC,CAAC;IACnF,SAAS,EAAE,yBAAyB,CAAC,KAAK,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,IAAI,CAAA;KAAE,CAAC,EAAE,eAAe,CAAC,CAAC;CAC5F;AAGD,QAAA,MAAM,0BAA0B,6DAA6D,CAAC;AAC9F,QAAA,MAAM,0BAA0B,6DAA6D,CAAC;AAE9F,wBAAgB,mBAAmB,IAyC1B,mBAAmB,CAC3B"}
@@ -1,4 +1,4 @@
1
- import net from 'node:net';
1
+ import { isIPv4, isIPv6 } from 'node:net';
2
2
  import { createBaseSchemaBuilderFactory } from './base.mjs';
3
3
 
4
4
  const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
@@ -14,7 +14,7 @@ function stringSchemaBuilder() {
14
14
  schema.trim = true;
15
15
  schema.validate = {
16
16
  message,
17
- validator: (value) => net.isIPv4(value),
17
+ validator: (value) => isIPv4(value),
18
18
  };
19
19
  return receiver;
20
20
  };
@@ -24,7 +24,7 @@ function stringSchemaBuilder() {
24
24
  schema.trim = true;
25
25
  schema.validate = {
26
26
  message,
27
- validator: (value) => net.isIPv6(value),
27
+ validator: (value) => isIPv6(value),
28
28
  };
29
29
  return receiver;
30
30
  };
@@ -1 +1 @@
1
- {"version":3,"file":"string.mjs","sources":["../../src/schema-builders/string.ts"],"sourcesContent":["import net 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/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendStringSchemaBuilder<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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { minlength: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendStringSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendStringSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n text: ExtendStringSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendStringSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendStringSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendStringSchemaBuilder<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) => net.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) => net.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"],"names":[],"mappings":";;;AAsIA,MAAM,kBAAkB,GAAG,8BAA8B,CAAC,MAAM,CAAC;AACjE,MAAM,0BAA0B,GAAG,0DAA0D;AAC7F,MAAM,0BAA0B,GAAG,0DAA0D;SAE7E,mBAAmB,GAAA;IAC/B,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,OAAO,IAAI,KAAK,CACZ,WAAW,EACX;AACI,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACrB,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;qBAClD;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;qBAClD;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,QAAQ,EAAE;gBAClB,OAAO,CAAC,KAAU,KAAI;oBAClB,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,GAAG,KAAK;AAC3C,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;YAGL,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC5C;AACJ,KAAA,CACmB;AAC5B;;;;"}
1
+ {"version":3,"file":"string.mjs","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/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendStringSchemaBuilder<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) => ExtendStringSchemaBuilder<\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) => ExtendStringSchemaBuilder<\n Merge<Props, { minlength: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendStringSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendStringSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n text: ExtendStringSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendStringSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendStringSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendStringSchemaBuilder<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"],"names":[],"mappings":";;;AAyIA,MAAM,kBAAkB,GAAG,8BAA8B,CAAC,MAAM,CAAC;AACjE,MAAM,0BAA0B,GAAG,0DAA0D;AAC7F,MAAM,0BAA0B,GAAG,0DAA0D;SAE7E,mBAAmB,GAAA;IAC/B,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,OAAO,IAAI,KAAK,CACZ,WAAW,EACX;AACI,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACrB,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAK,MAAM,CAAC,KAAK,CAAC;qBAC9C;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAK,MAAM,CAAC,KAAK,CAAC;qBAC9C;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,QAAQ,EAAE;gBAClB,OAAO,CAAC,KAAU,KAAI;oBAClB,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,GAAG,KAAK;AAC3C,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;YAGL,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC5C;AACJ,KAAA,CACmB;AAC5B;;;;"}
@@ -1,53 +1,18 @@
1
1
  import type { IfElse } from './utils';
2
- /**
3
- * Interface for the base data of a Mongoose model, optionally including timestamp fields.
4
- *
5
- * This interface extends `LocalWithTimestampFieldsData` to optionally include `createdAt`
6
- * and `updatedAt` fields based on the `CreatedAtField` and `UpdatedAtField` flags.
7
- * It also includes a mandatory `id` field.
8
- *
9
- * @template CreatedAtField - A boolean flag indicating whether the `createdAt` field should be included.
10
- * @template UpdatedAtField - A boolean flag indicating whether the `updatedAt` field should be included.
11
- */
12
- interface LocalBaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> extends LocalWithTimestampFieldsData<CreatedAtField, UpdatedAtField> {
13
- id: string;
14
- }
15
- /**
16
- * Interface for including timestamp fields conditionally based on the provided flags.
17
- *
18
- * This interface conditionally includes `createdAt` and `updatedAt` fields based on
19
- * the `CreatedAt` and `UpdatedAt` boolean flags. If the flag is true, the respective
20
- * field is included, otherwise it is set to `never`.
21
- *
22
- * @template CreatedAt - A boolean flag indicating whether the `createdAt` field should be included.
23
- * @template UpdatedAt - A boolean flag indicating whether the `updatedAt` field should be included.
24
- */
25
- interface LocalWithTimestampFieldsData<CreatedAt extends boolean = true, UpdatedAt extends boolean = true> {
26
- createdAt: IfElse<CreatedAt, string, never>;
27
- updatedAt: IfElse<UpdatedAt, string, never>;
28
- }
29
- /**
30
- * Utility type to omit properties that are set to `never` in a given type.
31
- *
32
- * This type alias iterates over the properties of a given type `T` and removes any
33
- * properties that are set to `never`.
34
- *
35
- * @template T - The type from which to omit `never` properties.
36
- */
37
- type OmitNever<T> = {
38
- [P in keyof T as IfElse<T[P], never, P, never>]: T[P];
39
- };
40
2
  declare global {
41
3
  /**
42
4
  * Type definition for the base data of a Mongoose model, optionally including timestamp fields.
43
5
  *
44
- * This type alias uses `OmitNever` to remove any `never` properties from `LocalBaseMongooseModelData`
45
- * based on the presence of the `CreatedAtField` and `UpdatedAtField` flags.
46
- *
47
6
  * @template CreatedAtField - A boolean flag indicating whether the `createdAt` field should be included.
48
7
  * @template UpdatedAtField - A boolean flag indicating whether the `updatedAt` field should be included.
49
8
  */
50
- type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = OmitNever<LocalBaseMongooseModelData<CreatedAtField, UpdatedAtField>>;
9
+ type BaseMongooseModelData<CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = IfElse<CreatedAtField, {
10
+ createdAt: string;
11
+ }, unknown> & IfElse<UpdatedAtField, {
12
+ updatedAt: string;
13
+ }, unknown> & {
14
+ id: string;
15
+ };
51
16
  /**
52
17
  * Type definition to omit timestamp fields (`createdAt`, `updatedAt`)
53
18
  * and other specified fields (`OT`) from a given type `T`.
@@ -67,13 +32,13 @@ declare global {
67
32
  /**
68
33
  * Type definition for including timestamp fields conditionally based on the provided flags.
69
34
  *
70
- * This type alias uses `OmitNever` to remove any `never` properties from `LocalWithTimestampFieldsData`
71
- * based on the presence of the `CreatedAt` and `UpdatedAt` flags.
72
- *
73
35
  * @template CreatedAt - A boolean flag indicating whether the `createdAt` field should be included.
74
36
  * @template UpdatedAt - A boolean flag indicating whether the `updatedAt` field should be included.
75
37
  */
76
- type WithMongooseTimestampFieldsData<CreatedAt extends boolean = true, UpdatedAt extends boolean = true> = OmitNever<LocalWithTimestampFieldsData<CreatedAt, UpdatedAt>>;
38
+ type WithMongooseTimestampFieldsData<CreatedAt extends boolean = true, UpdatedAt extends boolean = true> = IfElse<CreatedAt, {
39
+ createdAt: string;
40
+ }, object> & IfElse<UpdatedAt, {
41
+ updatedAt: string;
42
+ }, object>;
77
43
  }
78
- export {};
79
44
  //# sourceMappingURL=data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/types/data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;GASG;AACH,UAAU,0BAA0B,CAChC,cAAc,SAAS,OAAO,GAAG,IAAI,EACrC,cAAc,SAAS,OAAO,GAAG,IAAI,CACvC,SAAQ,4BAA4B,CAAC,cAAc,EAAE,cAAc,CAAC;IAClE,EAAE,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;G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.d.ts","sourceRoot":"","sources":["../../src/types/data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,CAAC,MAAM,CAAC;IACX;;;;;OAKG;IACH,KAAK,qBAAqB,CACtB,cAAc,SAAS,OAAO,GAAG,IAAI,EACrC,cAAc,SAAS,OAAO,GAAG,IAAI,IAErC,MAAM,CAAC,cAAc,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,GACtD,MAAM,CAAC,cAAc,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,GACtD;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAEnB;;;;;;OAMG;IACH,KAAK,qCAAqC,CAAC,CAAC,EAAE,EAAE,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,EAAE,CAAC,CAAC;IAE5G;;;;;;OAMG;IACH,KAAK,mCAAmC,CACpC,CAAC,EACD,EAAE,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,IAC3C,IAAI,CACJ,CAAC,EACD,WAAW,GAAG,WAAW,GAAG,EAAE,CACjC,CAAC;IAEF;;;;;OAKG;IACH,KAAK,+BAA+B,CAChC,SAAS,SAAS,OAAO,GAAG,IAAI,EAChC,SAAS,SAAS,OAAO,GAAG,IAAI,IAEhC,MAAM,CAAC,SAAS,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,MAAM,CAAC,GAChD,MAAM,CAAC,SAAS,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,MAAM,CAAC,CAAC;CACxD"}
@@ -21,9 +21,9 @@ declare global {
21
21
  */
22
22
  type BaseMongooseDocType<T, CreatedAtField extends boolean = true, UpdatedAtField extends boolean = true> = IfElse<CreatedAtField, {
23
23
  createdAt: Date;
24
- }, object> & IfElse<UpdatedAtField, {
24
+ }, unknown> & IfElse<UpdatedAtField, {
25
25
  updatedAt: Date;
26
- }, object> & Omit<T, 'createdAt' | 'id' | 'updatedAt'>;
26
+ }, unknown> & Omit<T, 'createdAt' | 'id' | 'updatedAt'>;
27
27
  /**
28
28
  * Type definition for a Mongoose model with pagination and aggregation capabilities.
29
29
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,KAAK,EACR,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC3C,YAAY,EAAE,MAAM,YAAY,CAAC;AAIjC,MAAM,WAAW,gBAAgB,CAAC,UAAU,EAAE,2BAA2B,GAAG,MAAM,EAAE,YAAY,GAAG,MAAM;CAAI;AAE7G,MAAM,WAAW,mBAAmB;IAChC,OAAO,CAAC,EAAE,UAAU,CAAC;CACxB;AAED,OAAO,CAAC,MAAM,CAAC;IACX;;;;;;;;;;OAUG;IACH,KAAK,mBAAmB,CACpB,CAAC,EACD,cAAc,SAAS,OAAO,GAAG,IAAI,EACrC,cAAc,SAAS,OAAO,GAAG,IAAI,IAErC,MAAM,CAAC,cAAc,EAAE;QAAE,SAAS,EAAE,IAAI,CAAA;KAAE,EAAE,MAAM,CAAC,GACnD,MAAM,CAAC,cAAc,EAAE;QAAE,SAAS,EAAE,IAAI,CAAA;KAAE,EAAE,MAAM,CAAC,GACnD,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC;IAE9C;;;;;;;;;OASG;IACH,KAAK,yBAAyB,CAC1B,UAAU,EACV,2BAA2B,GAAG,MAAM,EACpC,YAAY,GAAG,MAAM,IAErB,sBAAsB,CAAC,UA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CAAC,EACD,cAAc,SAAS,OAAO,GAAG,IAAI,EACrC,cAAc,SAAS,OAAO,GAAG,IAAI,IAErC,MAAM,CAAC,cAAc,EAAE;QAAE,SAAS,EAAE,IAAI,CAAA;KAAE,EAAE,OAAO,CAAC,GACpD,MAAM,CAAC,cAAc,EAAE;QAAE,SAAS,EAAE,IAAI,CAAA;KAAE,EAAE,OAAO,CAAC,GACpD,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC;IAE9C;;;;;;;;;OASG;IACH,KAAK,yBAAyB,CAC1B,UAAU,EACV,2BAA2B,GAAG,MAAM,EACpC,YAAY,GAAG,MAAM,IAErB,sBAAsB,CAAC,UAAU,EAAE,YAAY,EAAE,2BAA2B,CAAC,GAC7E,gBAAgB,CAAC,UAAU,EAAE,2BAA2B,EAAE,YAAY,CAAC,GACvE,aAAa,CAAC,UAAU,EAAE,YAAY,EAAE,2BAA2B,CAAC,CAAC;IAEzE;;;;;;;;OAQG;IACH,KAAK,0BAA0B,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC;IAEjE;;;;;;;;;;;;;;OAcG;IACH,KAAK,yBAAyB,CAC1B,UAAU,EACV,OAAO,EACP,YAAY,GAAG,MAAM,EACrB,2BAA2B,GAAG,MAAM,IACpC,gBAAgB,CAChB,OAAO,GAAG,IAAI,EACd,OAAO,EACP,YAAY,EACZ,UAAU,EACV,SAAS,EACT,2BAA2B,CAC9B,CAAC;IAEF;;;;;;;;;;;OAWG;IACH,KAAK,wBAAwB,CACzB,OAAO,EACP,2BAA2B,GAAG,MAAM,EACpC,YAAY,GAAG,MAAM,IACrB,gBAAgB,CAChB,OAAO,EACP,2BAA2B,EAC3B,YAAY,CACf,CAAC;CACL"}
package/dist/utils.cjs CHANGED
@@ -9,7 +9,6 @@ const normalize = require('./plugins/normalize.cjs');
9
9
 
10
10
  const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
11
11
 
12
- const mongoose__default = /*#__PURE__*/_interopDefaultCompat(mongoose);
13
12
  const mongooseAggregatePaginate__default = /*#__PURE__*/_interopDefaultCompat(mongooseAggregatePaginate);
14
13
  const mongoosePaginate__default = /*#__PURE__*/_interopDefaultCompat(mongoosePaginate);
15
14
 
@@ -71,7 +70,7 @@ function buildMongooseModel(collection, name, schema, options) {
71
70
  schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);
72
71
  _internals.customMongooseOptions.beforeModelBuild?.(schema);
73
72
  // eslint-disable-next-line style/max-len
74
- const connection = options?.connection || (constants.mongooseConnections.default ||= mongoose__default.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));
73
+ const connection = options?.connection || (constants.mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));
75
74
  return connection.model(name, schema, collection);
76
75
  }
77
76
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sources":["../src/utils.ts"],"sourcesContent":["import type { mongo } from 'mongoose';\nimport mongoose, { Types } from 'mongoose';\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';\nimport mongoosePaginate from 'mongoose-paginate-v2';\n\nimport { customMongooseOptions } from './_internals';\nimport { mongooseConnections } from './constants';\nimport type { setCustomMongooseOptions } from './options';\nimport { mongooseNormalizePlugin } from './plugins/normalize';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;\n\n/**\n * Asserts that a Mongoose update operation was successful by checking that it was acknowledged\n * and that at least the expected number of documents were modified.\n *\n * This function is intended for use with `updateOne`, `updateMany`, or any update operation\n * that returns a MongoDB `UpdateResult`.\n *\n * @template T - The shape of the document being updated.\n * @param updatePromise - A promise returned from a Mongoose update operation.\n * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.\n * @throws Will throw an error if:\n * - The operation was not acknowledged by MongoDB,\n * - Fewer documents were modified than expected.\n */\nexport async function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(\n updatePromise: Promise<mongo.UpdateResult<T>>,\n expectedModifiedCount = 1,\n) {\n const updateResult = await updatePromise;\n if (!updateResult.acknowledged) throw new Error('Update was not acknowledged.');\n if (updateResult.modifiedCount < expectedModifiedCount) {\n // eslint-disable-next-line style/max-len\n throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}.`);\n }\n}\n\n/**\n * Builds and returns a Mongoose model with specified schema and options.\n *\n * This function sets up a Mongoose model with optional plugins and timestamp settings.\n * It can optionally use a specified connection or the default connection.\n *\n * Determine the connection to use:\n * 1. Use the connection provided in the options, if available.\n * 2. Otherwise, use the default connection stored in `mongooseConnections`.\n * 3. If there's no default connection, create one using the MongoDB URI from the environment variables,\n * or fallback to a local MongoDB instance.\n *\n * You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.\n * However, ensure that this option is configured before calling {@link buildMongooseModel}.\n *\n * @template DocType - The type of the document.\n * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param collection - The name of the collection.\n * @param name - The name of the model.\n * @param schema - The Mongoose schema to use for the model.\n * @param options - Optional settings for building the model.\n *\n * @returns The created Mongoose model.\n */\nexport function buildMongooseModel<\n DocType,\n Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n collection: string,\n name: string,\n schema: mongoose.Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n options?: BuildMongooseModelOptions,\n) {\n if (options?.enableNormalizePlugin !== false) schema.plugin(mongooseNormalizePlugin);\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n // eslint-disable-next-line style/max-len\n const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\n\n/**\n * Converts a document or ObjectId to a document using the specified model.\n *\n * This function takes a document or ObjectId and returns the corresponding document\n * from the database using the specified model. Optionally, specific fields can be selected.\n *\n * @template D - The type of the hydrated document.\n * @template DocType - The type of the document.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param documentOrObjectId - The document or ObjectId to convert.\n * @param model - The Mongoose model to use for the conversion.\n * @param selectFields - Optional fields to select from the document.\n *\n * @returns The corresponding document or null if not found.\n */\nexport async function mongooseDocumentOrObjectIdToDocument<\n D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n DocType,\n InstanceMethodsAndOverrides,\n QueryHelpers,\n>(\n documentOrObjectId: MongooseDocumentOrObjectId<D>,\n model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n selectFields?: string[],\n): Promise<D | null> {\n if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {\n return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n }\n\n return documentOrObjectId;\n}\n"],"names":["mongooseNormalizePlugin","mongooseAggregatePaginate","mongoosePaginate","customMongooseOptions","mongooseConnections","mongoose","Types"],"mappings":";;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;AAaG;AACI,eAAe,2BAA2B,CAC7C,aAA6C,EAC7C,qBAAqB,GAAG,CAAC,EAAA;AAEzB,IAAA,MAAM,YAAY,GAAG,MAAM,aAAa;IACxC,IAAI,CAAC,YAAY,CAAC,YAAY;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;AAC/E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAqB,EAAE;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3,"file":"utils.cjs","sources":["../src/utils.ts"],"sourcesContent":["import {\n createConnection,\n Types,\n} from 'mongoose';\nimport type {\n mongo,\n Schema,\n} from 'mongoose';\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';\nimport mongoosePaginate from 'mongoose-paginate-v2';\n\nimport { customMongooseOptions } from './_internals';\nimport { mongooseConnections } from './constants';\nimport type { setCustomMongooseOptions } from './options';\nimport { mongooseNormalizePlugin } from './plugins/normalize';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;\n\n/**\n * Asserts that a Mongoose update operation was successful by checking that it was acknowledged\n * and that at least the expected number of documents were modified.\n *\n * This function is intended for use with `updateOne`, `updateMany`, or any update operation\n * that returns a MongoDB `UpdateResult`.\n *\n * @template T - The shape of the document being updated.\n * @param updatePromise - A promise returned from a Mongoose update operation.\n * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.\n * @throws Will throw an error if:\n * - The operation was not acknowledged by MongoDB,\n * - Fewer documents were modified than expected.\n */\nexport async function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(\n updatePromise: Promise<mongo.UpdateResult<T>>,\n expectedModifiedCount = 1,\n) {\n const updateResult = await updatePromise;\n if (!updateResult.acknowledged) throw new Error('Update was not acknowledged.');\n if (updateResult.modifiedCount < expectedModifiedCount) {\n // eslint-disable-next-line style/max-len\n throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}.`);\n }\n}\n\n/**\n * Builds and returns a Mongoose model with specified schema and options.\n *\n * This function sets up a Mongoose model with optional plugins and timestamp settings.\n * It can optionally use a specified connection or the default connection.\n *\n * Determine the connection to use:\n * 1. Use the connection provided in the options, if available.\n * 2. Otherwise, use the default connection stored in `mongooseConnections`.\n * 3. If there's no default connection, create one using the MongoDB URI from the environment variables,\n * or fallback to a local MongoDB instance.\n *\n * You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.\n * However, ensure that this option is configured before calling {@link buildMongooseModel}.\n *\n * @template DocType - The type of the document.\n * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param collection - The name of the collection.\n * @param name - The name of the model.\n * @param schema - The Mongoose schema to use for the model.\n * @param options - Optional settings for building the model.\n *\n * @returns The created Mongoose model.\n */\nexport function buildMongooseModel<\n DocType,\n Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n collection: string,\n name: string,\n schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n options?: BuildMongooseModelOptions,\n) {\n if (options?.enableNormalizePlugin !== false) schema.plugin(mongooseNormalizePlugin);\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n // eslint-disable-next-line style/max-len\n const connection = options?.connection || (mongooseConnections.default ||= createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\n\n/**\n * Converts a document or ObjectId to a document using the specified model.\n *\n * This function takes a document or ObjectId and returns the corresponding document\n * from the database using the specified model. Optionally, specific fields can be selected.\n *\n * @template D - The type of the hydrated document.\n * @template DocType - The type of the document.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param documentOrObjectId - The document or ObjectId to convert.\n * @param model - The Mongoose model to use for the conversion.\n * @param selectFields - Optional fields to select from the document.\n *\n * @returns The corresponding document or null if not found.\n */\nexport async function mongooseDocumentOrObjectIdToDocument<\n D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n DocType,\n InstanceMethodsAndOverrides,\n QueryHelpers,\n>(\n documentOrObjectId: MongooseDocumentOrObjectId<D>,\n model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n selectFields?: string[],\n) {\n if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {\n return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n }\n\n return documentOrObjectId;\n}\n"],"names":["mongooseNormalizePlugin","mongooseAggregatePaginate","mongoosePaginate","customMongooseOptions","mongooseConnections","createConnection","Types"],"mappings":";;;;;;;;;;;;;;AAmBA;;;;;;;;;;;;;AAaG;AACI,eAAe,2BAA2B,CAC7C,aAA6C,EAC7C,qBAAqB,GAAG,CAAC,EAAA;AAEzB,IAAA,MAAM,YAAY,GAAG,MAAM,aAAa;IACxC,IAAI,CAAC,YAAY,CAAC,YAAY;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;AAC/E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAqB,EAAE;;QAEpD,MAAM,IAAI,KAAK,CAAC,CAA+B,4BAAA,EAAA,qBAAqB,CAA8B,2BAAA,EAAA,YAAY,CAAC,aAAa,CAAG,CAAA,CAAA,CAAC;;AAExI;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,kBAAkB,CAM9B,UAAkB,EAClB,IAAY,EACZ,MAAyE,EACzE,OAAmC,EAAA;AAEnC,IAAA,IAAI,OAAO,EAAE,qBAAqB,KAAK,KAAK;AAAE,QAAA,MAAM,CAAC,MAAM,CAACA,iCAAuB,CAAC;AACpF,IAAA,MAAM,CAAC,MAAM,CAACC,kCAAyB,CAAC;AACxC,IAAA,MAAM,CAAC,MAAM,CAACC,yBAAgB,CAAC;AAC/B,IAAA,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,UAAU,IAAI,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC;AACjF,IAAAC,gCAAqB,CAAC,gBAAgB,GAAG,MAAM,CAAC;;IAEhD,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,KAAKC,6BAAmB,CAAC,OAAO,KAAKC,yBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,2BAA2B,CAAC,CAAC;IACpJ,OAAO,UAAU,CAAC,KAAK,CAA+B,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC;AACnF;AAEA;;;;;;;;;;;;;;;;AAgBG;AACI,eAAe,oCAAoC,CAMtD,kBAAiD,EACjD,KAAoF,EACpF,YAAuB,EAAA;IAEvB,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,YAAYC,cAAK,CAAC,QAAQ,EAAE;AACxF,QAAA,QAAQ,MAAM,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;;AAG/E,IAAA,OAAO,kBAAkB;AAC7B;;;;;;"}
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import type { mongo } from 'mongoose';
2
- import mongoose from 'mongoose';
1
+ import type { mongo, Schema } from 'mongoose';
3
2
  import type { setCustomMongooseOptions } from './options';
4
3
  import type { BuildMongooseModelOptions } from './types/options';
5
4
  export type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;
@@ -45,7 +44,7 @@ export declare function assertMongooseUpdateSuccess<T extends mongo.BSON.Documen
45
44
  *
46
45
  * @returns The created Mongoose model.
47
46
  */
48
- export declare function buildMongooseModel<DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(collection: string, name: string, schema: mongoose.Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>, options?: BuildMongooseModelOptions): Model;
47
+ 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;
49
48
  /**
50
49
  * Converts a document or ObjectId to a document using the specified model.
51
50
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,QAAmB,MAAM,UAAU,CAAC;AAM3C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAEjE,MAAM,MAAM,wBAAwB,GAAG,OAAO,wBAAwB,CAAC;AAEvE;;;;;;;;;;;;;GAaG;AACH,wBAAsB,2BAA2B,CAAC,CAAC,SAAS,KAAK,CAAC,IAAI,CAAC,QAAQ,EAC3E,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAC7C,qBAAqB,SAAI,iBAQ5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,kBAAkB,CAC9B,OAAO,EACP,KAAK,SAAS,yBAAyB,CAAC,OAAO,EAAE,2BAA2B,EAAE,YAAY,CAAC,EAC3F,2BAA2B,GAAG,MAAM,EACpC,YAAY,GAAG,MAAM,EAErB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,2BAA2B,EAAE,YAAY,CAAC,EAClF,OAAO,CAAC,EAAE,yBAAyB,SAUtC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,oCAAoC,CACtD,CAAC,SAAS,wBAAwB,CAAC,OAAO,EAAE,2BAA2B,EAAE,YAAY,CAAC,EACtF,OAAO,EACP,2BAA2B,EAC3B,YAAY,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B,YAAY,EAEZ,kBAAkB,EAAE,0BAA0B,CAAC,CAAC,CAAC,EACjD,KAAK,EAAE,yBAAyB,CAAC,OAAO,EAAE,2BAA2B,EAAE,YAAY,CAAC,EACpF,YAAY,CAAC,EAAE,MAAM,EAAE,qBAO1B"}
package/dist/utils.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import mongoose, { Types } from 'mongoose';
1
+ import { createConnection, Types } from 'mongoose';
2
2
  import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
3
3
  import mongoosePaginate from 'mongoose-paginate-v2';
4
4
  import { customMongooseOptions } from './_internals.mjs';
@@ -63,7 +63,7 @@ function buildMongooseModel(collection, name, schema, options) {
63
63
  schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);
64
64
  customMongooseOptions.beforeModelBuild?.(schema);
65
65
  // eslint-disable-next-line style/max-len
66
- const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));
66
+ const connection = options?.connection || (mongooseConnections.default ||= createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));
67
67
  return connection.model(name, schema, collection);
68
68
  }
69
69
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sources":["../src/utils.ts"],"sourcesContent":["import type { mongo } from 'mongoose';\nimport mongoose, { Types } from 'mongoose';\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';\nimport mongoosePaginate from 'mongoose-paginate-v2';\n\nimport { customMongooseOptions } from './_internals';\nimport { mongooseConnections } from './constants';\nimport type { setCustomMongooseOptions } from './options';\nimport { mongooseNormalizePlugin } from './plugins/normalize';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;\n\n/**\n * Asserts that a Mongoose update operation was successful by checking that it was acknowledged\n * and that at least the expected number of documents were modified.\n *\n * This function is intended for use with `updateOne`, `updateMany`, or any update operation\n * that returns a MongoDB `UpdateResult`.\n *\n * @template T - The shape of the document being updated.\n * @param updatePromise - A promise returned from a Mongoose update operation.\n * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.\n * @throws Will throw an error if:\n * - The operation was not acknowledged by MongoDB,\n * - Fewer documents were modified than expected.\n */\nexport async function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(\n updatePromise: Promise<mongo.UpdateResult<T>>,\n expectedModifiedCount = 1,\n) {\n const updateResult = await updatePromise;\n if (!updateResult.acknowledged) throw new Error('Update was not acknowledged.');\n if (updateResult.modifiedCount < expectedModifiedCount) {\n // eslint-disable-next-line style/max-len\n throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}.`);\n }\n}\n\n/**\n * Builds and returns a Mongoose model with specified schema and options.\n *\n * This function sets up a Mongoose model with optional plugins and timestamp settings.\n * It can optionally use a specified connection or the default connection.\n *\n * Determine the connection to use:\n * 1. Use the connection provided in the options, if available.\n * 2. Otherwise, use the default connection stored in `mongooseConnections`.\n * 3. If there's no default connection, create one using the MongoDB URI from the environment variables,\n * or fallback to a local MongoDB instance.\n *\n * You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.\n * However, ensure that this option is configured before calling {@link buildMongooseModel}.\n *\n * @template DocType - The type of the document.\n * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param collection - The name of the collection.\n * @param name - The name of the model.\n * @param schema - The Mongoose schema to use for the model.\n * @param options - Optional settings for building the model.\n *\n * @returns The created Mongoose model.\n */\nexport function buildMongooseModel<\n DocType,\n Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n collection: string,\n name: string,\n schema: mongoose.Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n options?: BuildMongooseModelOptions,\n) {\n if (options?.enableNormalizePlugin !== false) schema.plugin(mongooseNormalizePlugin);\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n // eslint-disable-next-line style/max-len\n const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\n\n/**\n * Converts a document or ObjectId to a document using the specified model.\n *\n * This function takes a document or ObjectId and returns the corresponding document\n * from the database using the specified model. Optionally, specific fields can be selected.\n *\n * @template D - The type of the hydrated document.\n * @template DocType - The type of the document.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param documentOrObjectId - The document or ObjectId to convert.\n * @param model - The Mongoose model to use for the conversion.\n * @param selectFields - Optional fields to select from the document.\n *\n * @returns The corresponding document or null if not found.\n */\nexport async function mongooseDocumentOrObjectIdToDocument<\n D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n DocType,\n InstanceMethodsAndOverrides,\n QueryHelpers,\n>(\n documentOrObjectId: MongooseDocumentOrObjectId<D>,\n model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n selectFields?: string[],\n): Promise<D | null> {\n if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {\n return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n }\n\n return documentOrObjectId;\n}\n"],"names":[],"mappings":";;;;;;;AAaA;;;;;;;;;;;;;AAaG;AACI,eAAe,2BAA2B,CAC7C,aAA6C,EAC7C,qBAAqB,GAAG,CAAC,EAAA;AAEzB,IAAA,MAAM,YAAY,GAAG,MAAM,aAAa;IACxC,IAAI,CAAC,YAAY,CAAC,YAAY;AAAE,QAAA,MAAM,IAAI,K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AY,IAAI,EAAE,CAAC;;AAG/E,IAAA,OAAO,kBAAkB;AAC7B;;;;"}
1
+ {"version":3,"file":"utils.mjs","sources":["../src/utils.ts"],"sourcesContent":["import {\n createConnection,\n Types,\n} from 'mongoose';\nimport type {\n mongo,\n Schema,\n} from 'mongoose';\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';\nimport mongoosePaginate from 'mongoose-paginate-v2';\n\nimport { customMongooseOptions } from './_internals';\nimport { mongooseConnections } from './constants';\nimport type { setCustomMongooseOptions } from './options';\nimport { mongooseNormalizePlugin } from './plugins/normalize';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;\n\n/**\n * Asserts that a Mongoose update operation was successful by checking that it was acknowledged\n * and that at least the expected number of documents were modified.\n *\n * This function is intended for use with `updateOne`, `updateMany`, or any update operation\n * that returns a MongoDB `UpdateResult`.\n *\n * @template T - The shape of the document being updated.\n * @param updatePromise - A promise returned from a Mongoose update operation.\n * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.\n * @throws Will throw an error if:\n * - The operation was not acknowledged by MongoDB,\n * - Fewer documents were modified than expected.\n */\nexport async function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(\n updatePromise: Promise<mongo.UpdateResult<T>>,\n expectedModifiedCount = 1,\n) {\n const updateResult = await updatePromise;\n if (!updateResult.acknowledged) throw new Error('Update was not acknowledged.');\n if (updateResult.modifiedCount < expectedModifiedCount) {\n // eslint-disable-next-line style/max-len\n throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}.`);\n }\n}\n\n/**\n * Builds and returns a Mongoose model with specified schema and options.\n *\n * This function sets up a Mongoose model with optional plugins and timestamp settings.\n * It can optionally use a specified connection or the default connection.\n *\n * Determine the connection to use:\n * 1. Use the connection provided in the options, if available.\n * 2. Otherwise, use the default connection stored in `mongooseConnections`.\n * 3. If there's no default connection, create one using the MongoDB URI from the environment variables,\n * or fallback to a local MongoDB instance.\n *\n * You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.\n * However, ensure that this option is configured before calling {@link buildMongooseModel}.\n *\n * @template DocType - The type of the document.\n * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param collection - The name of the collection.\n * @param name - The name of the model.\n * @param schema - The Mongoose schema to use for the model.\n * @param options - Optional settings for building the model.\n *\n * @returns The created Mongoose model.\n */\nexport function buildMongooseModel<\n DocType,\n Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n collection: string,\n name: string,\n schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n options?: BuildMongooseModelOptions,\n) {\n if (options?.enableNormalizePlugin !== false) schema.plugin(mongooseNormalizePlugin);\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n // eslint-disable-next-line style/max-len\n const connection = options?.connection || (mongooseConnections.default ||= createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\n\n/**\n * Converts a document or ObjectId to a document using the specified model.\n *\n * This function takes a document or ObjectId and returns the corresponding document\n * from the database using the specified model. Optionally, specific fields can be selected.\n *\n * @template D - The type of the hydrated document.\n * @template DocType - The type of the document.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param documentOrObjectId - The document or ObjectId to convert.\n * @param model - The Mongoose model to use for the conversion.\n * @param selectFields - Optional fields to select from the document.\n *\n * @returns The corresponding document or null if not found.\n */\nexport async function mongooseDocumentOrObjectIdToDocument<\n D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n DocType,\n InstanceMethodsAndOverrides,\n QueryHelpers,\n>(\n documentOrObjectId: MongooseDocumentOrObjectId<D>,\n model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n selectFields?: string[],\n) {\n if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {\n return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n }\n\n return documentOrObjectId;\n}\n"],"names":[],"mappings":";;;;;;;AAmBA;;;;;;;;;;;;;AAaG;AACI,eAAe,2BAA2B,CAC7C,aAA6C,EAC7C,qBAAqB,GAAG,CAAC,EAAA;AAEzB,IAAA,MAAM,YAAY,GAAG,MAAM,aAAa;IACxC,IAAI,CAAC,YAAY,CAAC,YAAY;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;AAC/E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAqB,EAAE;;QAEpD,MAAM,IAAI,KAAK,CAAC,CAA+B,4BAAA,EAAA,qBAAqB,CAA8B,2BAAA,EAAA,YAAY,CAAC,aAAa,CAAG,CAAA,CAAA,CAAC;;AAExI;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,kBAAkB,CAM9B,UAAkB,EAClB,IAAY,EACZ,MAAyE,EACzE,OAAmC,EAAA;AAEnC,IAAA,IAAI,OAAO,EAAE,qBAAqB,KAAK,KAAK;AAAE,QAAA,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC;AACpF,IAAA,MAAM,CAAC,MAAM,CAAC,yBAAyB,CAAC;AACxC,IAAA,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;AAC/B,IAAA,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,UAAU,IAAI,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC;AACjF,IAAA,qBAAqB,CAAC,gBAAgB,GAAG,MAAM,CAAC;;IAEhD,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,KAAK,mBAAmB,CAAC,OAAO,KAAK,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,2BAA2B,CAAC,CAAC;IACpJ,OAAO,UAAU,CAAC,KAAK,CAA+B,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC;AACnF;AAEA;;;;;;;;;;;;;;;;AAgBG;AACI,eAAe,oCAAoC,CAMtD,kBAAiD,EACjD,KAAoF,EACpF,YAAuB,EAAA;IAEvB,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,YAAY,KAAK,CAAC,QAAQ,EAAE;AACxF,QAAA,QAAQ,MAAM,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;;AAG/E,IAAA,OAAO,kBAAkB;AAC7B;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.",
5
5
  "author": "kiki-kanri",
6
6
  "license": "MIT",
@@ -18,6 +18,7 @@
18
18
  "plugin",
19
19
  "schema"
20
20
  ],
21
+ "sideEffects": false,
21
22
  "exports": {
22
23
  "./*": {
23
24
  "types": "./dist/*.d.ts",
@@ -73,8 +74,7 @@
73
74
  "@types/node": "^22.14.0",
74
75
  "jest": "^29.7.0",
75
76
  "ts-jest": "^29.3.1",
76
- "ts-project-builder": "^4.0.0",
77
- "tslib": "^2.8.1"
77
+ "ts-project-builder": "^4.0.0"
78
78
  },
79
79
  "pnpm": {
80
80
  "onlyBuiltDependencies": [
@@ -1,6 +1,6 @@
1
- import lodashGet from 'lodash/get';
2
- import lodashSet from 'lodash/set';
3
- import lodashUnset from 'lodash/unset';
1
+ import lodashGet from 'lodash/get.js';
2
+ import lodashSet from 'lodash/set.js';
3
+ import lodashUnset from 'lodash/unset.js';
4
4
  import type {
5
5
  Schema,
6
6
  Types,
@@ -1,4 +1,4 @@
1
- import Decimal from 'decimal.js';
1
+ import { Decimal } from 'decimal.js';
2
2
  import { Schema } from 'mongoose';
3
3
  import type {
4
4
  DefaultType,
@@ -1,4 +1,7 @@
1
- import net from 'node:net';
1
+ import {
2
+ isIPv4,
3
+ isIPv6,
4
+ } from 'node:net';
2
5
 
3
6
  import type {
4
7
  DefaultType,
@@ -148,7 +151,7 @@ export function stringSchemaBuilder() {
148
151
  schema.trim = true;
149
152
  schema.validate = {
150
153
  message,
151
- validator: (value: string) => net.isIPv4(value),
154
+ validator: (value: string) => isIPv4(value),
152
155
  };
153
156
 
154
157
  return receiver;
@@ -160,7 +163,7 @@ export function stringSchemaBuilder() {
160
163
  schema.trim = true;
161
164
  schema.validate = {
162
165
  message,
163
- validator: (value: string) => net.isIPv6(value),
166
+ validator: (value: string) => isIPv6(value),
164
167
  };
165
168
 
166
169
  return receiver;
package/src/types/data.ts CHANGED
@@ -1,61 +1,19 @@
1
1
  import type { IfElse } from './utils';
2
2
 
3
- /**
4
- * Interface for the base data of a Mongoose model, optionally including timestamp fields.
5
- *
6
- * This interface extends `LocalWithTimestampFieldsData` to optionally include `createdAt`
7
- * and `updatedAt` fields based on the `CreatedAtField` and `UpdatedAtField` flags.
8
- * It also includes a mandatory `id` field.
9
- *
10
- * @template CreatedAtField - A boolean flag indicating whether the `createdAt` field should be included.
11
- * @template UpdatedAtField - A boolean flag indicating whether the `updatedAt` field should be included.
12
- */
13
- interface LocalBaseMongooseModelData<
14
- CreatedAtField extends boolean = true,
15
- UpdatedAtField extends boolean = true,
16
- > extends LocalWithTimestampFieldsData<CreatedAtField, UpdatedAtField> {
17
- id: string;
18
- }
19
-
20
- /**
21
- * Interface for including timestamp fields conditionally based on the provided flags.
22
- *
23
- * This interface conditionally includes `createdAt` and `updatedAt` fields based on
24
- * the `CreatedAt` and `UpdatedAt` boolean flags. If the flag is true, the respective
25
- * field is included, otherwise it is set to `never`.
26
- *
27
- * @template CreatedAt - A boolean flag indicating whether the `createdAt` field should be included.
28
- * @template UpdatedAt - A boolean flag indicating whether the `updatedAt` field should be included.
29
- */
30
- interface LocalWithTimestampFieldsData<CreatedAt extends boolean = true, UpdatedAt extends boolean = true> {
31
- createdAt: IfElse<CreatedAt, string, never>;
32
- updatedAt: IfElse<UpdatedAt, string, never>;
33
- }
34
-
35
- /**
36
- * Utility type to omit properties that are set to `never` in a given type.
37
- *
38
- * This type alias iterates over the properties of a given type `T` and removes any
39
- * properties that are set to `never`.
40
- *
41
- * @template T - The type from which to omit `never` properties.
42
- */
43
- type OmitNever<T> = { [P in keyof T as IfElse<T[P], never, P, never>]: T[P] };
44
-
45
3
  declare global {
46
4
  /**
47
5
  * Type definition for the base data of a Mongoose model, optionally including timestamp fields.
48
6
  *
49
- * This type alias uses `OmitNever` to remove any `never` properties from `LocalBaseMongooseModelData`
50
- * based on the presence of the `CreatedAtField` and `UpdatedAtField` flags.
51
- *
52
7
  * @template CreatedAtField - A boolean flag indicating whether the `createdAt` field should be included.
53
8
  * @template UpdatedAtField - A boolean flag indicating whether the `updatedAt` field should be included.
54
9
  */
55
10
  type BaseMongooseModelData<
56
11
  CreatedAtField extends boolean = true,
57
12
  UpdatedAtField extends boolean = true,
58
- > = OmitNever<LocalBaseMongooseModelData<CreatedAtField, UpdatedAtField>>;
13
+ > =
14
+ & IfElse<CreatedAtField, { createdAt: string }, unknown>
15
+ & IfElse<UpdatedAtField, { updatedAt: string }, unknown>
16
+ & { id: string };
59
17
 
60
18
  /**
61
19
  * Type definition to omit timestamp fields (`createdAt`, `updatedAt`)
@@ -84,16 +42,13 @@ declare global {
84
42
  /**
85
43
  * Type definition for including timestamp fields conditionally based on the provided flags.
86
44
  *
87
- * This type alias uses `OmitNever` to remove any `never` properties from `LocalWithTimestampFieldsData`
88
- * based on the presence of the `CreatedAt` and `UpdatedAt` flags.
89
- *
90
45
  * @template CreatedAt - A boolean flag indicating whether the `createdAt` field should be included.
91
46
  * @template UpdatedAt - A boolean flag indicating whether the `updatedAt` field should be included.
92
47
  */
93
48
  type WithMongooseTimestampFieldsData<
94
49
  CreatedAt extends boolean = true,
95
50
  UpdatedAt extends boolean = true,
96
- > = OmitNever<LocalWithTimestampFieldsData<CreatedAt, UpdatedAt>>;
51
+ > =
52
+ & IfElse<CreatedAt, { createdAt: string }, object>
53
+ & IfElse<UpdatedAt, { updatedAt: string }, object>;
97
54
  }
98
-
99
- export {};
@@ -37,8 +37,8 @@ declare global {
37
37
  CreatedAtField extends boolean = true,
38
38
  UpdatedAtField extends boolean = true,
39
39
  > =
40
- & IfElse<CreatedAtField, { createdAt: Date }, object>
41
- & IfElse<UpdatedAtField, { updatedAt: Date }, object>
40
+ & IfElse<CreatedAtField, { createdAt: Date }, unknown>
41
+ & IfElse<UpdatedAtField, { updatedAt: Date }, unknown>
42
42
  & Omit<T, 'createdAt' | 'id' | 'updatedAt'>;
43
43
 
44
44
  /**
package/src/utils.ts CHANGED
@@ -1,5 +1,11 @@
1
- import type { mongo } from 'mongoose';
2
- import mongoose, { Types } from 'mongoose';
1
+ import {
2
+ createConnection,
3
+ Types,
4
+ } from 'mongoose';
5
+ import type {
6
+ mongo,
7
+ Schema,
8
+ } from 'mongoose';
3
9
  import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
4
10
  import mongoosePaginate from 'mongoose-paginate-v2';
5
11
 
@@ -72,7 +78,7 @@ export function buildMongooseModel<
72
78
  >(
73
79
  collection: string,
74
80
  name: string,
75
- schema: mongoose.Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,
81
+ schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,
76
82
  options?: BuildMongooseModelOptions,
77
83
  ) {
78
84
  if (options?.enableNormalizePlugin !== false) schema.plugin(mongooseNormalizePlugin);
@@ -81,7 +87,7 @@ export function buildMongooseModel<
81
87
  schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);
82
88
  customMongooseOptions.beforeModelBuild?.(schema);
83
89
  // eslint-disable-next-line style/max-len
84
- const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));
90
+ const connection = options?.connection || (mongooseConnections.default ||= createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));
85
91
  return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);
86
92
  }
87
93
 
@@ -111,7 +117,7 @@ export async function mongooseDocumentOrObjectIdToDocument<
111
117
  documentOrObjectId: MongooseDocumentOrObjectId<D>,
112
118
  model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,
113
119
  selectFields?: string[],
114
- ): Promise<D | null> {
120
+ ) {
115
121
  if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {
116
122
  return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;
117
123
  }