@kikiutils/mongoose 7.0.2 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/_internals.d.ts +1 -3
  2. package/dist/_internals.d.ts.map +1 -1
  3. package/dist/_internals.js.map +1 -1
  4. package/dist/assertions.d.ts +1 -3
  5. package/dist/assertions.d.ts.map +1 -1
  6. package/dist/assertions.js.map +1 -1
  7. package/dist/builders.d.ts +3 -5
  8. package/dist/builders.d.ts.map +1 -1
  9. package/dist/builders.js.map +1 -1
  10. package/dist/constants.d.ts +1 -3
  11. package/dist/constants.d.ts.map +1 -1
  12. package/dist/constants.js.map +1 -1
  13. package/dist/helpers.d.ts +1 -3
  14. package/dist/helpers.d.ts.map +1 -1
  15. package/dist/helpers.js.map +1 -1
  16. package/dist/options.d.ts +1 -3
  17. package/dist/options.d.ts.map +1 -1
  18. package/dist/options.js.map +1 -1
  19. package/dist/plugins/assertions.d.ts +1 -3
  20. package/dist/plugins/assertions.d.ts.map +1 -1
  21. package/dist/plugins/assertions.js.map +1 -1
  22. package/dist/plugins/normalize.d.ts +2 -4
  23. package/dist/plugins/normalize.d.ts.map +1 -1
  24. package/dist/plugins/normalize.js +4 -2
  25. package/dist/plugins/normalize.js.map +1 -1
  26. package/dist/schema-builders/base.d.ts +1 -3
  27. package/dist/schema-builders/base.d.ts.map +1 -1
  28. package/dist/schema-builders/base.js +1 -1
  29. package/dist/schema-builders/base.js.map +1 -1
  30. package/dist/schema-builders/boolean.d.ts +2 -4
  31. package/dist/schema-builders/boolean.d.ts.map +1 -1
  32. package/dist/schema-builders/boolean.js.map +1 -1
  33. package/dist/schema-builders/date.d.ts +2 -4
  34. package/dist/schema-builders/date.d.ts.map +1 -1
  35. package/dist/schema-builders/date.js.map +1 -1
  36. package/dist/schema-builders/decimal128.d.ts +18 -5
  37. package/dist/schema-builders/decimal128.d.ts.map +1 -1
  38. package/dist/schema-builders/decimal128.js +24 -1
  39. package/dist/schema-builders/decimal128.js.map +1 -1
  40. package/dist/schema-builders/number.d.ts +2 -4
  41. package/dist/schema-builders/number.d.ts.map +1 -1
  42. package/dist/schema-builders/number.js.map +1 -1
  43. package/dist/schema-builders/object-id.d.ts +2 -4
  44. package/dist/schema-builders/object-id.d.ts.map +1 -1
  45. package/dist/schema-builders/object-id.js.map +1 -1
  46. package/dist/schema-builders/ref.d.ts +2 -4
  47. package/dist/schema-builders/ref.d.ts.map +1 -1
  48. package/dist/schema-builders/ref.js.map +1 -1
  49. package/dist/schema-builders/string.d.ts +32 -6
  50. package/dist/schema-builders/string.d.ts.map +1 -1
  51. package/dist/schema-builders/string.js +13 -1
  52. package/dist/schema-builders/string.js.map +1 -1
  53. package/dist/types/_internals.d.ts +1 -2
  54. package/dist/types/_internals.d.ts.map +1 -1
  55. package/dist/types/aggregate-paginate.d.ts +6 -7
  56. package/dist/types/aggregate-paginate.d.ts.map +1 -1
  57. package/dist/types/data.d.ts +2 -4
  58. package/dist/types/data.d.ts.map +1 -1
  59. package/dist/types/index.d.ts +10 -12
  60. package/dist/types/index.d.ts.map +1 -1
  61. package/dist/types/options.d.ts +2 -4
  62. package/dist/types/options.d.ts.map +1 -1
  63. package/dist/types/paginate.d.ts +9 -10
  64. package/dist/types/paginate.d.ts.map +1 -1
  65. package/package.json +18 -21
  66. package/src/schema-builders/base.ts +2 -0
  67. package/src/schema-builders/decimal128.ts +81 -2
  68. package/src/schema-builders/string.ts +66 -3
@@ -1,7 +1,5 @@
1
1
  import { CustomMongooseOptions } from "./types/options.js";
2
-
3
2
  //#region src/_internals.d.ts
4
- declare const customMongooseOptions: CustomMongooseOptions;
3
+ export declare const customMongooseOptions: CustomMongooseOptions;
5
4
  //#endregion
6
- export { customMongooseOptions };
7
5
  //# sourceMappingURL=_internals.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_internals.d.ts","names":[],"sources":["../src/_internals.ts"],"mappings":";;;cAEa,qBAAA,EAAuB,qBAAA"}
1
+ {"version":3,"file":"_internals.d.ts","names":[],"sources":["../src/_internals.ts"],"mappings":";;qBAEa,uBAAuB"}
@@ -1 +1 @@
1
- {"version":3,"file":"_internals.js","names":[],"sources":["../src/_internals.ts"],"sourcesContent":["import type { CustomMongooseOptions } from './types/options';\n\nexport const customMongooseOptions: CustomMongooseOptions = {};\n"],"mappings":";AAEA,MAAa,wBAA+C,EAAE"}
1
+ {"version":3,"file":"_internals.js","names":[],"sources":["../src/_internals.ts"],"sourcesContent":["import type { CustomMongooseOptions } from './types/options';\n\nexport const customMongooseOptions: CustomMongooseOptions = {};\n"],"mappings":";AAEA,MAAa,wBAA+C,CAAC"}
@@ -1,7 +1,5 @@
1
1
  import { Document, mongo } from "mongoose";
2
-
3
2
  //#region src/assertions.d.ts
4
- declare function assertMongooseUpdateSuccess<T extends Document>(updatePromise: Promise<mongo.UpdateResult<T>>, expectedModifiedCount?: number): Promise<void>;
3
+ export declare function assertMongooseUpdateSuccess<T extends Document>(updatePromise: Promise<mongo.UpdateResult<T>>, expectedModifiedCount?: number): Promise<void>;
5
4
  //#endregion
6
- export { assertMongooseUpdateSuccess };
7
5
  //# sourceMappingURL=assertions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assertions.d.ts","names":[],"sources":["../src/assertions.ts"],"mappings":";;;iBAKsB,2BAAA,WAAsC,QAAA,CAAA,CACxD,aAAA,EAAe,OAAA,CAAQ,KAAA,CAAM,YAAA,CAAa,CAAA,IAC1C,qBAAA,YAAyB,OAAA"}
1
+ {"version":3,"file":"assertions.d.ts","names":[],"sources":["../src/assertions.ts"],"mappings":";;wBAKsB,4BAA4B,UAAU,UACxD,eAAe,QAAQ,MAAM,aAAa,KAC1C,iCAAyB"}
@@ -1 +1 @@
1
- {"version":3,"file":"assertions.js","names":[],"sources":["../src/assertions.ts"],"sourcesContent":["import type {\n Document,\n mongo,\n} from 'mongoose';\n\nexport async function assertMongooseUpdateSuccess<T extends 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"],"mappings":";AAKA,eAAsB,4BAClB,eACA,wBAAwB,GAC1B;CACE,MAAM,eAAe,MAAM;AAC3B,KAAI,CAAC,aAAa,aAAc,OAAM,IAAI,MAAM,8BAA8B;AAC9E,KAAI,aAAa,gBAAgB,sBAE7B,OAAM,IAAI,MAAM,+BAA+B,sBAAsB,6BAA6B,aAAa,gBAAgB"}
1
+ {"version":3,"file":"assertions.js","names":[],"sources":["../src/assertions.ts"],"sourcesContent":["import type {\n Document,\n mongo,\n} from 'mongoose';\n\nexport async function assertMongooseUpdateSuccess<T extends 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"],"mappings":";AAKA,eAAsB,4BAClB,eACA,wBAAwB,GAC1B;CACE,MAAM,eAAe,MAAM;CAC3B,IAAI,CAAC,aAAa,cAAc,MAAM,IAAI,MAAM,6BAA6B;CAC7E,IAAI,aAAa,gBAAgB,uBAE7B,MAAM,IAAI,MAAM,+BAA+B,sBAAsB,6BAA6B,aAAa,eAAe;AAEtI"}
@@ -3,11 +3,9 @@ import { BaseMongoosePaginateModel } from "./types/index.js";
3
3
  import { BuildMongooseModelOptions } from "./types/options.js";
4
4
  import { mongooseAssertionsPlugin } from "./plugins/assertions.js";
5
5
  import { Model, Schema } from "mongoose";
6
-
7
6
  //#region src/builders.d.ts
8
- type DoNotRemoveOrUseThisType = typeof mongooseAssertionsPlugin;
9
- declare function buildMongooseModel<DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(collection: string, name: string, schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>, options?: BuildMongooseModelOptions): Model;
10
- declare function registerMongooseNormalizePlugin<DocType, Model$1 extends Model<DocType, QueryHelpers, InstanceMethodsAndOverrides>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(schema: Schema<DocType, Model$1, InstanceMethodsAndOverrides, QueryHelpers>, recursive?: boolean, options?: MongooseNormalizePluginOptions): void;
7
+ export type DoNotRemoveOrUseThisType = typeof mongooseAssertionsPlugin;
8
+ export declare function buildMongooseModel<DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(collection: string, name: string, schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>, options?: BuildMongooseModelOptions): Model;
9
+ export declare function registerMongooseNormalizePlugin<DocType, Model$1 extends Model<DocType, QueryHelpers, InstanceMethodsAndOverrides>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(schema: Schema<DocType, Model$1, InstanceMethodsAndOverrides, QueryHelpers>, recursive?: boolean, options?: MongooseNormalizePluginOptions): void;
11
10
  //#endregion
12
- export { DoNotRemoveOrUseThisType, buildMongooseModel, registerMongooseNormalizePlugin };
13
11
  //# sourceMappingURL=builders.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"builders.d.ts","names":[],"sources":["../src/builders.ts"],"mappings":";;;;;;;KAgBY,wBAAA,UAAkC,wBAAA;AAAA,iBAE9B,kBAAA,wBAEE,yBAAA,CAA0B,OAAA,EAAS,2BAAA,EAA6B,YAAA,+DAAA,CAI9E,UAAA,UACA,IAAA,UACA,MAAA,EAAQ,MAAA,CAAO,OAAA,EAAS,KAAA,EAAO,2BAAA,EAA6B,YAAA,GAC5D,OAAA,GAAU,yBAAA,GACX,KAAA;AAAA,iBAoBa,+BAAA,0BAEE,KAAA,CAAc,OAAA,EAAS,YAAA,EAAc,2BAAA,+DAAA,CAInD,MAAA,EAAQ,MAAA,CAAO,OAAA,EAAS,OAAA,EAAO,2BAAA,EAA6B,YAAA,GAC5D,SAAA,YACA,OAAA,GAAU,8BAAA"}
1
+ {"version":3,"file":"builders.d.ts","names":["MongooseModel","Model"],"sources":["../src/builders.ts"],"mappings":";;;;;;YAgBY,kCAAkC;wBAE9B,mBACZ,SACA,cAAc,0BAA0B,SAAS,6BAA6B,eAC9E,sCACA,uBAEA,oBACA,cACA,QAAQ,OAAO,SAAS,OAAO,6BAA6B,eAC5D,UAAU,4BACX;wBAoBa,gCACZ,SACA,gBAAcA,MAAc,SAAS,cAAc,8BACnD,sCACA,uBAEA,QAAQ,OAAO,SAASC,SAAO,6BAA6B,eAC5D,qBACA,UAAU"}
@@ -1 +1 @@
1
- {"version":3,"file":"builders.js","names":[],"sources":["../src/builders.ts"],"sourcesContent":["import mongoose from 'mongoose';\nimport type {\n Model as MongooseModel,\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 { mongooseAssertionsPlugin } from './plugins/assertions';\nimport { mongooseNormalizePlugin } from './plugins/normalize';\nimport type { MongooseNormalizePluginOptions } from './plugins/normalize';\nimport type { BaseMongoosePaginateModel } from './types';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof mongooseAssertionsPlugin;\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): Model {\n if (options?.enableNormalizePlugin !== false) {\n registerMongooseNormalizePlugin(schema, options?.normalizePluginRecursive, options?.normalizePluginOptions);\n }\n\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongooseAssertionsPlugin);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n const connection =\n options?.connection\n || (\n mongooseConnections.default ||= mongoose.createConnection(\n process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017',\n )\n );\n\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\nexport function registerMongooseNormalizePlugin<\n DocType,\n Model extends MongooseModel<DocType, QueryHelpers, InstanceMethodsAndOverrides>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n recursive: boolean = true,\n options?: MongooseNormalizePluginOptions,\n) {\n schema.plugin(mongooseNormalizePlugin, options);\n if (recursive) {\n schema.childSchemas.forEach(({ schema }) => registerMongooseNormalizePlugin(schema, recursive, options));\n }\n}\n"],"mappings":";;;;;;;;AAkBA,SAAgB,mBAMZ,YACA,MACA,QACA,SACK;AACL,KAAI,SAAS,0BAA0B,MACnC,iCAAgC,QAAQ,SAAS,0BAA0B,SAAS,uBAAuB;AAG/G,QAAO,OAAO,0BAA0B;AACxC,QAAO,OAAO,yBAAyB;AACvC,QAAO,OAAO,iBAAiB;AAC/B,QAAO,IAAI,cAAc,SAAS,cAAc,OAAO,IAAI,aAAa,IAAI,KAAK;AACjF,uBAAsB,mBAAmB,OAAO;AAShD,SAPI,SAAS,eAEL,oBAAoB,YAAY,SAAS,iBACrC,QAAQ,IAAI,eAAe,4BAC9B,GAGS,MAAoC,MAAM,QAAQ,WAAW;;AAEnF,SAAgB,gCAMZ,QACA,YAAqB,MACrB,SACF;AACE,QAAO,OAAO,yBAAyB,QAAQ;AAC/C,KAAI,UACA,QAAO,aAAa,SAAS,EAAE,aAAa,gCAAgC,QAAQ,WAAW,QAAQ,CAAC"}
1
+ {"version":3,"file":"builders.js","names":[],"sources":["../src/builders.ts"],"sourcesContent":["import mongoose from 'mongoose';\nimport type {\n Model as MongooseModel,\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 { mongooseAssertionsPlugin } from './plugins/assertions';\nimport { mongooseNormalizePlugin } from './plugins/normalize';\nimport type { MongooseNormalizePluginOptions } from './plugins/normalize';\nimport type { BaseMongoosePaginateModel } from './types';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof mongooseAssertionsPlugin;\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): Model {\n if (options?.enableNormalizePlugin !== false) {\n registerMongooseNormalizePlugin(schema, options?.normalizePluginRecursive, options?.normalizePluginOptions);\n }\n\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongooseAssertionsPlugin);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n const connection =\n options?.connection\n || (\n mongooseConnections.default ||= mongoose.createConnection(\n process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017',\n )\n );\n\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\nexport function registerMongooseNormalizePlugin<\n DocType,\n Model extends MongooseModel<DocType, QueryHelpers, InstanceMethodsAndOverrides>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n recursive: boolean = true,\n options?: MongooseNormalizePluginOptions,\n) {\n schema.plugin(mongooseNormalizePlugin, options);\n if (recursive) {\n schema.childSchemas.forEach(({ schema }) => registerMongooseNormalizePlugin(schema, recursive, options));\n }\n}\n"],"mappings":";;;;;;;;AAkBA,SAAgB,mBAMZ,YACA,MACA,QACA,SACK;CACL,IAAI,SAAS,0BAA0B,OACnC,gCAAgC,QAAQ,SAAS,0BAA0B,SAAS,sBAAsB;CAG9G,OAAO,OAAO,yBAAyB;CACvC,OAAO,OAAO,wBAAwB;CACtC,OAAO,OAAO,gBAAgB;CAC9B,OAAO,IAAI,cAAc,SAAS,cAAc,OAAO,IAAI,YAAY,KAAK,IAAI;CAChF,sBAAsB,mBAAmB,MAAM;CAS/C,QAPI,SAAS,eAEL,oBAAoB,YAAY,SAAS,iBACrC,QAAQ,IAAI,eAAe,2BAC/B,GAAA,CAGU,MAAoC,MAAM,QAAQ,UAAU;AAClF;AACA,SAAgB,gCAMZ,QACA,YAAqB,MACrB,SACF;CACE,OAAO,OAAO,yBAAyB,OAAO;CAC9C,IAAI,WACA,OAAO,aAAa,SAAS,EAAE,aAAa,gCAAgC,QAAQ,WAAW,OAAO,CAAC;AAE/G"}
@@ -1,7 +1,5 @@
1
1
  import { MongooseConnections } from "./types/index.js";
2
-
3
2
  //#region src/constants.d.ts
4
- declare const mongooseConnections: MongooseConnections;
3
+ export declare const mongooseConnections: MongooseConnections;
5
4
  //#endregion
6
- export { mongooseConnections };
7
5
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;;cAEa,mBAAA,EAAqB,mBAAA"}
1
+ {"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;qBAEa,qBAAqB"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { MongooseConnections } from './types';\n\nexport const mongooseConnections: MongooseConnections = {};\n"],"mappings":";AAEA,MAAa,sBAA2C,EAAE"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { MongooseConnections } from './types';\n\nexport const mongooseConnections: MongooseConnections = {};\n"],"mappings":";AAEA,MAAa,sBAA2C,CAAC"}
package/dist/helpers.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { Types } from "mongoose";
2
-
3
2
  //#region src/helpers.d.ts
4
- declare function toObjectIdHexString(id: string | Types.ObjectId): string;
3
+ export declare function toObjectIdHexString(id: string | Types.ObjectId): string;
5
4
  //#endregion
6
- export { toObjectIdHexString };
7
5
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","names":[],"sources":["../src/helpers.ts"],"mappings":";;;iBAEgB,mBAAA,CAAoB,EAAA,WAAa,KAAA,CAAM,QAAA"}
1
+ {"version":3,"file":"helpers.d.ts","names":[],"sources":["../src/helpers.ts"],"mappings":";;wBAEgB,oBAAoB,aAAa,MAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["import { Types } from 'mongoose';\n\nexport function toObjectIdHexString(id: string | Types.ObjectId) {\n return id instanceof Types.ObjectId ? id.toHexString() : id;\n}\n"],"mappings":";;AAEA,SAAgB,oBAAoB,IAA6B;AAC7D,QAAO,cAAc,MAAM,WAAW,GAAG,aAAa,GAAG"}
1
+ {"version":3,"file":"helpers.js","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["import { Types } from 'mongoose';\n\nexport function toObjectIdHexString(id: string | Types.ObjectId) {\n return id instanceof Types.ObjectId ? id.toHexString() : id;\n}\n"],"mappings":";;AAEA,SAAgB,oBAAoB,IAA6B;CAC7D,OAAO,cAAc,MAAM,WAAW,GAAG,YAAY,IAAI;AAC7D"}
package/dist/options.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { CustomMongooseOptions } from "./types/options.js";
2
-
3
2
  //#region src/options.d.ts
4
- declare function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(key: K, value: CustomMongooseOptions[K]): void;
3
+ export declare function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(key: K, value: CustomMongooseOptions[K]): void;
5
4
  //#endregion
6
- export { setCustomMongooseOptions };
7
5
  //# sourceMappingURL=options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","names":[],"sources":["../src/options.ts"],"mappings":";;;iBAGgB,wBAAA,iBAAyC,qBAAA,CAAA,CACrD,GAAA,EAAK,CAAA,EACL,KAAA,EAAO,qBAAA,CAAsB,CAAA"}
1
+ {"version":3,"file":"options.d.ts","names":[],"sources":["../src/options.ts"],"mappings":";;wBAGgB,yBAAyB,gBAAgB,uBACrD,KAAK,GACL,OAAO,sBAAsB"}
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","names":[],"sources":["../src/options.ts"],"sourcesContent":["import { customMongooseOptions } from './_internals';\nimport type { CustomMongooseOptions } from './types/options';\n\nexport function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(\n key: K,\n value: CustomMongooseOptions[K],\n) {\n customMongooseOptions[key] = value;\n}\n"],"mappings":";;AAGA,SAAgB,yBACZ,KACA,OACF;AACE,uBAAsB,OAAO"}
1
+ {"version":3,"file":"options.js","names":[],"sources":["../src/options.ts"],"sourcesContent":["import { customMongooseOptions } from './_internals';\nimport type { CustomMongooseOptions } from './types/options';\n\nexport function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(\n key: K,\n value: CustomMongooseOptions[K],\n) {\n customMongooseOptions[key] = value;\n}\n"],"mappings":";;AAGA,SAAgB,yBACZ,KACA,OACF;CACE,sBAAsB,OAAO;AACjC"}
@@ -1,5 +1,4 @@
1
1
  import { Schema, mongo } from "mongoose";
2
-
3
2
  //#region src/plugins/assertions.d.ts
4
3
  declare module 'mongoose' {
5
4
  interface Document<T = Types.ObjectId, TQueryHelpers = any, DocType = any, TVirtuals = Record<string, any>, TSchemaOptions = {}> {
@@ -9,7 +8,6 @@ declare module 'mongoose' {
9
8
  assertUpdateSuccess: (filter: QueryFilter<TRawDocType>, update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline, options?: (mongo.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null, expectedModifiedCount?: number) => Promise<void>;
10
9
  }
11
10
  }
12
- declare function mongooseAssertionsPlugin<S extends Schema>(schema: S): void;
11
+ export declare function mongooseAssertionsPlugin<S extends Schema>(schema: S): void;
13
12
  //#endregion
14
- export { mongooseAssertionsPlugin };
15
13
  //# sourceMappingURL=assertions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assertions.d.ts","names":[],"sources":["../../src/plugins/assertions.ts"],"mappings":";;;;YAac,QAAA,KACF,KAAA,CAAM,QAAA,kDAGE,MAAA;IAIZ,mBAAA,GACI,MAAA,GACI,WAAA,CAAY,QAAA,CAAS,CAAA,EAAG,aAAA,EAAe,OAAA,EAAS,SAAA,EAAW,cAAA,KAC3D,6BAAA,EACJ,OAAA,UAAiB,YAAA,EACjB,qBAAA,cACC,OAAA;EAAA;EAAA,UAGC,KAAA,iGASkB,gBAAA,CAAiB,WAAA,EAAa,gBAAA,GAAmB,SAAA,EAAW,aAAA,EAAe,SAAA;IAInG,mBAAA,GACI,MAAA,EAAQ,WAAA,CAAY,WAAA,GACpB,MAAA,EAAQ,WAAA,CAAY,WAAA,IAAe,6BAAA,EACnC,OAAA,IAAW,KAAA,CAAM,aAAA,GAAgB,0BAAA,CAA2B,WAAA,WAC5D,qBAAA,cACC,OAAA;EAAA;AAAA;AAAA,iBAIG,wBAAA,WAAmC,MAAA,CAAA,CAAQ,MAAA,EAAQ,CAAA"}
1
+ {"version":3,"file":"assertions.d.ts","names":[],"sources":["../../src/plugins/assertions.ts"],"mappings":";;;YAac,SACN,IAAI,MAAM,UACV,qBACA,eACA,YAAY,qBAEZ;IAEA,sBACI,SACI,YAAY,SAAS,GAAG,eAAe,SAAS,WAAW,mBAC3D,+BACJ,iBAAiB,cACjB,mCACC;;YAGC,MACN,aAEA,oBAEA,uBAEA,gBAEA,wBAAwB,iBAAiB,aAAa,mBAAmB,WAAW,eAAe,YAEnG;IAEA,sBACI,QAAQ,YAAY,cACpB,QAAQ,YAAY,eAAe,+BACnC,WAAW,MAAM,gBAAgB,2BAA2B,sBAC5D,mCACC;;;wBAIG,yBAAyB,UAAU,QAAQ,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"assertions.js","names":[],"sources":["../../src/plugins/assertions.ts"],"sourcesContent":["import type {\n mongo,\n MongooseUpdateQueryOptions,\n QueryFilter,\n QueryOptions,\n Schema,\n UpdateQuery,\n UpdateWithAggregationPipeline,\n} from 'mongoose';\n\nimport { assertMongooseUpdateSuccess } from '../assertions';\n\ndeclare module 'mongoose' {\n interface Document<\n T = Types.ObjectId,\n TQueryHelpers = any,\n DocType = any,\n TVirtuals = Record<string, any>,\n // eslint-disable-next-line ts/no-empty-object-type\n TSchemaOptions = {},\n > {\n assertUpdateSuccess: (\n update?:\n | UpdateQuery<Document<T, TQueryHelpers, DocType, TVirtuals, TSchemaOptions>>\n | UpdateWithAggregationPipeline,\n options?: null | QueryOptions,\n expectedModifiedCount?: number,\n ) => Promise<void>;\n }\n\n interface Model<\n TRawDocType,\n // eslint-disable-next-line ts/no-empty-object-type\n TQueryHelpers = {},\n // eslint-disable-next-line ts/no-empty-object-type\n TInstanceMethods = {},\n // eslint-disable-next-line ts/no-empty-object-type\n TVirtuals = {},\n // eslint-disable-next-line unused-imports/no-unused-vars\n THydratedDocumentType = HydratedDocument<TRawDocType, TInstanceMethods & TVirtuals, TQueryHelpers, TVirtuals>,\n // eslint-disable-next-line unused-imports/no-unused-vars\n TSchema = any,\n > {\n assertUpdateSuccess: (\n filter: QueryFilter<TRawDocType>,\n update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,\n options?: (mongo.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null,\n expectedModifiedCount?: number,\n ) => Promise<void>;\n }\n}\n\nexport function mongooseAssertionsPlugin<S extends Schema>(schema: S) {\n schema.method(\n 'assertUpdateSuccess',\n function (\n update?: UpdateQuery<any> | UpdateWithAggregationPipeline,\n options?: null | QueryOptions,\n expectedModifiedCount?: number,\n ) {\n return assertMongooseUpdateSuccess(this.updateOne(update, options), expectedModifiedCount);\n },\n );\n\n schema.static(\n 'assertUpdateSuccess',\n function (\n filter: QueryFilter<any>,\n update: UpdateQuery<any> | UpdateWithAggregationPipeline,\n options?: (mongo.UpdateOptions & MongooseUpdateQueryOptions<any>) | null,\n expectedModifiedCount: number = 1,\n ) {\n return assertMongooseUpdateSuccess(\n expectedModifiedCount === 1\n ? this.updateOne(filter, update, options)\n : this.updateMany(filter, update, options),\n expectedModifiedCount,\n );\n },\n );\n}\n"],"mappings":";;AAoDA,SAAgB,yBAA2C,QAAW;AAClE,QAAO,OACH,uBACA,SACI,QACA,SACA,uBACF;AACE,SAAO,4BAA4B,KAAK,UAAU,QAAQ,QAAQ,EAAE,sBAAsB;GAEjG;AAED,QAAO,OACH,uBACA,SACI,QACA,QACA,SACA,wBAAgC,GAClC;AACE,SAAO,4BACH,0BAA0B,IACpB,KAAK,UAAU,QAAQ,QAAQ,QAAQ,GACvC,KAAK,WAAW,QAAQ,QAAQ,QAAQ,EAC9C,sBACH;GAER"}
1
+ {"version":3,"file":"assertions.js","names":[],"sources":["../../src/plugins/assertions.ts"],"sourcesContent":["import type {\n mongo,\n MongooseUpdateQueryOptions,\n QueryFilter,\n QueryOptions,\n Schema,\n UpdateQuery,\n UpdateWithAggregationPipeline,\n} from 'mongoose';\n\nimport { assertMongooseUpdateSuccess } from '../assertions';\n\ndeclare module 'mongoose' {\n interface Document<\n T = Types.ObjectId,\n TQueryHelpers = any,\n DocType = any,\n TVirtuals = Record<string, any>,\n // eslint-disable-next-line ts/no-empty-object-type\n TSchemaOptions = {},\n > {\n assertUpdateSuccess: (\n update?:\n | UpdateQuery<Document<T, TQueryHelpers, DocType, TVirtuals, TSchemaOptions>>\n | UpdateWithAggregationPipeline,\n options?: null | QueryOptions,\n expectedModifiedCount?: number,\n ) => Promise<void>;\n }\n\n interface Model<\n TRawDocType,\n // eslint-disable-next-line ts/no-empty-object-type\n TQueryHelpers = {},\n // eslint-disable-next-line ts/no-empty-object-type\n TInstanceMethods = {},\n // eslint-disable-next-line ts/no-empty-object-type\n TVirtuals = {},\n // eslint-disable-next-line unused-imports/no-unused-vars\n THydratedDocumentType = HydratedDocument<TRawDocType, TInstanceMethods & TVirtuals, TQueryHelpers, TVirtuals>,\n // eslint-disable-next-line unused-imports/no-unused-vars\n TSchema = any,\n > {\n assertUpdateSuccess: (\n filter: QueryFilter<TRawDocType>,\n update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,\n options?: (mongo.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null,\n expectedModifiedCount?: number,\n ) => Promise<void>;\n }\n}\n\nexport function mongooseAssertionsPlugin<S extends Schema>(schema: S) {\n schema.method(\n 'assertUpdateSuccess',\n function (\n update?: UpdateQuery<any> | UpdateWithAggregationPipeline,\n options?: null | QueryOptions,\n expectedModifiedCount?: number,\n ) {\n return assertMongooseUpdateSuccess(this.updateOne(update, options), expectedModifiedCount);\n },\n );\n\n schema.static(\n 'assertUpdateSuccess',\n function (\n filter: QueryFilter<any>,\n update: UpdateQuery<any> | UpdateWithAggregationPipeline,\n options?: (mongo.UpdateOptions & MongooseUpdateQueryOptions<any>) | null,\n expectedModifiedCount: number = 1,\n ) {\n return assertMongooseUpdateSuccess(\n expectedModifiedCount === 1\n ? this.updateOne(filter, update, options)\n : this.updateMany(filter, update, options),\n expectedModifiedCount,\n );\n },\n );\n}\n"],"mappings":";;AAoDA,SAAgB,yBAA2C,QAAW;CAClE,OAAO,OACH,uBACA,SACI,QACA,SACA,uBACF;EACE,OAAO,4BAA4B,KAAK,UAAU,QAAQ,OAAO,GAAG,qBAAqB;CAC7F,CACJ;CAEA,OAAO,OACH,uBACA,SACI,QACA,QACA,SACA,wBAAgC,GAClC;EACE,OAAO,4BACH,0BAA0B,IACpB,KAAK,UAAU,QAAQ,QAAQ,OAAO,IACtC,KAAK,WAAW,QAAQ,QAAQ,OAAO,GAC7C,qBACJ;CACJ,CACJ;AACJ"}
@@ -1,7 +1,6 @@
1
1
  import { Schema } from "mongoose";
2
-
3
2
  //#region src/plugins/normalize.d.ts
4
- interface MongooseNormalizePluginOptions {
3
+ export interface MongooseNormalizePluginOptions {
5
4
  /**
6
5
  * Whether to convert `_id` field to `id`.
7
6
  * If true, the `_id` field will be replaced with `id`.
@@ -30,7 +29,6 @@ interface MongooseNormalizePluginOptions {
30
29
  *
31
30
  * @param schema - The Mongoose schema to apply the plugin to.
32
31
  */
33
- declare function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions): void;
32
+ export declare function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptions?: MongooseNormalizePluginOptions): void;
34
33
  //#endregion
35
- export { MongooseNormalizePluginOptions, mongooseNormalizePlugin };
36
34
  //# sourceMappingURL=normalize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","names":[],"sources":["../../src/plugins/normalize.ts"],"mappings":";;;UAQiB,8BAAA;;AAAjB;;;;;EAOI,cAAA;EAwBmC;;;;;EAjBnC,iBAAA;AAAA;;;;;;;;;;;;;;;iBAiBY,uBAAA,WAAkC,MAAA,CAAA,CAC9C,MAAA,EAAQ,CAAA,EACR,aAAA,GAAgB,8BAAA"}
1
+ {"version":3,"file":"normalize.d.ts","names":[],"sources":["../../src/plugins/normalize.ts"],"mappings":";;iBAQiB;;;;;;;EAOb;;;;;;EAOA;;;;;;;;;;;;;;;;wBAiBY,wBAAwB,UAAU,QAC9C,QAAQ,GACR,gBAAgB"}
@@ -30,8 +30,10 @@ function mongooseNormalizePlugin(schema, pluginOptions) {
30
30
  let _id = copiedRet._id;
31
31
  delete copiedRet._id;
32
32
  if (pluginOptions?.toHexIdIfObjectId !== false && _id instanceof Types.ObjectId) _id = _id.toHexString();
33
- if (_id !== void 0) if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;
34
- else copiedRet._id = _id;
33
+ if (_id !== void 0) {
34
+ if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;
35
+ else copiedRet._id = _id;
36
+ }
35
37
  for (const path of privatePaths) unset(copiedRet, path);
36
38
  for (const path of decimalPaths) {
37
39
  const value = get(copiedRet, path);
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.js","names":["getProp"],"sources":["../../src/plugins/normalize.ts"],"sourcesContent":["import {\n get as getProp,\n set as setProp,\n unset as unsetProp,\n} from 'es-toolkit/compat';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(\n schema: S,\n pluginOptions?: MongooseNormalizePluginOptions,\n) {\n // Collect special paths (Decimal128 & private)\n const decimalPaths: string[] = [];\n const privatePaths: string[] = [];\n for (const [path, schemaType] of Object.entries(schema.paths)) {\n if (schemaType?.options?.private) privatePaths.push(path);\n else if (schemaType?.instance === 'Decimal128') decimalPaths.push(path);\n }\n\n // Get original toJSON configuration\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n\n // Override toJSON with custom transform\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // Copy object and remove __v\n const copiedRet = { ...ret };\n // @ts-expect-error Ignore this error\n delete copiedRet.__v;\n\n // Normalize _id (convert to hex and/or move to id)\n let _id = copiedRet._id;\n delete copiedRet._id;\n if (pluginOptions?.toHexIdIfObjectId !== false && _id instanceof Types.ObjectId) {\n _id = _id.toHexString();\n }\n\n if (_id !== undefined) {\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _id;\n }\n\n // Remove private fields\n for (const path of privatePaths) unsetProp(copiedRet, path);\n\n // Convert Decimal128 fields to string\n for (const path of decimalPaths) {\n const value = getProp(copiedRet, path) as Types.Decimal128 | undefined;\n if (value) setProp(copiedRet, path, value.toString());\n }\n\n // Run original toJSON transform\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc as any, copiedRet as any, options as any);\n }\n\n // Return normalized object\n return copiedRet;\n },\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuCA,SAAgB,wBACZ,QACA,eACF;CAEE,MAAM,eAAyB,EAAE;CACjC,MAAM,eAAyB,EAAE;AACjC,MAAK,MAAM,CAAC,MAAM,eAAe,OAAO,QAAQ,OAAO,MAAM,CACzD,KAAI,YAAY,SAAS,QAAS,cAAa,KAAK,KAAK;UAChD,YAAY,aAAa,aAAc,cAAa,KAAK,KAAK;CAI3E,MAAM,SAAS,OAAO,IAAI,SAAS;CACnC,MAAM,kBAAkB,QAAQ;AAGhC,QAAO,IACH,UACA;EACI,GAAG;EACH,UAAU,KAAK,KAAK,SAAS;GAEzB,MAAM,YAAY,EAAE,GAAG,KAAK;AAE5B,UAAO,UAAU;GAGjB,IAAI,MAAM,UAAU;AACpB,UAAO,UAAU;AACjB,OAAI,eAAe,sBAAsB,SAAS,eAAe,MAAM,SACnE,OAAM,IAAI,aAAa;AAG3B,OAAI,QAAQ,KAAA,EACR,KAAI,eAAe,mBAAmB,MAAO,WAAU,KAAK;OACvD,WAAU,MAAM;AAIzB,QAAK,MAAM,QAAQ,aAAc,OAAU,WAAW,KAAK;AAG3D,QAAK,MAAM,QAAQ,cAAc;IAC7B,MAAM,QAAQA,IAAQ,WAAW,KAAK;AACtC,QAAI,MAAO,KAAQ,WAAW,MAAM,MAAM,UAAU,CAAC;;AAIzD,OAAI,mBAAmB,OAAO,oBAAoB,UAC9C,QAAO,gBAAgB,KAAY,WAAkB,QAAe;AAIxE,UAAO;;EAEd,CACJ"}
1
+ {"version":3,"file":"normalize.js","names":["getProp"],"sources":["../../src/plugins/normalize.ts"],"sourcesContent":["import {\n get as getProp,\n set as setProp,\n unset as unsetProp,\n} from 'es-toolkit/compat';\nimport { Types } from 'mongoose';\nimport type { Schema } from 'mongoose';\n\nexport interface MongooseNormalizePluginOptions {\n /**\n * Whether to convert `_id` field to `id`.\n * If true, the `_id` field will be replaced with `id`.\n *\n * @default true\n */\n convertIdField?: boolean;\n\n /**\n * Whether to convert the `_id` field to a hex string if it's an ObjectId.\n *\n * @default true\n */\n toHexIdIfObjectId?: boolean;\n}\n\n/**\n * Mongoose plugin to normalize the JSON output of documents.\n *\n * This plugin modifies the `toJSON` method of Mongoose schemas to:\n * - Add an `id` field equal to the string representation of `_id`\n * - Remove the `_id` field\n * - Exclude fields marked as `private` from the JSON output\n * - Convert `Decimal128` fields to strings\n * - Remove the `__v` version key\n *\n * @template S - The type of the schema.\n *\n * @param schema - The Mongoose schema to apply the plugin to.\n */\nexport function mongooseNormalizePlugin<S extends Schema>(\n schema: S,\n pluginOptions?: MongooseNormalizePluginOptions,\n) {\n // Collect special paths (Decimal128 & private)\n const decimalPaths: string[] = [];\n const privatePaths: string[] = [];\n for (const [path, schemaType] of Object.entries(schema.paths)) {\n if (schemaType?.options?.private) privatePaths.push(path);\n else if (schemaType?.instance === 'Decimal128') decimalPaths.push(path);\n }\n\n // Get original toJSON configuration\n const toJson = schema.get('toJSON');\n const toJsonTransform = toJson?.transform;\n\n // Override toJSON with custom transform\n schema.set(\n 'toJSON',\n {\n ...toJson,\n transform(doc, ret, options) {\n // Copy object and remove __v\n const copiedRet = { ...ret };\n // @ts-expect-error Ignore this error\n delete copiedRet.__v;\n\n // Normalize _id (convert to hex and/or move to id)\n let _id = copiedRet._id;\n delete copiedRet._id;\n if (pluginOptions?.toHexIdIfObjectId !== false && _id instanceof Types.ObjectId) {\n _id = _id.toHexString();\n }\n\n if (_id !== undefined) {\n if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;\n else copiedRet._id = _id;\n }\n\n // Remove private fields\n for (const path of privatePaths) unsetProp(copiedRet, path);\n\n // Convert Decimal128 fields to string\n for (const path of decimalPaths) {\n const value = getProp(copiedRet, path) as Types.Decimal128 | undefined;\n if (value) setProp(copiedRet, path, value.toString());\n }\n\n // Run original toJSON transform\n if (toJsonTransform && typeof toJsonTransform !== 'boolean') {\n return toJsonTransform(doc as any, copiedRet as any, options as any);\n }\n\n // Return normalized object\n return copiedRet;\n },\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuCA,SAAgB,wBACZ,QACA,eACF;CAEE,MAAM,eAAyB,CAAC;CAChC,MAAM,eAAyB,CAAC;CAChC,KAAK,MAAM,CAAC,MAAM,eAAe,OAAO,QAAQ,OAAO,KAAK,GACxD,IAAI,YAAY,SAAS,SAAS,aAAa,KAAK,IAAI;MACnD,IAAI,YAAY,aAAa,cAAc,aAAa,KAAK,IAAI;CAI1E,MAAM,SAAS,OAAO,IAAI,QAAQ;CAClC,MAAM,kBAAkB,QAAQ;CAGhC,OAAO,IACH,UACA;EACI,GAAG;EACH,UAAU,KAAK,KAAK,SAAS;GAEzB,MAAM,YAAY,EAAE,GAAG,IAAI;GAE3B,OAAO,UAAU;GAGjB,IAAI,MAAM,UAAU;GACpB,OAAO,UAAU;GACjB,IAAI,eAAe,sBAAsB,SAAS,eAAe,MAAM,UACnE,MAAM,IAAI,YAAY;GAG1B,IAAI,QAAQ,KAAA,GAAW;IACnB,IAAI,eAAe,mBAAmB,OAAO,UAAU,KAAK;SACvD,UAAU,MAAM;GACzB;GAGA,KAAK,MAAM,QAAQ,cAAc,MAAU,WAAW,IAAI;GAG1D,KAAK,MAAM,QAAQ,cAAc;IAC7B,MAAM,QAAQA,IAAQ,WAAW,IAAI;IACrC,IAAI,OAAO,IAAQ,WAAW,MAAM,MAAM,SAAS,CAAC;GACxD;GAGA,IAAI,mBAAmB,OAAO,oBAAoB,WAC9C,OAAO,gBAAgB,KAAY,WAAkB,OAAc;GAIvE,OAAO;EACX;CACJ,CACJ;AACJ"}
@@ -1,8 +1,6 @@
1
1
  import { Schema } from "mongoose";
2
-
3
2
  //#region src/schema-builders/base.d.ts
4
3
  type BaseSchemaType = BooleanConstructor | DateConstructor | NumberConstructor | Schema.Types.ObjectId['constructor'] | StringConstructor;
5
- declare function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType): (schema?: Record<string, any>) => Builder;
4
+ export declare function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType): (schema?: Record<string, any>) => Builder;
6
5
  //#endregion
7
- export { createBaseSchemaBuilderFactory };
8
6
  //# sourceMappingURL=base.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","names":[],"sources":["../../src/schema-builders/base.ts"],"mappings":";;;KAEK,cAAA,GACD,kBAAA,GACA,eAAA,GACA,iBAAA,GACA,MAAA,CAAO,KAAA,CAAM,QAAA,kBACb,iBAAA;AAAA,iBAYY,8BAAA,WAAyC,QAAA,CAAS,MAAA,eAAA,CAAsB,IAAA,EAAM,cAAA,IAClF,MAAA,GAAQ,MAAA,kBA2BP,OAAA"}
1
+ {"version":3,"file":"base.d.ts","names":[],"sources":["../../src/schema-builders/base.ts"],"mappings":";;KAEK,iBACD,qBACA,kBACA,oBACA,OAAO,MAAM,0BACb;wBAcY,+BAA+B,UAAU,SAAS,sBAAsB,MAAM,kBAClF,SAAQ,wBA2BP"}
@@ -1,5 +1,5 @@
1
1
  //#region src/schema-builders/base.ts
2
- const isFunctionKeys = new Set([
2
+ const isFunctionKeys = /* @__PURE__ */ new Set([
3
3
  "default",
4
4
  "enum",
5
5
  "index",
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","names":[],"sources":["../../src/schema-builders/base.ts"],"sourcesContent":["import type { Schema } from 'mongoose';\n\ntype BaseSchemaType =\n | BooleanConstructor\n | DateConstructor\n | NumberConstructor\n | Schema.Types.ObjectId['constructor']\n | StringConstructor;\n\nconst isFunctionKeys = new Set([\n 'default',\n 'enum',\n 'index',\n 'max',\n 'maxlength',\n 'min',\n 'minlength',\n]);\n\nexport function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType) {\n return (schema: Record<string, any> = {}) => {\n schema.type = type;\n return new Proxy(\n Object.freeze({}),\n {\n get(_, key, receiver) {\n if (typeof key === 'symbol') throw new Error('Cannot use symbol as a schema attribute');\n if (key in schema) throw new Error(`Duplicate schema attribute: ${key}`);\n if (isFunctionKeys.has(key)) {\n return (value: any) => {\n schema[key] = value;\n return receiver;\n };\n }\n\n if (key === 'nonRequired') return { ...schema };\n if (key === 'required') {\n return {\n ...schema,\n required: true,\n };\n }\n\n schema[key] = true;\n return receiver;\n },\n },\n ) as Builder;\n };\n}\n"],"mappings":";AASA,MAAM,iBAAiB,IAAI,IAAI;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACH,CAAC;AAEF,SAAgB,+BAAwE,MAAsB;AAC1G,SAAQ,SAA8B,EAAE,KAAK;AACzC,SAAO,OAAO;AACd,SAAO,IAAI,MACP,OAAO,OAAO,EAAE,CAAC,EACjB,EACI,IAAI,GAAG,KAAK,UAAU;AAClB,OAAI,OAAO,QAAQ,SAAU,OAAM,IAAI,MAAM,0CAA0C;AACvF,OAAI,OAAO,OAAQ,OAAM,IAAI,MAAM,+BAA+B,MAAM;AACxE,OAAI,eAAe,IAAI,IAAI,CACvB,SAAQ,UAAe;AACnB,WAAO,OAAO;AACd,WAAO;;AAIf,OAAI,QAAQ,cAAe,QAAO,EAAE,GAAG,QAAQ;AAC/C,OAAI,QAAQ,WACR,QAAO;IACH,GAAG;IACH,UAAU;IACb;AAGL,UAAO,OAAO;AACd,UAAO;KAEd,CACJ"}
1
+ {"version":3,"file":"base.js","names":[],"sources":["../../src/schema-builders/base.ts"],"sourcesContent":["import type { Schema } from 'mongoose';\n\ntype BaseSchemaType =\n | BooleanConstructor\n | DateConstructor\n | NumberConstructor\n | Schema.Types.ObjectId['constructor']\n | StringConstructor;\n\n// Constants/Variables\nconst isFunctionKeys = new Set([\n 'default',\n 'enum',\n 'index',\n 'max',\n 'maxlength',\n 'min',\n 'minlength',\n]);\n\n// Functions\nexport function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BaseSchemaType) {\n return (schema: Record<string, any> = {}) => {\n schema.type = type;\n return new Proxy(\n Object.freeze({}),\n {\n get(_, key, receiver) {\n if (typeof key === 'symbol') throw new Error('Cannot use symbol as a schema attribute');\n if (key in schema) throw new Error(`Duplicate schema attribute: ${key}`);\n if (isFunctionKeys.has(key)) {\n return (value: any) => {\n schema[key] = value;\n return receiver;\n };\n }\n\n if (key === 'nonRequired') return { ...schema };\n if (key === 'required') {\n return {\n ...schema,\n required: true,\n };\n }\n\n schema[key] = true;\n return receiver;\n },\n },\n ) as Builder;\n };\n}\n"],"mappings":";AAUA,MAAM,iCAAiB,IAAI,IAAI;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;AACJ,CAAC;AAGD,SAAgB,+BAAwE,MAAsB;CAC1G,QAAQ,SAA8B,CAAC,MAAM;EACzC,OAAO,OAAO;EACd,OAAO,IAAI,MACP,OAAO,OAAO,CAAC,CAAC,GAChB,EACI,IAAI,GAAG,KAAK,UAAU;GAClB,IAAI,OAAO,QAAQ,UAAU,MAAM,IAAI,MAAM,yCAAyC;GACtF,IAAI,OAAO,QAAQ,MAAM,IAAI,MAAM,+BAA+B,KAAK;GACvE,IAAI,eAAe,IAAI,GAAG,GACtB,QAAQ,UAAe;IACnB,OAAO,OAAO;IACd,OAAO;GACX;GAGJ,IAAI,QAAQ,eAAe,OAAO,EAAE,GAAG,OAAO;GAC9C,IAAI,QAAQ,YACR,OAAO;IACH,GAAG;IACH,UAAU;GACd;GAGJ,OAAO,OAAO;GACd,OAAO;EACX,EACJ,CACJ;CACJ;AACJ"}
@@ -1,12 +1,11 @@
1
1
  import { BooleanSchemaDefinition, DefaultType, IndexDirection, IndexOptions } from "mongoose";
2
2
  import { Merge } from "type-fest";
3
-
4
3
  //#region src/schema-builders/boolean.d.ts
5
4
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<BooleanSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
6
5
  interface BaseProps {
7
6
  type: BooleanSchemaDefinition;
8
7
  }
9
- interface BooleanSchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFields extends string = never> {
8
+ export interface BooleanSchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFields extends string = never> {
10
9
  default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends boolean>(value: T) => ExtendSchemaBuilder<Merge<Props, {
11
10
  default: T;
12
11
  }>, ExtraOmitFields>;
@@ -30,7 +29,6 @@ interface BooleanSchemaBuilder<Props extends BaseProps = BaseProps, ExtraOmitFie
30
29
  unique: true;
31
30
  }>, ExtraOmitFields>;
32
31
  }
33
- declare const booleanSchemaBuilder: (schema?: Record<string, any>) => BooleanSchemaBuilder<BaseProps, never>;
32
+ export declare const booleanSchemaBuilder: (schema?: Record<string, any>) => BooleanSchemaBuilder<BaseProps, never>;
34
33
  //#endregion
35
- export { BooleanSchemaBuilder, booleanSchemaBuilder };
36
34
  //# sourceMappingURL=boolean.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"boolean.d.ts","names":[],"sources":["../../src/schema-builders/boolean.ts"],"mappings":";;;;KAUK,mBAAA,eACa,SAAA,oCAEd,IAAA,CACA,oBAAA,CAAqB,KAAA,EAAO,eAAA,GAC5B,eAAA,SAAwB,KAAA;AAAA,UAGlB,SAAA;EACN,IAAA,EAAM,uBAAA;AAAA;AAAA,UAGO,oBAAA,eACC,SAAA,GAAY,SAAA;EAG1B,OAAA,eACgB,IAAA,OAAW,GAAA,UAAa,WAAA,CAAY,CAAA,KAAM,WAAA,CAAY,CAAA,6BAEpE,KAAA,EAAO,CAAA,KAAM,mBAAA,CACX,KAAA,CAAM,KAAA;IAAS,OAAA,EAAS,CAAA;EAAA,IACxB,eAAA;EAGJ,SAAA,EAAW,mBAAA,CAAoB,KAAA,CAAM,KAAA;IAAS,SAAA;EAAA,IAAoB,eAAA;EAClE,KAAA,uBAA4B,cAAA,GAAiB,YAAA,EAAc,KAAA,EAAO,CAAA,KAAM,mBAAA,CACpE,KAAA,CAAM,KAAA;IAAS,KAAA,EAAO,CAAA;EAAA,IACtB,eAAA;EAGJ,WAAA,EAAa,KAAA;EACb,OAAA,EAAS,mBAAA,CAAoB,KAAA,CAAM,KAAA;IAAS,OAAA;EAAA,IAAkB,eAAA;EAC9D,QAAA,EAAU,KAAA,CAAM,KAAA;IAAS,QAAA;EAAA;EACzB,MAAA,EAAQ,mBAAA,CAAoB,KAAA,CAAM,KAAA;IAAS,MAAA;EAAA,IAAiB,eAAA;EAC5D,MAAA,EAAQ,mBAAA,CAAoB,KAAA,CAAM,KAAA;IAAS,MAAA;EAAA,IAAiB,eAAA;AAAA;AAAA,cAGnD,oBAAA,GAAoB,MAAA,GAAA,MAAA,kBAAA,oBAAA,CAAA,SAAA"}
1
+ {"version":3,"file":"boolean.d.ts","names":[],"sources":["../../src/schema-builders/boolean.ts"],"mappings":";;;KAUK,oBACD,cAAc,WACd,kCACA,KACA,qBAAqB,OAAO,kBAC5B,wBAAwB;UAGlB;EACN,MAAM;;iBAGO,qBACb,cAAc,YAAY,WAC1B;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,mBACF,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,WAAW,oBAAoB,MAAM;IAAS;MAAoB;EAClE,QAAQ,oBAAoB,iBAAiB,cAAc,OAAO,MAAM,oBACpE,MAAM;IAAS,OAAO;MACtB;EAGJ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;EACzB,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;;qBAGnD,uBAAoB,SAAA,wBAAA,qBAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"boolean.js","names":[],"sources":["../../src/schema-builders/boolean.ts"],"sourcesContent":["import type {\n BooleanSchemaDefinition,\n DefaultType,\n IndexDirection,\n IndexOptions,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n BooleanSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: BooleanSchemaDefinition;\n}\n\nexport interface BooleanSchemaBuilder<\n Props extends BaseProps = BaseProps,\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends boolean,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\nexport const booleanSchemaBuilder = createBaseSchemaBuilderFactory<BooleanSchemaBuilder>(Boolean);\n"],"mappings":";;AA+CA,MAAa,uBAAuB,+BAAqD,QAAQ"}
1
+ {"version":3,"file":"boolean.js","names":[],"sources":["../../src/schema-builders/boolean.ts"],"sourcesContent":["import type {\n BooleanSchemaDefinition,\n DefaultType,\n IndexDirection,\n IndexOptions,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n BooleanSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: BooleanSchemaDefinition;\n}\n\nexport interface BooleanSchemaBuilder<\n Props extends BaseProps = BaseProps,\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends boolean,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\nexport const booleanSchemaBuilder = createBaseSchemaBuilderFactory<BooleanSchemaBuilder>(Boolean);\n"],"mappings":";;AA+CA,MAAa,uBAAuB,+BAAqD,OAAO"}
@@ -1,13 +1,12 @@
1
1
  import { Readonlyable } from "../types/_internals.js";
2
2
  import { DateSchemaDefinition, DefaultType, IndexDirection, IndexOptions } from "mongoose";
3
3
  import { Merge } from "type-fest";
4
-
5
4
  //#region src/schema-builders/date.d.ts
6
5
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<DateSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
7
6
  interface BaseProps {
8
7
  type: DateSchemaDefinition;
9
8
  }
10
- interface DateSchemaBuilder<Props extends {
9
+ export interface DateSchemaBuilder<Props extends {
11
10
  type: DateSchemaDefinition;
12
11
  } = {
13
12
  type: DateSchemaDefinition;
@@ -49,9 +48,8 @@ interface DateSchemaBuilder<Props extends {
49
48
  unique: true;
50
49
  }>, ExtraOmitFields>;
51
50
  }
52
- declare const dateSchemaBuilder: (schema?: Record<string, any>) => DateSchemaBuilder<{
51
+ export declare const dateSchemaBuilder: (schema?: Record<string, any>) => DateSchemaBuilder<{
53
52
  type: DateSchemaDefinition;
54
53
  }, never>;
55
54
  //#endregion
56
- export { DateSchemaBuilder, dateSchemaBuilder };
57
55
  //# sourceMappingURL=date.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"date.d.ts","names":[],"sources":["../../src/schema-builders/date.ts"],"mappings":";;;;;KAYK,mBAAA,eACa,SAAA,oCAEd,IAAA,CACA,iBAAA,CAAkB,KAAA,EAAO,eAAA,GACzB,eAAA,SAAwB,KAAA;AAAA,UAGlB,SAAA;EACN,IAAA,EAAM,oBAAA;AAAA;AAAA,UAGO,iBAAA;EACG,IAAA,EAAM,oBAAA;AAAA;EAA2B,IAAA,EAAM,oBAAA;AAAA;EAGvD,OAAA,eACgB,IAAA,OAAW,GAAA,UAAa,WAAA,CAAY,CAAA,KAAM,WAAA,CAAY,CAAA,oBACxD,UAAA,EACZ,KAAA,EAAO,CAAA,KAAM,mBAAA,CACX,KAAA,CAAM,KAAA;IAAS,OAAA,EAAS,CAAA;EAAA,IACxB,eAAA;EAGJ,IAAA,aAEM,YAAA,CAAa,KAAA,CAAM,CAAA;IAAA,CAChB,IAAA,WAAe,CAAA;EAAA;IAChB,OAAA,GAAU,CAAA;IAAG,MAAA,EAAQ,YAAA,CAAa,KAAA,CAAM,CAAA;EAAA,aAClC,UAAA,oBAEZ,KAAA,EAAO,CAAA,KAAM,mBAAA,CACX,KAAA,CAAM,KAAA;IAAS,IAAA,EAAM,CAAA;EAAA,IACrB,eAAA;EAGJ,SAAA,EAAW,mBAAA,CAAoB,KAAA,CAAM,KAAA;IAAS,SAAA;EAAA,IAAoB,eAAA;EAClE,KAAA,uBAA4B,cAAA,GAAiB,YAAA,EAAc,KAAA,EAAO,CAAA,KAAM,mBAAA,CACpE,KAAA,CAAM,KAAA;IAAS,KAAA,EAAO,CAAA;EAAA,IACtB,eAAA;EAGJ,GAAA,aACc,CAAA,GAAI,YAAA,EAAc,CAAA,EAAG,CAAA,cACrB,UAAA,oBAEZ,KAAA,EAAO,CAAA,KAAM,mBAAA,CACX,KAAA,CAAM,KAAA;IAAS,GAAA,EAAK,CAAA;EAAA,IACpB,eAAA;EAGJ,GAAA,aACc,CAAA,GAAI,YAAA,EAAc,CAAA,EAAG,CAAA,cACrB,UAAA,oBAEZ,KAAA,EAAO,CAAA,KAAM,mBAAA,CACX,KAAA,CAAM,KAAA;IAAS,GAAA,EAAK,CAAA;EAAA,IACpB,eAAA;EAGJ,WAAA,EAAa,KAAA;EACb,OAAA,EAAS,mBAAA,CAAoB,KAAA,CAAM,KAAA;IAAS,OAAA;EAAA,IAAkB,eAAA;EAC9D,QAAA,EAAU,KAAA,CAAM,KAAA;IAAS,QAAA;EAAA;EACzB,MAAA,EAAQ,mBAAA,CAAoB,KAAA,CAAM,KAAA;IAAS,MAAA;EAAA,IAAiB,eAAA;EAC5D,MAAA,EAAQ,mBAAA,CAAoB,KAAA,CAAM,KAAA;IAAS,MAAA;EAAA,IAAiB,eAAA;AAAA;AAAA,cAGnD,iBAAA,GAAiB,MAAA,GAAA,MAAA,kBAAA,iBAAA;QAtD6B,oBAAA;AAAA"}
1
+ {"version":3,"file":"date.d.ts","names":[],"sources":["../../src/schema-builders/date.ts"],"mappings":";;;;KAYK,oBACD,cAAc,WACd,kCACA,KACA,kBAAkB,OAAO,kBACzB,wBAAwB;UAGlB;EACN,MAAM;;iBAGO,kBACb;EAAgB,MAAM;;EAA2B,MAAM;GACvD;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,UAAU,YACZ,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,UACE,aAAa,MAAM;KAChB,eAAe;;IAChB,UAAU;IAAG,QAAQ,aAAa,MAAM;KAC5C,UAAU,YACV,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,MAAM;MACrB;EAGJ,WAAW,oBAAoB,MAAM;IAAS;MAAoB;EAClE,QAAQ,oBAAoB,iBAAiB,cAAc,OAAO,MAAM,oBACpE,MAAM;IAAS,OAAO;MACtB;EAGJ,MACI,UAAU,IAAI,cAAc,GAAG,KAC/B,UAAU,YACV,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,KAAK;MACpB;EAGJ,MACI,UAAU,IAAI,cAAc,GAAG,KAC/B,UAAU,YACV,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,KAAK;MACpB;EAGJ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;EACzB,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;;qBAGnD,oBAAiB,SAAA,wBAAA;EAtD6B,MAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"date.js","names":[],"sources":["../../src/schema-builders/date.ts"],"sourcesContent":["import type {\n DateSchemaDefinition,\n DefaultType,\n IndexDirection,\n IndexOptions,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n DateSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: DateSchemaDefinition;\n}\n\nexport interface DateSchemaBuilder<\n Props extends { type: DateSchemaDefinition } = { type: DateSchemaDefinition },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends NativeDate,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<D | null>>\n | { [path: string]: D | null }\n | { message?: M; values: Readonlyable<Array<D | null>> },\n D extends NativeDate,\n M extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n max: <\n T extends D | Readonlyable<[D, S]>,\n D extends NativeDate,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { max: T }>,\n ExtraOmitFields\n >;\n\n min: <\n T extends D | Readonlyable<[D, S]>,\n D extends NativeDate,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { min: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\nexport const dateSchemaBuilder = createBaseSchemaBuilderFactory<DateSchemaBuilder>(Date);\n"],"mappings":";;AA+EA,MAAa,oBAAoB,+BAAkD,KAAK"}
1
+ {"version":3,"file":"date.js","names":[],"sources":["../../src/schema-builders/date.ts"],"sourcesContent":["import type {\n DateSchemaDefinition,\n DefaultType,\n IndexDirection,\n IndexOptions,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n DateSchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: DateSchemaDefinition;\n}\n\nexport interface DateSchemaBuilder<\n Props extends { type: DateSchemaDefinition } = { type: DateSchemaDefinition },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends NativeDate,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<D | null>>\n | { [path: string]: D | null }\n | { message?: M; values: Readonlyable<Array<D | null>> },\n D extends NativeDate,\n M extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n max: <\n T extends D | Readonlyable<[D, S]>,\n D extends NativeDate,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { max: T }>,\n ExtraOmitFields\n >;\n\n min: <\n T extends D | Readonlyable<[D, S]>,\n D extends NativeDate,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { min: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\nexport const dateSchemaBuilder = createBaseSchemaBuilderFactory<DateSchemaBuilder>(Date);\n"],"mappings":";;AA+EA,MAAa,oBAAoB,+BAAkD,IAAI"}
@@ -2,13 +2,22 @@ import { Readonlyable } from "../types/_internals.js";
2
2
  import { DefaultType, IndexDirection, IndexOptions, Schema, Types } from "mongoose";
3
3
  import { Decimal } from "decimal.js";
4
4
  import { Merge } from "type-fest";
5
-
6
5
  //#region src/schema-builders/decimal128.d.ts
6
+ type Decimal128Limit = Decimal.Value | Types.Decimal128 | {
7
+ toString: () => string;
8
+ };
7
9
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<Decimal128SchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
8
10
  interface BaseProps {
9
11
  type: typeof Schema.Types.Decimal128;
10
12
  }
11
- interface Decimal128SchemaBuilder<Props extends {
13
+ interface Decimal128LimitValidator {
14
+ max?: string;
15
+ message: string;
16
+ min?: string;
17
+ type: 'max' | 'min';
18
+ validator: (value: null | Types.Decimal128 | undefined) => boolean;
19
+ }
20
+ export interface Decimal128SchemaBuilder<Props extends {
12
21
  type: typeof Schema.Types.Decimal128;
13
22
  } = {
14
23
  type: typeof Schema.Types.Decimal128;
@@ -30,6 +39,8 @@ interface Decimal128SchemaBuilder<Props extends {
30
39
  index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<Merge<Props, {
31
40
  index: T;
32
41
  }>, ExtraOmitFields>;
42
+ max: <T extends D | Readonlyable<[D, S]>, D extends Decimal128Limit, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, Decimal128ValidationSchema>, 'max' | ExtraOmitFields>;
43
+ min: <T extends D | Readonlyable<[D, S]>, D extends Decimal128Limit, S extends string>(value: T) => ExtendSchemaBuilder<Merge<Props, Decimal128ValidationSchema>, 'min' | ExtraOmitFields>;
33
44
  nonRequired: Props;
34
45
  private: ExtendSchemaBuilder<Merge<Props, {
35
46
  private: true;
@@ -65,15 +76,17 @@ interface Decimal128SchemaBuilder<Props extends {
65
76
  unique: true;
66
77
  }>, ExtraOmitFields>;
67
78
  }
79
+ interface Decimal128ValidationSchema {
80
+ validate: Decimal128LimitValidator[];
81
+ }
68
82
  interface ToStringGetterSchema {
69
83
  get: (value?: Types.Decimal128) => string | undefined;
70
84
  }
71
85
  interface ToStringSetterSchema {
72
86
  set: (value?: {
73
87
  toString: () => string;
74
- }) => string;
88
+ }) => string | undefined;
75
89
  }
76
- declare function decimal128SchemaBuilder(): Decimal128SchemaBuilder;
90
+ export declare function decimal128SchemaBuilder(): Decimal128SchemaBuilder;
77
91
  //#endregion
78
- export { Decimal128SchemaBuilder, decimal128SchemaBuilder };
79
92
  //# sourceMappingURL=decimal128.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decimal128.d.ts","names":[],"sources":["../../src/schema-builders/decimal128.ts"],"mappings":";;;;;;KAcK,mBAAA,eACa,SAAA,oCAEd,IAAA,CACA,uBAAA,CAAwB,KAAA,EAAO,eAAA,GAC/B,eAAA,SAAwB,KAAA;AAAA,UAGlB,SAAA;EACN,IAAA,SAAa,MAAA,CAAO,KAAA,CAAM,UAAA;AAAA;AAAA,UAGb,uBAAA;EACG,IAAA,SAAa,MAAA,CAAO,KAAA,CAAM,UAAA;AAAA;EAAiB,IAAA,SAAa,MAAA,CAAO,KAAA,CAAM,UAAA;AAAA;EAGrF,OAAA,eACgB,IAAA,OAAW,GAAA,UAAa,WAAA,CAAY,CAAA,KAAM,WAAA,CAAY,CAAA,oBACxD,KAAA,CAAM,UAAA,EAClB,KAAA,EAAO,CAAA,KAAM,mBAAA,CACX,KAAA,CAAM,KAAA;IAAS,OAAA,EAAS,CAAA;EAAA,IACxB,eAAA;EAGJ,IAAA,aAEM,YAAA,CAAa,KAAA,CAAM,CAAA;IAAA,CAChB,IAAA,WAAe,CAAA;EAAA;IAChB,OAAA,GAAU,CAAA;IAAG,MAAA,EAAQ,YAAA,CAAa,KAAA,CAAM,CAAA;EAAA,aAClC,KAAA,CAAM,UAAA,oBAElB,KAAA,EAAO,CAAA,KAAM,mBAAA,CACX,KAAA,CAAM,KAAA;IAAS,IAAA,EAAM,CAAA;EAAA,IACrB,eAAA;EAGJ,SAAA,EAAW,mBAAA,CAAoB,KAAA,CAAM,KAAA;IAAS,SAAA;EAAA,IAAoB,eAAA;EAClE,KAAA,uBAA4B,cAAA,GAAiB,YAAA,EAAc,KAAA,EAAO,CAAA,KAAM,mBAAA,CACpE,KAAA,CAAM,KAAA;IAAS,KAAA,EAAO,CAAA;EAAA,IACtB,eAAA;EAGJ,WAAA,EAAa,KAAA;EACb,OAAA,EAAS,mBAAA,CAAoB,KAAA,CAAM,KAAA;IAAS,OAAA;EAAA,IAAkB,eAAA;EAC9D,QAAA,EAAU,KAAA,CAAM,KAAA;IAAS,QAAA;EAAA;EAnCW;AAGxC;;;;;;;;;EA4CI,wBAAA,GAA2B,MAAA,WAAiB,QAAA,GAAW,OAAA,CAAQ,QAAA,KAAa,mBAAA,CACxE,KAAA,CAAM,KAAA,EAAO,oBAAA,gCACgB,eAAA;EAvCxB;;;;;;;;;EAmDT,iBAAA,EAAmB,mBAAA,CAAoB,KAAA,CAAM,KAAA,EAAO,oBAAA,yBAA6C,eAAA;EACjG,MAAA,EAAQ,mBAAA,CAAoB,KAAA,CAAM,KAAA;IAAS,MAAA;EAAA,IAAiB,eAAA;EAC5D,MAAA,EAAQ,mBAAA,CAAoB,KAAA,CAAM,KAAA;IAAS,MAAA;EAAA,IAAiB,eAAA;AAAA;AAAA,UAGtD,oBAAA;EACN,GAAA,GAAM,KAAA,GAAQ,KAAA,CAAM,UAAA;AAAA;AAAA,UAGd,oBAAA;EACN,GAAA,GAAM,KAAA;IAAU,QAAA;EAAA;AAAA;AAAA,iBAKJ,uBAAA,CAAA,GAyBP,uBAAA"}
1
+ {"version":3,"file":"decimal128.d.ts","names":[],"sources":["../../src/schema-builders/decimal128.ts"],"mappings":";;;;;KAcK,kBAAkB,QAAQ,QAAQ,MAAM;EAAe;;KACvD,oBACD,cAAc,WACd,kCACA,KACA,wBAAwB,OAAO,kBAC/B,wBAAwB;UAGlB;EACN,aAAa,OAAO,MAAM;;UAGpB;EACN;EACA;EACA;EACA;EACA,YAAY,cAAc,MAAM;;iBAGnB,wBACb;EAAgB,aAAa,OAAO,MAAM;;EAAiB,aAAa,OAAO,MAAM;GACrF;EAEA,UACI,YAAY,WAAW,aAAa,YAAY,MAAM,YAAY,WAClE,UAAU,MAAM,YAClB,OAAO,MAAM,oBACX,MAAM;IAAS,SAAS;MACxB;EAGJ,OACI,UACE,aAAa,MAAM;KAChB,eAAe;;IAChB,UAAU;IAAG,QAAQ,aAAa,MAAM;KAC5C,UAAU,MAAM,YAChB,kBACF,OAAO,MAAM,oBACX,MAAM;IAAS,MAAM;MACrB;EAGJ,WAAW,oBAAoB,MAAM;IAAS;MAAoB;EAClE,QAAQ,oBAAoB,iBAAiB,cAAc,OAAO,MAAM,oBACpE,MAAM;IAAS,OAAO;MACtB;EAGJ,MACI,UAAU,IAAI,cAAc,GAAG,KAC/B,UAAU,iBACV,kBACF,OAAO,MAAM,oBACX,MAAM,OAAO,qCACL;EAGZ,MACI,UAAU,IAAI,cAAc,GAAG,KAC/B,UAAU,iBACV,kBACF,OAAO,MAAM,oBACX,MAAM,OAAO,qCACL;EAGZ,aAAa;EACb,SAAS,oBAAoB,MAAM;IAAS;MAAkB;EAC9D,UAAU,MAAM;IAAS;;;;;;;;;;;;EAYzB,2BAA2B,iBAAiB,WAAW,QAAQ,aAAa,oBACxE,MAAM,OAAO,oDACgB;;;;;;;;;;EAYjC,mBAAmB,oBAAoB,MAAM,OAAO,6CAA6C;EACjG,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;EAC5D,QAAQ,oBAAoB,MAAM;IAAS;MAAiB;;UAGtD;EACN,UAAU;;UAGJ;EACN,MAAM,QAAQ,MAAM;;UAGd;EACN,MAAM;IAAU;;;wBAqCJ,2BAyCP"}
@@ -2,14 +2,37 @@ import { createBaseSchemaBuilderFactory } from "./base.js";
2
2
  import { Schema } from "mongoose";
3
3
  import { Decimal } from "decimal.js";
4
4
  //#region src/schema-builders/decimal128.ts
5
+ const defaultMinValidateMessage = "Path `{PATH}` ({VALUE}) is less than minimum allowed value ({MIN}).";
6
+ const defaultMaxValidateMessage = "Path `{PATH}` ({VALUE}) is more than maximum allowed value ({MAX}).";
5
7
  const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);
8
+ function createLimitValidator(type, value) {
9
+ const [limit, message] = Array.isArray(value) ? value : [value, void 0];
10
+ const decimalLimit = new Decimal(limit.toString());
11
+ if (!decimalLimit.isFinite()) throw new RangeError(`Decimal128 ${type} limit must be finite`);
12
+ return {
13
+ message: message ?? (type === "min" ? defaultMinValidateMessage : defaultMaxValidateMessage),
14
+ [type]: decimalLimit.toString(),
15
+ type,
16
+ validator: (value) => {
17
+ if (value === null || value === void 0) return true;
18
+ const decimalValue = new Decimal(value.toString());
19
+ return type === "min" ? decimalValue.gte(decimalLimit) : decimalValue.lte(decimalLimit);
20
+ }
21
+ };
22
+ }
6
23
  function decimal128SchemaBuilder() {
7
24
  const schema = {};
8
25
  const baseBuilder = baseBuilderFactory(schema);
9
26
  return new Proxy(baseBuilder, { get(target, key, receiver) {
27
+ if (key === "max" || key === "min") return (value) => {
28
+ const validator = createLimitValidator(key, value);
29
+ const validators = Array.isArray(schema.validate) ? schema.validate : [];
30
+ schema.validate = [...validators.filter(({ type }) => type !== key), validator];
31
+ return receiver;
32
+ };
10
33
  if (key === "setRoundAndToFixedSetter") return (places = 2, rounding = Decimal.ROUND_DOWN) => {
11
34
  schema.set = (value) => {
12
- if (value) return new Decimal(value.toString()).toFixed(places, rounding);
35
+ if (value !== void 0 && value !== null) return (Decimal.isDecimal(value) ? value : new Decimal(value.toString())).toFixed(places, rounding);
13
36
  };
14
37
  return receiver;
15
38
  };
@@ -1 +1 @@
1
- {"version":3,"file":"decimal128.js","names":[],"sources":["../../src/schema-builders/decimal128.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\nimport { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n Decimal128SchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: typeof Schema.Types.Decimal128;\n}\n\nexport interface Decimal128SchemaBuilder<\n Props extends { type: typeof Schema.Types.Decimal128 } = { type: typeof Schema.Types.Decimal128 },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends Types.Decimal128,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<D | null>>\n | { [path: string]: D | null }\n | { message?: M; values: Readonlyable<Array<D | null>> },\n D extends Types.Decimal128,\n M extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n\n /**\n * Sets the rounding and toFixed behavior for Decimal128 fields.\n * This method allows specifying the number of decimal places and the rounding strategy to be used when\n * saving the field to the database.\n *\n * @param places - The number of decimal places to round to (default is 2).\n * @param rounding - The rounding strategy from the Decimal.js library (default is Decimal.ROUND_DOWN).\n *\n * @returns A schema builder with the rounding and toFixed behavior applied to the `set` option in Mongoose.\n */\n setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendSchemaBuilder<\n Merge<Props, ToStringSetterSchema>,\n 'setRoundAndToFixedSetter' | ExtraOmitFields\n >;\n\n /**\n * Sets the toString behavior for Decimal128 fields.\n * This method defines how the Decimal128 field should be converted to a string when processing or\n * retrieving the value in the application (e.g., via getters), while still storing the value as Decimal128\n * in the database.\n *\n * @returns A schema builder with the custom `get` behavior applied to convert the Decimal128 field to a string\n * when accessed in the application.\n */\n setToStringGetter: ExtendSchemaBuilder<Merge<Props, ToStringGetterSchema>, 'setToStringGetter' | ExtraOmitFields>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\ninterface ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string;\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"],"mappings":";;;;AAiGA,MAAM,qBAAqB,+BAA+B,OAAO,MAAM,WAAW;AAElF,SAAgB,0BAA0B;CACtC,MAAM,SAA8B,EAAE;CACtC,MAAM,cAAc,mBAAmB,OAAO;AAC9C,QAAO,IAAI,MACP,aACA,EACI,IAAI,QAAQ,KAAK,UAAU;AACvB,MAAI,QAAQ,2BACR,SAAQ,SAAiB,GAAG,WAA6B,QAAQ,eAAe;AAC5E,UAAO,OAAO,UAAuC;AACjD,QAAI,MAAO,QAAO,IAAI,QAAQ,MAAM,UAAU,CAAC,CAAC,QAAQ,QAAQ,SAAS;;AAG7E,UAAO;;AAIf,MAAI,QAAQ,qBAAqB;AAC7B,UAAO,OAAO,UAA6B,OAAO,UAAU;AAC5D,UAAO;;AAGX,SAAO,QAAQ,IAAI,QAAQ,KAAK,SAAS;IAEhD,CACJ"}
1
+ {"version":3,"file":"decimal128.js","names":[],"sources":["../../src/schema-builders/decimal128.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\nimport { Schema } from 'mongoose';\nimport type {\n DefaultType,\n IndexDirection,\n IndexOptions,\n Types,\n} from 'mongoose';\nimport type { Merge } from 'type-fest';\n\nimport type { Readonlyable } from '../types/_internals';\n\nimport { createBaseSchemaBuilderFactory } from './base';\n\ntype Decimal128Limit = Decimal.Value | Types.Decimal128 | { toString: () => string };\ntype ExtendSchemaBuilder<\n Props extends BaseProps,\n ExtraOmitFields extends string,\n> = Omit<\n Decimal128SchemaBuilder<Props, ExtraOmitFields>,\n ExtraOmitFields | keyof Props\n>;\n\ninterface BaseProps {\n type: typeof Schema.Types.Decimal128;\n}\n\ninterface Decimal128LimitValidator {\n max?: string;\n message: string;\n min?: string;\n type: 'max' | 'min';\n validator: (value: null | Types.Decimal128 | undefined) => boolean;\n}\n\nexport interface Decimal128SchemaBuilder<\n Props extends { type: typeof Schema.Types.Decimal128 } = { type: typeof Schema.Types.Decimal128 },\n ExtraOmitFields extends string = never,\n> {\n default: <\n T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null,\n D extends Types.Decimal128,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { default: T }>,\n ExtraOmitFields\n >;\n\n enum: <\n T extends\n | Readonlyable<Array<D | null>>\n | { [path: string]: D | null }\n | { message?: M; values: Readonlyable<Array<D | null>> },\n D extends Types.Decimal128,\n M extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, { enum: T }>,\n ExtraOmitFields\n >;\n\n immutable: ExtendSchemaBuilder<Merge<Props, { immutable: true }>, ExtraOmitFields>;\n index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendSchemaBuilder<\n Merge<Props, { index: T }>,\n ExtraOmitFields\n >;\n\n max: <\n T extends D | Readonlyable<[D, S]>,\n D extends Decimal128Limit,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, Decimal128ValidationSchema>,\n 'max' | ExtraOmitFields\n >;\n\n min: <\n T extends D | Readonlyable<[D, S]>,\n D extends Decimal128Limit,\n S extends string,\n >(value: T) => ExtendSchemaBuilder<\n Merge<Props, Decimal128ValidationSchema>,\n 'min' | ExtraOmitFields\n >;\n\n nonRequired: Props;\n private: ExtendSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;\n required: Merge<Props, { required: true }>;\n\n /**\n * Sets the rounding and toFixed behavior for Decimal128 fields.\n * This method allows specifying the number of decimal places and the rounding strategy to be used when\n * saving the field to the database.\n *\n * @param places - The number of decimal places to round to (default is 2).\n * @param rounding - The rounding strategy from the Decimal.js library (default is Decimal.ROUND_DOWN).\n *\n * @returns A schema builder with the rounding and toFixed behavior applied to the `set` option in Mongoose.\n */\n setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendSchemaBuilder<\n Merge<Props, ToStringSetterSchema>,\n 'setRoundAndToFixedSetter' | ExtraOmitFields\n >;\n\n /**\n * Sets the toString behavior for Decimal128 fields.\n * This method defines how the Decimal128 field should be converted to a string when processing or\n * retrieving the value in the application (e.g., via getters), while still storing the value as Decimal128\n * in the database.\n *\n * @returns A schema builder with the custom `get` behavior applied to convert the Decimal128 field to a string\n * when accessed in the application.\n */\n setToStringGetter: ExtendSchemaBuilder<Merge<Props, ToStringGetterSchema>, 'setToStringGetter' | ExtraOmitFields>;\n sparse: ExtendSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;\n unique: ExtendSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;\n}\n\ninterface Decimal128ValidationSchema {\n validate: Decimal128LimitValidator[];\n}\n\ninterface ToStringGetterSchema {\n get: (value?: Types.Decimal128) => string | undefined;\n}\n\ninterface ToStringSetterSchema {\n set: (value?: { toString: () => string }) => string | undefined;\n}\n\n// Constants/Variables\nconst defaultMinValidateMessage = 'Path `{PATH}` ({VALUE}) is less than minimum allowed value ({MIN}).';\nconst defaultMaxValidateMessage = 'Path `{PATH}` ({VALUE}) is more than maximum allowed value ({MAX}).';\n\n// Functions\nconst baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);\n\nfunction createLimitValidator(\n type: 'max' | 'min',\n value: Decimal128Limit | Readonlyable<[Decimal128Limit, string]>,\n): Decimal128LimitValidator {\n const [limit, message] = Array.isArray(value)\n ? value as Readonly<[Decimal128Limit, string]>\n : [\n value,\n undefined,\n ];\n\n const decimalLimit = new Decimal(limit.toString());\n if (!decimalLimit.isFinite()) throw new RangeError(`Decimal128 ${type} limit must be finite`);\n\n return {\n message: message ?? (type === 'min' ? defaultMinValidateMessage : defaultMaxValidateMessage),\n [type]: decimalLimit.toString(),\n type,\n validator: (value) => {\n if (value === null || value === undefined) return true;\n\n const decimalValue = new Decimal(value.toString());\n return type === 'min' ? decimalValue.gte(decimalLimit) : decimalValue.lte(decimalLimit);\n },\n };\n}\n\nexport function decimal128SchemaBuilder() {\n const schema: Record<string, any> = {};\n const baseBuilder = baseBuilderFactory(schema);\n return new Proxy(\n baseBuilder,\n {\n get(target, key, receiver) {\n if (key === 'max' || key === 'min') {\n return (value: Decimal128Limit | Readonlyable<[Decimal128Limit, string]>) => {\n const validator = createLimitValidator(key, value);\n const validators = Array.isArray(schema.validate) ? schema.validate : [];\n schema.validate = [\n ...validators.filter(({ type }) => type !== key),\n validator,\n ];\n\n return receiver;\n };\n }\n\n if (key === 'setRoundAndToFixedSetter') {\n return (places: number = 2, rounding: Decimal.Rounding = Decimal.ROUND_DOWN) => {\n schema.set = (value?: { toString: () => string }) => {\n if (value !== undefined && value !== null) {\n const decimal = Decimal.isDecimal(value) ? value : new Decimal(value.toString());\n return decimal.toFixed(places, rounding);\n }\n };\n\n return receiver;\n };\n }\n\n if (key === 'setToStringGetter') {\n schema.get = (value?: Types.Decimal128) => value?.toString();\n return receiver;\n }\n\n return Reflect.get(target, key, receiver);\n },\n },\n ) as Decimal128SchemaBuilder;\n}\n"],"mappings":";;;;AAiIA,MAAM,4BAA4B;AAClC,MAAM,4BAA4B;AAGlC,MAAM,qBAAqB,+BAA+B,OAAO,MAAM,UAAU;AAEjF,SAAS,qBACL,MACA,OACwB;CACxB,MAAM,CAAC,OAAO,WAAW,MAAM,QAAQ,KAAK,IACtC,QACA,CACE,OACA,KAAA,CACJ;CAEJ,MAAM,eAAe,IAAI,QAAQ,MAAM,SAAS,CAAC;CACjD,IAAI,CAAC,aAAa,SAAS,GAAG,MAAM,IAAI,WAAW,cAAc,KAAK,sBAAsB;CAE5F,OAAO;EACH,SAAS,YAAY,SAAS,QAAQ,4BAA4B;GACjE,OAAO,aAAa,SAAS;EAC9B;EACA,YAAY,UAAU;GAClB,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;GAElD,MAAM,eAAe,IAAI,QAAQ,MAAM,SAAS,CAAC;GACjD,OAAO,SAAS,QAAQ,aAAa,IAAI,YAAY,IAAI,aAAa,IAAI,YAAY;EAC1F;CACJ;AACJ;AAEA,SAAgB,0BAA0B;CACtC,MAAM,SAA8B,CAAC;CACrC,MAAM,cAAc,mBAAmB,MAAM;CAC7C,OAAO,IAAI,MACP,aACA,EACI,IAAI,QAAQ,KAAK,UAAU;EACvB,IAAI,QAAQ,SAAS,QAAQ,OACzB,QAAQ,UAAqE;GACzE,MAAM,YAAY,qBAAqB,KAAK,KAAK;GACjD,MAAM,aAAa,MAAM,QAAQ,OAAO,QAAQ,IAAI,OAAO,WAAW,CAAC;GACvE,OAAO,WAAW,CACd,GAAG,WAAW,QAAQ,EAAE,WAAW,SAAS,GAAG,GAC/C,SACJ;GAEA,OAAO;EACX;EAGJ,IAAI,QAAQ,4BACR,QAAQ,SAAiB,GAAG,WAA6B,QAAQ,eAAe;GAC5E,OAAO,OAAO,UAAuC;IACjD,IAAI,UAAU,KAAA,KAAa,UAAU,MAEjC,QADgB,QAAQ,UAAU,KAAK,IAAI,QAAQ,IAAI,QAAQ,MAAM,SAAS,CAAC,EAAA,CAChE,QAAQ,QAAQ,QAAQ;GAE/C;GAEA,OAAO;EACX;EAGJ,IAAI,QAAQ,qBAAqB;GAC7B,OAAO,OAAO,UAA6B,OAAO,SAAS;GAC3D,OAAO;EACX;EAEA,OAAO,QAAQ,IAAI,QAAQ,KAAK,QAAQ;CAC5C,EACJ,CACJ;AACJ"}
@@ -1,13 +1,12 @@
1
1
  import { Readonlyable } from "../types/_internals.js";
2
2
  import { DefaultType, IndexDirection, IndexOptions, NumberSchemaDefinition } from "mongoose";
3
3
  import { Merge } from "type-fest";
4
-
5
4
  //#region src/schema-builders/number.d.ts
6
5
  type ExtendSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<NumberSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
7
6
  interface BaseProps {
8
7
  type: NumberSchemaDefinition;
9
8
  }
10
- interface NumberSchemaBuilder<Props extends {
9
+ export interface NumberSchemaBuilder<Props extends {
11
10
  type: NumberSchemaDefinition;
12
11
  } = {
13
12
  type: NumberSchemaDefinition;
@@ -49,9 +48,8 @@ interface NumberSchemaBuilder<Props extends {
49
48
  unique: true;
50
49
  }>, ExtraOmitFields>;
51
50
  }
52
- declare const numberSchemaBuilder: (schema?: Record<string, any>) => NumberSchemaBuilder<{
51
+ export declare const numberSchemaBuilder: (schema?: Record<string, any>) => NumberSchemaBuilder<{
53
52
  type: NumberSchemaDefinition;
54
53
  }, never>;
55
54
  //#endregion
56
- export { NumberSchemaBuilder, numberSchemaBuilder };
57
55
  //# sourceMappingURL=number.d.ts.map