@midwayjs/mongoose 3.0.2 → 3.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/mongoose",
3
- "version": "3.0.2",
3
+ "version": "3.0.5",
4
4
  "description": "Midway Component for mongoose",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -14,21 +14,20 @@
14
14
  "author": "czy88840616@gmail.com",
15
15
  "files": [
16
16
  "dist/**/*.js",
17
- "dist/**/*.d.ts",
18
- "dist/**/*.js.map"
17
+ "dist/**/*.d.ts"
19
18
  ],
20
19
  "engines": {
21
20
  "node": ">=12"
22
21
  },
23
22
  "license": "MIT",
24
23
  "devDependencies": {
25
- "@midwayjs/core": "^3.0.2",
26
- "@midwayjs/decorator": "^3.0.2",
27
- "@midwayjs/mock": "^3.0.2",
28
- "mongoose": "6.1.7"
24
+ "@midwayjs/core": "^3.0.4",
25
+ "@midwayjs/decorator": "^3.0.4",
26
+ "@midwayjs/mock": "^3.0.5",
27
+ "mongoose": "6.2.1"
29
28
  },
30
29
  "peerDependencies": {
31
30
  "mongoose": "*"
32
31
  },
33
- "gitHead": "ca77247d229978a736e79bb208579c014ed226fc"
32
+ "gitHead": "9b17898f10faeef2e7f1011eaea67f1d0b085261"
34
33
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mDAAoD;AAEpD,uCAA6D;AAY7D,IAAa,qBAAqB,GAAlC,MAAa,qBAAqB;IAChC,KAAK,CAAC,OAAO,CAAC,SAA2B;QACvC,MAAM,SAAS,CAAC,QAAQ,CAAC,0CAAgC,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,SAA2B;QACtC,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,0CAAgC,CAAC,CAAC;QAC3E,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC;CACF,CAAA;AATY,qBAAqB;IAVjC,IAAA,yBAAa,EAAC;QACb,SAAS,EAAE,UAAU;QACrB,aAAa,EAAE;YACb;gBACE,OAAO,EAAE;oBACP,QAAQ,EAAE,EAAE;iBACb;aACF;SACF;KACF,CAAC;GACW,qBAAqB,CASjC;AATY,sDAAqB","sourcesContent":["import { Configuration } from '@midwayjs/decorator';\nimport { ILifeCycle, IMidwayContainer } from '@midwayjs/core';\nimport { MongooseConnectionServiceFactory } from './manager';\n\n@Configuration({\n namespace: 'mongoose',\n importConfigs: [\n {\n default: {\n mongoose: {},\n },\n },\n ],\n})\nexport class MongooseConfiguration implements ILifeCycle {\n async onReady(container: IMidwayContainer) {\n await container.getAsync(MongooseConnectionServiceFactory);\n }\n\n async onStop(container: IMidwayContainer) {\n const factory = await container.getAsync(MongooseConnectionServiceFactory);\n await factory.stop();\n }\n}\n"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAAyE;AAAhE,8GAAA,qBAAqB,OAAiB;AAC/C,8CAA4B;AAC5B,4CAA0B","sourcesContent":["export { MongooseConfiguration as Configuration } from './configuration';\nexport * from './interface';\nexport * from './manager';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"","sourcesContent":["import * as mongoose from 'mongoose';\n\ninterface M5 {\n ConnectionOptions: unknown;\n}\ninterface M6 {\n ConnectOptions: unknown;\n}\ninterface Plus {\n Connection: any;\n}\n\n// 不同的 mongoose 版本 options 字段定义不同\ndeclare type ExtractConnectionOptionsFromConnection<T extends (...args: any[]) => any> = Parameters<T>[1];\n\ndeclare type ExtractConnectionOptions<T> =\n T extends M5 ? T['ConnectionOptions'] :\n T extends M6 ? T['ConnectOptions'] :\n T extends Plus ? ExtractConnectionOptionsFromConnection<T['Connection']['prototype']['openUri']> :\n never;\ntype ConnectionOptions = ExtractConnectionOptions<typeof mongoose>;\n\ndeclare module '@midwayjs/core/dist/interface' {\n interface MidwayConfig {\n mongoose?: ServiceFactoryConfigOption<{\n uri: string;\n options: ConnectionOptions;\n }>;\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"manager.js","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAIwB;AACxB,mDAQ6B;AAC7B,qCAAqC;AAIrC,IAAa,gCAAgC,GAA7C,MAAa,gCAAiC,SAAQ,qBAAmC;IAQvF,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,MAAW,EAAE,IAAY;QACpD,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,gBAAgB,CAChD,MAAM,CAAC,GAAG,EACV,MAAM,CAAC,OAAO,CACf,CAAC;QACF,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE;YAC3B,GAAG,CAAC,OAAO,GAAG,aAAa,GAAG,CAAC,OAAO,EAAE,CAAC;YACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;QAEH,0BAA0B;QAC1B,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE;YACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,IAAI,eAAe,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE;YAC9B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,IAAI,yBAAyB,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;QAEH,0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,aAAa;IACb,OAAO;IACP,OAAO;CACR,CAAC,CAAC;AAEH,IAAA,+BAAwB,EAAC,yBAAyB,EAAE;IAClD,QAAQ;IACR,aAAa;IACb,QAAQ;IACR,IAAI;IACJ,MAAM;IACN,IAAI;IACJ,QAAQ;IACR,MAAM;IACN,MAAM;IACN,SAAS;IACT,MAAM;IACN,YAAY;IACZ,MAAM;CACP,CAAC,CAAC","sourcesContent":["import {\n delegateTargetMethod,\n delegateTargetProperties,\n ServiceFactory,\n} from '@midwayjs/core';\nimport {\n Config,\n Init,\n Inject,\n Logger,\n Provide,\n Scope,\n ScopeEnum,\n} from '@midwayjs/decorator';\nimport * as mongoose from 'mongoose';\n\n@Provide()\n@Scope(ScopeEnum.Singleton)\nexport class MongooseConnectionServiceFactory extends ServiceFactory<mongoose.Connection> {\n @Config('mongoose')\n config;\n\n @Logger('coreLogger')\n logger;\n\n @Init()\n async init() {\n await this.initClients(this.config);\n }\n\n protected async createClient(config: any, name: string) {\n const connection = await mongoose.createConnection(\n config.uri,\n config.options\n );\n connection.on('error', err => {\n err.message = `[mongoose]${err.message}`;\n this.logger.error(err);\n });\n\n /* istanbul ignore next */\n connection.on('disconnected', () => {\n this.logger.info(`[mongoose] ${name} disconnected`);\n });\n\n connection.on('connected', () => {\n this.logger.info(`[mongoose] ${name} connected successfully`);\n });\n\n /* istanbul ignore next */\n connection.on('reconnected', () => {\n this.logger.info(`[mongoose] ${name} reconnected successfully`);\n });\n\n return connection;\n }\n\n getName() {\n return 'mongoose';\n }\n\n async destroyClient(connection: mongoose.Connection) {\n await connection.close();\n }\n}\n\n@Provide()\n@Scope(ScopeEnum.Singleton)\nexport class MongooseConnectionService implements mongoose.Connection {\n @Inject()\n private serviceFactory: MongooseConnectionServiceFactory;\n\n // @ts-expect-error used\n private instance: mongoose.Connection;\n\n @Init()\n async init() {\n this.instance = this.serviceFactory.get('default');\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface MongooseConnectionService extends mongoose.Connection {\n // empty\n}\n\ndelegateTargetMethod(MongooseConnectionService, [\n 'close',\n 'collection',\n 'createCollection',\n 'deleteModel',\n 'dropCollection',\n 'dropDatabase',\n 'get',\n 'getClient',\n 'model',\n 'modelNames',\n 'openUri',\n 'plugin',\n 'set',\n 'setClient',\n 'startSession',\n 'transaction',\n 'useDb',\n 'watch',\n]);\n\ndelegateTargetProperties(MongooseConnectionService, [\n 'client',\n 'collections',\n 'config',\n 'db',\n 'host',\n 'id',\n 'models',\n 'name',\n 'pass',\n 'plugins',\n 'port',\n 'readyState',\n 'user',\n]);\n"]}