@kikiutils/mongoose 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/options.cjs.map +1 -1
- package/dist/options.mjs.map +1 -1
- package/dist/plugins/normalize.cjs.map +1 -1
- package/dist/plugins/normalize.mjs.map +1 -1
- package/dist/schema-builders/base.cjs.map +1 -1
- package/dist/schema-builders/base.mjs.map +1 -1
- package/dist/schema-builders/decimal128.cjs.map +1 -1
- package/dist/schema-builders/decimal128.mjs.map +1 -1
- package/dist/schema-builders/number.cjs.map +1 -1
- package/dist/schema-builders/number.d.ts.map +1 -1
- package/dist/schema-builders/number.mjs.map +1 -1
- package/dist/schema-builders/string.cjs +2 -2
- package/dist/schema-builders/string.cjs.map +1 -1
- package/dist/schema-builders/string.d.ts +2 -2
- package/dist/schema-builders/string.d.ts.map +1 -1
- package/dist/schema-builders/string.mjs +2 -2
- package/dist/schema-builders/string.mjs.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils.cjs +2 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.mjs +2 -2
- package/dist/utils.mjs.map +1 -1
- package/package.json +14 -10
- package/src/plugins/normalize.ts +1 -1
- package/src/schema-builders/number.ts +4 -3
- package/src/schema-builders/string.ts +2 -2
- package/src/types/index.ts +3 -0
- package/src/utils.ts +2 -2
package/dist/options.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.cjs","sources":["../src/options.ts"],"sourcesContent":["import { customMongooseOptions } from './_internals';\nimport type { CustomMongooseOptions } from './types/options';\nimport type { buildMongooseModel } from './utils';\n\nexport type DoNotRemoveOrUseThisType = typeof buildMongooseModel;\n\n/**\n * Sets custom options.\n *\n * For example, you can set {@link CustomMongooseOptions.beforeModelBuild} to define a function that will be called\n * every time {@link buildMongooseModel} is used. Inside this function, you can modify\n * the schema, allowing you to apply common settings to all global schemas.\n */\nexport function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(\n key: K,\n value: CustomMongooseOptions[K],\n) {\n return customMongooseOptions[key] = value;\n}\n"],"names":["customMongooseOptions"],"mappings":";;;;AAMA;;;;;;AAMG;
|
|
1
|
+
{"version":3,"file":"options.cjs","sources":["../src/options.ts"],"sourcesContent":["import { customMongooseOptions } from './_internals';\nimport type { CustomMongooseOptions } from './types/options';\nimport type { buildMongooseModel } from './utils';\n\nexport type DoNotRemoveOrUseThisType = typeof buildMongooseModel;\n\n/**\n * Sets custom options.\n *\n * For example, you can set {@link CustomMongooseOptions.beforeModelBuild} to define a function that will be called\n * every time {@link buildMongooseModel} is used. Inside this function, you can modify\n * the schema, allowing you to apply common settings to all global schemas.\n */\nexport function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(\n key: K,\n value: CustomMongooseOptions[K],\n) {\n return customMongooseOptions[key] = value;\n}\n"],"names":["customMongooseOptions"],"mappings":";;;;AAMA;;;;;;AAMG;AACG,SAAU,wBAAwB,CACpC,GAAM,EACN,KAA+B,EAAA;AAE/B,IAAA,OAAOA,gCAAqB,CAAC,GAAG,CAAC,GAAG,KAAK;AAC7C;;;;"}
|
package/dist/options.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.mjs","sources":["../src/options.ts"],"sourcesContent":["import { customMongooseOptions } from './_internals';\nimport type { CustomMongooseOptions } from './types/options';\nimport type { buildMongooseModel } from './utils';\n\nexport type DoNotRemoveOrUseThisType = typeof buildMongooseModel;\n\n/**\n * Sets custom options.\n *\n * For example, you can set {@link CustomMongooseOptions.beforeModelBuild} to define a function that will be called\n * every time {@link buildMongooseModel} is used. Inside this function, you can modify\n * the schema, allowing you to apply common settings to all global schemas.\n */\nexport function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(\n key: K,\n value: CustomMongooseOptions[K],\n) {\n return customMongooseOptions[key] = value;\n}\n"],"names":[],"mappings":";;AAMA;;;;;;AAMG;
|
|
1
|
+
{"version":3,"file":"options.mjs","sources":["../src/options.ts"],"sourcesContent":["import { customMongooseOptions } from './_internals';\nimport type { CustomMongooseOptions } from './types/options';\nimport type { buildMongooseModel } from './utils';\n\nexport type DoNotRemoveOrUseThisType = typeof buildMongooseModel;\n\n/**\n * Sets custom options.\n *\n * For example, you can set {@link CustomMongooseOptions.beforeModelBuild} to define a function that will be called\n * every time {@link buildMongooseModel} is used. Inside this function, you can modify\n * the schema, allowing you to apply common settings to all global schemas.\n */\nexport function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(\n key: K,\n value: CustomMongooseOptions[K],\n) {\n return customMongooseOptions[key] = value;\n}\n"],"names":[],"mappings":";;AAMA;;;;;;AAMG;AACG,SAAU,wBAAwB,CACpC,GAAM,EACN,KAA+B,EAAA;AAE/B,IAAA,OAAO,qBAAqB,CAAC,GAAG,CAAC,GAAG,KAAK;AAC7C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.cjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["// @ts-expect-error Ignore this error.\nimport lodashGet from 'lodash/get.js';\n// @ts-expect-error Ignore this error.\nimport lodashSet from 'lodash/set.js';\n// @ts-expect-error Ignore this error.\nimport lodashUnset from 'lodash/unset.js';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // eslint-disable-next-line style/object-curly-newline\n let { __v, _id, ...copiedRet } = ret;\n if (pluginOptions?.toHexIdIfObjectId !== false) {\n _id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;\n }\n\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _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 if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc, copiedRet, options);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":["Types","lodashUnset","lodashGet","lodashSet"],"mappings":";;;;;;;;;;;;;AAAA;AA0BA;;;;;;;;;;;;;AAaG;
|
|
1
|
+
{"version":3,"file":"normalize.cjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["// @ts-expect-error Ignore this error.\nimport lodashGet from 'lodash/get.js';\n// @ts-expect-error Ignore this error.\nimport lodashSet from 'lodash/set.js';\n// @ts-expect-error Ignore this error.\nimport lodashUnset from 'lodash/unset.js';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // eslint-disable-next-line style/object-curly-newline\n let { __v, _id, ...copiedRet } = ret;\n if (pluginOptions?.toHexIdIfObjectId !== false) {\n _id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;\n }\n\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _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 if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc as any, copiedRet as any, options as any);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":["Types","lodashUnset","lodashGet","lodashSet"],"mappings":";;;;;;;;;;;;;AAAA;AA0BA;;;;;;;;;;;;;AAaG;AACG,SAAU,uBAAuB,CAAmB,MAAS,EAAE,aAA8C,EAAA;IAC/G,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,GAAG,EAAE,GAAG,EAAE,OAAO,EAAA;;YAEvB,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,GAAG;AACpC,YAAA,IAAI,aAAa,EAAE,iBAAiB,KAAK,KAAK,EAAE;AAC5C,gBAAA,GAAG,GAAG,GAAG,YAAYA,cAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,GAAG,GAAG;YACjE;AAEA,YAAA,IAAI,aAAa,EAAE,cAAc,KAAK,KAAK;AAAE,gBAAA,SAAS,CAAC,EAAE,GAAG,GAAG;;AAC1D,gBAAA,SAAS,CAAC,GAAG,GAAG,GAAG;AACxB,YAAA,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;gBAC7B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO;AAAE,oBAAAC,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;gBAC3D;YACJ;AAEA,YAAA,IAAI,eAAe,IAAI,OAAO,eAAe,KAAK,SAAS,EAAE;gBACzD,OAAO,eAAe,CAAC,GAAU,EAAE,SAAgB,EAAE,OAAc,CAAC;YACxE;AAEA,YAAA,OAAO,SAAS;QACpB,CAAC;AACJ,KAAA,CACJ;AACL;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.mjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["// @ts-expect-error Ignore this error.\nimport lodashGet from 'lodash/get.js';\n// @ts-expect-error Ignore this error.\nimport lodashSet from 'lodash/set.js';\n// @ts-expect-error Ignore this error.\nimport lodashUnset from 'lodash/unset.js';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // eslint-disable-next-line style/object-curly-newline\n let { __v, _id, ...copiedRet } = ret;\n if (pluginOptions?.toHexIdIfObjectId !== false) {\n _id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;\n }\n\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _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 if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc, copiedRet, options);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":[],"mappings":";;;;;AAAA;AA0BA;;;;;;;;;;;;;AAaG;
|
|
1
|
+
{"version":3,"file":"normalize.mjs","sources":["../../src/plugins/normalize.ts"],"sourcesContent":["// @ts-expect-error Ignore this error.\nimport lodashGet from 'lodash/get.js';\n// @ts-expect-error Ignore this error.\nimport lodashSet from 'lodash/set.js';\n// @ts-expect-error Ignore this error.\nimport lodashUnset from 'lodash/unset.js';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions) {\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // eslint-disable-next-line style/object-curly-newline\n let { __v, _id, ...copiedRet } = ret;\n if (pluginOptions?.toHexIdIfObjectId !== false) {\n _id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;\n }\n\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _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 if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc as any, copiedRet as any, options as any);\n }\n\n return copiedRet;\n },\n },\n );\n}\n"],"names":[],"mappings":";;;;;AAAA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E,SAAgB,EAAE,OAAc,CAAC;YACxE;AAEA,YAAA,OAAO,SAAS;QACpB,CAAC;AACJ,KAAA,CACJ;AACL;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.cjs","sources":["../../src/schema-builders/base.ts"],"sourcesContent":["import type { Schema } from 'mongoose';\n\ntype BaseSchemaType =\n | BooleanConstructor\n | DateConstructor\n | NumberConstructor\n | Schema.Types.ObjectId['constructor']\n | StringConstructor;\n\nconst isFunctionKeys = new Set([\n 'default',\n 'enum',\n 'index',\n 'max',\n 'maxlength',\n 'min',\n 'minlength',\n]);\n\nexport function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType) {\n return (schema: Record<string, any> = {}) => {\n schema.type = type;\n return new Proxy(\n Object.freeze({}),\n {\n get(_, key, receiver) {\n if (typeof key === 'symbol') throw new Error('Cannot use symbol as a schema attribute');\n if (key in schema) throw new Error(`Duplicate schema attribute: ${key}`);\n if (isFunctionKeys.has(key)) {\n return (value: any) => {\n schema[key] = value;\n return receiver;\n };\n }\n\n if (key === 'nonRequired') return { ...schema };\n if (key === 'required') {\n return {\n ...schema,\n required: true,\n };\n }\n\n schema[key] = true;\n return receiver;\n },\n },\n ) as Builder;\n };\n}\n"],"names":[],"mappings":";;AASA,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC3B,SAAS;IACT,MAAM;IACN,OAAO;IACP,KAAK;IACL,WAAW;IACX,KAAK;IACL,WAAW;AACd,CAAA,CAAC;AAEI,SAAU,8BAA8B,CAA0C,IAAoB,EAAA;AACxG,IAAA,OAAO,CAAC,MAAA,GAA8B,EAAE,KAAI;AACxC,QAAA,MAAM,CAAC,IAAI,GAAG,IAAI;QAClB,OAAO,IAAI,KAAK,CACZ,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EACjB;AACI,YAAA,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAA;gBAChB,IAAI,OAAO,GAAG,KAAK,QAAQ;AAAE,oBAAA,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC;gBACvF,IAAI,GAAG,IAAI,MAAM;AAAE,oBAAA,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,CAAA,CAAE,CAAC;AACxE,gBAAA,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;oBACzB,OAAO,CAAC,KAAU,KAAI;AAClB,wBAAA,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK;AACnB,wBAAA,OAAO,QAAQ;AACnB,
|
|
1
|
+
{"version":3,"file":"base.cjs","sources":["../../src/schema-builders/base.ts"],"sourcesContent":["import type { Schema } from 'mongoose';\n\ntype BaseSchemaType =\n | BooleanConstructor\n | DateConstructor\n | NumberConstructor\n | Schema.Types.ObjectId['constructor']\n | StringConstructor;\n\nconst isFunctionKeys = new Set([\n 'default',\n 'enum',\n 'index',\n 'max',\n 'maxlength',\n 'min',\n 'minlength',\n]);\n\nexport function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType) {\n return (schema: Record<string, any> = {}) => {\n schema.type = type;\n return new Proxy(\n Object.freeze({}),\n {\n get(_, key, receiver) {\n if (typeof key === 'symbol') throw new Error('Cannot use symbol as a schema attribute');\n if (key in schema) throw new Error(`Duplicate schema attribute: ${key}`);\n if (isFunctionKeys.has(key)) {\n return (value: any) => {\n schema[key] = value;\n return receiver;\n };\n }\n\n if (key === 'nonRequired') return { ...schema };\n if (key === 'required') {\n return {\n ...schema,\n required: true,\n };\n }\n\n schema[key] = true;\n return receiver;\n },\n },\n ) as Builder;\n };\n}\n"],"names":[],"mappings":";;AASA,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC3B,SAAS;IACT,MAAM;IACN,OAAO;IACP,KAAK;IACL,WAAW;IACX,KAAK;IACL,WAAW;AACd,CAAA,CAAC;AAEI,SAAU,8BAA8B,CAA0C,IAAoB,EAAA;AACxG,IAAA,OAAO,CAAC,MAAA,GAA8B,EAAE,KAAI;AACxC,QAAA,MAAM,CAAC,IAAI,GAAG,IAAI;QAClB,OAAO,IAAI,KAAK,CACZ,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EACjB;AACI,YAAA,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAA;gBAChB,IAAI,OAAO,GAAG,KAAK,QAAQ;AAAE,oBAAA,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC;gBACvF,IAAI,GAAG,IAAI,MAAM;AAAE,oBAAA,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,CAAA,CAAE,CAAC;AACxE,gBAAA,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;oBACzB,OAAO,CAAC,KAAU,KAAI;AAClB,wBAAA,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK;AACnB,wBAAA,OAAO,QAAQ;AACnB,oBAAA,CAAC;gBACL;gBAEA,IAAI,GAAG,KAAK,aAAa;AAAE,oBAAA,OAAO,EAAE,GAAG,MAAM,EAAE;AAC/C,gBAAA,IAAI,GAAG,KAAK,UAAU,EAAE;oBACpB,OAAO;AACH,wBAAA,GAAG,MAAM;AACT,wBAAA,QAAQ,EAAE,IAAI;qBACjB;gBACL;AAEA,gBAAA,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI;AAClB,gBAAA,OAAO,QAAQ;YACnB,CAAC;AACJ,SAAA,CACO;AAChB,IAAA,CAAC;AACL;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.mjs","sources":["../../src/schema-builders/base.ts"],"sourcesContent":["import type { Schema } from 'mongoose';\n\ntype BaseSchemaType =\n | BooleanConstructor\n | DateConstructor\n | NumberConstructor\n | Schema.Types.ObjectId['constructor']\n | StringConstructor;\n\nconst isFunctionKeys = new Set([\n 'default',\n 'enum',\n 'index',\n 'max',\n 'maxlength',\n 'min',\n 'minlength',\n]);\n\nexport function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType) {\n return (schema: Record<string, any> = {}) => {\n schema.type = type;\n return new Proxy(\n Object.freeze({}),\n {\n get(_, key, receiver) {\n if (typeof key === 'symbol') throw new Error('Cannot use symbol as a schema attribute');\n if (key in schema) throw new Error(`Duplicate schema attribute: ${key}`);\n if (isFunctionKeys.has(key)) {\n return (value: any) => {\n schema[key] = value;\n return receiver;\n };\n }\n\n if (key === 'nonRequired') return { ...schema };\n if (key === 'required') {\n return {\n ...schema,\n required: true,\n };\n }\n\n schema[key] = true;\n return receiver;\n },\n },\n ) as Builder;\n };\n}\n"],"names":[],"mappings":"AASA,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC3B,SAAS;IACT,MAAM;IACN,OAAO;IACP,KAAK;IACL,WAAW;IACX,KAAK;IACL,WAAW;AACd,CAAA,CAAC;AAEI,SAAU,8BAA8B,CAA0C,IAAoB,EAAA;AACxG,IAAA,OAAO,CAAC,MAAA,GAA8B,EAAE,KAAI;AACxC,QAAA,MAAM,CAAC,IAAI,GAAG,IAAI;QAClB,OAAO,IAAI,KAAK,CACZ,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EACjB;AACI,YAAA,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAA;gBAChB,IAAI,OAAO,GAAG,KAAK,QAAQ;AAAE,oBAAA,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC;gBACvF,IAAI,GAAG,IAAI,MAAM;AAAE,oBAAA,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,CAAA,CAAE,CAAC;AACxE,gBAAA,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;oBACzB,OAAO,CAAC,KAAU,KAAI;AAClB,wBAAA,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK;AACnB,wBAAA,OAAO,QAAQ;AACnB,
|
|
1
|
+
{"version":3,"file":"base.mjs","sources":["../../src/schema-builders/base.ts"],"sourcesContent":["import type { Schema } from 'mongoose';\n\ntype BaseSchemaType =\n | BooleanConstructor\n | DateConstructor\n | NumberConstructor\n | Schema.Types.ObjectId['constructor']\n | StringConstructor;\n\nconst isFunctionKeys = new Set([\n 'default',\n 'enum',\n 'index',\n 'max',\n 'maxlength',\n 'min',\n 'minlength',\n]);\n\nexport function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType) {\n return (schema: Record<string, any> = {}) => {\n schema.type = type;\n return new Proxy(\n Object.freeze({}),\n {\n get(_, key, receiver) {\n if (typeof key === 'symbol') throw new Error('Cannot use symbol as a schema attribute');\n if (key in schema) throw new Error(`Duplicate schema attribute: ${key}`);\n if (isFunctionKeys.has(key)) {\n return (value: any) => {\n schema[key] = value;\n return receiver;\n };\n }\n\n if (key === 'nonRequired') return { ...schema };\n if (key === 'required') {\n return {\n ...schema,\n required: true,\n };\n }\n\n schema[key] = true;\n return receiver;\n },\n },\n ) as Builder;\n };\n}\n"],"names":[],"mappings":"AASA,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC3B,SAAS;IACT,MAAM;IACN,OAAO;IACP,KAAK;IACL,WAAW;IACX,KAAK;IACL,WAAW;AACd,CAAA,CAAC;AAEI,SAAU,8BAA8B,CAA0C,IAAoB,EAAA;AACxG,IAAA,OAAO,CAAC,MAAA,GAA8B,EAAE,KAAI;AACxC,QAAA,MAAM,CAAC,IAAI,GAAG,IAAI;QAClB,OAAO,IAAI,KAAK,CACZ,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EACjB;AACI,YAAA,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAA;gBAChB,IAAI,OAAO,GAAG,KAAK,QAAQ;AAAE,oBAAA,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC;gBACvF,IAAI,GAAG,IAAI,MAAM;AAAE,oBAAA,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,CAAA,CAAE,CAAC;AACxE,gBAAA,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;oBACzB,OAAO,CAAC,KAAU,KAAI;AAClB,wBAAA,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK;AACnB,wBAAA,OAAO,QAAQ;AACnB,oBAAA,CAAC;gBACL;gBAEA,IAAI,GAAG,KAAK,aAAa;AAAE,oBAAA,OAAO,EAAE,GAAG,MAAM,EAAE;AAC/C,gBAAA,IAAI,GAAG,KAAK,UAAU,EAAE;oBACpB,OAAO;AACH,wBAAA,GAAG,MAAM;AACT,wBAAA,QAAQ,EAAE,IAAI;qBACjB;gBACL;AAEA,gBAAA,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI;AAClB,gBAAA,OAAO,QAAQ;YACnB,CAAC;AACJ,SAAA,CACO;AAChB,IAAA,CAAC;AACL;;;;"}
|
|
@@ -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\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\ninterface ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string;\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,
|
|
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\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\ninterface ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string;\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,oBAAA,CAAC;AAED,oBAAA,OAAO,QAAQ;AACnB,gBAAA,CAAC;YACL;AAEA,YAAA,IAAI,GAAG,KAAK,mBAAmB,EAAE;AAC7B,gBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAwB,KAAK,KAAK,EAAE,QAAQ,EAAE;AAC5D,gBAAA,OAAO,QAAQ;YACnB;YAEA,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;QAC7C,CAAC;AACJ,KAAA,CACuB;AAChC;;;;"}
|
|
@@ -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\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\ninterface ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string;\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,
|
|
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\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\ninterface ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string;\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,oBAAA,CAAC;AAED,oBAAA,OAAO,QAAQ;AACnB,gBAAA,CAAC;YACL;AAEA,YAAA,IAAI,GAAG,KAAK,mBAAmB,EAAE;AAC7B,gBAAA,MAAM,CAAC,GAAG,GAAG,CAAC,KAAwB,KAAK,KAAK,EAAE,QAAQ,EAAE;AAC5D,gBAAA,OAAO,QAAQ;YACnB;YAEA,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;QAC7C,CAAC;AACJ,KAAA,CACuB;AAChC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.cjs","sources":["../../src/schema-builders/number.ts"],"sourcesContent":["import type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n NumberSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendNumberSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n NumberSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: NumberSchemaDefinition;\n}\n\nexport interface NumberSchemaBuilder<\n Props extends { type: NumberSchemaDefinition } = { type: NumberSchemaDefinition },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends number,\n >(value: T) => ExtendNumberSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<N | null>>\n | { [path: string]: N | null }\n | { message?: M; values: Readonlyable<Array<N | null>> },\n M extends string,\n N extends number,\n >(
|
|
1
|
+
{"version":3,"file":"number.cjs","sources":["../../src/schema-builders/number.ts"],"sourcesContent":["import type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n NumberSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendNumberSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n NumberSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: NumberSchemaDefinition;\n}\n\nexport interface NumberSchemaBuilder<\n Props extends { type: NumberSchemaDefinition } = { type: NumberSchemaDefinition },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends number,\n >(value: T) => ExtendNumberSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<N | null>>\n | { [path: string]: N | null }\n | { message?: M; values: Readonlyable<Array<N | null>> },\n M extends string,\n N extends number,\n >(value: T) => ExtendNumberSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendNumberSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n max: <\n T extends N | Readonlyable<[N, S]>,\n N extends number,\n S extends string,\n >(value: T) => ExtendNumberSchemaBuilder<\n Merge<Props, { max: T }>,\n ExtraOmitFields\n >;\n\n min: <\n T extends N | Readonlyable<[N, S]>,\n N extends number,\n S extends string,\n >(value: T) => ExtendNumberSchemaBuilder<\n Merge<Props, { min: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendNumberSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendNumberSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendNumberSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\nexport const numberSchemaBuilder = createBaseSchemaBuilderFactory<NumberSchemaBuilder>(Number);\n"],"names":["createBaseSchemaBuilderFactory"],"mappings":";;;;MA8Ea,mBAAmB,GAAGA,mCAA8B,CAAsB,MAAM;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/schema-builders/number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,WAAW,EACX,cAAc,EACd,YAAY,EACZ,sBAAsB,EACzB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAInD,MAAM,MAAM,yBAAyB,CACjC,KAAK,SAAS,SAAS,EACvB,eAAe,SAAS,MAAM,IAC9B,IAAI,CACJ,mBAAmB,CAAC,KAAK,EAAE,eAAe,CAAC,EAC3C,eAAe,GAAG,MAAM,KAAK,CAChC,CAAC;AAEF,UAAU,SAAS;IACf,IAAI,EAAE,sB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../../src/schema-builders/number.ts"],"sourcesContent":["import type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n NumberSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendNumberSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n NumberSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: NumberSchemaDefinition;\n}\n\nexport interface NumberSchemaBuilder<\n Props extends { type: NumberSchemaDefinition } = { type: NumberSchemaDefinition },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends number,\n >(value: T) => ExtendNumberSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<N | null>>\n | { [path: string]: N | null }\n | { message?: M; values: Readonlyable<Array<N | null>> },\n M extends string,\n N extends number,\n >(
|
|
1
|
+
{"version":3,"file":"number.mjs","sources":["../../src/schema-builders/number.ts"],"sourcesContent":["import type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n NumberSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendNumberSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n NumberSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: NumberSchemaDefinition;\n}\n\nexport interface NumberSchemaBuilder<\n Props extends { type: NumberSchemaDefinition } = { type: NumberSchemaDefinition },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends number,\n >(value: T) => ExtendNumberSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<N | null>>\n | { [path: string]: N | null }\n | { message?: M; values: Readonlyable<Array<N | null>> },\n M extends string,\n N extends number,\n >(value: T) => ExtendNumberSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendNumberSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n max: <\n T extends N | Readonlyable<[N, S]>,\n N extends number,\n S extends string,\n >(value: T) => ExtendNumberSchemaBuilder<\n Merge<Props, { max: T }>,\n ExtraOmitFields\n >;\n\n min: <\n T extends N | Readonlyable<[N, S]>,\n N extends number,\n S extends string,\n >(value: T) => ExtendNumberSchemaBuilder<\n Merge<Props, { min: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendNumberSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendNumberSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendNumberSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\nexport const numberSchemaBuilder = createBaseSchemaBuilderFactory<NumberSchemaBuilder>(Number);\n"],"names":[],"mappings":";;MA8Ea,mBAAmB,GAAG,8BAA8B,CAAsB,MAAM;;;;"}
|
|
@@ -4,8 +4,8 @@ const node_net = require('node:net');
|
|
|
4
4
|
const base = require('./base.cjs');
|
|
5
5
|
|
|
6
6
|
const baseBuilderFactory = base.createBaseSchemaBuilderFactory(String);
|
|
7
|
-
const defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}
|
|
8
|
-
const defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}
|
|
7
|
+
const defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`';
|
|
8
|
+
const defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`';
|
|
9
9
|
function stringSchemaBuilder() {
|
|
10
10
|
const schema = {};
|
|
11
11
|
const baseBuilder = baseBuilderFactory(schema);
|
|
@@ -1 +1 @@
|
|
|
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}
|
|
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,yDAAyD;AAC5F,MAAM,0BAA0B,GAAG,yDAAyD;SAE5E,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,gBAAA,CAAC;YACL;AAEA,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,gBAAA,CAAC;YACL;AAEA,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,gBAAA,CAAC;YACL;YAEA,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;QAC7C,CAAC;AACJ,KAAA,CACmB;AAC5B;;;;"}
|
|
@@ -95,8 +95,8 @@ export interface StringSchemaBuilder<Props extends {
|
|
|
95
95
|
uppercase: true;
|
|
96
96
|
}>, ExtraOmitFields>;
|
|
97
97
|
}
|
|
98
|
-
declare const defaultIpv4ValidateMessage = "`{VALUE}` is not a valid IPv4 address for path `{PATH}
|
|
99
|
-
declare const defaultIpv6ValidateMessage = "`{VALUE}` is not a valid IPv6 address for path `{PATH}
|
|
98
|
+
declare const defaultIpv4ValidateMessage = "`{VALUE}` is not a valid IPv4 address for path `{PATH}`";
|
|
99
|
+
declare const defaultIpv6ValidateMessage = "`{VALUE}` is not a valid IPv6 address for path `{PATH}`";
|
|
100
100
|
export declare function stringSchemaBuilder(): StringSchemaBuilder;
|
|
101
101
|
export {};
|
|
102
102
|
//# sourceMappingURL=string.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/schema-builders/string.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACR,WAAW,EACX,cAAc,EACd,YAAY,EACZ,sBAAsB,EACzB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAInD,MAAM,MAAM,yBAAyB,CACjC,KAAK,SAAS,SAAS,EACvB,eAAe,SAAS,MAAM,IAC9B,IAAI,CACJ,mBAAmB,CAAC,KAAK,EAAE,eAAe,CAAC,EAC3C,eAAe,GAAG,MAAM,KAAK,CAChC,CAAC;AAEF,UAAU,SAAS;IACf,IAAI,EAAE,sBAAsB,CAAC;CAChC;AAED,UAAU,QAAQ,CAAC,CAAC,SAAS,MAAM;IAC/B,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE;QAAE,OAAO,EAAE,CAAC,CAAC;QAAC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;KAAE,CAAC;CACnE;AAED,MAAM,WAAW,mBAAmB,CAChC,KAAK,SAAS;IAAE,IAAI,EAAE,sBAAsB,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,sBAAsB,CAAA;CAAE,EACjF,eAAe,SAAS,MAAM,GAAG,KAAK;IAEtC,OAAO,EAAE,CACL,CAAC,SAAS,CAAC,C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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,4DAA4D,CAAC;AAC7F,QAAA,MAAM,0BAA0B,4DAA4D,CAAC;AAE7F,wBAAgB,mBAAmB,IAyC1B,mBAAmB,CAC3B"}
|
|
@@ -2,8 +2,8 @@ import { isIPv4, isIPv6 } from 'node:net';
|
|
|
2
2
|
import { createBaseSchemaBuilderFactory } from './base.mjs';
|
|
3
3
|
|
|
4
4
|
const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
|
|
5
|
-
const defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}
|
|
6
|
-
const defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}
|
|
5
|
+
const defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`';
|
|
6
|
+
const defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`';
|
|
7
7
|
function stringSchemaBuilder() {
|
|
8
8
|
const schema = {};
|
|
9
9
|
const baseBuilder = baseBuilderFactory(schema);
|
|
@@ -1 +1 @@
|
|
|
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}
|
|
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,yDAAyD;AAC5F,MAAM,0BAA0B,GAAG,yDAAyD;SAE5E,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,gBAAA,CAAC;YACL;AAEA,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,gBAAA,CAAC;YACL;AAEA,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,gBAAA,CAAC;YACL;YAEA,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;QAC7C,CAAC;AACJ,KAAA,CACmB;AAC5B;;;;"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AggregatePaginateModel, Connection, HydratedDocument, PaginateModel, QueryWithHelpers, Types } from 'mongoose';
|
|
2
|
+
import type { SetFieldType } from 'type-fest';
|
|
2
3
|
import type { IfElse } from './utils';
|
|
3
4
|
export type {} from './aggregate-paginate';
|
|
4
5
|
export type {} from './paginate';
|
|
@@ -74,5 +75,6 @@ declare global {
|
|
|
74
75
|
* @template QueryHelpers - Optional type parameter for additional query helper methods.
|
|
75
76
|
*/
|
|
76
77
|
type MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides = object, QueryHelpers = object> = HydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>;
|
|
78
|
+
type SetFieldsToObjectId<T, F extends keyof T> = SetFieldType<T, F, Types.ObjectId>;
|
|
77
79
|
}
|
|
78
80
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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;
|
|
1
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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;IAEF,KAAK,mBAAmB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CACvF"}
|
package/dist/utils.cjs
CHANGED
|
@@ -30,10 +30,10 @@ const mongoosePaginate__default = /*#__PURE__*/_interopDefaultCompat(mongoosePag
|
|
|
30
30
|
async function assertMongooseUpdateSuccess(updatePromise, expectedModifiedCount = 1) {
|
|
31
31
|
const updateResult = await updatePromise;
|
|
32
32
|
if (!updateResult.acknowledged)
|
|
33
|
-
throw new Error('Update was not acknowledged
|
|
33
|
+
throw new Error('Update was not acknowledged');
|
|
34
34
|
if (updateResult.modifiedCount < expectedModifiedCount) {
|
|
35
35
|
// eslint-disable-next-line style/max-len
|
|
36
|
-
throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}
|
|
36
|
+
throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}`);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
/**
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sources":["../src/utils.ts"],"sourcesContent":["import mongoose, { Types } 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
|
|
1
|
+
{"version":3,"file":"utils.cjs","sources":["../src/utils.ts"],"sourcesContent":["import mongoose, { Types } 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) {\n schema.plugin(mongooseNormalizePlugin, options?.normalizePluginOptions);\n }\n\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) {\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":";;;;;;;;;;;;;;;AAgBA;;;;;;;;;;;;;A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D,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;IAC/E;AAEA,IAAA,OAAO,kBAAkB;AAC7B;;;;;;"}
|
package/dist/utils.mjs
CHANGED
|
@@ -22,10 +22,10 @@ import { mongooseNormalizePlugin } from './plugins/normalize.mjs';
|
|
|
22
22
|
async function assertMongooseUpdateSuccess(updatePromise, expectedModifiedCount = 1) {
|
|
23
23
|
const updateResult = await updatePromise;
|
|
24
24
|
if (!updateResult.acknowledged)
|
|
25
|
-
throw new Error('Update was not acknowledged
|
|
25
|
+
throw new Error('Update was not acknowledged');
|
|
26
26
|
if (updateResult.modifiedCount < expectedModifiedCount) {
|
|
27
27
|
// eslint-disable-next-line style/max-len
|
|
28
|
-
throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}
|
|
28
|
+
throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}`);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
/**
|
package/dist/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../src/utils.ts"],"sourcesContent":["import mongoose, { Types } 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
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../src/utils.ts"],"sourcesContent":["import mongoose, { Types } 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) {\n schema.plugin(mongooseNormalizePlugin, options?.normalizePluginOptions);\n }\n\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) {\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":";;;;;;;AAgBA;;;;;;;;;;;;;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,6BAA6B,CAAC;AAC9E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAqB,EAAE;;QAEpD,MAAM,IAAI,KAAK,CAAC,CAAA,4BAAA,EAA+B,qBAAqB,CAAA,2BAAA,EAA8B,YAAY,CAAC,aAAa,CAAA,CAAE,CAAC;IACnI;AACJ;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAA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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",
|
|
@@ -52,32 +52,36 @@
|
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "ts-project-builder './src/**/*.ts' --clean --preserve-modules --sourcemaps",
|
|
54
54
|
"bumplog": "changelogen --bump --hideAuthorEmail",
|
|
55
|
+
"depcheck": "depcheck",
|
|
55
56
|
"lint": "eslint --max-warnings 0",
|
|
56
57
|
"lint:fix": "eslint --fix --max-warnings 0",
|
|
57
58
|
"prepack": "pnpm run build",
|
|
58
59
|
"release": "pnpm run lint && pnpm run typecheck && pnpm run test && pnpm run build && changelogen --hideAuthorEmail --push --release && npm publish",
|
|
59
60
|
"test": "vitest run --coverage",
|
|
60
61
|
"test:watch": "vitest watch --coverage",
|
|
61
|
-
"typecheck": "tsc --noEmit"
|
|
62
|
+
"typecheck": "tsc --noEmit",
|
|
63
|
+
"unused-exports": "ts-unused-exports ./tsconfig.json"
|
|
62
64
|
},
|
|
63
65
|
"dependencies": {
|
|
64
|
-
"decimal.js": "^10.
|
|
66
|
+
"decimal.js": "^10.6.0",
|
|
65
67
|
"lodash": "^4.17.21",
|
|
66
|
-
"mongoose": "^8.
|
|
68
|
+
"mongoose": "^8.16.3",
|
|
67
69
|
"mongoose-aggregate-paginate-v2": "^1.1.4",
|
|
68
70
|
"mongoose-paginate-v2": "^1.9.1",
|
|
69
71
|
"type-fest": "^4.41.0"
|
|
70
72
|
},
|
|
71
73
|
"devDependencies": {
|
|
72
|
-
"@kikiutils/changelogen": "^0.8.
|
|
73
|
-
"@kikiutils/eslint-config": "^1.2.
|
|
74
|
+
"@kikiutils/changelogen": "^0.8.1",
|
|
75
|
+
"@kikiutils/eslint-config": "^1.2.7",
|
|
74
76
|
"@kikiutils/tsconfigs": "^5.0.4",
|
|
75
|
-
"@types/lodash": "^4.17.
|
|
76
|
-
"@types/node": "^
|
|
77
|
-
"@vitest/coverage-v8": "^3.2.
|
|
77
|
+
"@types/lodash": "^4.17.20",
|
|
78
|
+
"@types/node": "^24.0.14",
|
|
79
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
80
|
+
"depcheck": "^1.4.7",
|
|
78
81
|
"ts-project-builder": "^5.0.2",
|
|
82
|
+
"ts-unused-exports": "^11.0.1",
|
|
79
83
|
"typescript": "^5.8.3",
|
|
80
|
-
"vitest": "^3.2.
|
|
84
|
+
"vitest": "^3.2.4"
|
|
81
85
|
},
|
|
82
86
|
"pnpm": {
|
|
83
87
|
"onlyBuiltDependencies": [
|
package/src/plugins/normalize.ts
CHANGED
|
@@ -63,7 +63,7 @@ export function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptio
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
if (toJsonTransform && typeof toJsonTransform !== 'boolean') {
|
|
66
|
-
return toJsonTransform(doc, copiedRet, options);
|
|
66
|
+
return toJsonTransform(doc as any, copiedRet as any, options as any);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
return copiedRet;
|
|
@@ -41,9 +41,10 @@ export interface NumberSchemaBuilder<
|
|
|
41
41
|
| { message?: M; values: Readonlyable<Array<N | null>> },
|
|
42
42
|
M extends string,
|
|
43
43
|
N extends number,
|
|
44
|
-
>(
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
>(value: T) => ExtendNumberSchemaBuilder<
|
|
45
|
+
Merge<Props, { enum: T }>,
|
|
46
|
+
ExtraOmitFields
|
|
47
|
+
>;
|
|
47
48
|
|
|
48
49
|
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendNumberSchemaBuilder<
|
|
49
50
|
Merge<Props, { index: T }>,
|
|
@@ -136,8 +136,8 @@ export interface StringSchemaBuilder<
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
|
|
139
|
-
const defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}
|
|
140
|
-
const defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}
|
|
139
|
+
const defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`';
|
|
140
|
+
const defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`';
|
|
141
141
|
|
|
142
142
|
export function stringSchemaBuilder() {
|
|
143
143
|
const schema: Record<string, any> = {};
|
package/src/types/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
QueryWithHelpers,
|
|
7
7
|
Types,
|
|
8
8
|
} from 'mongoose';
|
|
9
|
+
import type { SetFieldType } from 'type-fest';
|
|
9
10
|
|
|
10
11
|
import type { IfElse } from './utils';
|
|
11
12
|
|
|
@@ -121,4 +122,6 @@ declare global {
|
|
|
121
122
|
InstanceMethodsAndOverrides,
|
|
122
123
|
QueryHelpers
|
|
123
124
|
>;
|
|
125
|
+
|
|
126
|
+
type SetFieldsToObjectId<T, F extends keyof T> = SetFieldType<T, F, Types.ObjectId>;
|
|
124
127
|
}
|
package/src/utils.ts
CHANGED
|
@@ -33,10 +33,10 @@ export async function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>
|
|
|
33
33
|
expectedModifiedCount = 1,
|
|
34
34
|
) {
|
|
35
35
|
const updateResult = await updatePromise;
|
|
36
|
-
if (!updateResult.acknowledged) throw new Error('Update was not acknowledged
|
|
36
|
+
if (!updateResult.acknowledged) throw new Error('Update was not acknowledged');
|
|
37
37
|
if (updateResult.modifiedCount < expectedModifiedCount) {
|
|
38
38
|
// eslint-disable-next-line style/max-len
|
|
39
|
-
throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}
|
|
39
|
+
throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}`);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|