@tsed/mongoose 7.8.1 → 7.8.3

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/jest.config.js CHANGED
@@ -5,10 +5,10 @@ module.exports = {
5
5
  ...require("@tsed/jest-config")(__dirname, "mongoose"),
6
6
  coverageThreshold: {
7
7
  global: {
8
- statements: 99.25,
9
- branches: 94.83,
10
- functions: 98.97,
11
- lines: 99.21
8
+ statements: 99.5,
9
+ branches: 95.48,
10
+ functions: 100,
11
+ lines: 99.47
12
12
  }
13
13
  }
14
14
  };
@@ -1 +1 @@
1
- {"version":3,"file":"MongooseSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseSchemaOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {Schema, SchemaOptions} from \"mongoose\";\nimport {MongooseDocument} from \"./MongooseDocument\";\n\nexport type MongooseNextCB = (err?: Error) => void;\n\nexport interface MongooseHookOptions {\n document?: boolean;\n query?: boolean;\n parallel?: boolean;\n}\n\nexport type MongoosePreHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>) => Promise<void> | void);\n\nexport type MongoosePostHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, error: Error, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>, error: Error) => Promise<void> | void)\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>) => Promise<void> | void);\n\nexport interface MongoosePreHook<T = any> {\n method: string | RegExp;\n fn: MongoosePreHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePostHook<T = any> {\n method: string | RegExp;\n fn: MongoosePostHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePluginOptions {\n plugin: (schema: Schema, options?: any) => void;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseIndexOptions {\n fields: Record<any, any>;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseSchemaOptions {\n schemaOptions?: SchemaOptions;\n plugins?: MongoosePluginOptions[];\n indexes?: MongooseIndexOptions[];\n pre?: MongoosePreHook[];\n post?: MongoosePostHook[];\n}\n"]}
1
+ {"version":3,"file":"MongooseSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseSchemaOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {Schema, SchemaOptions} from \"mongoose\";\nimport {MongooseDocument} from \"./MongooseDocument\";\n\nexport type MongooseNextCB = (err?: Error) => void;\n\nexport interface MongooseHookOptions {\n document?: boolean;\n query?: boolean;\n parallel?: boolean;\n}\n\nexport type MongooseHookPromised<T = any> = (doc: T | MongooseDocument<T>) => Promise<void> | void;\n\nexport type MongoosePreHookCB<T = any> = ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void) | MongooseHookPromised;\n\nexport type MongoosePostHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, error: Error, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>, error: Error) => Promise<void> | void)\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | MongooseHookPromised;\n\nexport interface MongoosePreHook<T = any> {\n method: string | RegExp;\n fn: MongoosePreHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePostHook<T = any> {\n method: string | RegExp;\n fn: MongoosePostHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePluginOptions {\n plugin: (schema: Schema, options?: any) => void;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseIndexOptions {\n fields: Record<any, any>;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseSchemaOptions {\n schemaOptions?: SchemaOptions;\n plugins?: MongoosePluginOptions[];\n indexes?: MongooseIndexOptions[];\n pre?: MongoosePreHook[];\n post?: MongoosePostHook[];\n}\n"]}
@@ -24,12 +24,12 @@ function mapHookArgs(hook) {
24
24
  * @ignore
25
25
  */
26
26
  function buildPreHook(fn) {
27
- return fn.length === 2
28
- ? function (next) {
29
- return fn(this, next);
27
+ return fn.length === 1
28
+ ? function () {
29
+ return fn(this);
30
30
  }
31
- : function (next, options) {
32
- return fn(this, next, options);
31
+ : function (next) {
32
+ return fn(this, next);
33
33
  };
34
34
  }
35
35
  exports.buildPreHook = buildPreHook;
@@ -1 +1 @@
1
- {"version":3,"file":"schemaOptions.js","sourceRoot":"","sources":["../../../src/utils/schemaOptions.ts"],"names":[],"mappings":";;;AAAA,qCAA4C;AAE5C,sDAA+D;AAG/D;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAW,EAAE,OAA+B;IACxE,MAAM,KAAK,GAAG,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEjC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,mCAAuB,CAAC,EAAE;QACvC,KAAK,CAAC,GAAG,CAAC,mCAAuB,EAAE,EAAE,CAAC,CAAC;KACxC;IAED,IAAI,OAAO,EAAE;QACX,KAAK,CAAC,GAAG,CAAC,mCAAuB,EAAE,IAAA,gBAAS,EAAC,KAAK,CAAC,GAAG,CAAC,mCAAuB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;KAC5F;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,mCAAuB,CAAC,CAAC;AAC5C,CAAC;AAZD,sCAYC;AAED,SAAS,WAAW,CAAC,IAAwC;IAC3D,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAQ,CAAC;AAC3G,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,EAAY;IACvC,OAAO,EAAE,CAAC,MAAM,KAAK,CAAC;QACpB,CAAC,CAAC,UAAU,IAAoB;YAC5B,OAAO,EAAE,CAAC,IAAI,EAAE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SCHEMA_OPTIONS} from \"../constants/constants\";\nimport {MongooseNextCB, MongoosePostHook, MongoosePreHook, MongooseSchemaOptions} from \"../interfaces/MongooseSchemaOptions\";\n\n/**\n * @ignore\n */\nexport function schemaOptions(target: any, options?: MongooseSchemaOptions) {\n const store = Store.from(target);\n\n if (!store.has(MONGOOSE_SCHEMA_OPTIONS)) {\n store.set(MONGOOSE_SCHEMA_OPTIONS, {});\n }\n\n if (options) {\n store.set(MONGOOSE_SCHEMA_OPTIONS, deepMerge(store.get(MONGOOSE_SCHEMA_OPTIONS), options));\n }\n\n return store.get(MONGOOSE_SCHEMA_OPTIONS);\n}\n\nfunction mapHookArgs(hook: MongoosePreHook | MongoosePostHook): [string | RegExp, Function] {\n return [hook.method, hook.options || hook.fn, hook.options ? hook.fn : undefined].filter(Boolean) as any;\n}\n\n/**\n * @ignore\n */\nexport function buildPreHook(fn: Function) {\n return fn.length === 2\n ? function (next: MongooseNextCB) {\n return fn(this, next);\n }\n : function (next: MongooseNextCB, options: any) {\n return fn(this, next, options);\n };\n}\n\n/**\n * @ignore\n */\nexport function applySchemaOptions(schema: Schema, options: MongooseSchemaOptions) {\n if (options.plugins) {\n options.plugins.forEach((item) => schema.plugin(item.plugin, item.options));\n }\n\n if (options.indexes) {\n options.indexes.forEach((item) => schema.index(item.fields, item.options));\n }\n\n if (options.pre) {\n options.pre.forEach((item) => {\n item = {\n ...item,\n fn: buildPreHook(item.fn)\n };\n\n (schema.pre as any)(...mapHookArgs(item));\n });\n }\n\n if (options.post) {\n options.post.forEach((item) => (schema.post as any)(...mapHookArgs(item)));\n }\n}\n"]}
1
+ {"version":3,"file":"schemaOptions.js","sourceRoot":"","sources":["../../../src/utils/schemaOptions.ts"],"names":[],"mappings":";;;AAAA,qCAA4C;AAE5C,sDAA+D;AAU/D;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAW,EAAE,OAA+B;IACxE,MAAM,KAAK,GAAG,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC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AAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;KAC5E;IAED,IAAI,OAAO,CAAC,GAAG,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC3B,IAAI,GAAG;gBACL,GAAG,IAAI;gBACP,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;aAC1B,CAAC;YAED,MAAM,CAAC,GAAW,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAE,MAAM,CAAC,IAAY,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAC5E;AACH,CAAC;AAvBD,gDAuBC","sourcesContent":["import {deepMerge, Store} from \"@tsed/core\";\nimport {Schema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants/constants\";\nimport {\n MongooseHookPromised,\n MongooseNextCB,\n MongoosePostHook,\n MongoosePreHook,\n MongoosePreHookCB,\n MongooseSchemaOptions\n} from \"../interfaces/MongooseSchemaOptions\";\n\n/**\n * @ignore\n */\nexport function schemaOptions(target: any, options?: MongooseSchemaOptions) {\n const store = Store.from(target);\n\n if (!store.has(MONGOOSE_SCHEMA_OPTIONS)) {\n store.set(MONGOOSE_SCHEMA_OPTIONS, {});\n }\n\n if (options) {\n store.set(MONGOOSE_SCHEMA_OPTIONS, deepMerge(store.get(MONGOOSE_SCHEMA_OPTIONS), options));\n }\n\n return store.get(MONGOOSE_SCHEMA_OPTIONS);\n}\n\nfunction mapHookArgs(hook: MongoosePreHook | MongoosePostHook): [string | RegExp, Function] {\n return [hook.method, hook.options || hook.fn, hook.options ? hook.fn : undefined].filter(Boolean) as any;\n}\n\n/**\n * @ignore\n */\nexport function buildPreHook(fn: MongoosePreHookCB) {\n return fn.length === 1\n ? function () {\n return (fn as MongooseHookPromised)(this);\n }\n : function (next: MongooseNextCB) {\n return fn(this, next);\n };\n}\n\n/**\n * @ignore\n */\nexport function applySchemaOptions(schema: Schema, options: MongooseSchemaOptions) {\n if (options.plugins) {\n options.plugins.forEach((item) => schema.plugin(item.plugin, item.options));\n }\n\n if (options.indexes) {\n options.indexes.forEach((item) => schema.index(item.fields, item.options));\n }\n\n if (options.pre) {\n options.pre.forEach((item) => {\n item = {\n ...item,\n fn: buildPreHook(item.fn)\n };\n\n (schema.pre as any)(...mapHookArgs(item));\n });\n }\n\n if (options.post) {\n options.post.forEach((item) => (schema.post as any)(...mapHookArgs(item)));\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MongooseSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseSchemaOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {Schema, SchemaOptions} from \"mongoose\";\nimport {MongooseDocument} from \"./MongooseDocument\";\n\nexport type MongooseNextCB = (err?: Error) => void;\n\nexport interface MongooseHookOptions {\n document?: boolean;\n query?: boolean;\n parallel?: boolean;\n}\n\nexport type MongoosePreHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>) => Promise<void> | void);\n\nexport type MongoosePostHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, error: Error, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>, error: Error) => Promise<void> | void)\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>) => Promise<void> | void);\n\nexport interface MongoosePreHook<T = any> {\n method: string | RegExp;\n fn: MongoosePreHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePostHook<T = any> {\n method: string | RegExp;\n fn: MongoosePostHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePluginOptions {\n plugin: (schema: Schema, options?: any) => void;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseIndexOptions {\n fields: Record<any, any>;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseSchemaOptions {\n schemaOptions?: SchemaOptions;\n plugins?: MongoosePluginOptions[];\n indexes?: MongooseIndexOptions[];\n pre?: MongoosePreHook[];\n post?: MongoosePostHook[];\n}\n"]}
1
+ {"version":3,"file":"MongooseSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseSchemaOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {Schema, SchemaOptions} from \"mongoose\";\nimport {MongooseDocument} from \"./MongooseDocument\";\n\nexport type MongooseNextCB = (err?: Error) => void;\n\nexport interface MongooseHookOptions {\n document?: boolean;\n query?: boolean;\n parallel?: boolean;\n}\n\nexport type MongooseHookPromised<T = any> = (doc: T | MongooseDocument<T>) => Promise<void> | void;\n\nexport type MongoosePreHookCB<T = any> = ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void) | MongooseHookPromised;\n\nexport type MongoosePostHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, error: Error, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>, error: Error) => Promise<void> | void)\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | MongooseHookPromised;\n\nexport interface MongoosePreHook<T = any> {\n method: string | RegExp;\n fn: MongoosePreHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePostHook<T = any> {\n method: string | RegExp;\n fn: MongoosePostHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePluginOptions {\n plugin: (schema: Schema, options?: any) => void;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseIndexOptions {\n fields: Record<any, any>;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseSchemaOptions {\n schemaOptions?: SchemaOptions;\n plugins?: MongoosePluginOptions[];\n indexes?: MongooseIndexOptions[];\n pre?: MongoosePreHook[];\n post?: MongoosePostHook[];\n}\n"]}
@@ -20,12 +20,12 @@ function mapHookArgs(hook) {
20
20
  * @ignore
21
21
  */
22
22
  export function buildPreHook(fn) {
23
- return fn.length === 2
24
- ? function (next) {
25
- return fn(this, next);
23
+ return fn.length === 1
24
+ ? function () {
25
+ return fn(this);
26
26
  }
27
- : function (next, options) {
28
- return fn(this, next, options);
27
+ : function (next) {
28
+ return fn(this, next);
29
29
  };
30
30
  }
31
31
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"schemaOptions.js","sourceRoot":"","sources":["../../../src/utils/schemaOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,KAAK,EAAC,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAC,uBAAuB,EAAC,MAAM,wBAAwB,CAAC;AAG/D;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAW,EAAE,OAA+B;IACxE,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEjC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,uBAAuB,CAAC,EAAE;QACvC,KAAK,CAAC,GAAG,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;KACxC;IAED,IAAI,OAAO,EAAE;QACX,KAAK,CAAC,GAAG,CAAC,uBAAuB,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;KAC5F;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,WAAW,CAAC,IAAwC;IAC3D,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CA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CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAE,MAAM,CAAC,IAAY,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAC5E;AACH,CAAC","sourcesContent":["import {deepMerge, Store} from \"@tsed/core\";\nimport {Schema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants/constants\";\nimport {MongooseNextCB, MongoosePostHook, MongoosePreHook, MongooseSchemaOptions} from \"../interfaces/MongooseSchemaOptions\";\n\n/**\n * @ignore\n */\nexport function schemaOptions(target: any, options?: MongooseSchemaOptions) {\n const store = Store.from(target);\n\n if (!store.has(MONGOOSE_SCHEMA_OPTIONS)) {\n store.set(MONGOOSE_SCHEMA_OPTIONS, {});\n }\n\n if (options) {\n store.set(MONGOOSE_SCHEMA_OPTIONS, deepMerge(store.get(MONGOOSE_SCHEMA_OPTIONS), options));\n }\n\n return store.get(MONGOOSE_SCHEMA_OPTIONS);\n}\n\nfunction mapHookArgs(hook: MongoosePreHook | MongoosePostHook): [string | RegExp, Function] {\n return [hook.method, hook.options || hook.fn, hook.options ? hook.fn : undefined].filter(Boolean) as any;\n}\n\n/**\n * @ignore\n */\nexport function buildPreHook(fn: Function) {\n return fn.length === 2\n ? function (next: MongooseNextCB) {\n return fn(this, next);\n }\n : function (next: MongooseNextCB, options: any) {\n return fn(this, next, options);\n };\n}\n\n/**\n * @ignore\n */\nexport function applySchemaOptions(schema: Schema, options: MongooseSchemaOptions) {\n if (options.plugins) {\n options.plugins.forEach((item) => schema.plugin(item.plugin, item.options));\n }\n\n if (options.indexes) {\n options.indexes.forEach((item) => schema.index(item.fields, item.options));\n }\n\n if (options.pre) {\n options.pre.forEach((item) => {\n item = {\n ...item,\n fn: buildPreHook(item.fn)\n };\n\n (schema.pre as any)(...mapHookArgs(item));\n });\n }\n\n if (options.post) {\n options.post.forEach((item) => (schema.post as any)(...mapHookArgs(item)));\n }\n}\n"]}
1
+ {"version":3,"file":"schemaOpt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,MAAc,EAAE,OAA8B;IAC/E,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;KAC7E;IAED,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;KAC5E;IAED,IAAI,OAAO,CAAC,GAAG,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC3B,IAAI,GAAG;gBACL,GAAG,IAAI;gBACP,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;aAC1B,CAAC;YAED,MAAM,CAAC,GAAW,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAE,MAAM,CAAC,IAAY,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAC5E;AACH,CAAC","sourcesContent":["import {deepMerge, Store} from \"@tsed/core\";\nimport {Schema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants/constants\";\nimport {\n MongooseHookPromised,\n MongooseNextCB,\n MongoosePostHook,\n MongoosePreHook,\n MongoosePreHookCB,\n MongooseSchemaOptions\n} from \"../interfaces/MongooseSchemaOptions\";\n\n/**\n * @ignore\n */\nexport function schemaOptions(target: any, options?: MongooseSchemaOptions) {\n const store = Store.from(target);\n\n if (!store.has(MONGOOSE_SCHEMA_OPTIONS)) {\n store.set(MONGOOSE_SCHEMA_OPTIONS, {});\n }\n\n if (options) {\n store.set(MONGOOSE_SCHEMA_OPTIONS, deepMerge(store.get(MONGOOSE_SCHEMA_OPTIONS), options));\n }\n\n return store.get(MONGOOSE_SCHEMA_OPTIONS);\n}\n\nfunction mapHookArgs(hook: MongoosePreHook | MongoosePostHook): [string | RegExp, Function] {\n return [hook.method, hook.options || hook.fn, hook.options ? hook.fn : undefined].filter(Boolean) as any;\n}\n\n/**\n * @ignore\n */\nexport function buildPreHook(fn: MongoosePreHookCB) {\n return fn.length === 1\n ? function () {\n return (fn as MongooseHookPromised)(this);\n }\n : function (next: MongooseNextCB) {\n return fn(this, next);\n };\n}\n\n/**\n * @ignore\n */\nexport function applySchemaOptions(schema: Schema, options: MongooseSchemaOptions) {\n if (options.plugins) {\n options.plugins.forEach((item) => schema.plugin(item.plugin, item.options));\n }\n\n if (options.indexes) {\n options.indexes.forEach((item) => schema.index(item.fields, item.options));\n }\n\n if (options.pre) {\n options.pre.forEach((item) => {\n item = {\n ...item,\n fn: buildPreHook(item.fn)\n };\n\n (schema.pre as any)(...mapHookArgs(item));\n });\n }\n\n if (options.post) {\n options.post.forEach((item) => (schema.post as any)(...mapHookArgs(item)));\n }\n}\n"]}
@@ -6,8 +6,9 @@ export interface MongooseHookOptions {
6
6
  query?: boolean;
7
7
  parallel?: boolean;
8
8
  }
9
- export declare type MongoosePreHookCB<T = any> = ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void) | ((doc: T | MongooseDocument<T>) => Promise<void> | void);
10
- export declare type MongoosePostHookCB<T = any> = ((doc: T | MongooseDocument<T>, error: Error, next: MongooseNextCB) => void) | ((doc: T | MongooseDocument<T>, error: Error) => Promise<void> | void) | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void) | ((doc: T | MongooseDocument<T>) => Promise<void> | void);
9
+ export declare type MongooseHookPromised<T = any> = (doc: T | MongooseDocument<T>) => Promise<void> | void;
10
+ export declare type MongoosePreHookCB<T = any> = ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void) | MongooseHookPromised;
11
+ export declare type MongoosePostHookCB<T = any> = ((doc: T | MongooseDocument<T>, error: Error, next: MongooseNextCB) => void) | ((doc: T | MongooseDocument<T>, error: Error) => Promise<void> | void) | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void) | MongooseHookPromised;
11
12
  export interface MongoosePreHook<T = any> {
12
13
  method: string | RegExp;
13
14
  fn: MongoosePreHookCB<T>;
@@ -1,5 +1,5 @@
1
1
  import { Schema } from "mongoose";
2
- import { MongooseNextCB, MongooseSchemaOptions } from "../interfaces/MongooseSchemaOptions";
2
+ import { MongooseNextCB, MongoosePreHookCB, MongooseSchemaOptions } from "../interfaces/MongooseSchemaOptions";
3
3
  /**
4
4
  * @ignore
5
5
  */
@@ -7,7 +7,7 @@ export declare function schemaOptions(target: any, options?: MongooseSchemaOptio
7
7
  /**
8
8
  * @ignore
9
9
  */
10
- export declare function buildPreHook(fn: Function): (next: MongooseNextCB, options: any) => any;
10
+ export declare function buildPreHook(fn: MongoosePreHookCB): (next: MongooseNextCB) => void | Promise<void>;
11
11
  /**
12
12
  * @ignore
13
13
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/mongoose",
3
- "version": "7.8.1",
3
+ "version": "7.8.3",
4
4
  "description": "Mongoose package for Ts.ED framework",
5
5
  "private": false,
6
6
  "keywords": [
@@ -32,21 +32,21 @@
32
32
  "tslib": "2.4.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@tsed/ajv": "7.8.1",
36
- "@tsed/core": "7.8.1",
37
- "@tsed/di": "7.8.1",
38
- "@tsed/json-mapper": "7.8.1",
35
+ "@tsed/ajv": "7.8.3",
36
+ "@tsed/core": "7.8.3",
37
+ "@tsed/di": "7.8.3",
38
+ "@tsed/json-mapper": "7.8.3",
39
39
  "@tsed/logger": ">=6.2.2",
40
- "@tsed/schema": "7.8.1",
40
+ "@tsed/schema": "7.8.3",
41
41
  "mongoose": "6.5.1"
42
42
  },
43
43
  "peerDependencies": {
44
- "@tsed/ajv": "^7.8.1",
45
- "@tsed/core": "^7.8.1",
46
- "@tsed/di": "^7.8.1",
47
- "@tsed/json-mapper": "^7.8.1",
44
+ "@tsed/ajv": "^7.8.3",
45
+ "@tsed/core": "^7.8.3",
46
+ "@tsed/di": "^7.8.3",
47
+ "@tsed/json-mapper": "^7.8.3",
48
48
  "@tsed/logger": ">=6.2.2",
49
- "@tsed/schema": "^7.8.1",
49
+ "@tsed/schema": "^7.8.3",
50
50
  "mongoose": ">=6.0.0"
51
51
  },
52
52
  "repository": "https://github.com/tsedio/tsed",