@kikiutils/mongoose 2.3.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/plugins/normalize.cjs +9 -9
  2. package/dist/plugins/normalize.cjs.map +1 -1
  3. package/dist/plugins/normalize.d.ts +0 -1
  4. package/dist/plugins/normalize.d.ts.map +1 -1
  5. package/dist/plugins/normalize.mjs +4 -3
  6. package/dist/plugins/normalize.mjs.map +1 -1
  7. package/dist/schema-builders/base.d.ts.map +1 -1
  8. package/dist/schema-builders/boolean.cjs.map +1 -1
  9. package/dist/schema-builders/boolean.d.ts.map +1 -1
  10. package/dist/schema-builders/boolean.mjs.map +1 -1
  11. package/dist/schema-builders/date.cjs.map +1 -1
  12. package/dist/schema-builders/date.d.ts.map +1 -1
  13. package/dist/schema-builders/date.mjs.map +1 -1
  14. package/dist/schema-builders/decimal128.cjs.map +1 -1
  15. package/dist/schema-builders/decimal128.d.ts.map +1 -1
  16. package/dist/schema-builders/decimal128.mjs.map +1 -1
  17. package/dist/schema-builders/index.cjs +9 -13
  18. package/dist/schema-builders/index.cjs.map +1 -1
  19. package/dist/schema-builders/index.d.ts +8 -19
  20. package/dist/schema-builders/index.d.ts.map +1 -1
  21. package/dist/schema-builders/index.mjs +7 -19
  22. package/dist/schema-builders/index.mjs.map +1 -1
  23. package/dist/schema-builders/number.cjs.map +1 -1
  24. package/dist/schema-builders/number.d.ts.map +1 -1
  25. package/dist/schema-builders/number.mjs.map +1 -1
  26. package/dist/schema-builders/object-id.cjs.map +1 -1
  27. package/dist/schema-builders/object-id.d.ts.map +1 -1
  28. package/dist/schema-builders/object-id.mjs.map +1 -1
  29. package/dist/schema-builders/ref.cjs.map +1 -1
  30. package/dist/schema-builders/ref.d.ts.map +1 -1
  31. package/dist/schema-builders/ref.mjs.map +1 -1
  32. package/dist/schema-builders/string.cjs.map +1 -1
  33. package/dist/schema-builders/string.d.ts.map +1 -1
  34. package/dist/schema-builders/string.mjs.map +1 -1
  35. package/dist/types/data.d.ts.map +1 -1
  36. package/dist/types/index.d.ts.map +1 -1
  37. package/dist/types/options.d.ts.map +1 -1
  38. package/dist/utils.cjs +24 -24
  39. package/dist/utils.cjs.map +1 -1
  40. package/dist/utils.d.ts +15 -15
  41. package/dist/utils.d.ts.map +1 -1
  42. package/dist/utils.mjs +24 -24
  43. package/dist/utils.mjs.map +1 -1
  44. package/package.json +12 -7
  45. package/src/plugins/normalize.ts +3 -9
  46. package/src/schema-builders/boolean.ts +4 -1
  47. package/src/schema-builders/date.ts +4 -1
  48. package/src/schema-builders/decimal128.ts +5 -5
  49. package/src/schema-builders/index.ts +14 -20
  50. package/src/schema-builders/number.ts +4 -1
  51. package/src/schema-builders/object-id.ts +8 -4
  52. package/src/schema-builders/ref.ts +11 -7
  53. package/src/schema-builders/string.ts +8 -4
  54. package/src/types/data.ts +4 -1
  55. package/src/types/index.ts +15 -3
  56. package/src/types/options.ts +6 -1
  57. package/src/utils.ts +27 -27
@@ -1 +1 @@
1
- {"version":3,"file":"string.cjs","sources":["../../src/schema-builders/string.ts"],"sourcesContent":["import net from 'node:net';\n\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n StringSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendStringSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<StringSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;\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 >(\n value: T\n ) => ExtendStringSchemaBuilder<Merge<Props, { enum: T }>, ExtraOmitFields>;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n /**\n * Adds IPv4 validation to the string schema.\n * Ensures the string is a valid IPv4 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv4 validation message.\n *\n * @returns A schema builder with IPv4 validation and the `trim` option enabled.\n */\n ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | ExtraOmitFields\n >;\n\n /**\n * Adds IPv6 validation to the string schema.\n * Ensures the string is a valid IPv6 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv6 validation message.\n *\n * @returns A schema builder with IPv6 validation and the `trim` option enabled.\n */\n ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | ExtraOmitFields\n >;\n\n /**\n * Sets both the maximum and minimum length of the string.\n * This method ensures the string length is exactly or within a specified range.\n *\n * @param value - A number representing the exact length or an array specifying [minimum, maximum] length.\n *\n * @returns A schema builder with both `maxlength` and `minlength` options applied.\n */\n length: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendStringSchemaBuilder<Merge<Props, { lowercase: true }>, ExtraOmitFields>;\n maxlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T }>,\n ExtraOmitFields\n >;\n\n minlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { minlength: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendStringSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendStringSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n text: ExtendStringSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendStringSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendStringSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendStringSchemaBuilder<Merge<Props, { uppercase: true }>, ExtraOmitFields>;\n}\n\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(String);\nconst defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.';\nconst defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.';\n\nexport function stringSchemaBuilder() {\n const schema: Record<string, any> = {};\n const baseBuilder = baseBuilderFactory(schema);\n return new Proxy(\n baseBuilder,\n {\n get(target, key, receiver) {\n if (key === 'ipv4') {\n return (message: string = defaultIpv4ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => net.isIPv4(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'ipv6') {\n return (message: string = defaultIpv6ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => net.isIPv6(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'length') {\n return (value: any) => {\n schema.maxlength = schema.minlength = value;\n return receiver;\n };\n }\n\n return Reflect.get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OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC5C;AACJ,KAAA,CACmB;AAC5B;;;;"}
1
+ {"version":3,"file":"string.cjs","sources":["../../src/schema-builders/string.ts"],"sourcesContent":["import net from 'node:net';\n\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n StringSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendStringSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n StringSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: StringSchemaDefinition;\n}\n\ninterface IpSchema<T extends string> {\n trim: true;\n validate: { message: T; validator: (value: string) => boolean };\n}\n\nexport interface StringSchemaBuilder<\n Props extends { type: StringSchemaDefinition } = { type: StringSchemaDefinition },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<null | S>>\n | { [path: string]: null | S }\n | { message?: M; values: Readonlyable<Array<null | S>> },\n M extends string,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n /**\n * Adds IPv4 validation to the string schema.\n * Ensures the string is a valid IPv4 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv4 validation message.\n *\n * @returns A schema builder with IPv4 validation and the `trim` option enabled.\n */\n ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | ExtraOmitFields\n >;\n\n /**\n * Adds IPv6 validation to the string schema.\n * Ensures the string is a valid IPv6 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv6 validation message.\n *\n * @returns A schema builder with IPv6 validation and the `trim` option enabled.\n */\n ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | ExtraOmitFields\n >;\n\n /**\n * Sets both the maximum and minimum length of the string.\n * This method ensures the string length is exactly or within a specified range.\n *\n * @param value - A number representing the exact length or an array specifying [minimum, maximum] length.\n *\n * @returns A schema builder with both `maxlength` and `minlength` options applied.\n */\n length: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendStringSchemaBuilder<Merge<Props, { lowercase: true }>, ExtraOmitFields>;\n maxlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T }>,\n ExtraOmitFields\n >;\n\n minlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { minlength: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendStringSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendStringSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n text: ExtendStringSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendStringSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendStringSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendStringSchemaBuilder<Merge<Props, { uppercase: true }>, ExtraOmitFields>;\n}\n\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(String);\nconst defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.';\nconst defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.';\n\nexport function stringSchemaBuilder() {\n const schema: Record<string, any> = {};\n const baseBuilder = baseBuilderFactory(schema);\n return new Proxy(\n baseBuilder,\n {\n get(target, key, receiver) {\n if (key === 'ipv4') {\n return (message: string = defaultIpv4ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => net.isIPv4(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'ipv6') {\n return (message: string = defaultIpv6ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => net.isIPv6(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'length') {\n return (value: any) => {\n schema.maxlength = schema.minlength = value;\n return receiver;\n };\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as StringSchemaBuilder;\n}\n"],"names":["createBaseSchemaBuilderFactory","net"],"mappings":";;;;;;;;;AAsIA,MAAM,kBAAkB,GAAGA,mCAA8B,CAAC,MAAM,CAAC;AACjE,MAAM,0BAA0B,GAAG,0DAA0D;AAC7F,MAAM,0BAA0B,GAAG,0DAA0D;SAE7E,mBAAmB,GAAA;IAC/B,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,OAAO,IAAI,KAAK,CACZ,WAAW,EACX;AACI,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACrB,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oB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AI,CAAA;KAAE,CAAC,EAAE,eAAe,CAAC,CAAC;IACrF,QAAQ,EAAE,KAAK,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,IAAI,CAAA;KAAE,CAAC,CAAC;IAC3C,MAAM,EAAE,yBAAyB,CAAC,KAAK,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,IAAI,CAAA;KAAE,CAAC,EAAE,eAAe,CAAC,CAAC;IACnF,IAAI,EAAE,yBAAyB,CAAC,KAAK,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC,EAAE,eAAe,CAAC,CAAC;IAC/E,IAAI,EAAE,yBAAyB,CAAC,KAAK,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC,EAAE,eAAe,CAAC,CAAC;IAC/E,MAAM,EAAE,yBAAyB,CAAC,KAAK,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,IAAI,CAAA;KAAE,CAAC,EAAE,eAAe,CAAC,CAAC;IACnF,SAAS,EAAE,yBAAyB,CAAC,KAAK,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,IAAI,CAAA;KAAE,CAAC,EAAE,eAAe,CAAC,CAAC;CAC5F;AAGD,QAAA,MAAM,0BAA0B,6DAA6D,CAAC;AAC9F,QAAA,MAAM,0BAA0B,6DAA6D,CAAC;AAE9F,wBAAgB,mBAAmB,IAyC1B,mBAAmB,CAC3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"string.mjs","sources":["../../src/schema-builders/string.ts"],"sourcesContent":["import net from 'node:net';\n\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n StringSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendStringSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<StringSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;\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 >(\n value: T\n ) => ExtendStringSchemaBuilder<Merge<Props, { enum: T }>, ExtraOmitFields>;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n /**\n * Adds IPv4 validation to the string schema.\n * Ensures the string is a valid IPv4 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv4 validation message.\n *\n * @returns A schema builder with IPv4 validation and the `trim` option enabled.\n */\n ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | ExtraOmitFields\n >;\n\n /**\n * Adds IPv6 validation to the string schema.\n * Ensures the string is a valid IPv6 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv6 validation message.\n *\n * @returns A schema builder with IPv6 validation and the `trim` option enabled.\n */\n ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | ExtraOmitFields\n >;\n\n /**\n * Sets both the maximum and minimum length of the string.\n * This method ensures the string length is exactly or within a specified range.\n *\n * @param value - A number representing the exact length or an array specifying [minimum, maximum] length.\n *\n * @returns A schema builder with both `maxlength` and `minlength` options applied.\n */\n length: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendStringSchemaBuilder<Merge<Props, { lowercase: true }>, ExtraOmitFields>;\n maxlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T }>,\n ExtraOmitFields\n >;\n\n minlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { minlength: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendStringSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendStringSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n text: ExtendStringSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendStringSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendStringSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendStringSchemaBuilder<Merge<Props, { uppercase: true }>, ExtraOmitFields>;\n}\n\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(String);\nconst defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.';\nconst defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.';\n\nexport function stringSchemaBuilder() {\n const schema: Record<string, any> = {};\n const baseBuilder = baseBuilderFactory(schema);\n return new Proxy(\n baseBuilder,\n {\n get(target, key, receiver) {\n if (key === 'ipv4') {\n return (message: string = defaultIpv4ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => net.isIPv4(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'ipv6') {\n return (message: string = defaultIpv6ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => net.isIPv6(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'length') {\n return (value: any) => {\n schema.maxlength = schema.minlength = value;\n return receiver;\n };\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as StringSchemaBuilder;\n}\n"],"names":[],"mappings":";;;AAkIA,MAAM,kBAAkB,GAAG,8BAA8B,CAAC,MAAM,CAAC;AACjE,MAAM,0BAA0B,GAAG,0DAA0D;AAC7F,MAAM,0BAA0B,GAAG,0DAA0D;SAE7E,mBAAmB,GAAA;IAC/B,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,OAAO,IAAI,KAAK,CACZ,WAAW,EACX;AACI,QAAA,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAA;AACrB,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;qBAClD;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,MAAM,EAAE;AAChB,gBAAA,OAAO,CAAC,OAAA,GAAkB,0BAA0B,KAAI;AACpD,oBAAA,MAAM,CAAC,IAAI,GAAG,IAAI;oBAClB,MAAM,CAAC,QAAQ,GAAG;wBACd,OAAO;wBACP,SAAS,EAAE,CAAC,KAAa,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;qBAClD;AAED,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;AAGL,YAAA,IAAI,GAAG,KAAK,QAAQ,EAAE;gBAClB,OAAO,CAAC,KAAU,KAAI;oBAClB,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,GAAG,KAAK;AAC3C,oBAAA,OAAO,QAAQ;AACnB,iBAAC;;YAGL,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC5C;AACJ,KAAA,CACmB;AAC5B;;;;"}
1
+ {"version":3,"file":"string.mjs","sources":["../../src/schema-builders/string.ts"],"sourcesContent":["import net from 'node:net';\n\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n StringSchemaDefinition,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/utils';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\nexport type ExtendStringSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n StringSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: StringSchemaDefinition;\n}\n\ninterface IpSchema<T extends string> {\n trim: true;\n validate: { message: T; validator: (value: string) => boolean };\n}\n\nexport interface StringSchemaBuilder<\n Props extends { type: StringSchemaDefinition } = { type: StringSchemaDefinition },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<null | S>>\n | { [path: string]: null | S }\n | { message?: M; values: Readonlyable<Array<null | S>> },\n M extends string,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n /**\n * Adds IPv4 validation to the string schema.\n * Ensures the string is a valid IPv4 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv4 validation message.\n *\n * @returns A schema builder with IPv4 validation and the `trim` option enabled.\n */\n ipv4: <T extends string = typeof defaultIpv4ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | ExtraOmitFields\n >;\n\n /**\n * Adds IPv6 validation to the string schema.\n * Ensures the string is a valid IPv6 address and trims the input. The validation message can be customized.\n *\n * @param message - The custom error message to return if validation fails. Defaults to a standard\n * IPv6 validation message.\n *\n * @returns A schema builder with IPv6 validation and the `trim` option enabled.\n */\n ipv6: <T extends string = typeof defaultIpv6ValidateMessage>(message?: T) => ExtendStringSchemaBuilder<\n Merge<Props, IpSchema<T>>,\n 'ipv4' | 'ipv6' | ExtraOmitFields\n >;\n\n /**\n * Sets both the maximum and minimum length of the string.\n * This method ensures the string length is exactly or within a specified range.\n *\n * @param value - A number representing the exact length or an array specifying [minimum, maximum] length.\n *\n * @returns A schema builder with both `maxlength` and `minlength` options applied.\n */\n length: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T; minlength: T }>,\n ExtraOmitFields\n >;\n\n lowercase: ExtendStringSchemaBuilder<Merge<Props, { lowercase: true }>, ExtraOmitFields>;\n maxlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { maxlength: T }>,\n ExtraOmitFields\n >;\n\n minlength: <\n T extends L | Readonlyable<[L, S]>,\n L extends number,\n S extends string,\n >(value: T) => ExtendStringSchemaBuilder<\n Merge<Props, { minlength: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendStringSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendStringSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n text: ExtendStringSchemaBuilder<Merge<Props, { text: true }>, ExtraOmitFields>;\n trim: ExtendStringSchemaBuilder<Merge<Props, { trim: true }>, ExtraOmitFields>;\n unique: ExtendStringSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n uppercase: ExtendStringSchemaBuilder<Merge<Props, { uppercase: true }>, ExtraOmitFields>;\n}\n\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(String);\nconst defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.';\nconst defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.';\n\nexport function stringSchemaBuilder() {\n const schema: Record<string, any> = {};\n const baseBuilder = baseBuilderFactory(schema);\n return new Proxy(\n baseBuilder,\n {\n get(target, key, receiver) {\n if (key === 'ipv4') {\n return (message: string = defaultIpv4ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => net.isIPv4(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'ipv6') {\n return (message: string = defaultIpv6ValidateMessage) => {\n schema.trim = true;\n schema.validate = {\n message,\n validator: (value: string) => net.isIPv6(value),\n };\n\n return receiver;\n };\n }\n\n if (key === 'length') {\n return (value: any) => {\n schema.maxlength = schema.minlength = value;\n return receiver;\n };\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as StringSchemaBuilder;\n}\n"],"names":[],"mappings":";;;AAsIA,MAAM,kBAAkB,GAAG,8BAA8B,CAAC,MAAM,CAAC;AACjE,MAAM,0BAA0B,GAAG,0DAA0D;AAC7F,MAAM,0BAA0B,GAAG,0DAA0D;SAE7E,mBAAmB,GAAA;IAC/B,MAAM,MAAM,GAAwB,EAAE;AACtC,IAAA,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC9C,IAAA,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AAY,GAAG,MAAM,IACrB,gBAAgB,CAChB,OAAO,EACP,2BAA2B,EAC3B,YAAY,CACf,CAAC;CACL"}
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,MAAM,EACN,sBAAsB,EACzB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,MAAM,MAAM,wBAAwB,GAAG,OAAO,kBAAkB,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB;;;;;;;OAOG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,sBAAsB,CAAC;CACjD;AAED,MAAM,WAAW,qBAAqB;IAClC;;OAEG;IACH,gBAAgB,CAAC,EAAE,CACf,OAAO,EACP,KAAK,SAAS,yBAAyB,CAAC,OAAO,EAAE,2BAA2B,EAAE,YAAY,CAAC,EAC3F,2BAA2B,GAAG,MAAM,EACpC,YAAY,GAAG,MAAM,EAErB,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,2BAA2B,EAAE,YAAY,CAAC,KACxE,IAAI,CAAC;CACb"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,MAAM,EACN,sBAAsB,EACzB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,MAAM,MAAM,wBAAwB,GAAG,OAAO,kBAAkB,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB;;;;;;;OAOG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,sBAAsB,CAAC;CACjD;AAED,MAAM,WAAW,qBAAqB;IAClC;;OAEG;IACH,gBAAgB,CAAC,EAAE,CACf,OAAO,EACP,KAAK,SAAS,yBAAyB,CAAC,OAAO,EAAE,2BAA2B,EAAE,YAAY,CAAC,EAC3F,2BAA2B,GAAG,MAAM,EACpC,YAAY,GAAG,MAAM,EAErB,MAAM,EAAE,MAAM,CACV,OAAO,EACP,KAAK,EACL,2BAA2B,EAC3B,YAAY,CACf,KACA,IAAI,CAAC;CACb"}
package/dist/utils.cjs CHANGED
@@ -13,6 +13,29 @@ const mongoose__default = /*#__PURE__*/_interopDefaultCompat(mongoose);
13
13
  const mongooseAggregatePaginate__default = /*#__PURE__*/_interopDefaultCompat(mongooseAggregatePaginate);
14
14
  const mongoosePaginate__default = /*#__PURE__*/_interopDefaultCompat(mongoosePaginate);
15
15
 
16
+ /**
17
+ * Asserts that a Mongoose update operation was successful by checking that it was acknowledged
18
+ * and that at least the expected number of documents were modified.
19
+ *
20
+ * This function is intended for use with `updateOne`, `updateMany`, or any update operation
21
+ * that returns a MongoDB `UpdateResult`.
22
+ *
23
+ * @template T - The shape of the document being updated.
24
+ * @param updatePromise - A promise returned from a Mongoose update operation.
25
+ * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.
26
+ * @throws Will throw an error if:
27
+ * - The operation was not acknowledged by MongoDB,
28
+ * - Fewer documents were modified than expected.
29
+ */
30
+ async function assertMongooseUpdateSuccess(updatePromise, expectedModifiedCount = 1) {
31
+ const updateResult = await updatePromise;
32
+ if (!updateResult.acknowledged)
33
+ throw new Error('Update was not acknowledged.');
34
+ if (updateResult.modifiedCount < expectedModifiedCount) {
35
+ // eslint-disable-next-line style/max-len
36
+ throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}.`);
37
+ }
38
+ }
16
39
  /**
17
40
  * Builds and returns a Mongoose model with specified schema and options.
18
41
  *
@@ -51,29 +74,6 @@ function buildMongooseModel(collection, name, schema, options) {
51
74
  const connection = options?.connection || (constants.mongooseConnections.default ||= mongoose__default.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));
52
75
  return connection.model(name, schema, collection);
53
76
  }
54
- /**
55
- * Ensures that a MongoDB update operation was acknowledged and modified
56
- * at least the expected number of documents.
57
- *
58
- * This utility is intended for use with `updateOne`, `updateMany`, or any
59
- * update operation that returns a `UpdateResult`.
60
- *
61
- * @template T - The shape of the document being updated.
62
- * @param updatePromise - A Promise returned from a MongoDB update operation (e.g., `updateOne`, `updateMany`).
63
- * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.
64
- * @throws Will throw an error if:
65
- * - The update operation was not acknowledged,
66
- * - Fewer documents were modified than expected.
67
- */
68
- async function ensureUpdateSuccess(updatePromise, expectedModifiedCount = 1) {
69
- const updateResult = await updatePromise;
70
- if (!updateResult.acknowledged)
71
- throw new Error('Update was not acknowledged.');
72
- if (updateResult.modifiedCount < expectedModifiedCount) {
73
- // eslint-disable-next-line style/max-len
74
- throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}.`);
75
- }
76
- }
77
77
  /**
78
78
  * Converts a document or ObjectId to a document using the specified model.
79
79
  *
@@ -98,7 +98,7 @@ async function mongooseDocumentOrObjectIdToDocument(documentOrObjectId, model, s
98
98
  return documentOrObjectId;
99
99
  }
100
100
 
101
+ exports.assertMongooseUpdateSuccess = assertMongooseUpdateSuccess;
101
102
  exports.buildMongooseModel = buildMongooseModel;
102
- exports.ensureUpdateSuccess = ensureUpdateSuccess;
103
103
  exports.mongooseDocumentOrObjectIdToDocument = mongooseDocumentOrObjectIdToDocument;
104
104
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sources":["../src/utils.ts"],"sourcesContent":["import type { mongo } from 'mongoose';\nimport mongoose, { Types } from 'mongoose';\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';\nimport mongoosePaginate from 'mongoose-paginate-v2';\n\nimport { customMongooseOptions } from './_internals';\nimport { mongooseConnections } from './constants';\nimport type { setCustomMongooseOptions } from './options';\nimport mongooseNormalizePlugin from './plugins/normalize';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;\n\n/**\n * Builds and returns a Mongoose model with specified schema and options.\n *\n * This function sets up a Mongoose model with optional plugins and timestamp settings.\n * It can optionally use a specified connection or the default connection.\n *\n * Determine the connection to use:\n * 1. Use the connection provided in the options, if available.\n * 2. Otherwise, use the default connection stored in `mongooseConnections`.\n * 3. If there's no default connection, create one using the MongoDB URI from the environment variables,\n * or fallback to a local MongoDB instance.\n *\n * You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.\n * However, ensure that this option is configured before calling {@link buildMongooseModel}.\n *\n * @template DocType - The type of the document.\n * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param collection - The name of the collection.\n * @param name - The name of the model.\n * @param schema - The Mongoose schema to use for the model.\n * @param options - Optional settings for building the model.\n *\n * @returns The created Mongoose model.\n */\nexport function buildMongooseModel<\n DocType,\n Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n collection: string,\n name: string,\n schema: mongoose.Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n options?: BuildMongooseModelOptions,\n) {\n if (options?.enableNormalizePlugin !== false) schema.plugin(mongooseNormalizePlugin);\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n // eslint-disable-next-line style/max-len\n const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\n\n/**\n * Ensures that a MongoDB update operation was acknowledged and modified\n * at least the expected number of documents.\n *\n * This utility is intended for use with `updateOne`, `updateMany`, or any\n * update operation that returns a `UpdateResult`.\n *\n * @template T - The shape of the document being updated.\n * @param updatePromise - A Promise returned from a MongoDB update operation (e.g., `updateOne`, `updateMany`).\n * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.\n * @throws Will throw an error if:\n * - The update operation was not acknowledged,\n * - Fewer documents were modified than expected.\n */\nexport async function ensureUpdateSuccess<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 * Converts a document or ObjectId to a document using the specified model.\n *\n * This function takes a document or ObjectId and returns the corresponding document\n * from the database using the specified model. Optionally, specific fields can be selected.\n *\n * @template D - The type of the hydrated document.\n * @template DocType - The type of the document.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param documentOrObjectId - The document or ObjectId to convert.\n * @param model - The Mongoose model to use for the conversion.\n * @param selectFields - Optional fields to select from the document.\n *\n * @returns The corresponding document or null if not found.\n */\nexport async function mongooseDocumentOrObjectIdToDocument<\n D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n DocType,\n InstanceMethodsAndOverrides,\n QueryHelpers,\n>(\n documentOrObjectId: MongooseDocumentOrObjectId<D>,\n model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n selectFields?: string[],\n): Promise<D | null> {\n if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {\n return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n }\n\n return documentOrObjectId;\n}\n"],"names":["mongooseNormalizePlugin","mongooseAggregatePaginate","mongoosePaginate","customMongooseOptions","mongooseConnections","mongoose","Types"],"mappings":";;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,kBAAkB,CAM9B,UAAkB,EAClB,IAAY,EACZ,MAAkF,EAClF,OAAmC,EAAA;AAEnC,IAAA,IAAI,OAAO,EAAE,qBAAqB,KAAK,KAAK;AAAE,QAAA,MAAM,CAAC,MAAM,CAACA,iCAAuB,CAAC;AACpF,IAAA,MAAM,CAAC,MAAM,CAACC,kCAAyB,CAAC;AACxC,IAAA,MAAM,CAAC,MAAM,CAACC,yBAAgB,CAAC;AAC/B,IAAA,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,UAAU,IAAI,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC;AACjF,IAAAC,gCAAqB,CAAC,gBAAgB,GAAG,MAAM,CAAC;;IAEhD,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,KAAKC,6BAAmB,CAAC,OAAO,KAAKC,iBAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,2BAA2B,CAAC,CAAC;IAC7J,OAAO,UAAU,CAAC,KAAK,CAA+B,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC;AACnF;AAEA;;;;;;;;;;;;;AAaG;AACI,eAAe,mBAAmB,CACrC,aAA6C,EAC7C,qBAAqB,GAAG,CAAC,EAAA;AAEzB,IAAA,MAAM,YAAY,GAAG,MAAM,aAAa;IACxC,IAAI,CAAC,YAAY,CAAC,YAAY;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;AAC/E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAqB,EAAE;;QAEpD,MAAM,IAAI,KAAK,CAAC,CAA+B,4BAAA,EAAA,qBAAqB,CAA8B,2BAAA,EAAA,YAAY,CAAC,aAAa,CAAG,CAAA,CAAA,CAAC;;AAExI;AAEA;;;;;;;;;;;;;;;;AAgBG;AACI,eAAe,oCAAoC,CAMtD,kBAAiD,EACjD,KAAoF,EACpF,YAAuB,EAAA;IAEvB,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,YAAYC,cAAK,CAAC,QAAQ,EAAE;AACxF,QAAA,QAAQ,MAAM,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;;AAG/E,IAAA,OAAO,kBAAkB;AAC7B;;;;;;"}
1
+ {"version":3,"file":"utils.cjs","sources":["../src/utils.ts"],"sourcesContent":["import type { mongo } from 'mongoose';\nimport mongoose, { Types } from 'mongoose';\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';\nimport mongoosePaginate from 'mongoose-paginate-v2';\n\nimport { customMongooseOptions } from './_internals';\nimport { mongooseConnections } from './constants';\nimport type { setCustomMongooseOptions } from './options';\nimport { mongooseNormalizePlugin } from './plugins/normalize';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;\n\n/**\n * Asserts that a Mongoose update operation was successful by checking that it was acknowledged\n * and that at least the expected number of documents were modified.\n *\n * This function is intended for use with `updateOne`, `updateMany`, or any update operation\n * that returns a MongoDB `UpdateResult`.\n *\n * @template T - The shape of the document being updated.\n * @param updatePromise - A promise returned from a Mongoose update operation.\n * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.\n * @throws Will throw an error if:\n * - The operation was not acknowledged by MongoDB,\n * - Fewer documents were modified than expected.\n */\nexport async function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(\n updatePromise: Promise<mongo.UpdateResult<T>>,\n expectedModifiedCount = 1,\n) {\n const updateResult = await updatePromise;\n if (!updateResult.acknowledged) throw new Error('Update was not acknowledged.');\n if (updateResult.modifiedCount < expectedModifiedCount) {\n // eslint-disable-next-line style/max-len\n throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}.`);\n }\n}\n\n/**\n * Builds and returns a Mongoose model with specified schema and options.\n *\n * This function sets up a Mongoose model with optional plugins and timestamp settings.\n * It can optionally use a specified connection or the default connection.\n *\n * Determine the connection to use:\n * 1. Use the connection provided in the options, if available.\n * 2. Otherwise, use the default connection stored in `mongooseConnections`.\n * 3. If there's no default connection, create one using the MongoDB URI from the environment variables,\n * or fallback to a local MongoDB instance.\n *\n * You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.\n * However, ensure that this option is configured before calling {@link buildMongooseModel}.\n *\n * @template DocType - The type of the document.\n * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param collection - The name of the collection.\n * @param name - The name of the model.\n * @param schema - The Mongoose schema to use for the model.\n * @param options - Optional settings for building the model.\n *\n * @returns The created Mongoose model.\n */\nexport function buildMongooseModel<\n DocType,\n Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n collection: string,\n name: string,\n schema: mongoose.Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n options?: BuildMongooseModelOptions,\n) {\n if (options?.enableNormalizePlugin !== false) schema.plugin(mongooseNormalizePlugin);\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n // eslint-disable-next-line style/max-len\n const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\n\n/**\n * Converts a document or ObjectId to a document using the specified model.\n *\n * This function takes a document or ObjectId and returns the corresponding document\n * from the database using the specified model. Optionally, specific fields can be selected.\n *\n * @template D - The type of the hydrated document.\n * @template DocType - The type of the document.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param documentOrObjectId - The document or ObjectId to convert.\n * @param model - The Mongoose model to use for the conversion.\n * @param selectFields - Optional fields to select from the document.\n *\n * @returns The corresponding document or null if not found.\n */\nexport async function mongooseDocumentOrObjectIdToDocument<\n D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n DocType,\n InstanceMethodsAndOverrides,\n QueryHelpers,\n>(\n documentOrObjectId: MongooseDocumentOrObjectId<D>,\n model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n selectFields?: string[],\n): Promise<D | null> {\n if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {\n return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n }\n\n return documentOrObjectId;\n}\n"],"names":["mongooseNormalizePlugin","mongooseAggregatePaginate","mongoosePaginate","customMongooseOptions","mongooseConnections","mongoose","Types"],"mappings":";;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;AAaG;AACI,eAAe,2BAA2B,CAC7C,aAA6C,EAC7C,qBAAqB,GAAG,CAAC,EAAA;AAEzB,IAAA,MAAM,YAAY,GAAG,MAAM,aAAa;IACxC,IAAI,CAAC,YAAY,CAAC,YAAY;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;AAC/E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAq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/dist/utils.d.ts CHANGED
@@ -3,6 +3,21 @@ import mongoose from 'mongoose';
3
3
  import type { setCustomMongooseOptions } from './options';
4
4
  import type { BuildMongooseModelOptions } from './types/options';
5
5
  export type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;
6
+ /**
7
+ * Asserts that a Mongoose update operation was successful by checking that it was acknowledged
8
+ * and that at least the expected number of documents were modified.
9
+ *
10
+ * This function is intended for use with `updateOne`, `updateMany`, or any update operation
11
+ * that returns a MongoDB `UpdateResult`.
12
+ *
13
+ * @template T - The shape of the document being updated.
14
+ * @param updatePromise - A promise returned from a Mongoose update operation.
15
+ * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.
16
+ * @throws Will throw an error if:
17
+ * - The operation was not acknowledged by MongoDB,
18
+ * - Fewer documents were modified than expected.
19
+ */
20
+ export declare function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(updatePromise: Promise<mongo.UpdateResult<T>>, expectedModifiedCount?: number): Promise<void>;
6
21
  /**
7
22
  * Builds and returns a Mongoose model with specified schema and options.
8
23
  *
@@ -31,21 +46,6 @@ export type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;
31
46
  * @returns The created Mongoose model.
32
47
  */
33
48
  export declare function buildMongooseModel<DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(collection: string, name: string, schema: mongoose.Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>, options?: BuildMongooseModelOptions): Model;
34
- /**
35
- * Ensures that a MongoDB update operation was acknowledged and modified
36
- * at least the expected number of documents.
37
- *
38
- * This utility is intended for use with `updateOne`, `updateMany`, or any
39
- * update operation that returns a `UpdateResult`.
40
- *
41
- * @template T - The shape of the document being updated.
42
- * @param updatePromise - A Promise returned from a MongoDB update operation (e.g., `updateOne`, `updateMany`).
43
- * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.
44
- * @throws Will throw an error if:
45
- * - The update operation was not acknowledged,
46
- * - Fewer documents were modified than expected.
47
- */
48
- export declare function ensureUpdateSuccess<T extends mongo.BSON.Document>(updatePromise: Promise<mongo.UpdateResult<T>>, expectedModifiedCount?: number): Promise<void>;
49
49
  /**
50
50
  * Converts a document or ObjectId to a document using the specified model.
51
51
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,QAAmB,MAAM,UAAU,CAAC;AAM3C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAEjE,MAAM,MAAM,wBAAwB,GAAG,OAAO,wBAAwB,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,kBAAkB,CAC9B,OAAO,EACP,KAAK,SAAS,yBAAyB,CAAC,OAAO,EAAE,2BAA2B,EAAE,YAAY,CAAC,EAC3F,2BAA2B,GAAG,MAAM,EACpC,YAAY,GAAG,MAAM,EAErB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,2BAA2B,EAAE,YAAY,CAAC,EAClF,OAAO,CAAC,EAAE,yBAAyB,SAUtC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,KAAK,CAAC,IAAI,CAAC,QAAQ,EACnE,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAC7C,qBAAqB,SAAI,iBAQ5B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,oCAAoC,CACtD,CAAC,SAAS,wBAAwB,CAAC,OAAO,EAAE,2B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oC,CACtD,CAAC,SAAS,wBAAwB,CAAC,OAAO,EAAE,2BAA2B,EAAE,YAAY,CAAC,EACtF,OAAO,EACP,2BAA2B,EAC3B,YAAY,EAEZ,kBAAkB,EAAE,0BAA0B,CAAC,CAAC,CAAC,EACjD,KAAK,EAAE,yBAAyB,CAAC,OAAO,EAAE,2BAA2B,EAAE,YAAY,CAAC,EACpF,YAAY,CAAC,EAAE,MAAM,EAAE,GACxB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAMnB"}
package/dist/utils.mjs CHANGED
@@ -5,6 +5,29 @@ import { customMongooseOptions } from './_internals.mjs';
5
5
  import { mongooseConnections } from './constants.mjs';
6
6
  import { mongooseNormalizePlugin } from './plugins/normalize.mjs';
7
7
 
8
+ /**
9
+ * Asserts that a Mongoose update operation was successful by checking that it was acknowledged
10
+ * and that at least the expected number of documents were modified.
11
+ *
12
+ * This function is intended for use with `updateOne`, `updateMany`, or any update operation
13
+ * that returns a MongoDB `UpdateResult`.
14
+ *
15
+ * @template T - The shape of the document being updated.
16
+ * @param updatePromise - A promise returned from a Mongoose update operation.
17
+ * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.
18
+ * @throws Will throw an error if:
19
+ * - The operation was not acknowledged by MongoDB,
20
+ * - Fewer documents were modified than expected.
21
+ */
22
+ async function assertMongooseUpdateSuccess(updatePromise, expectedModifiedCount = 1) {
23
+ const updateResult = await updatePromise;
24
+ if (!updateResult.acknowledged)
25
+ throw new Error('Update was not acknowledged.');
26
+ if (updateResult.modifiedCount < expectedModifiedCount) {
27
+ // eslint-disable-next-line style/max-len
28
+ throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}.`);
29
+ }
30
+ }
8
31
  /**
9
32
  * Builds and returns a Mongoose model with specified schema and options.
10
33
  *
@@ -43,29 +66,6 @@ function buildMongooseModel(collection, name, schema, options) {
43
66
  const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));
44
67
  return connection.model(name, schema, collection);
45
68
  }
46
- /**
47
- * Ensures that a MongoDB update operation was acknowledged and modified
48
- * at least the expected number of documents.
49
- *
50
- * This utility is intended for use with `updateOne`, `updateMany`, or any
51
- * update operation that returns a `UpdateResult`.
52
- *
53
- * @template T - The shape of the document being updated.
54
- * @param updatePromise - A Promise returned from a MongoDB update operation (e.g., `updateOne`, `updateMany`).
55
- * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.
56
- * @throws Will throw an error if:
57
- * - The update operation was not acknowledged,
58
- * - Fewer documents were modified than expected.
59
- */
60
- async function ensureUpdateSuccess(updatePromise, expectedModifiedCount = 1) {
61
- const updateResult = await updatePromise;
62
- if (!updateResult.acknowledged)
63
- throw new Error('Update was not acknowledged.');
64
- if (updateResult.modifiedCount < expectedModifiedCount) {
65
- // eslint-disable-next-line style/max-len
66
- throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}.`);
67
- }
68
- }
69
69
  /**
70
70
  * Converts a document or ObjectId to a document using the specified model.
71
71
  *
@@ -90,5 +90,5 @@ async function mongooseDocumentOrObjectIdToDocument(documentOrObjectId, model, s
90
90
  return documentOrObjectId;
91
91
  }
92
92
 
93
- export { buildMongooseModel, ensureUpdateSuccess, mongooseDocumentOrObjectIdToDocument };
93
+ export { assertMongooseUpdateSuccess, buildMongooseModel, mongooseDocumentOrObjectIdToDocument };
94
94
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sources":["../src/utils.ts"],"sourcesContent":["import type { mongo } from 'mongoose';\nimport mongoose, { Types } from 'mongoose';\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';\nimport mongoosePaginate from 'mongoose-paginate-v2';\n\nimport { customMongooseOptions } from './_internals';\nimport { mongooseConnections } from './constants';\nimport type { setCustomMongooseOptions } from './options';\nimport mongooseNormalizePlugin from './plugins/normalize';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;\n\n/**\n * Builds and returns a Mongoose model with specified schema and options.\n *\n * This function sets up a Mongoose model with optional plugins and timestamp settings.\n * It can optionally use a specified connection or the default connection.\n *\n * Determine the connection to use:\n * 1. Use the connection provided in the options, if available.\n * 2. Otherwise, use the default connection stored in `mongooseConnections`.\n * 3. If there's no default connection, create one using the MongoDB URI from the environment variables,\n * or fallback to a local MongoDB instance.\n *\n * You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.\n * However, ensure that this option is configured before calling {@link buildMongooseModel}.\n *\n * @template DocType - The type of the document.\n * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param collection - The name of the collection.\n * @param name - The name of the model.\n * @param schema - The Mongoose schema to use for the model.\n * @param options - Optional settings for building the model.\n *\n * @returns The created Mongoose model.\n */\nexport function buildMongooseModel<\n DocType,\n Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n collection: string,\n name: string,\n schema: mongoose.Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n options?: BuildMongooseModelOptions,\n) {\n if (options?.enableNormalizePlugin !== false) schema.plugin(mongooseNormalizePlugin);\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n // eslint-disable-next-line style/max-len\n const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\n\n/**\n * Ensures that a MongoDB update operation was acknowledged and modified\n * at least the expected number of documents.\n *\n * This utility is intended for use with `updateOne`, `updateMany`, or any\n * update operation that returns a `UpdateResult`.\n *\n * @template T - The shape of the document being updated.\n * @param updatePromise - A Promise returned from a MongoDB update operation (e.g., `updateOne`, `updateMany`).\n * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.\n * @throws Will throw an error if:\n * - The update operation was not acknowledged,\n * - Fewer documents were modified than expected.\n */\nexport async function ensureUpdateSuccess<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 * Converts a document or ObjectId to a document using the specified model.\n *\n * This function takes a document or ObjectId and returns the corresponding document\n * from the database using the specified model. Optionally, specific fields can be selected.\n *\n * @template D - The type of the hydrated document.\n * @template DocType - The type of the document.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param documentOrObjectId - The document or ObjectId to convert.\n * @param model - The Mongoose model to use for the conversion.\n * @param selectFields - Optional fields to select from the document.\n *\n * @returns The corresponding document or null if not found.\n */\nexport async function mongooseDocumentOrObjectIdToDocument<\n D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n DocType,\n InstanceMethodsAndOverrides,\n QueryHelpers,\n>(\n documentOrObjectId: MongooseDocumentOrObjectId<D>,\n model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n selectFields?: string[],\n): Promise<D | null> {\n if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {\n return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n }\n\n return documentOrObjectId;\n}\n"],"names":[],"mappings":";;;;;;;AAaA;;;;;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,YAAuB,EAAA;IAEvB,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,YAAY,KAAK,CAAC,QAAQ,EAAE;AACxF,QAAA,QAAQ,MAAM,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;;AAG/E,IAAA,OAAO,kBAAkB;AAC7B;;;;"}
1
+ {"version":3,"file":"utils.mjs","sources":["../src/utils.ts"],"sourcesContent":["import type { mongo } from 'mongoose';\nimport mongoose, { Types } from 'mongoose';\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';\nimport mongoosePaginate from 'mongoose-paginate-v2';\n\nimport { customMongooseOptions } from './_internals';\nimport { mongooseConnections } from './constants';\nimport type { setCustomMongooseOptions } from './options';\nimport { mongooseNormalizePlugin } from './plugins/normalize';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;\n\n/**\n * Asserts that a Mongoose update operation was successful by checking that it was acknowledged\n * and that at least the expected number of documents were modified.\n *\n * This function is intended for use with `updateOne`, `updateMany`, or any update operation\n * that returns a MongoDB `UpdateResult`.\n *\n * @template T - The shape of the document being updated.\n * @param updatePromise - A promise returned from a Mongoose update operation.\n * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.\n * @throws Will throw an error if:\n * - The operation was not acknowledged by MongoDB,\n * - Fewer documents were modified than expected.\n */\nexport async function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(\n updatePromise: Promise<mongo.UpdateResult<T>>,\n expectedModifiedCount = 1,\n) {\n const updateResult = await updatePromise;\n if (!updateResult.acknowledged) throw new Error('Update was not acknowledged.');\n if (updateResult.modifiedCount < expectedModifiedCount) {\n // eslint-disable-next-line style/max-len\n throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}.`);\n }\n}\n\n/**\n * Builds and returns a Mongoose model with specified schema and options.\n *\n * This function sets up a Mongoose model with optional plugins and timestamp settings.\n * It can optionally use a specified connection or the default connection.\n *\n * Determine the connection to use:\n * 1. Use the connection provided in the options, if available.\n * 2. Otherwise, use the default connection stored in `mongooseConnections`.\n * 3. If there's no default connection, create one using the MongoDB URI from the environment variables,\n * or fallback to a local MongoDB instance.\n *\n * You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.\n * However, ensure that this option is configured before calling {@link buildMongooseModel}.\n *\n * @template DocType - The type of the document.\n * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param collection - The name of the collection.\n * @param name - The name of the model.\n * @param schema - The Mongoose schema to use for the model.\n * @param options - Optional settings for building the model.\n *\n * @returns The created Mongoose model.\n */\nexport function buildMongooseModel<\n DocType,\n Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n collection: string,\n name: string,\n schema: mongoose.Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n options?: BuildMongooseModelOptions,\n) {\n if (options?.enableNormalizePlugin !== false) schema.plugin(mongooseNormalizePlugin);\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n // eslint-disable-next-line style/max-len\n const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\n\n/**\n * Converts a document or ObjectId to a document using the specified model.\n *\n * This function takes a document or ObjectId and returns the corresponding document\n * from the database using the specified model. Optionally, specific fields can be selected.\n *\n * @template D - The type of the hydrated document.\n * @template DocType - The type of the document.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param documentOrObjectId - The document or ObjectId to convert.\n * @param model - The Mongoose model to use for the conversion.\n * @param selectFields - Optional fields to select from the document.\n *\n * @returns The corresponding document or null if not found.\n */\nexport async function mongooseDocumentOrObjectIdToDocument<\n D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n DocType,\n InstanceMethodsAndOverrides,\n QueryHelpers,\n>(\n documentOrObjectId: MongooseDocumentOrObjectId<D>,\n model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n selectFields?: string[],\n): Promise<D | null> {\n if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {\n return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n }\n\n return documentOrObjectId;\n}\n"],"names":[],"mappings":";;;;;;;AAaA;;;;;;;;;;;;;AAaG;AACI,eAAe,2BAA2B,CAC7C,aAA6C,EAC7C,qBAAqB,GAAG,CAAC,EAAA;AAEzB,IAAA,MAAM,YAAY,GAAG,MAAM,aAAa;IACxC,IAAI,CAAC,YAAY,CAAC,YAAY;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;AAC/E,IAAA,IAAI,YAAY,CAAC,aAAa,GAAG,qBAAqB,EAAE;;QAEpD,MAAM,IAAI,KAAK,CAAC,CAA+B,4BAAA,EAAA,qBAAqB,CAA8B,2BAAA,EAAA,YAAY,CAAC,aAAa,CAAG,CAAA,CAAA,CAAC;;AAExI;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACG,SAAU,kBAAkB,CAM9B,UAAkB,EAClB,IAAY,EACZ,MAAkF,EAClF,OAAmC,EAAA;AAEnC,IAAA,IAAI,OAAO,EAAE,qBAAqB,KAAK,KAAK;AAAE,QAAA,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC;AACpF,IAAA,MAAM,CAAC,MAAM,CAAC,yBAAyB,CAAC;AACxC,IAAA,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;AAC/B,IAAA,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,UAAU,IAAI,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC;AACjF,IAAA,qBAAqB,CAAC,gBAAgB,GAAG,MAAM,CAAC;;IAEhD,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,KAAK,mBAAmB,CAAC,OAAO,KAAK,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,2BAA2B,CAAC,CAAC;IAC7J,OAAO,UAAU,CAAC,KAAK,CAA+B,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC;AACnF;AAEA;;;;;;;;;;;;;;;;AAgBG;AACI,eAAe,oCAAoC,CAMtD,kBAAiD,EACjD,KAAoF,EACpF,YAAuB,EAAA;IAEvB,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,YAAY,KAAK,CAAC,QAAQ,EAAE;AACxF,QAAA,QAAQ,MAAM,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;;AAG/E,IAAA,OAAO,kBAAkB;AAC7B;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kikiutils/mongoose",
3
- "version": "2.3.0",
3
+ "version": "3.0.0",
4
4
  "description": "A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.",
5
5
  "author": "kiki-kanri",
6
6
  "license": "MIT",
@@ -59,21 +59,26 @@
59
59
  "dependencies": {
60
60
  "decimal.js": "^10.5.0",
61
61
  "lodash": "^4.17.21",
62
- "mongoose": "^8.13.0",
62
+ "mongoose": "^8.13.2",
63
63
  "mongoose-aggregate-paginate-v2": "^1.1.4",
64
64
  "mongoose-paginate-v2": "^1.9.0",
65
- "type-fest": "^4.38.0"
65
+ "type-fest": "^4.39.1"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@kikiutils/changelogen": "^0.8.0",
69
69
  "@kikiutils/eslint-config": "^0.12.0",
70
- "@kikiutils/tsconfigs": "^3.0.3",
70
+ "@kikiutils/tsconfigs": "^4.0.0",
71
71
  "@types/jest": "^29.5.14",
72
72
  "@types/lodash": "^4.17.16",
73
- "@types/node": "^22.13.13",
73
+ "@types/node": "^22.14.0",
74
74
  "jest": "^29.7.0",
75
- "ts-jest": "^29.3.0",
76
- "ts-project-builder": "^3.4.3",
75
+ "ts-jest": "^29.3.1",
76
+ "ts-project-builder": "^4.0.0",
77
77
  "tslib": "^2.8.1"
78
+ },
79
+ "pnpm": {
80
+ "onlyBuiltDependencies": [
81
+ "esbuild"
82
+ ]
78
83
  }
79
84
  }
@@ -1,15 +1,11 @@
1
- import lodash from 'lodash';
1
+ import lodashGet from 'lodash/get';
2
+ import lodashSet from 'lodash/set';
3
+ import lodashUnset from 'lodash/unset';
2
4
  import type {
3
5
  Schema,
4
6
  Types,
5
7
  } from 'mongoose';
6
8
 
7
- const {
8
- get: lodashGet,
9
- set: lodashSet,
10
- unset: lodashUnset,
11
- } = lodash;
12
-
13
9
  /**
14
10
  * Mongoose plugin to normalize the JSON output of documents.
15
11
  *
@@ -53,5 +49,3 @@ export function mongooseNormalizePlugin<S extends Schema>(schema: S) {
53
49
  },
54
50
  );
55
51
  }
56
-
57
- export default mongooseNormalizePlugin;
@@ -11,7 +11,10 @@ import { createBaseSchemaBuilderFactory } from './base';
11
11
  export type ExtendBooleanSchemaBuilder<
12
12
  Props extends BaseBooleanSchemaProps,
13
13
  ExtraOmitFields extends string,
14
- > = Omit<BooleanSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
14
+ > = Omit<
15
+ BooleanSchemaBuilder<Props, ExtraOmitFields>,
16
+ ExtraOmitFields | keyof Props
17
+ >;
15
18
 
16
19
  export interface BaseBooleanSchemaProps {
17
20
  type: BooleanSchemaDefinition;
@@ -13,7 +13,10 @@ import { createBaseSchemaBuilderFactory } from './base';
13
13
  export type ExtendDateSchemaBuilder<
14
14
  Props extends BaseProps,
15
15
  ExtraOmitFields extends string,
16
- > = Omit<DateSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
16
+ > = Omit<
17
+ DateSchemaBuilder<Props, ExtraOmitFields>,
18
+ ExtraOmitFields | keyof Props
19
+ >;
17
20
 
18
21
  interface BaseProps {
19
22
  type: DateSchemaDefinition;
@@ -15,7 +15,10 @@ import { createBaseSchemaBuilderFactory } from './base';
15
15
  export type ExtendDecimal128SchemaBuilder<
16
16
  Props extends BaseProps,
17
17
  ExtraOmitFields extends string,
18
- > = Omit<Decimal128SchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
18
+ > = Omit<
19
+ Decimal128SchemaBuilder<Props, ExtraOmitFields>,
20
+ ExtraOmitFields | keyof Props
21
+ >;
19
22
 
20
23
  interface BaseProps {
21
24
  type: typeof Schema.Types.Decimal128;
@@ -72,10 +75,7 @@ export interface Decimal128SchemaBuilder<
72
75
  *
73
76
  * @returns A schema builder with the rounding and toFixed behavior applied to the `set` option in Mongoose.
74
77
  */
75
- setRoundAndToFixedSetter: (
76
- places?: number,
77
- rounding?: Decimal.Rounding
78
- ) => ExtendDecimal128SchemaBuilder<
78
+ setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendDecimal128SchemaBuilder<
79
79
  Merge<Props, ToStringSetterSchema>,
80
80
  'setRoundAndToFixedSetter' | ExtraOmitFields
81
81
  >;
@@ -1,26 +1,20 @@
1
- import { booleanSchemaBuilder } from './boolean';
2
- import { dateSchemaBuilder } from './date';
3
- import { decimal128SchemaBuilder } from './decimal128';
4
- import { numberSchemaBuilder } from './number';
5
- import { objectIdSchemaBuilder } from './object-id';
6
- import { refSchemaBuilder } from './ref';
7
- import { stringSchemaBuilder } from './string';
8
-
1
+ export { booleanSchemaBuilder as boolean } from './boolean';
9
2
  export * from './boolean';
3
+
4
+ export { dateSchemaBuilder as date } from './date';
10
5
  export * from './date';
6
+
7
+ export { decimal128SchemaBuilder as decimal128 } from './decimal128';
11
8
  export * from './decimal128';
9
+
10
+ export { numberSchemaBuilder as number } from './number';
12
11
  export * from './number';
13
- export * from './ref';
14
- export * from './string';
15
12
 
16
- export const schemaBuilders = {
17
- boolean: booleanSchemaBuilder,
18
- date: dateSchemaBuilder,
19
- decimal128: decimal128SchemaBuilder,
20
- number: numberSchemaBuilder,
21
- objectId: objectIdSchemaBuilder,
22
- ref: refSchemaBuilder,
23
- string: stringSchemaBuilder,
24
- };
13
+ export { objectIdSchemaBuilder as objectId } from './object-id';
14
+ export * from './object-id';
15
+
16
+ export { refSchemaBuilder as ref } from './ref';
17
+ export * from './ref';
25
18
 
26
- export default schemaBuilders;
19
+ export { stringSchemaBuilder as string } from './string';
20
+ export * from './string';
@@ -13,7 +13,10 @@ import { createBaseSchemaBuilderFactory } from './base';
13
13
  export type ExtendNumberSchemaBuilder<
14
14
  Props extends BaseProps,
15
15
  ExtraOmitFields extends string,
16
- > = Omit<NumberSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
16
+ > = Omit<
17
+ NumberSchemaBuilder<Props, ExtraOmitFields>,
18
+ ExtraOmitFields | keyof Props
19
+ >;
17
20
 
18
21
  interface BaseProps {
19
22
  type: NumberSchemaDefinition;
@@ -14,7 +14,10 @@ import { createBaseSchemaBuilderFactory } from './base';
14
14
  export type ExtendObjectIdSchemaBuilder<
15
15
  Props extends BaseProps,
16
16
  ExtraOmitFields extends string,
17
- > = Omit<ObjectIdSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
17
+ > = Omit<
18
+ ObjectIdSchemaBuilder<Props, ExtraOmitFields>,
19
+ ExtraOmitFields | keyof Props
20
+ >;
18
21
 
19
22
  interface BaseProps {
20
23
  type: typeof Schema.Types.ObjectId;
@@ -39,9 +42,10 @@ export interface ObjectIdSchemaBuilder<
39
42
  | { message?: M; values: Readonlyable<Array<null | O>> },
40
43
  M extends string,
41
44
  O extends Types.ObjectId,
42
- >(
43
- value: T
44
- ) => ExtendObjectIdSchemaBuilder<Merge<Props, { enum: T }>, ExtraOmitFields>;
45
+ >(value: T) => ExtendObjectIdSchemaBuilder<
46
+ Merge<Props, { enum: T }>,
47
+ ExtraOmitFields
48
+ >;
45
49
 
46
50
  index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendObjectIdSchemaBuilder<
47
51
  Merge<Props, { index: T }>,