@kikiutils/mongoose 4.0.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/_internals.js +6 -0
- package/dist/_internals.js.map +1 -0
- package/dist/constants.d.ts +7 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +13 -0
- package/dist/constants.js.map +1 -0
- package/dist/options.d.ts +8 -4
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +17 -0
- package/dist/options.js.map +1 -0
- package/dist/plugins/normalize.d.ts +20 -16
- package/dist/plugins/normalize.d.ts.map +1 -1
- package/dist/plugins/normalize.js +47 -0
- package/dist/plugins/normalize.js.map +1 -0
- package/dist/schema-builders/base.d.ts +6 -3
- package/dist/schema-builders/base.d.ts.map +1 -1
- package/dist/schema-builders/base.js +34 -0
- package/dist/schema-builders/base.js.map +1 -0
- package/dist/schema-builders/boolean.d.ts +30 -26
- package/dist/schema-builders/boolean.d.ts.map +1 -1
- package/dist/schema-builders/boolean.js +8 -0
- package/dist/schema-builders/boolean.js.map +1 -0
- package/dist/schema-builders/date.d.ts +47 -44
- package/dist/schema-builders/date.d.ts.map +1 -1
- package/dist/schema-builders/date.js +8 -0
- package/dist/schema-builders/date.js.map +1 -0
- package/dist/schema-builders/decimal128.d.ts +66 -64
- package/dist/schema-builders/decimal128.d.ts.map +1 -1
- package/dist/schema-builders/decimal128.js +27 -0
- package/dist/schema-builders/decimal128.js.map +1 -0
- package/dist/schema-builders/index.d.ts +8 -15
- package/dist/schema-builders/index.js +9 -0
- package/dist/schema-builders/number.d.ts +47 -44
- package/dist/schema-builders/number.d.ts.map +1 -1
- package/dist/schema-builders/number.js +8 -0
- package/dist/schema-builders/number.js.map +1 -0
- package/dist/schema-builders/object-id.d.ts +41 -39
- package/dist/schema-builders/object-id.d.ts.map +1 -1
- package/dist/schema-builders/object-id.js +9 -0
- package/dist/schema-builders/object-id.js.map +1 -0
- package/dist/schema-builders/ref.d.ts +42 -40
- package/dist/schema-builders/ref.d.ts.map +1 -1
- package/dist/schema-builders/ref.js +12 -0
- package/dist/schema-builders/ref.js.map +1 -0
- package/dist/schema-builders/string.d.ts +95 -92
- package/dist/schema-builders/string.d.ts.map +1 -1
- package/dist/schema-builders/string.js +38 -0
- package/dist/schema-builders/string.js.map +1 -0
- package/dist/types/aggregate-paginate.d.ts +67 -64
- package/dist/types/aggregate-paginate.d.ts.map +1 -1
- package/dist/types/aggregate-paginate.js +1 -0
- package/dist/types/data.d.ts +46 -43
- package/dist/types/data.d.ts.map +1 -1
- package/dist/types/data.js +1 -0
- package/dist/types/index.d.ts +78 -76
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/options.d.ts +44 -40
- package/dist/types/options.d.ts.map +1 -1
- package/dist/types/options.js +1 -0
- package/dist/types/paginate.d.ts +109 -106
- package/dist/types/paginate.d.ts.map +1 -1
- package/dist/types/paginate.js +1 -0
- package/dist/types/utils.d.ts +5 -2
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/utils.js +1 -0
- package/dist/utils.d.ts +12 -9
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +98 -0
- package/dist/utils.js.map +1 -0
- package/package.json +35 -33
- package/src/options.ts +2 -2
- package/src/plugins/normalize.ts +21 -12
- package/src/schema-builders/decimal128.ts +1 -1
- package/src/schema-builders/ref.ts +1 -1
- package/src/schema-builders/string.ts +1 -1
- package/src/utils.ts +4 -4
- package/dist/_internals.cjs +0 -6
- package/dist/_internals.cjs.map +0 -1
- package/dist/_internals.d.ts +0 -3
- package/dist/_internals.d.ts.map +0 -1
- package/dist/_internals.mjs +0 -4
- package/dist/_internals.mjs.map +0 -1
- package/dist/constants.cjs +0 -13
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.mjs +0 -11
- package/dist/constants.mjs.map +0 -1
- package/dist/options.cjs +0 -17
- package/dist/options.cjs.map +0 -1
- package/dist/options.mjs +0 -15
- package/dist/options.mjs.map +0 -1
- package/dist/plugins/normalize.cjs +0 -62
- package/dist/plugins/normalize.cjs.map +0 -1
- package/dist/plugins/normalize.mjs +0 -54
- package/dist/plugins/normalize.mjs.map +0 -1
- package/dist/schema-builders/base.cjs +0 -43
- package/dist/schema-builders/base.cjs.map +0 -1
- package/dist/schema-builders/base.mjs +0 -41
- package/dist/schema-builders/base.mjs.map +0 -1
- package/dist/schema-builders/boolean.cjs +0 -8
- package/dist/schema-builders/boolean.cjs.map +0 -1
- package/dist/schema-builders/boolean.mjs +0 -6
- package/dist/schema-builders/boolean.mjs.map +0 -1
- package/dist/schema-builders/date.cjs +0 -8
- package/dist/schema-builders/date.cjs.map +0 -1
- package/dist/schema-builders/date.mjs +0 -6
- package/dist/schema-builders/date.mjs.map +0 -1
- package/dist/schema-builders/decimal128.cjs +0 -32
- package/dist/schema-builders/decimal128.cjs.map +0 -1
- package/dist/schema-builders/decimal128.mjs +0 -30
- package/dist/schema-builders/decimal128.mjs.map +0 -1
- package/dist/schema-builders/index.cjs +0 -27
- package/dist/schema-builders/index.cjs.map +0 -1
- package/dist/schema-builders/index.d.ts.map +0 -1
- package/dist/schema-builders/index.mjs +0 -8
- package/dist/schema-builders/index.mjs.map +0 -1
- package/dist/schema-builders/number.cjs +0 -8
- package/dist/schema-builders/number.cjs.map +0 -1
- package/dist/schema-builders/number.mjs +0 -6
- package/dist/schema-builders/number.mjs.map +0 -1
- package/dist/schema-builders/object-id.cjs +0 -9
- package/dist/schema-builders/object-id.cjs.map +0 -1
- package/dist/schema-builders/object-id.mjs +0 -7
- package/dist/schema-builders/object-id.mjs.map +0 -1
- package/dist/schema-builders/ref.cjs +0 -12
- package/dist/schema-builders/ref.cjs.map +0 -1
- package/dist/schema-builders/ref.mjs +0 -10
- package/dist/schema-builders/ref.mjs.map +0 -1
- package/dist/schema-builders/string.cjs +0 -46
- package/dist/schema-builders/string.cjs.map +0 -1
- package/dist/schema-builders/string.mjs +0 -44
- package/dist/schema-builders/string.mjs.map +0 -1
- package/dist/types/aggregate-paginate.cjs +0 -14
- package/dist/types/aggregate-paginate.cjs.map +0 -1
- package/dist/types/aggregate-paginate.mjs +0 -10
- package/dist/types/aggregate-paginate.mjs.map +0 -1
- package/dist/types/data.cjs +0 -3
- package/dist/types/data.cjs.map +0 -1
- package/dist/types/data.mjs +0 -2
- package/dist/types/data.mjs.map +0 -1
- package/dist/types/index.cjs +0 -3
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.mjs +0 -2
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/options.cjs +0 -3
- package/dist/types/options.cjs.map +0 -1
- package/dist/types/options.mjs +0 -2
- package/dist/types/options.mjs.map +0 -1
- package/dist/types/paginate.cjs +0 -8
- package/dist/types/paginate.cjs.map +0 -1
- package/dist/types/paginate.mjs +0 -4
- package/dist/types/paginate.mjs.map +0 -1
- package/dist/types/utils.cjs +0 -3
- package/dist/types/utils.cjs.map +0 -1
- package/dist/types/utils.mjs +0 -2
- package/dist/types/utils.mjs.map +0 -1
- package/dist/utils.cjs +0 -117
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.mjs +0 -106
- package/dist/utils.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.d.ts","
|
|
1
|
+
{"version":3,"file":"paginate.d.ts","names":[],"sources":["../../src/types/paginate.ts"],"sourcesContent":[],"mappings":";;;;;8DAckB,4BACV,OACA,WACA,OACI,iBACA;IAZ0B,EAAA,EAAA,MAAA;EAAA,CAAA,EAa1B,MAb0B,CActB,CAdsB,CAAA,kBAAA,CAAA,EAetB,CAfsB,GAAA;IAOpB,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,GAAA;KASF,CAPR,CAAA,CAAA,EAUA,gBAVA,CAUiB,CAVjB,EAUoB,QAVpB,EAU8B,aAV9B,CAAA,CAAA;YAEI,oBAAA,CAAA,IAAA,OAAA,GAAA,MAAA,GAAA,SAAA,CAAA,CAAA;IACA,IAAA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AA,GAsCL,CAtCK;IAAf,QAAA,EAAA,GAAA,GAuCQ,WAvCR,CAuCoB,CAvCpB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/types/utils.d.ts
|
|
2
|
+
type IfElse<Condition, Then, Else, ReferenceCondition = true> = Condition extends ReferenceCondition ? Then : Else;
|
|
3
|
+
type Readonlyable<T> = Readonly<T> | T;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { IfElse, Readonlyable };
|
|
3
6
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","
|
|
1
|
+
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/types/utils.ts"],"sourcesContent":[],"mappings":";KAAY,2DAKR,kBAAkB,qBAAqB,OAAO;AALtC,KAOA,YAPM,CAAA,CAAA,CAAA,GAOY,QAPZ,CAOqB,CAPrB,CAAA,GAO0B,CAP1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { BuildMongooseModelOptions } from "./types/options.js";
|
|
2
|
+
import { setCustomMongooseOptions } from "./options.js";
|
|
3
|
+
import { Schema, Types, mongo } from "mongoose";
|
|
4
|
+
|
|
5
|
+
//#region src/utils.d.ts
|
|
6
|
+
type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;
|
|
6
7
|
/**
|
|
7
8
|
* Asserts that a Mongoose update operation was successful by checking that it was acknowledged
|
|
8
9
|
* and that at least the expected number of documents were modified.
|
|
@@ -17,7 +18,7 @@ export type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;
|
|
|
17
18
|
* - The operation was not acknowledged by MongoDB,
|
|
18
19
|
* - Fewer documents were modified than expected.
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
declare function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(updatePromise: Promise<mongo.UpdateResult<T>>, expectedModifiedCount?: number): Promise<void>;
|
|
21
22
|
/**
|
|
22
23
|
* Builds and returns a Mongoose model with specified schema and options.
|
|
23
24
|
*
|
|
@@ -45,7 +46,7 @@ export declare function assertMongooseUpdateSuccess<T extends mongo.BSON.Documen
|
|
|
45
46
|
*
|
|
46
47
|
* @returns The created Mongoose model.
|
|
47
48
|
*/
|
|
48
|
-
|
|
49
|
+
declare function buildMongooseModel<DocType, Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>, InstanceMethodsAndOverrides = object, QueryHelpers = object>(collection: string, name: string, schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>, options?: BuildMongooseModelOptions): Model;
|
|
49
50
|
/**
|
|
50
51
|
* Converts a document or ObjectId to a document using the specified model.
|
|
51
52
|
*
|
|
@@ -63,7 +64,7 @@ export declare function buildMongooseModel<DocType, Model extends BaseMongoosePa
|
|
|
63
64
|
*
|
|
64
65
|
* @returns The corresponding document or null if not found.
|
|
65
66
|
*/
|
|
66
|
-
|
|
67
|
+
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>;
|
|
67
68
|
/**
|
|
68
69
|
* Converts the input, which can be a MongoDB ObjectId or a string,
|
|
69
70
|
* into a 24-character hexadecimal string representation of the ObjectId.
|
|
@@ -72,5 +73,7 @@ export declare function mongooseDocumentOrObjectIdToDocument<D extends MongooseH
|
|
|
72
73
|
*
|
|
73
74
|
* @returns {string} The hexadecimal string representation of the ObjectId
|
|
74
75
|
*/
|
|
75
|
-
|
|
76
|
+
declare function toObjectIdHexString(id: string | Types.ObjectId): string;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { DoNotRemoveOrUseThisType, assertMongooseUpdateSuccess, buildMongooseModel, mongooseDocumentOrObjectIdToDocument, toObjectIdHexString };
|
|
76
79
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","
|
|
1
|
+
{"version":3,"file":"utils.d.ts","names":[],"sources":["../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;KAcY,wBAAA,UAAkC;AAA9C;AAgBA;;;;;;;;AAuCA;;;;;AAEkB,iBAzCI,2BAyCJ,CAAA,UAzC0C,KAAA,CAAM,IAAA,CAAK,QAyCrD,CAAA,CAAA,aAAA,EAxCC,OAwCD,CAxCS,KAAA,CAAM,YAwCf,CAxC4B,CAwC5B,CAAA,CAAA,EAAA,qBAAA,CAAA,EAAA,MAAA,CAAA,EAtCf,OAsCe,CAAA,IAAA,CAAA;;;;;;;;;AAuClB;;;;;;;;;;;;;;;AAyBA;;;;iBAlEgB,0CAEE,0BAA0B,SAAS,6BAA6B,sHAMtE,OAAO,SAAS,OAAO,6BAA6B,yBAClD,4BACX;;;;;;;;;;;;;;;;;;iBA+BmB,+CACR,yBAAyB,SAAS,6BAA6B,uFAKrD,2BAA2B,WACxC,0BAA0B,SAAS,6BAA6B,yCAExE,QAAQ;;;;;;;;;iBAgBK,mBAAA,cAAiC,KAAA,CAAM"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { mongooseConnections } from "./constants.js";
|
|
2
|
+
import { customMongooseOptions } from "./_internals.js";
|
|
3
|
+
import { mongooseNormalizePlugin } from "./plugins/normalize.js";
|
|
4
|
+
import mongoose, { Types } from "mongoose";
|
|
5
|
+
import mongooseAggregatePaginate from "mongoose-aggregate-paginate-v2";
|
|
6
|
+
import mongoosePaginate from "mongoose-paginate-v2";
|
|
7
|
+
|
|
8
|
+
//#region src/utils.ts
|
|
9
|
+
/**
|
|
10
|
+
* Asserts that a Mongoose update operation was successful by checking that it was acknowledged
|
|
11
|
+
* and that at least the expected number of documents were modified.
|
|
12
|
+
*
|
|
13
|
+
* This function is intended for use with `updateOne`, `updateMany`, or any update operation
|
|
14
|
+
* that returns a MongoDB `UpdateResult`.
|
|
15
|
+
*
|
|
16
|
+
* @template T - The shape of the document being updated.
|
|
17
|
+
* @param updatePromise - A promise returned from a Mongoose update operation.
|
|
18
|
+
* @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.
|
|
19
|
+
* @throws Will throw an error if:
|
|
20
|
+
* - The operation was not acknowledged by MongoDB,
|
|
21
|
+
* - Fewer documents were modified than expected.
|
|
22
|
+
*/
|
|
23
|
+
async function assertMongooseUpdateSuccess(updatePromise, expectedModifiedCount = 1) {
|
|
24
|
+
const updateResult = await updatePromise;
|
|
25
|
+
if (!updateResult.acknowledged) throw new Error("Update was not acknowledged");
|
|
26
|
+
if (updateResult.modifiedCount < expectedModifiedCount) throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}`);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Builds and returns a Mongoose model with specified schema and options.
|
|
30
|
+
*
|
|
31
|
+
* This function sets up a Mongoose model with optional plugins and timestamp settings.
|
|
32
|
+
* It can optionally use a specified connection or the default connection.
|
|
33
|
+
*
|
|
34
|
+
* Determine the connection to use:
|
|
35
|
+
* 1. Use the connection provided in the options, if available.
|
|
36
|
+
* 2. Otherwise, use the default connection stored in `mongooseConnections`.
|
|
37
|
+
* 3. If there's no default connection, create one using the MongoDB URI from the environment variables,
|
|
38
|
+
* or fallback to a local MongoDB instance.
|
|
39
|
+
*
|
|
40
|
+
* You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.
|
|
41
|
+
* However, ensure that this option is configured before calling {@link buildMongooseModel}.
|
|
42
|
+
*
|
|
43
|
+
* @template DocType - The type of the document.
|
|
44
|
+
* @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.
|
|
45
|
+
* @template InstanceMethodsAndOverrides - The type for instance methods and overrides.
|
|
46
|
+
* @template QueryHelpers - The type for additional query helpers.
|
|
47
|
+
*
|
|
48
|
+
* @param collection - The name of the collection.
|
|
49
|
+
* @param name - The name of the model.
|
|
50
|
+
* @param schema - The Mongoose schema to use for the model.
|
|
51
|
+
* @param options - Optional settings for building the model.
|
|
52
|
+
*
|
|
53
|
+
* @returns The created Mongoose model.
|
|
54
|
+
*/
|
|
55
|
+
function buildMongooseModel(collection, name, schema, options) {
|
|
56
|
+
if (options?.enableNormalizePlugin !== false) schema.plugin(mongooseNormalizePlugin, options?.normalizePluginOptions);
|
|
57
|
+
schema.plugin(mongooseAggregatePaginate);
|
|
58
|
+
schema.plugin(mongoosePaginate);
|
|
59
|
+
schema.set("timestamps", options?.timestamps ?? schema.get("timestamps") ?? true);
|
|
60
|
+
customMongooseOptions.beforeModelBuild?.(schema);
|
|
61
|
+
return (options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || "mongodb://127.0.0.1:27017"))).model(name, schema, collection);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Converts a document or ObjectId to a document using the specified model.
|
|
65
|
+
*
|
|
66
|
+
* This function takes a document or ObjectId and returns the corresponding document
|
|
67
|
+
* from the database using the specified model. Optionally, specific fields can be selected.
|
|
68
|
+
*
|
|
69
|
+
* @template D - The type of the hydrated document.
|
|
70
|
+
* @template DocType - The type of the document.
|
|
71
|
+
* @template InstanceMethodsAndOverrides - The type for instance methods and overrides.
|
|
72
|
+
* @template QueryHelpers - The type for additional query helpers.
|
|
73
|
+
*
|
|
74
|
+
* @param documentOrObjectId - The document or ObjectId to convert.
|
|
75
|
+
* @param model - The Mongoose model to use for the conversion.
|
|
76
|
+
* @param selectFields - Optional fields to select from the document.
|
|
77
|
+
*
|
|
78
|
+
* @returns The corresponding document or null if not found.
|
|
79
|
+
*/
|
|
80
|
+
async function mongooseDocumentOrObjectIdToDocument(documentOrObjectId, model, selectFields) {
|
|
81
|
+
if (typeof documentOrObjectId === "string" || documentOrObjectId instanceof Types.ObjectId) return await model.findById(documentOrObjectId).select(selectFields || []);
|
|
82
|
+
return documentOrObjectId;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Converts the input, which can be a MongoDB ObjectId or a string,
|
|
86
|
+
* into a 24-character hexadecimal string representation of the ObjectId.
|
|
87
|
+
*
|
|
88
|
+
* @param {string | Types.ObjectId} id - The ObjectId instance or its string representation
|
|
89
|
+
*
|
|
90
|
+
* @returns {string} The hexadecimal string representation of the ObjectId
|
|
91
|
+
*/
|
|
92
|
+
function toObjectIdHexString(id) {
|
|
93
|
+
return id instanceof Types.ObjectId ? id.toHexString() : id;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
export { assertMongooseUpdateSuccess, buildMongooseModel, mongooseDocumentOrObjectIdToDocument, toObjectIdHexString };
|
|
98
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import mongoose, { Types } from 'mongoose';\nimport type {\n mongo,\n Schema,\n} from 'mongoose';\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';\nimport mongoosePaginate from 'mongoose-paginate-v2';\n\nimport { customMongooseOptions } from './_internals';\nimport { mongooseConnections } from './constants';\nimport type { setCustomMongooseOptions } from './options';\nimport { mongooseNormalizePlugin } from './plugins/normalize';\nimport type { BuildMongooseModelOptions } from './types/options';\n\nexport type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;\n\n/**\n * Asserts that a Mongoose update operation was successful by checking that it was acknowledged\n * and that at least the expected number of documents were modified.\n *\n * This function is intended for use with `updateOne`, `updateMany`, or any update operation\n * that returns a MongoDB `UpdateResult`.\n *\n * @template T - The shape of the document being updated.\n * @param updatePromise - A promise returned from a Mongoose update operation.\n * @param expectedModifiedCount - The minimum number of documents expected to be modified. Defaults to 1.\n * @throws Will throw an error if:\n * - The operation was not acknowledged by MongoDB,\n * - Fewer documents were modified than expected.\n */\nexport async function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(\n updatePromise: Promise<mongo.UpdateResult<T>>,\n expectedModifiedCount = 1,\n): Promise<void> {\n const updateResult = await updatePromise;\n if (!updateResult.acknowledged) throw new Error('Update was not acknowledged');\n if (updateResult.modifiedCount < expectedModifiedCount) {\n // eslint-disable-next-line style/max-len\n throw new Error(`Expected to modify at least ${expectedModifiedCount} document(s), but modified ${updateResult.modifiedCount}`);\n }\n}\n\n/**\n * Builds and returns a Mongoose model with specified schema and options.\n *\n * This function sets up a Mongoose model with optional plugins and timestamp settings.\n * It can optionally use a specified connection or the default connection.\n *\n * Determine the connection to use:\n * 1. Use the connection provided in the options, if available.\n * 2. Otherwise, use the default connection stored in `mongooseConnections`.\n * 3. If there's no default connection, create one using the MongoDB URI from the environment variables,\n * or fallback to a local MongoDB instance.\n *\n * You can set a function to be executed before the final build by using {@link setCustomMongooseOptions}.\n * However, ensure that this option is configured before calling {@link buildMongooseModel}.\n *\n * @template DocType - The type of the document.\n * @template Model - The type of the model, which extends `BaseMongoosePaginateModel`.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param collection - The name of the collection.\n * @param name - The name of the model.\n * @param schema - The Mongoose schema to use for the model.\n * @param options - Optional settings for building the model.\n *\n * @returns The created Mongoose model.\n */\nexport function buildMongooseModel<\n DocType,\n Model extends BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n InstanceMethodsAndOverrides = object,\n QueryHelpers = object,\n>(\n collection: string,\n name: string,\n schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,\n options?: BuildMongooseModelOptions,\n): Model {\n if (options?.enableNormalizePlugin !== false) {\n schema.plugin(mongooseNormalizePlugin, options?.normalizePluginOptions);\n }\n\n schema.plugin(mongooseAggregatePaginate);\n schema.plugin(mongoosePaginate);\n schema.set('timestamps', options?.timestamps ?? schema.get('timestamps') ?? true);\n customMongooseOptions.beforeModelBuild?.(schema);\n // eslint-disable-next-line style/max-len\n const connection = options?.connection || (mongooseConnections.default ||= mongoose.createConnection(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017'));\n return connection.model<DocType, Model, QueryHelpers>(name, schema, collection);\n}\n\n/**\n * Converts a document or ObjectId to a document using the specified model.\n *\n * This function takes a document or ObjectId and returns the corresponding document\n * from the database using the specified model. Optionally, specific fields can be selected.\n *\n * @template D - The type of the hydrated document.\n * @template DocType - The type of the document.\n * @template InstanceMethodsAndOverrides - The type for instance methods and overrides.\n * @template QueryHelpers - The type for additional query helpers.\n *\n * @param documentOrObjectId - The document or ObjectId to convert.\n * @param model - The Mongoose model to use for the conversion.\n * @param selectFields - Optional fields to select from the document.\n *\n * @returns The corresponding document or null if not found.\n */\nexport async function mongooseDocumentOrObjectIdToDocument<\n D extends MongooseHydratedDocument<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n DocType,\n InstanceMethodsAndOverrides,\n QueryHelpers,\n>(\n documentOrObjectId: MongooseDocumentOrObjectId<D>,\n model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,\n selectFields?: string[],\n): Promise<D | null> {\n if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {\n return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;\n }\n\n return documentOrObjectId;\n}\n\n/**\n * Converts the input, which can be a MongoDB ObjectId or a string,\n * into a 24-character hexadecimal string representation of the ObjectId.\n *\n * @param {string | Types.ObjectId} id - The ObjectId instance or its string representation\n *\n * @returns {string} The hexadecimal string representation of the ObjectId\n */\nexport function toObjectIdHexString(id: string | Types.ObjectId): string {\n return id instanceof Types.ObjectId ? id.toHexString() : id;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8BA,eAAsB,4BAClB,eACA,wBAAwB,GACX;CACb,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BvI,SAAgB,mBAMZ,YACA,MACA,QACA,SACK;AACL,KAAI,SAAS,0BAA0B,MACnC,QAAO,OAAO,yBAAyB,SAAS,uBAAuB;AAG3E,QAAO,OAAO,0BAA0B;AACxC,QAAO,OAAO,iBAAiB;AAC/B,QAAO,IAAI,cAAc,SAAS,cAAc,OAAO,IAAI,aAAa,IAAI,KAAK;AACjF,uBAAsB,mBAAmB,OAAO;AAGhD,SADmB,SAAS,eAAe,oBAAoB,YAAY,SAAS,iBAAiB,QAAQ,IAAI,eAAe,4BAA4B,GAC1I,MAAoC,MAAM,QAAQ,WAAW;;;;;;;;;;;;;;;;;;;AAoBnF,eAAsB,qCAMlB,oBACA,OACA,cACiB;AACjB,KAAI,OAAO,uBAAuB,YAAY,8BAA8B,MAAM,SAC9E,QAAQ,MAAM,MAAM,SAAS,mBAAmB,CAAC,OAAO,gBAAgB,EAAE,CAAC;AAG/E,QAAO;;;;;;;;;;AAWX,SAAgB,oBAAoB,IAAqC;AACrE,QAAO,cAAc,MAAM,WAAW,GAAG,aAAa,GAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/mongoose",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "5.0.0",
|
|
4
5
|
"description": "A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.",
|
|
5
6
|
"author": "kiki-kanri",
|
|
6
7
|
"license": "MIT",
|
|
@@ -20,37 +21,36 @@
|
|
|
20
21
|
],
|
|
21
22
|
"sideEffects": false,
|
|
22
23
|
"exports": {
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"./
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"./schema-builders":
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"./types":
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"./
|
|
42
|
-
|
|
43
|
-
}
|
|
24
|
+
"./constants": "./dist/constants.js",
|
|
25
|
+
"./options": "./dist/options.js",
|
|
26
|
+
"./plugins/normalize": "./dist/plugins/normalize.js",
|
|
27
|
+
"./schema-builders": "./dist/schema-builders/index.js",
|
|
28
|
+
"./schema-builders/base": "./dist/schema-builders/base.js",
|
|
29
|
+
"./schema-builders/boolean": "./dist/schema-builders/boolean.js",
|
|
30
|
+
"./schema-builders/date": "./dist/schema-builders/date.js",
|
|
31
|
+
"./schema-builders/decimal128": "./dist/schema-builders/decimal128.js",
|
|
32
|
+
"./schema-builders/number": "./dist/schema-builders/number.js",
|
|
33
|
+
"./schema-builders/object-id": "./dist/schema-builders/object-id.js",
|
|
34
|
+
"./schema-builders/ref": "./dist/schema-builders/ref.js",
|
|
35
|
+
"./schema-builders/string": "./dist/schema-builders/string.js",
|
|
36
|
+
"./types": "./dist/types/index.js",
|
|
37
|
+
"./types/aggregate-paginate": "./dist/types/aggregate-paginate.js",
|
|
38
|
+
"./types/data": "./dist/types/data.js",
|
|
39
|
+
"./types/options": "./dist/types/options.js",
|
|
40
|
+
"./types/paginate": "./dist/types/paginate.js",
|
|
41
|
+
"./types/utils": "./dist/types/utils.js",
|
|
42
|
+
"./utils": "./dist/utils.js",
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"./dist",
|
|
47
47
|
"./src"
|
|
48
48
|
],
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
50
|
+
"node": ">=22.0.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"build": "
|
|
53
|
+
"build": "tsdown",
|
|
54
54
|
"bumplog": "changelogen --bump --hideAuthorEmail",
|
|
55
55
|
"depcheck": "depcheck",
|
|
56
56
|
"lint": "eslint --max-warnings 0",
|
|
@@ -64,23 +64,25 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"decimal.js": "^10.6.0",
|
|
67
|
-
"
|
|
68
|
-
"mongoose": "^8.
|
|
67
|
+
"es-toolkit": "^1.39.10",
|
|
68
|
+
"mongoose": "^8.18.1",
|
|
69
69
|
"mongoose-aggregate-paginate-v2": "^1.1.4",
|
|
70
70
|
"mongoose-paginate-v2": "^1.9.1",
|
|
71
|
-
"type-fest": "^
|
|
71
|
+
"type-fest": "^5.0.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@kikiutils/changelogen": "^0.
|
|
75
|
-
"@kikiutils/eslint-config": "^
|
|
76
|
-
"@kikiutils/tsconfigs": "^5.0.
|
|
77
|
-
"@types/
|
|
78
|
-
"@types/node": "^24.2.0",
|
|
74
|
+
"@kikiutils/changelogen": "^0.9.0",
|
|
75
|
+
"@kikiutils/eslint-config": "^3.0.0",
|
|
76
|
+
"@kikiutils/tsconfigs": "^5.0.5",
|
|
77
|
+
"@types/node": "^24.3.3",
|
|
79
78
|
"@vitest/coverage-v8": "^3.2.4",
|
|
80
79
|
"depcheck": "^1.4.7",
|
|
81
|
-
"
|
|
80
|
+
"publint": "^0.3.12",
|
|
82
81
|
"ts-unused-exports": "^11.0.1",
|
|
82
|
+
"tsconfck": "^3.1.6",
|
|
83
|
+
"tsdown": "^0.15.1",
|
|
83
84
|
"typescript": "^5.9.2",
|
|
85
|
+
"unplugin-unused": "^0.5.3",
|
|
84
86
|
"vitest": "^3.2.4"
|
|
85
87
|
},
|
|
86
88
|
"pnpm": {
|
package/src/options.ts
CHANGED
|
@@ -14,6 +14,6 @@ export type DoNotRemoveOrUseThisType = typeof buildMongooseModel;
|
|
|
14
14
|
export function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(
|
|
15
15
|
key: K,
|
|
16
16
|
value: CustomMongooseOptions[K],
|
|
17
|
-
) {
|
|
18
|
-
|
|
17
|
+
): void {
|
|
18
|
+
customMongooseOptions[key] = value;
|
|
19
19
|
}
|
package/src/plugins/normalize.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import lodashUnset from 'lodash/unset.js';
|
|
1
|
+
import {
|
|
2
|
+
get as getProp,
|
|
3
|
+
set as setProp,
|
|
4
|
+
unset as unsetProp,
|
|
5
|
+
} from 'es-toolkit/compat';
|
|
7
6
|
import { Types } from 'mongoose';
|
|
8
7
|
import type { Schema } from 'mongoose';
|
|
9
8
|
|
|
@@ -38,7 +37,10 @@ export interface MongooseNormalizePluginOptions {
|
|
|
38
37
|
*
|
|
39
38
|
* @param schema - The Mongoose schema to apply the plugin to.
|
|
40
39
|
*/
|
|
41
|
-
export function mongooseNormalizePlugin<S extends Schema>(
|
|
40
|
+
export function mongooseNormalizePlugin<S extends Schema>(
|
|
41
|
+
schema: S,
|
|
42
|
+
pluginOptions?: MongooseNormalizePluginOptions,
|
|
43
|
+
): void {
|
|
42
44
|
const toJson = schema.get('toJSON');
|
|
43
45
|
const toJsonTransform = toJson?.transform;
|
|
44
46
|
schema.set(
|
|
@@ -52,13 +54,20 @@ export function mongooseNormalizePlugin<S extends Schema>(schema: S, pluginOptio
|
|
|
52
54
|
_id = _id instanceof Types.ObjectId ? _id.toHexString() : _id;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
+
if (_id !== undefined) {
|
|
58
|
+
if (pluginOptions?.convertIdField !== false) copiedRet.id = _id;
|
|
59
|
+
else copiedRet._id = _id;
|
|
60
|
+
}
|
|
61
|
+
|
|
57
62
|
for (const path in schema.paths) {
|
|
58
|
-
if (schema.paths[path]?.options?.private)
|
|
63
|
+
if (schema.paths[path]?.options?.private) {
|
|
64
|
+
unsetProp(copiedRet, path);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
59
68
|
if (schema.paths[path]?.instance === 'Decimal128') {
|
|
60
|
-
const value
|
|
61
|
-
if (value)
|
|
69
|
+
const value = getProp(copiedRet, path) as Types.Decimal128 | undefined;
|
|
70
|
+
if (value) setProp(copiedRet, path, value.toString());
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
73
|
|
|
@@ -100,7 +100,7 @@ interface ToStringSetterSchema {
|
|
|
100
100
|
|
|
101
101
|
const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.Decimal128);
|
|
102
102
|
|
|
103
|
-
export function decimal128SchemaBuilder() {
|
|
103
|
+
export function decimal128SchemaBuilder(): Decimal128SchemaBuilder {
|
|
104
104
|
const schema: Record<string, any> = {};
|
|
105
105
|
const baseBuilder = baseBuilderFactory(schema);
|
|
106
106
|
return new Proxy(
|
|
@@ -64,6 +64,6 @@ const baseBuilderFactory = createBaseSchemaBuilderFactory(Schema.Types.ObjectId)
|
|
|
64
64
|
|
|
65
65
|
export function refSchemaBuilder<T extends ((this: any, doc: any) => Model<any> | string) | Model<any> | string>(
|
|
66
66
|
ref: T,
|
|
67
|
-
) {
|
|
67
|
+
): RefSchemaBuilder<{ ref: T; type: typeof Schema.Types.ObjectId }> {
|
|
68
68
|
return baseBuilderFactory({ ref }) as RefSchemaBuilder<{ ref: T; type: typeof Schema.Types.ObjectId }>;
|
|
69
69
|
}
|
|
@@ -139,7 +139,7 @@ const baseBuilderFactory = createBaseSchemaBuilderFactory(String);
|
|
|
139
139
|
const defaultIpv4ValidateMessage = '`{VALUE}` is not a valid IPv4 address for path `{PATH}`';
|
|
140
140
|
const defaultIpv6ValidateMessage = '`{VALUE}` is not a valid IPv6 address for path `{PATH}`';
|
|
141
141
|
|
|
142
|
-
export function stringSchemaBuilder() {
|
|
142
|
+
export function stringSchemaBuilder(): StringSchemaBuilder {
|
|
143
143
|
const schema: Record<string, any> = {};
|
|
144
144
|
const baseBuilder = baseBuilderFactory(schema);
|
|
145
145
|
return new Proxy(
|
package/src/utils.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type DoNotRemoveOrUseThisType = typeof setCustomMongooseOptions;
|
|
|
31
31
|
export async function assertMongooseUpdateSuccess<T extends mongo.BSON.Document>(
|
|
32
32
|
updatePromise: Promise<mongo.UpdateResult<T>>,
|
|
33
33
|
expectedModifiedCount = 1,
|
|
34
|
-
) {
|
|
34
|
+
): Promise<void> {
|
|
35
35
|
const updateResult = await updatePromise;
|
|
36
36
|
if (!updateResult.acknowledged) throw new Error('Update was not acknowledged');
|
|
37
37
|
if (updateResult.modifiedCount < expectedModifiedCount) {
|
|
@@ -77,7 +77,7 @@ export function buildMongooseModel<
|
|
|
77
77
|
name: string,
|
|
78
78
|
schema: Schema<DocType, Model, InstanceMethodsAndOverrides, QueryHelpers>,
|
|
79
79
|
options?: BuildMongooseModelOptions,
|
|
80
|
-
) {
|
|
80
|
+
): Model {
|
|
81
81
|
if (options?.enableNormalizePlugin !== false) {
|
|
82
82
|
schema.plugin(mongooseNormalizePlugin, options?.normalizePluginOptions);
|
|
83
83
|
}
|
|
@@ -117,7 +117,7 @@ export async function mongooseDocumentOrObjectIdToDocument<
|
|
|
117
117
|
documentOrObjectId: MongooseDocumentOrObjectId<D>,
|
|
118
118
|
model: BaseMongoosePaginateModel<DocType, InstanceMethodsAndOverrides, QueryHelpers>,
|
|
119
119
|
selectFields?: string[],
|
|
120
|
-
) {
|
|
120
|
+
): Promise<D | null> {
|
|
121
121
|
if (typeof documentOrObjectId === 'string' || documentOrObjectId instanceof Types.ObjectId) {
|
|
122
122
|
return (await model.findById(documentOrObjectId).select(selectFields || [])) as D | null;
|
|
123
123
|
}
|
|
@@ -133,6 +133,6 @@ export async function mongooseDocumentOrObjectIdToDocument<
|
|
|
133
133
|
*
|
|
134
134
|
* @returns {string} The hexadecimal string representation of the ObjectId
|
|
135
135
|
*/
|
|
136
|
-
export function toObjectIdHexString(id: string | Types.ObjectId) {
|
|
136
|
+
export function toObjectIdHexString(id: string | Types.ObjectId): string {
|
|
137
137
|
return id instanceof Types.ObjectId ? id.toHexString() : id;
|
|
138
138
|
}
|
package/dist/_internals.cjs
DELETED
package/dist/_internals.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_internals.cjs","sources":["../src/_internals.ts"],"sourcesContent":["import type { CustomMongooseOptions } from './types/options';\n\nexport const customMongooseOptions: CustomMongooseOptions = {};\n"],"names":[],"mappings":";;AAEO,MAAM,qBAAqB,GAA0B;;;;"}
|
package/dist/_internals.d.ts
DELETED
package/dist/_internals.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_internals.d.ts","sourceRoot":"","sources":["../src/_internals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,eAAO,MAAM,qBAAqB,EAAE,qBAA0B,CAAC"}
|
package/dist/_internals.mjs
DELETED
package/dist/_internals.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_internals.mjs","sources":["../src/_internals.ts"],"sourcesContent":["import type { CustomMongooseOptions } from './types/options';\n\nexport const customMongooseOptions: CustomMongooseOptions = {};\n"],"names":[],"mappings":"AAEO,MAAM,qBAAqB,GAA0B;;;;"}
|
package/dist/constants.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
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
|
-
const mongooseConnections = {};
|
|
11
|
-
|
|
12
|
-
exports.mongooseConnections = mongooseConnections;
|
|
13
|
-
//# sourceMappingURL=constants.cjs.map
|
package/dist/constants.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sources":["../src/constants.ts"],"sourcesContent":["import type { MongooseConnections } from './types';\n\n/**\n * Mongoose connections.\n *\n * This constant is a record of named Mongoose connections, allowing multiple\n * database connections to be managed within the application. An optional `default`\n * connection can also be specified for use when a specific connection is not provided.\n */\nexport const mongooseConnections: MongooseConnections = {};\n"],"names":[],"mappings":";;AAEA;;;;;;AAMG;AACI,MAAM,mBAAmB,GAAwB;;;;"}
|
package/dist/constants.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mongoose connections.
|
|
3
|
-
*
|
|
4
|
-
* This constant is a record of named Mongoose connections, allowing multiple
|
|
5
|
-
* database connections to be managed within the application. An optional `default`
|
|
6
|
-
* connection can also be specified for use when a specific connection is not provided.
|
|
7
|
-
*/
|
|
8
|
-
const mongooseConnections = {};
|
|
9
|
-
|
|
10
|
-
export { mongooseConnections };
|
|
11
|
-
//# sourceMappingURL=constants.mjs.map
|
package/dist/constants.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sources":["../src/constants.ts"],"sourcesContent":["import type { MongooseConnections } from './types';\n\n/**\n * Mongoose connections.\n *\n * This constant is a record of named Mongoose connections, allowing multiple\n * database connections to be managed within the application. An optional `default`\n * connection can also be specified for use when a specific connection is not provided.\n */\nexport const mongooseConnections: MongooseConnections = {};\n"],"names":[],"mappings":"AAEA;;;;;;AAMG;AACI,MAAM,mBAAmB,GAAwB;;;;"}
|
package/dist/options.cjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _internals = require('./_internals.cjs');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Sets custom options.
|
|
7
|
-
*
|
|
8
|
-
* For example, you can set {@link CustomMongooseOptions.beforeModelBuild} to define a function that will be called
|
|
9
|
-
* every time {@link buildMongooseModel} is used. Inside this function, you can modify
|
|
10
|
-
* the schema, allowing you to apply common settings to all global schemas.
|
|
11
|
-
*/
|
|
12
|
-
function setCustomMongooseOptions(key, value) {
|
|
13
|
-
return _internals.customMongooseOptions[key] = value;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.setCustomMongooseOptions = setCustomMongooseOptions;
|
|
17
|
-
//# sourceMappingURL=options.cjs.map
|
package/dist/options.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.cjs","sources":["../src/options.ts"],"sourcesContent":["import { customMongooseOptions } from './_internals';\nimport type { CustomMongooseOptions } from './types/options';\nimport type { buildMongooseModel } from './utils';\n\nexport type DoNotRemoveOrUseThisType = typeof buildMongooseModel;\n\n/**\n * Sets custom options.\n *\n * For example, you can set {@link CustomMongooseOptions.beforeModelBuild} to define a function that will be called\n * every time {@link buildMongooseModel} is used. Inside this function, you can modify\n * the schema, allowing you to apply common settings to all global schemas.\n */\nexport function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(\n key: K,\n value: CustomMongooseOptions[K],\n) {\n return customMongooseOptions[key] = value;\n}\n"],"names":["customMongooseOptions"],"mappings":";;;;AAMA;;;;;;AAMG;AACG,SAAU,wBAAwB,CACpC,GAAM,EACN,KAA+B,EAAA;AAE/B,IAAA,OAAOA,gCAAqB,CAAC,GAAG,CAAC,GAAG,KAAK;AAC7C;;;;"}
|
package/dist/options.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { customMongooseOptions } from './_internals.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Sets custom options.
|
|
5
|
-
*
|
|
6
|
-
* For example, you can set {@link CustomMongooseOptions.beforeModelBuild} to define a function that will be called
|
|
7
|
-
* every time {@link buildMongooseModel} is used. Inside this function, you can modify
|
|
8
|
-
* the schema, allowing you to apply common settings to all global schemas.
|
|
9
|
-
*/
|
|
10
|
-
function setCustomMongooseOptions(key, value) {
|
|
11
|
-
return customMongooseOptions[key] = value;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { setCustomMongooseOptions };
|
|
15
|
-
//# sourceMappingURL=options.mjs.map
|
package/dist/options.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.mjs","sources":["../src/options.ts"],"sourcesContent":["import { customMongooseOptions } from './_internals';\nimport type { CustomMongooseOptions } from './types/options';\nimport type { buildMongooseModel } from './utils';\n\nexport type DoNotRemoveOrUseThisType = typeof buildMongooseModel;\n\n/**\n * Sets custom options.\n *\n * For example, you can set {@link CustomMongooseOptions.beforeModelBuild} to define a function that will be called\n * every time {@link buildMongooseModel} is used. Inside this function, you can modify\n * the schema, allowing you to apply common settings to all global schemas.\n */\nexport function setCustomMongooseOptions<K extends keyof CustomMongooseOptions>(\n key: K,\n value: CustomMongooseOptions[K],\n) {\n return customMongooseOptions[key] = value;\n}\n"],"names":[],"mappings":";;AAMA;;;;;;AAMG;AACG,SAAU,wBAAwB,CACpC,GAAM,EACN,KAA+B,EAAA;AAE/B,IAAA,OAAO,qBAAqB,CAAC,GAAG,CAAC,GAAG,KAAK;AAC7C;;;;"}
|