@midwayjs/faas 3.7.1 → 3.7.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/dist/framework.js CHANGED
@@ -92,10 +92,32 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
92
92
  getEventMiddleware: () => {
93
93
  return this.getEventMiddleware();
94
94
  },
95
- getServerlessInstance: (serviceClass) => {
96
- return this.app
97
- .createAnonymousContext()
98
- .requestContext.getAsync(serviceClass);
95
+ getServerlessInstance: async (serviceClass, customContext = {}) => {
96
+ const instance = new Proxy({}, {
97
+ get: (target, prop) => {
98
+ let funcInfo;
99
+ if (typeof serviceClass === 'string') {
100
+ funcInfo = this.funMappingStore.get(`${serviceClass}.${prop}`);
101
+ }
102
+ else {
103
+ funcInfo = Array.from(this.funMappingStore.values()).find(item => {
104
+ return (item.id === (0, core_1.getProviderUUId)(serviceClass) &&
105
+ item.method === prop);
106
+ });
107
+ }
108
+ if (funcInfo) {
109
+ return async (...args) => {
110
+ const context = this.app.createAnonymousContext();
111
+ return this.getTriggerFunction(context, funcInfo.funcHandlerName, {
112
+ isHttpFunction: false,
113
+ originContext: customContext,
114
+ originEvent: args[0],
115
+ });
116
+ };
117
+ }
118
+ },
119
+ });
120
+ return instance;
99
121
  },
100
122
  getTriggerFunction: (context, handlerMapping, options) => {
101
123
  return this.getTriggerFunction(context, handlerMapping, options);
@@ -1,4 +1,4 @@
1
- import { MidwayRequestContainer, IMidwayApplication, IConfigurationOptions, IMidwayContext, NextFunction as BaseNextFunction, CommonMiddlewareUnion, ContextMiddlewareManager, IMidwayBootstrapOptions } from '@midwayjs/core';
1
+ import { MidwayRequestContainer, IMidwayApplication, IConfigurationOptions, IMidwayContext, NextFunction as BaseNextFunction, CommonMiddlewareUnion, ContextMiddlewareManager, IMidwayBootstrapOptions, ObjectIdentifier } from '@midwayjs/core';
2
2
  import { FaaSHTTPContext } from '@midwayjs/faas-typings';
3
3
  import { ILogger } from '@midwayjs/logger';
4
4
  import { Application as ServerlessHttpApplication } from '@midwayjs/serverless-http-parser';
@@ -36,7 +36,9 @@ export declare type IMidwayFaaSApplication = IMidwayApplication<Context, {
36
36
  useEventMiddleware(middleware: CommonMiddlewareUnion<Context, NextFunction, undefined>): void;
37
37
  getEventMiddleware(): ContextMiddlewareManager<Context, NextFunction, undefined>;
38
38
  getTriggerFunction(context: any, handler: string, options: HandlerOptions): Promise<any>;
39
- getServerlessInstance<T>(serviceClass: T): Promise<T>;
39
+ getServerlessInstance<T>(serviceClass: ObjectIdentifier | {
40
+ new (...args: any[]): T;
41
+ }, customContext?: any): Promise<T>;
40
42
  }> & ServerlessHttpApplication;
41
43
  export interface Application extends IMidwayFaaSApplication {
42
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/faas",
3
- "version": "3.7.1",
3
+ "version": "3.7.3",
4
4
  "main": "dist/index",
5
5
  "typings": "index.d.ts",
6
6
  "dependencies": {
@@ -11,7 +11,7 @@
11
11
  "@midwayjs/simple-lock": "^1.1.4"
12
12
  },
13
13
  "devDependencies": {
14
- "@midwayjs/mock": "^3.7.1",
14
+ "@midwayjs/mock": "^3.7.3",
15
15
  "@midwayjs/serverless-fc-starter": "^3.7.0",
16
16
  "@midwayjs/serverless-scf-starter": "^3.7.0",
17
17
  "mm": "3.2.0"
@@ -45,5 +45,5 @@
45
45
  "url": "git@github.com:midwayjs/midway.git"
46
46
  },
47
47
  "license": "MIT",
48
- "gitHead": "d41be2f6082d035ea4fb109e32b0e240c2435f9a"
48
+ "gitHead": "8e6c830bca52818e0086873b542423d16e609aef"
49
49
  }