@kikiutils/mongoose 2.1.3 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{_internals.cjs → dist/_internals.cjs} +1 -0
- package/dist/_internals.cjs.map +1 -0
- package/{_internals.d.ts → dist/_internals.d.ts} +1 -0
- package/dist/_internals.d.ts.map +1 -0
- package/{_internals.mjs → dist/_internals.mjs} +1 -0
- package/dist/_internals.mjs.map +1 -0
- package/{constants.cjs → dist/constants.cjs} +1 -0
- package/dist/constants.cjs.map +1 -0
- package/{constants.d.ts → dist/constants.d.ts} +1 -0
- package/dist/constants.d.ts.map +1 -0
- package/{constants.mjs → dist/constants.mjs} +1 -0
- package/dist/constants.mjs.map +1 -0
- package/{options.cjs → dist/options.cjs} +1 -0
- package/dist/options.cjs.map +1 -0
- package/{options.d.ts → dist/options.d.ts} +1 -0
- package/dist/options.d.ts.map +1 -0
- package/{options.mjs → dist/options.mjs} +1 -0
- package/dist/options.mjs.map +1 -0
- package/{plugins → dist/plugins}/normalize.cjs +1 -0
- package/dist/plugins/normalize.cjs.map +1 -0
- package/{plugins → dist/plugins}/normalize.d.ts +1 -0
- package/dist/plugins/normalize.d.ts.map +1 -0
- package/{plugins → dist/plugins}/normalize.mjs +1 -0
- package/dist/plugins/normalize.mjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/base.cjs +1 -0
- package/dist/schema-builders/base.cjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/base.d.ts +1 -0
- package/dist/schema-builders/base.d.ts.map +1 -0
- package/{schema-builders → dist/schema-builders}/base.mjs +1 -0
- package/dist/schema-builders/base.mjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/boolean.cjs +1 -0
- package/dist/schema-builders/boolean.cjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/boolean.d.ts +1 -0
- package/dist/schema-builders/boolean.d.ts.map +1 -0
- package/{schema-builders → dist/schema-builders}/boolean.mjs +1 -0
- package/dist/schema-builders/boolean.mjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/date.cjs +1 -0
- package/dist/schema-builders/date.cjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/date.d.ts +1 -0
- package/dist/schema-builders/date.d.ts.map +1 -0
- package/{schema-builders → dist/schema-builders}/date.mjs +1 -0
- package/dist/schema-builders/date.mjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/decimal128.cjs +1 -0
- package/dist/schema-builders/decimal128.cjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/decimal128.d.ts +1 -0
- package/dist/schema-builders/decimal128.d.ts.map +1 -0
- package/{schema-builders → dist/schema-builders}/decimal128.mjs +1 -0
- package/dist/schema-builders/decimal128.mjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/index.cjs +1 -0
- package/dist/schema-builders/index.cjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/index.d.ts +1 -0
- package/dist/schema-builders/index.d.ts.map +1 -0
- package/{schema-builders → dist/schema-builders}/index.mjs +1 -0
- package/dist/schema-builders/index.mjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/number.cjs +1 -0
- package/dist/schema-builders/number.cjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/number.d.ts +1 -0
- package/dist/schema-builders/number.d.ts.map +1 -0
- package/{schema-builders → dist/schema-builders}/number.mjs +1 -0
- package/dist/schema-builders/number.mjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/object-id.cjs +1 -0
- package/dist/schema-builders/object-id.cjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/object-id.d.ts +1 -0
- package/dist/schema-builders/object-id.d.ts.map +1 -0
- package/{schema-builders → dist/schema-builders}/object-id.mjs +1 -0
- package/dist/schema-builders/object-id.mjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/ref.cjs +1 -0
- package/dist/schema-builders/ref.cjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/ref.d.ts +1 -0
- package/dist/schema-builders/ref.d.ts.map +1 -0
- package/{schema-builders → dist/schema-builders}/ref.mjs +1 -0
- package/dist/schema-builders/ref.mjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/string.cjs +1 -0
- package/dist/schema-builders/string.cjs.map +1 -0
- package/{schema-builders → dist/schema-builders}/string.d.ts +1 -0
- package/dist/schema-builders/string.d.ts.map +1 -0
- package/{schema-builders → dist/schema-builders}/string.mjs +1 -0
- package/dist/schema-builders/string.mjs.map +1 -0
- package/{types → dist/types}/aggregate-paginate.d.ts +1 -0
- package/dist/types/aggregate-paginate.d.ts.map +1 -0
- package/{types → dist/types}/data.d.ts +1 -0
- package/dist/types/data.d.ts.map +1 -0
- package/{types → dist/types}/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/{types → dist/types}/options.d.ts +1 -0
- package/dist/types/options.d.ts.map +1 -0
- package/{types → dist/types}/paginate.d.ts +1 -0
- package/dist/types/paginate.d.ts.map +1 -0
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/{utils.cjs → dist/utils.cjs} +1 -0
- package/dist/utils.cjs.map +1 -0
- package/{utils.d.ts → dist/utils.d.ts} +1 -0
- package/dist/utils.d.ts.map +1 -0
- package/{utils.mjs → dist/utils.mjs} +1 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +20 -16
- package/src/_internals.ts +3 -0
- package/src/constants.ts +10 -0
- package/src/options.ts +14 -0
- package/src/plugins/normalize.ts +54 -0
- package/src/schema-builders/base.ts +43 -0
- package/src/schema-builders/boolean.ts +27 -0
- package/src/schema-builders/date.ts +42 -0
- package/src/schema-builders/decimal128.ts +98 -0
- package/src/schema-builders/index.ts +26 -0
- package/src/schema-builders/number.ts +42 -0
- package/src/schema-builders/object-id.ts +42 -0
- package/src/schema-builders/ref.ts +44 -0
- package/src/schema-builders/string.ts +128 -0
- package/src/types/aggregate-paginate.ts +89 -0
- package/src/types/data.ts +82 -0
- package/src/types/index.ts +99 -0
- package/src/types/options.ts +61 -0
- package/src/types/paginate.ts +134 -0
- package/src/utils.ts +88 -0
- /package/{types/utils.d.ts → src/types/utils.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate-paginate.d.ts","sourceRoot":"","sources":["../../src/types/aggregate-paginate.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACR,wBAAwB,EACxB,MAAM,EACT,MAAM,UAAU,CAAC;AAElB,OAAO,QAAQ,UAAU,CAAC;IACtB,UAAU,qBAAqB,CAAC,CAAC,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS;QAC5D,IAAI,CAAC,EAAE,CAAC,CAAC;QACT,WAAW,CAAC,EAAE,CAAC,CAAC;QAChB,WAAW,CAAC,EAAE,CAAC,CAAC;QAChB,KAAK,CAAC,EAAE,CAAC,CAAC;QACV,IAAI,CAAC,EAAE,CAAC,CAAC;QACT,QAAQ,CAAC,EAAE,CAAC,CAAC;QACb,IAAI,CAAC,EAAE,CAAC,CAAC;QACT,aAAa,CAAC,EAAE,CAAC,CAAC;QAClB,QAAQ,CAAC,EAAE,CAAC,CAAC;QACb,SAAS,CAAC,EAAE,CAAC,CAAC;QACd,UAAU,CAAC,EAAE,CAAC,CAAC;KAClB;IAED,UAAU,wBAAwB;QAC9B,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,qBAAqB,CAAC;QACrC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QAEd;;;;WAIG;QACH,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;KACtB;IAED,UAAU,qCAAqC;QAC3C,yCAAyC;QACzC,KAAK,CAAC,EAAE,GAAG,CAAC;QACZ,2CAA2C;QAC3C,KAAK,CAAC,EAAE,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,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,cAAc,SAAS,IAAI,GAAG;QAAE,SAAS,EAAE,IAAI,CAAA;KAAE,GAAG,MAAM,CAAC,CAAC;IAEpR;;;;;;;;;OASG;IACH,KAAK,yBAAyB,CAAC,UAAU,EAAE,2BAA2B,GAAG,MAAM,EAAE,YAAY,GAAG,MAAM,IAAI,sBAAsB,CAAC,UAAU,EAAE,YAAY,EAAE,2BAA2B,CAAC,GAAG,gBAAgB,CAAC,UAAU,EAAE,2BAA2B,EAAE,YAAY,CAAC,GAAG,aAAa,CAAC,UAAU,EAAE,YAAY,EAAE,2BAA2B,CAAC,CAAC;IAEzU;;;;;;;;OAQG;IACH,KAAK,0BAA0B,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC;IAEjE;;;;;;;;;;;;;OAaG;IACH,KAAK,yBAAyB,CAC1B,UAAU,EACV,OAAO,EACP,YAAY,GAAG,MAAM,EACrB,2BAA2B,GAAG,MAAM,IACpC,gBAAgB,CAChB,OAAO,GAAG,IAAI,EACd,OAAO,EACP,YAAY,EACZ,UAAU,EACV,SAAS,EACT,2BAA2B,CAC9B,CAAC;IAEF;;;;;;;;;;;OAWG;IACH,KAAK,wBAAwB,CAAC,OAAO,EAAE,2BAA2B,GAAG,MAAM,EAAE,YAAY,GAAG,MAAM,IAAI,gBAAgB,CAAC,OAAO,EAAE,2BAA2B,EAAE,YAAY,CAAC,CAAC;CAC9K"}
|
|
@@ -42,3 +42,4 @@ export interface CustomMongooseOptions {
|
|
|
42
42
|
*/
|
|
43
43
|
beforeModelBuild?: <DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>) => void;
|
|
44
44
|
}
|
|
45
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +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;;;;;;;;OAQG;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginate.d.ts","sourceRoot":"","sources":["../../src/types/paginate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,WAAW,EACX,KAAK,EACL,eAAe,EACf,MAAM,EACT,MAAM,UAAU,CAAC;AAElB,OAAO,QAAQ,UAAU,CAAC;IACtB,UAAU,oBAAoB,CAAC,CAAC,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS;QAC3D,IAAI,CAAC,EAAE,CAAC,CAAC;QACT,WAAW,CAAC,EAAE,CAAC,CAAC;QAChB,WAAW,CAAC,EAAE,CAAC,CAAC;QAChB,KAAK,CAAC,E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C,CAAC,EAAE,CAAC,SAAS,eAAe;oBACvC,OAAO,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;SAAE;QACpD,GAAG,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC,CAAC;QACpB,QAAQ,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,CAAC;KAClC;CACJ;AAED,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/types/utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sources":["../src/utils.ts"],"sourcesContent":["import 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 ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n return (options?.connection || mongooseConnections.default || (mongooseConnections.default = mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'))).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) return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n return documentOrObjectId;\n}\n"],"names":["mongooseNormalizePlugin","mongooseAggregatePaginate","mongoosePaginate","customMongooseOptions","mongooseConnections","mongoose","Types"],"mappings":";;;;;;;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;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;IAC/B,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,UAAU,IAAI,IAAI,CAAC;AACrD,IAAAC,gCAAqB,CAAC,gBAAgB,GAAG,MAAM,CAAC;AAChD,IAAA,OAAO,CAAC,OAAO,EAAE,UAAU,IAAIC,6BAAmB,CAAC,OAAO,KAAKA,6BAAmB,CAAC,OAAO,GAAGC,iBAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,2BAA2B,CAAC,CAAC,EAAE,KAAK,CAA+B,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC;AAClP;AAEA;;;;;;;;;;;;;;;;AAgBG;AACI,eAAe,oCAAoC,CAMtD,kBAAiD,EACjD,KAAoF,EACpF,YAAuB,EAAA;IAEvB,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,YAAYC,cAAK,CAAC,QAAQ;AAAE,QAAA,QAAQ,MAAM,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;AACvK,IAAA,OAAO,kBAAkB;AAC7B;;;;;"}
|
|
@@ -48,3 +48,4 @@ export declare function buildMongooseModel<DocType, Model extends BaseMongoosePa
|
|
|
48
48
|
* @returns The corresponding document or null if not found.
|
|
49
49
|
*/
|
|
50
50
|
export declare function mongooseDocumentOrObjectIdToDocument<D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>, DocType, InstanceMethodsAndOverrides, QueryHelpers>(documentOrObjectId: MongooseDocumentOrObjectId<D>, model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, selectFields?: string[]): Promise<D | null>;
|
|
51
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,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,SAQtC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,oCAAoC,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,CAGnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../src/utils.ts"],"sourcesContent":["import 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 ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n return (options?.connection || mongooseConnections.default || (mongooseConnections.default = mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'))).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) return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n return documentOrObjectId;\n}\n"],"names":[],"mappings":";;;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;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;IAC/B,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,UAAU,IAAI,IAAI,CAAC;AACrD,IAAA,qBAAqB,CAAC,gBAAgB,GAAG,MAAM,CAAC;AAChD,IAAA,OAAO,CAAC,OAAO,EAAE,UAAU,IAAI,mBAAmB,CAAC,OAAO,KAAK,mBAAmB,CAAC,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,2BAA2B,CAAC,CAAC,EAAE,KAAK,CAA+B,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC;AAClP;AAEA;;;;;;;;;;;;;;;;AAgBG;AACI,eAAe,oCAAoC,CAMtD,kBAAiD,EACjD,KAAoF,EACpF,YAAuB,EAAA;IAEvB,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,YAAY,KAAK,CAAC,QAAQ;AAAE,QAAA,QAAQ,MAAM,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;AACvK,IAAA,OAAO,kBAAkB;AAC7B;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/mongoose",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
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",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
],
|
|
21
21
|
"exports": {
|
|
22
22
|
"./*": {
|
|
23
|
-
"types": "
|
|
24
|
-
"import": "
|
|
25
|
-
"require": "
|
|
23
|
+
"types": "./dist/*.d.ts",
|
|
24
|
+
"import": "./dist/*.mjs",
|
|
25
|
+
"require": "./dist/*.cjs"
|
|
26
26
|
},
|
|
27
27
|
"./_internals": {
|
|
28
28
|
"types": null,
|
|
@@ -30,46 +30,50 @@
|
|
|
30
30
|
"require": null
|
|
31
31
|
},
|
|
32
32
|
"./schema-builders": {
|
|
33
|
-
"types": "./schema-builders/index.d.ts",
|
|
34
|
-
"import": "./schema-builders/index.mjs",
|
|
35
|
-
"require": "./schema-builders/index.cjs"
|
|
33
|
+
"types": "./dist/schema-builders/index.d.ts",
|
|
34
|
+
"import": "./dist/schema-builders/index.mjs",
|
|
35
|
+
"require": "./dist/schema-builders/index.cjs"
|
|
36
36
|
},
|
|
37
37
|
"./types": {
|
|
38
|
-
"types": "./types/index.d.ts"
|
|
38
|
+
"types": "./dist/types/index.d.ts"
|
|
39
39
|
},
|
|
40
40
|
"./types/*": {
|
|
41
|
-
"types": "./types/*.d.ts"
|
|
41
|
+
"types": "./dist/types/*.d.ts"
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
|
+
"files": [
|
|
45
|
+
"./dist",
|
|
46
|
+
"./src"
|
|
47
|
+
],
|
|
44
48
|
"engines": {
|
|
45
49
|
"node": ">=18.12.1"
|
|
46
50
|
},
|
|
47
51
|
"scripts": {
|
|
48
|
-
"build": "ts-project-builder ./src/constants.ts ./src/options.ts ./src/schema-builders/index.ts ./src/utils.ts --clean --preserve-modules",
|
|
52
|
+
"build": "ts-project-builder ./src/constants.ts ./src/options.ts ./src/schema-builders/index.ts ./src/utils.ts --clean --preserve-modules --sourcemaps",
|
|
49
53
|
"bumplog": "changelogen --bump",
|
|
50
54
|
"lint": "eslint",
|
|
51
55
|
"lint:fix": "eslint --fix",
|
|
52
|
-
"release": "pnpm run lint && pnpm run build && pnpm run test && changelogen --push --release &&
|
|
56
|
+
"release": "pnpm run lint && pnpm run build && pnpm run test && changelogen --push --release && npm publish",
|
|
53
57
|
"test": "jest --coverage"
|
|
54
58
|
},
|
|
55
59
|
"dependencies": {
|
|
56
60
|
"decimal.js": "^10.4.3",
|
|
57
61
|
"lodash": "^4.17.21",
|
|
58
|
-
"mongoose": "^8.9.
|
|
62
|
+
"mongoose": "^8.9.3",
|
|
59
63
|
"mongoose-aggregate-paginate-v2": "^1.1.2",
|
|
60
64
|
"mongoose-paginate-v2": "^1.8.5",
|
|
61
|
-
"type-fest": "^4.
|
|
65
|
+
"type-fest": "^4.31.0"
|
|
62
66
|
},
|
|
63
67
|
"devDependencies": {
|
|
64
68
|
"@kikiutils/changelogen": "^0.7.0",
|
|
65
69
|
"@kikiutils/eslint-config": "^0.7.3",
|
|
66
70
|
"@kikiutils/tsconfigs": "^3.0.2",
|
|
67
71
|
"@types/jest": "^29.5.14",
|
|
68
|
-
"@types/lodash": "^4.17.
|
|
69
|
-
"@types/node": "^22.10.
|
|
72
|
+
"@types/lodash": "^4.17.14",
|
|
73
|
+
"@types/node": "^22.10.5",
|
|
70
74
|
"jest": "^29.7.0",
|
|
71
75
|
"ts-jest": "^29.2.5",
|
|
72
|
-
"ts-project-builder": "^3.
|
|
76
|
+
"ts-project-builder": "^3.4.0",
|
|
73
77
|
"tslib": "^2.8.1"
|
|
74
78
|
}
|
|
75
79
|
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MongooseConnections } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mongoose connections.
|
|
5
|
+
*
|
|
6
|
+
* This constant is a record of named Mongoose connections, allowing multiple
|
|
7
|
+
* database connections to be managed within the application. An optional `default`
|
|
8
|
+
* connection can also be specified for use when a specific connection is not provided.
|
|
9
|
+
*/
|
|
10
|
+
export const mongooseConnections: MongooseConnections = {};
|
package/src/options.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { customMongooseOptions } from './_internals';
|
|
2
|
+
import type { CustomMongooseOptions } from './types/options';
|
|
3
|
+
import type { buildMongooseModel } from './utils';
|
|
4
|
+
|
|
5
|
+
export type DoNotRemoveOrUseThisType = typeof buildMongooseModel;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Sets custom options.
|
|
9
|
+
*
|
|
10
|
+
* For example, you can set {@link CustomMongooseOptions.beforeModelBuild} to define a function that will be called
|
|
11
|
+
* every time {@link buildMongooseModel} is used. Inside this function, you can modify
|
|
12
|
+
* the schema, allowing you to apply common settings to all global schemas.
|
|
13
|
+
*/
|
|
14
|
+
export const setCustomMongooseOptions = <K extends keyof CustomMongooseOptions>(key: K, value: CustomMongooseOptions[K]) => customMongooseOptions[key] = value;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import lodash from 'lodash';
|
|
2
|
+
import type {
|
|
3
|
+
Schema,
|
|
4
|
+
Types,
|
|
5
|
+
} from 'mongoose';
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
get: lodashGet,
|
|
9
|
+
set: lodashSet,
|
|
10
|
+
unset: lodashUnset,
|
|
11
|
+
} = lodash;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Mongoose plugin to normalize the JSON output of documents.
|
|
15
|
+
*
|
|
16
|
+
* This plugin modifies the `toJSON` method of Mongoose schemas to:
|
|
17
|
+
* - Add an `id` field equal to the string representation of `_id`
|
|
18
|
+
* - Remove the `_id` field
|
|
19
|
+
* - Exclude fields marked as `private` from the JSON output
|
|
20
|
+
* - Convert `Decimal128` fields to strings
|
|
21
|
+
* - Remove the `__v` version key
|
|
22
|
+
*
|
|
23
|
+
* @template S - The type of the schema.
|
|
24
|
+
*
|
|
25
|
+
* @param schema - The Mongoose schema to apply the plugin to.
|
|
26
|
+
*/
|
|
27
|
+
export function mongooseNormalizePlugin<S extends Schema>(schema: S) {
|
|
28
|
+
const toJSON = schema.get('toJSON');
|
|
29
|
+
const toJSONTransform = toJSON?.transform;
|
|
30
|
+
schema.set(
|
|
31
|
+
'toJSON',
|
|
32
|
+
{
|
|
33
|
+
...toJSON,
|
|
34
|
+
transform(doc: any, ret: any, options: any) {
|
|
35
|
+
const copiedRet = { ...ret };
|
|
36
|
+
copiedRet.id = copiedRet._id?.toHexString();
|
|
37
|
+
delete copiedRet._id;
|
|
38
|
+
for (const path in schema.paths) {
|
|
39
|
+
if (schema.paths[path]?.options?.private) lodashUnset(copiedRet, path);
|
|
40
|
+
if (schema.paths[path]?.instance === 'Decimal128') {
|
|
41
|
+
const value: Types.Decimal128 | undefined = lodashGet(copiedRet, path);
|
|
42
|
+
if (value) lodashSet(copiedRet, path, value.toString());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
delete copiedRet.__v;
|
|
47
|
+
if (toJSONTransform && typeof toJSONTransform !== 'boolean') return toJSONTransform(doc, copiedRet, options);
|
|
48
|
+
return copiedRet;
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default mongooseNormalizePlugin;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Schema } from 'mongoose';
|
|
2
|
+
|
|
3
|
+
const isFunctionKeys = new Set([
|
|
4
|
+
'default',
|
|
5
|
+
'enum',
|
|
6
|
+
'index',
|
|
7
|
+
'max',
|
|
8
|
+
'maxlength',
|
|
9
|
+
'min',
|
|
10
|
+
'minlength',
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
export function createBaseSchemaBuilderFactory<Builder = Readonly<Record<string, any>>>(type: BooleanConstructor | DateConstructor | NumberConstructor | Schema.Types.ObjectId['constructor'] | StringConstructor) {
|
|
14
|
+
return (schema: Record<string, any> = {}) => {
|
|
15
|
+
schema.type = type;
|
|
16
|
+
return new Proxy(
|
|
17
|
+
Object.freeze({}),
|
|
18
|
+
{
|
|
19
|
+
get(_, key, receiver) {
|
|
20
|
+
if (typeof key === 'symbol') throw new Error('Cannot use symbol as a schema attribute');
|
|
21
|
+
if (key in schema) throw new Error(`Duplicate schema attribute: ${key}`);
|
|
22
|
+
if (isFunctionKeys.has(key)) {
|
|
23
|
+
return (value: any) => {
|
|
24
|
+
schema[key] = value;
|
|
25
|
+
return receiver;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (key === 'nonRequired') return { ...schema };
|
|
30
|
+
if (key === 'required') {
|
|
31
|
+
return {
|
|
32
|
+
...schema,
|
|
33
|
+
required: true,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
schema[key] = true;
|
|
38
|
+
return receiver;
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
) as Builder;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BooleanSchemaDefinition,
|
|
3
|
+
DefaultType,
|
|
4
|
+
IndexDirection,
|
|
5
|
+
IndexOptions,
|
|
6
|
+
} from 'mongoose';
|
|
7
|
+
import type { Merge } from 'type-fest';
|
|
8
|
+
|
|
9
|
+
import { createBaseSchemaBuilderFactory } from './base';
|
|
10
|
+
|
|
11
|
+
export type ExtendBooleanSchemaBuilder<Props extends BaseBooleanSchemaProps, ExtraOmitFields extends string> = Omit<BooleanSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
12
|
+
|
|
13
|
+
export interface BaseBooleanSchemaProps {
|
|
14
|
+
type: BooleanSchemaDefinition;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface BooleanSchemaBuilder<Props extends BaseBooleanSchemaProps = BaseBooleanSchemaProps, ExtraOmitFields extends string = never> {
|
|
18
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends boolean>(value: T) => ExtendBooleanSchemaBuilder<Merge<Props, { default: T }>, ExtraOmitFields>;
|
|
19
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendBooleanSchemaBuilder<Merge<Props, { index: T }>, ExtraOmitFields>;
|
|
20
|
+
nonRequired: Props;
|
|
21
|
+
private: ExtendBooleanSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;
|
|
22
|
+
required: Merge<Props, { required: true }>;
|
|
23
|
+
sparse: ExtendBooleanSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;
|
|
24
|
+
unique: ExtendBooleanSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const booleanSchemaBuilder = createBaseSchemaBuilderFactory<BooleanSchemaBuilder>(Boolean);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DateSchemaDefinition,
|
|
3
|
+
DefaultType,
|
|
4
|
+
IndexDirection,
|
|
5
|
+
IndexOptions,
|
|
6
|
+
} from 'mongoose';
|
|
7
|
+
import type { Merge } from 'type-fest';
|
|
8
|
+
|
|
9
|
+
import type { Readonlyable } from '../types/utils';
|
|
10
|
+
|
|
11
|
+
import { createBaseSchemaBuilderFactory } from './base';
|
|
12
|
+
|
|
13
|
+
export type ExtendDateSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<DateSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
14
|
+
|
|
15
|
+
interface BaseProps {
|
|
16
|
+
type: DateSchemaDefinition;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface DateSchemaBuilder<Props extends { type: DateSchemaDefinition } = { type: DateSchemaDefinition }, ExtraOmitFields extends string = never> {
|
|
20
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends NativeDate>(value: T) => ExtendDateSchemaBuilder<Merge<Props, { default: T }>, ExtraOmitFields>;
|
|
21
|
+
enum: <
|
|
22
|
+
T extends
|
|
23
|
+
| Readonlyable<Array<D | null>>
|
|
24
|
+
| { [path: string]: D | null }
|
|
25
|
+
| { message?: M; values: Readonlyable<Array<D | null>> },
|
|
26
|
+
D extends NativeDate,
|
|
27
|
+
M extends string,
|
|
28
|
+
>(
|
|
29
|
+
value: T
|
|
30
|
+
) => ExtendDateSchemaBuilder<Merge<Props, { enum: T }>, ExtraOmitFields>;
|
|
31
|
+
|
|
32
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendDateSchemaBuilder<Merge<Props, { index: T }>, ExtraOmitFields>;
|
|
33
|
+
max: <T extends D | Readonlyable<[D, S]>, D extends NativeDate, S extends string>(value: T) => ExtendDateSchemaBuilder<Merge<Props, { max: T }>, ExtraOmitFields>;
|
|
34
|
+
min: <T extends D | Readonlyable<[D, S]>, D extends NativeDate, S extends string>(value: T) => ExtendDateSchemaBuilder<Merge<Props, { min: T }>, ExtraOmitFields>;
|
|
35
|
+
nonRequired: Props;
|
|
36
|
+
private: ExtendDateSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;
|
|
37
|
+
required: Merge<Props, { required: true }>;
|
|
38
|
+
sparse: ExtendDateSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;
|
|
39
|
+
unique: ExtendDateSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const dateSchemaBuilder = createBaseSchemaBuilderFactory<DateSchemaBuilder>(Date);
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
import { Schema } from 'mongoose';
|
|
3
|
+
import type {
|
|
4
|
+
DefaultType,
|
|
5
|
+
IndexDirection,
|
|
6
|
+
IndexOptions,
|
|
7
|
+
Types,
|
|
8
|
+
} from 'mongoose';
|
|
9
|
+
import type { Merge } from 'type-fest';
|
|
10
|
+
|
|
11
|
+
import type { Readonlyable } from '../types/utils';
|
|
12
|
+
|
|
13
|
+
import { createBaseSchemaBuilderFactory } from './base';
|
|
14
|
+
|
|
15
|
+
export type ExtendDecimal128SchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<Decimal128SchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
16
|
+
|
|
17
|
+
interface BaseProps {
|
|
18
|
+
type: Schema.Types.Decimal128;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface ToStringGetterSchema {
|
|
22
|
+
get: (value?: Types.Decimal128) => string | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface ToStringSetterSchema {
|
|
26
|
+
set: (value: { toString: () => string }) => string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Decimal128SchemaBuilder<Props extends { type: Schema.Types.Decimal128 } = { type: Schema.Types.Decimal128 }, ExtraOmitFields extends string = never> {
|
|
30
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends Types.Decimal128>(value: T) => ExtendDecimal128SchemaBuilder<Merge<Props, { default: T }>, ExtraOmitFields>;
|
|
31
|
+
enum: <
|
|
32
|
+
T extends
|
|
33
|
+
| Readonlyable<Array<D | null>>
|
|
34
|
+
| { [path: string]: D | null }
|
|
35
|
+
| { message?: M; values: Readonlyable<Array<D | null>> },
|
|
36
|
+
D extends Types.Decimal128,
|
|
37
|
+
M extends string,
|
|
38
|
+
>(
|
|
39
|
+
value: T
|
|
40
|
+
) => ExtendDecimal128SchemaBuilder<Merge<Props, { enum: T }>, ExtraOmitFields>;
|
|
41
|
+
|
|
42
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendDecimal128SchemaBuilder<Merge<Props, { index: T }>, ExtraOmitFields>;
|
|
43
|
+
nonRequired: Props;
|
|
44
|
+
private: ExtendDecimal128SchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;
|
|
45
|
+
required: Merge<Props, { required: true }>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Sets the rounding and toFixed behavior for Decimal128 fields.
|
|
49
|
+
* This method allows specifying the number of decimal places and the rounding strategy to be used when
|
|
50
|
+
* saving the field to the database.
|
|
51
|
+
*
|
|
52
|
+
* @param places - The number of decimal places to round to (default is 2).
|
|
53
|
+
* @param rounding - The rounding strategy from the Decimal.js library (default is Decimal.ROUND_DOWN).
|
|
54
|
+
*
|
|
55
|
+
* @returns A schema builder with the rounding and toFixed behavior applied to the `set` option in Mongoose.
|
|
56
|
+
*/
|
|
57
|
+
setRoundAndToFixedSetter: (places?: number, rounding?: Decimal.Rounding) => ExtendDecimal128SchemaBuilder<Merge<Props, ToStringSetterSchema>, 'setRoundAndToFixedSetter' | ExtraOmitFields>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Sets the toString behavior for Decimal128 fields.
|
|
61
|
+
* This method defines how the Decimal128 field should be converted to a string when processing or
|
|
62
|
+
* retrieving the value in the application (e.g., via getters), while still storing the value as Decimal128
|
|
63
|
+
* in the database.
|
|
64
|
+
*
|
|
65
|
+
* @returns A schema builder with the custom `get` behavior applied to convert the Decimal128 field to a string
|
|
66
|
+
* when accessed in the application.
|
|
67
|
+
*/
|
|
68
|
+
setToStringGetter: ExtendDecimal128SchemaBuilder<Merge<Props, ToStringGetterSchema>, 'setToStringGetter' | ExtraOmitFields>;
|
|
69
|
+
sparse: ExtendDecimal128SchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;
|
|
70
|
+
unique: ExtendDecimal128SchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);
|
|
74
|
+
|
|
75
|
+
export function decimal128SchemaBuilder() {
|
|
76
|
+
const schema: Record<string, any> = {};
|
|
77
|
+
const baseBuilder = baseBuilderFactory(schema);
|
|
78
|
+
return new Proxy(
|
|
79
|
+
baseBuilder,
|
|
80
|
+
{
|
|
81
|
+
get(target, key, receiver) {
|
|
82
|
+
if (key === 'setRoundAndToFixedSetter') {
|
|
83
|
+
return (places: number = 2, rounding: Decimal.Rounding = Decimal.ROUND_DOWN) => {
|
|
84
|
+
schema.set = (value: { toString: () => string }) => new Decimal(value.toString()).toFixed(places, rounding);
|
|
85
|
+
return receiver;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (key === 'setToStringGetter') {
|
|
90
|
+
schema.get = (value?: Types.Decimal128) => value?.toString();
|
|
91
|
+
return receiver;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return Reflect.get(target, key, receiver);
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
) as Decimal128SchemaBuilder;
|
|
98
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
|
|
9
|
+
export * from './boolean';
|
|
10
|
+
export * from './date';
|
|
11
|
+
export * from './decimal128';
|
|
12
|
+
export * from './number';
|
|
13
|
+
export * from './ref';
|
|
14
|
+
export * from './string';
|
|
15
|
+
|
|
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
|
+
};
|
|
25
|
+
|
|
26
|
+
export default schemaBuilders;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DefaultType,
|
|
3
|
+
IndexDirection,
|
|
4
|
+
IndexOptions,
|
|
5
|
+
NumberSchemaDefinition,
|
|
6
|
+
} from 'mongoose';
|
|
7
|
+
import type { Merge } from 'type-fest';
|
|
8
|
+
|
|
9
|
+
import type { Readonlyable } from '../types/utils';
|
|
10
|
+
|
|
11
|
+
import { createBaseSchemaBuilderFactory } from './base';
|
|
12
|
+
|
|
13
|
+
export type ExtendNumberSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<NumberSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
14
|
+
|
|
15
|
+
interface BaseProps {
|
|
16
|
+
type: NumberSchemaDefinition;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface NumberSchemaBuilder<Props extends { type: NumberSchemaDefinition } = { type: NumberSchemaDefinition }, ExtraOmitFields extends string = never> {
|
|
20
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends number>(value: T) => ExtendNumberSchemaBuilder<Merge<Props, { default: T }>, ExtraOmitFields>;
|
|
21
|
+
enum: <
|
|
22
|
+
T extends
|
|
23
|
+
| Readonlyable<Array<N | null>>
|
|
24
|
+
| { [path: string]: N | null }
|
|
25
|
+
| { message?: M; values: Readonlyable<Array<N | null>> },
|
|
26
|
+
M extends string,
|
|
27
|
+
N extends number,
|
|
28
|
+
>(
|
|
29
|
+
value: T
|
|
30
|
+
) => ExtendNumberSchemaBuilder<Merge<Props, { enum: T }>, ExtraOmitFields>;
|
|
31
|
+
|
|
32
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendNumberSchemaBuilder<Merge<Props, { index: T }>, ExtraOmitFields>;
|
|
33
|
+
max: <T extends N | Readonlyable<[N, S]>, N extends number, S extends string>(value: T) => ExtendNumberSchemaBuilder<Merge<Props, { max: T }>, ExtraOmitFields>;
|
|
34
|
+
min: <T extends N | Readonlyable<[N, S]>, N extends number, S extends string>(value: T) => ExtendNumberSchemaBuilder<Merge<Props, { min: T }>, ExtraOmitFields>;
|
|
35
|
+
nonRequired: Props;
|
|
36
|
+
private: ExtendNumberSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;
|
|
37
|
+
required: Merge<Props, { required: true }>;
|
|
38
|
+
sparse: ExtendNumberSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;
|
|
39
|
+
unique: ExtendNumberSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const numberSchemaBuilder = createBaseSchemaBuilderFactory<NumberSchemaBuilder>(Number);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
import type {
|
|
3
|
+
DefaultType,
|
|
4
|
+
IndexDirection,
|
|
5
|
+
IndexOptions,
|
|
6
|
+
ObjectIdSchemaDefinition,
|
|
7
|
+
Types,
|
|
8
|
+
} from 'mongoose';
|
|
9
|
+
import type { Merge } from 'type-fest';
|
|
10
|
+
|
|
11
|
+
import type { Readonlyable } from '../types/utils';
|
|
12
|
+
|
|
13
|
+
import { createBaseSchemaBuilderFactory } from './base';
|
|
14
|
+
|
|
15
|
+
export type ExtendObjectIdSchemaBuilder<Props extends BaseProps, ExtraOmitFields extends string> = Omit<ObjectIdSchemaBuilder<Props, ExtraOmitFields>, ExtraOmitFields | keyof Props>;
|
|
16
|
+
|
|
17
|
+
interface BaseProps {
|
|
18
|
+
type: ObjectIdSchemaDefinition;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ObjectIdSchemaBuilder<Props extends { type: ObjectIdSchemaDefinition } = { type: ObjectIdSchemaDefinition }, ExtraOmitFields extends string = never> {
|
|
22
|
+
default: <T extends ((this: any, doc: any) => DefaultType<D>) | DefaultType<D> | null, D extends Types.ObjectId>(value: T) => ExtendObjectIdSchemaBuilder<Merge<Props, { default: T }>, ExtraOmitFields>;
|
|
23
|
+
enum: <
|
|
24
|
+
T extends
|
|
25
|
+
| Readonlyable<Array<null | O>>
|
|
26
|
+
| { [path: string]: null | O }
|
|
27
|
+
| { message?: M; values: Readonlyable<Array<null | O>> },
|
|
28
|
+
M extends string,
|
|
29
|
+
O extends Types.ObjectId,
|
|
30
|
+
>(
|
|
31
|
+
value: T
|
|
32
|
+
) => ExtendObjectIdSchemaBuilder<Merge<Props, { enum: T }>, ExtraOmitFields>;
|
|
33
|
+
|
|
34
|
+
index: <T extends boolean | IndexDirection | IndexOptions>(value: T) => ExtendObjectIdSchemaBuilder<Merge<Props, { index: T }>, ExtraOmitFields>;
|
|
35
|
+
nonRequired: Props;
|
|
36
|
+
private: ExtendObjectIdSchemaBuilder<Merge<Props, { private: true }>, ExtraOmitFields>;
|
|
37
|
+
required: Merge<Props, { required: true }>;
|
|
38
|
+
sparse: ExtendObjectIdSchemaBuilder<Merge<Props, { sparse: true }>, ExtraOmitFields>;
|
|
39
|
+
unique: ExtendObjectIdSchemaBuilder<Merge<Props, { unique: true }>, ExtraOmitFields>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const objectIdSchemaBuilder = createBaseSchemaBuilderFactory<ObjectIdSchemaBuilder>(Schema.Types.ObjectId);
|