@kikiutils/mongoose 6.0.1 → 6.1.1
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.
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { Schema } from "mongoose";
|
|
1
|
+
import { Schema, mongo } from "mongoose";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/assertions.d.ts
|
|
4
4
|
declare module 'mongoose' {
|
|
5
5
|
interface Document<T = unknown, TQueryHelpers = any, DocType = any, TVirtuals = Record<string, any>, TSchemaOptions = {}> {
|
|
6
6
|
assertUpdateSuccess: (update?: UpdateQuery<Document<T, TQueryHelpers, DocType, TVirtuals, TSchemaOptions>> | UpdateWithAggregationPipeline, options?: null | QueryOptions, expectedModifiedCount?: number) => Promise<void>;
|
|
7
7
|
}
|
|
8
|
+
interface Model<TRawDocType, TQueryHelpers = {}, TInstanceMethods = {}, TVirtuals = {}, THydratedDocumentType = HydratedDocument<TRawDocType, TInstanceMethods & TVirtuals, TQueryHelpers, TVirtuals>, TSchema = any> {
|
|
9
|
+
assertUpdateSuccess: (filter: RootFilterQuery<TRawDocType>, update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline, options?: (mongo.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null, expectedModifiedCount?: number) => Promise<void>;
|
|
10
|
+
}
|
|
8
11
|
}
|
|
9
12
|
declare function mongooseAssertionsPlugin<S extends Schema>(schema: S): void;
|
|
10
13
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertions.d.ts","names":[],"sources":["../../src/plugins/assertions.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"assertions.d.ts","names":[],"sources":["../../src/plugins/assertions.ts"],"sourcesContent":[],"mappings":";;;;kFAiBoB;IATF,mBAAA,EAAA,CAAA,MAAA,CAAA,EAeF,WAfE,CAeU,QAfV,CAemB,CAfnB,EAesB,aAftB,EAeqC,OAfrC,EAe8C,SAf9C,EAeyD,cAfzD,CAAA,CAAA,GAgBF,6BAhBE,EAAA,OAAA,CAAA,EAAA,IAAA,GAiBW,YAjBX,EAAA,qBAAA,CAAA,EAAA,MAAA,EAAA,GAmBL,OAnBK,CAAA,IAAA,CAAA;EAAA;YASE,KAAA,CAAA,WAAA,EAAA,gBAAA,CAAA,CAAA,EAAA,mBAAA,CAAA,CAAA,EAAA,YAAA,CAAA,CAAA,EAAA,wBAsBY,gBAtBZ,CAsB6B,WAtB7B,EAsB0C,gBAtB1C,GAsB6D,SAtB7D,EAsBwE,aAtBxE,EAsBuF,SAtBvF,CAAA,EAAA,UAAA,GAAA,CAAA,CAAA;IAMiB,mBAAA,EAAA,CAAA,MAAA,EAqBjB,eArBiB,CAqBD,WArBC,CAAA,EAAA,MAAA,EAsBjB,WAtBiB,CAsBL,WAtBK,CAAA,GAsBU,6BAtBV,EAAA,OAAA,CAAA,EAAA,CAuBd,KAAA,CAAM,aAvBQ,GAuBQ,0BAvBR,CAuBmC,WAvBnC,CAAA,CAAA,GAAA,IAAA,EAAA,qBAAA,CAAA,EAAA,MAAA,EAAA,GAyBxB,OAzBwB,CAAA,IAAA,CAAA;;;AAA2B,iBA6BhD,wBA7BgD,CAAA,UA6Bb,MA7Ba,CAAA,CAAA,MAAA,EA6BG,CA7BH,CAAA,EAAA,IAAA"}
|
|
@@ -5,6 +5,9 @@ function mongooseAssertionsPlugin(schema) {
|
|
|
5
5
|
schema.method("assertUpdateSuccess", function(update, options, expectedModifiedCount) {
|
|
6
6
|
return assertMongooseUpdateSuccess(this.updateOne(update, options), expectedModifiedCount);
|
|
7
7
|
});
|
|
8
|
+
schema.static("assertUpdateSuccess", function(filter, update, options, expectedModifiedCount = 1) {
|
|
9
|
+
return assertMongooseUpdateSuccess(expectedModifiedCount === 1 ? this.updateOne(filter, update, options) : this.updateMany(filter, update, options), expectedModifiedCount);
|
|
10
|
+
});
|
|
8
11
|
}
|
|
9
12
|
|
|
10
13
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertions.js","names":[],"sources":["../../src/plugins/assertions.ts"],"sourcesContent":["import type {\n QueryOptions,\n Schema,\n UpdateQuery,\n UpdateWithAggregationPipeline,\n} from 'mongoose';\n\nimport { assertMongooseUpdateSuccess } from '../assertions';\n\ndeclare module 'mongoose' {\n
|
|
1
|
+
{"version":3,"file":"assertions.js","names":[],"sources":["../../src/plugins/assertions.ts"],"sourcesContent":["import type {\n mongo,\n MongooseUpdateQueryOptions,\n QueryOptions,\n RootFilterQuery,\n Schema,\n UpdateQuery,\n UpdateWithAggregationPipeline,\n} from 'mongoose';\n\nimport { assertMongooseUpdateSuccess } from '../assertions';\n\ndeclare module 'mongoose' {\n interface Document<\n T = unknown,\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: RootFilterQuery<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: RootFilterQuery<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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.d.ts","names":[],"sources":["../../src/schema-builders/number.ts"],"sourcesContent":[],"mappings":";;;;;KAYY,wCACM,6CAEd,KACA,oBAAoB,OAAO,kBAC3B,wBAAwB;UAGlB,SAAA;EARE,IAAA,EASF,sBAT2B;;AACnB,UAWD,mBAXC,CAAA,cAAA;MAGM,EASE,sBATF;;MAApB,EASyD,sBATzD;2BACA,MAAA,GAAA,KAAA,CAAA,CAAA;SAAwB,EAAA,CAAA,UAAA,CAAA,CAAA,IAAA,EAAA,GAAA,EAAA,GAAA,EAAA,GAAA,EAAA,GAYgB,WAZhB,CAY4B,CAZ5B,CAAA,CAAA,GAYkC,WAZl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B9B,CA8BoC,KA9BpC,EAAA;IAFW,MAAA,EAAA,IAAA;MAgCmD,eA3BtC,CAAA;;AAAsC,cA8BzD,mBA9ByD,EAAA,CAAA,MAAA,CAAA,EA8BtC,MA9BsC,CAAA,MAAA,EAAA,GAAA,CAAA,EAAA,GA8BtC,mBA9BsC,CAAA;MACxD,EAxB+C,sBAwB/C;QAAgB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/mongoose",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.1.1",
|
|
5
5
|
"description": "A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.",
|
|
6
6
|
"author": "kiki-kanri",
|
|
7
7
|
"license": "MIT",
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
mongo,
|
|
3
|
+
MongooseUpdateQueryOptions,
|
|
2
4
|
QueryOptions,
|
|
5
|
+
RootFilterQuery,
|
|
3
6
|
Schema,
|
|
4
7
|
UpdateQuery,
|
|
5
8
|
UpdateWithAggregationPipeline,
|
|
@@ -8,7 +11,7 @@ import type {
|
|
|
8
11
|
import { assertMongooseUpdateSuccess } from '../assertions';
|
|
9
12
|
|
|
10
13
|
declare module 'mongoose' {
|
|
11
|
-
|
|
14
|
+
interface Document<
|
|
12
15
|
T = unknown,
|
|
13
16
|
TQueryHelpers = any,
|
|
14
17
|
DocType = any,
|
|
@@ -24,6 +27,27 @@ declare module 'mongoose' {
|
|
|
24
27
|
expectedModifiedCount?: number,
|
|
25
28
|
) => Promise<void>;
|
|
26
29
|
}
|
|
30
|
+
|
|
31
|
+
interface Model<
|
|
32
|
+
TRawDocType,
|
|
33
|
+
// eslint-disable-next-line ts/no-empty-object-type
|
|
34
|
+
TQueryHelpers = {},
|
|
35
|
+
// eslint-disable-next-line ts/no-empty-object-type
|
|
36
|
+
TInstanceMethods = {},
|
|
37
|
+
// eslint-disable-next-line ts/no-empty-object-type
|
|
38
|
+
TVirtuals = {},
|
|
39
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
40
|
+
THydratedDocumentType = HydratedDocument<TRawDocType, TInstanceMethods & TVirtuals, TQueryHelpers, TVirtuals>,
|
|
41
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
42
|
+
TSchema = any,
|
|
43
|
+
> {
|
|
44
|
+
assertUpdateSuccess: (
|
|
45
|
+
filter: RootFilterQuery<TRawDocType>,
|
|
46
|
+
update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
|
|
47
|
+
options?: (mongo.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null,
|
|
48
|
+
expectedModifiedCount?: number,
|
|
49
|
+
) => Promise<void>;
|
|
50
|
+
}
|
|
27
51
|
}
|
|
28
52
|
|
|
29
53
|
export function mongooseAssertionsPlugin<S extends Schema>(schema: S) {
|
|
@@ -37,4 +61,21 @@ export function mongooseAssertionsPlugin<S extends Schema>(schema: S) {
|
|
|
37
61
|
return assertMongooseUpdateSuccess(this.updateOne(update, options), expectedModifiedCount);
|
|
38
62
|
},
|
|
39
63
|
);
|
|
64
|
+
|
|
65
|
+
schema.static(
|
|
66
|
+
'assertUpdateSuccess',
|
|
67
|
+
function (
|
|
68
|
+
filter: RootFilterQuery<any>,
|
|
69
|
+
update: UpdateQuery<any> | UpdateWithAggregationPipeline,
|
|
70
|
+
options?: (mongo.UpdateOptions & MongooseUpdateQueryOptions<any>) | null,
|
|
71
|
+
expectedModifiedCount: number = 1,
|
|
72
|
+
) {
|
|
73
|
+
return assertMongooseUpdateSuccess(
|
|
74
|
+
expectedModifiedCount === 1
|
|
75
|
+
? this.updateOne(filter, update, options)
|
|
76
|
+
: this.updateMany(filter, update, options),
|
|
77
|
+
expectedModifiedCount,
|
|
78
|
+
);
|
|
79
|
+
},
|
|
80
|
+
);
|
|
40
81
|
}
|