@venok/integration 2.1.0 → 2.2.0-next.2

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/index.d.ts CHANGED
@@ -255,6 +255,7 @@ type DiscoveryOptions = FilterByInclude | FilterByMetadataKey;
255
255
  type ExplorerSettings = Partial<{
256
256
  contextType: string;
257
257
  isRequestScopeSupported: boolean;
258
+ returnProxyValueFromRequestScope: boolean;
258
259
  requestContextArgIndex: number;
259
260
  options: ExternalContextOptions;
260
261
  exceptionsFilterClass: typeof VenokExceptionFilterContext;
@@ -342,6 +343,7 @@ declare abstract class ExplorerService<T = any> extends Reflector {
342
343
  protected readonly requestArgIndex: number;
343
344
  protected readonly options: Omit<ExternalContextOptions, "callback">;
344
345
  protected readonly metadataKey: string;
346
+ protected readonly returnProxyValueFromRequestScope: boolean;
345
347
  protected readonly exceptionsFilterClass: typeof VenokExceptionFilterContext;
346
348
  protected readonly contextCreatorClass: typeof VenokContextCreator;
347
349
  protected readonly exceptionsFilter: VenokExceptionFilterContext;
@@ -355,7 +357,8 @@ declare abstract class ExplorerService<T = any> extends Reflector {
355
357
  protected createCallback(wrapper: InstanceWrapper, methodName: string): (...args: any[]) => Promise<any>;
356
358
  protected createContextCallback(instance: object, callback: (...args: any[]) => any, methodName: string, contextId?: _venok_core.ContextId, inquirerId?: string | undefined): (...args: any[]) => Promise<any>;
357
359
  protected getContextArgForRequest(args: any[]): any;
358
- private createRequestScopeContextCallback;
360
+ protected getOriginalArgsForHandler(args: any[]): any[];
361
+ protected createRequestScopeContextCallback(wrapper: InstanceWrapper, methodName: string): (...args: any[]) => Promise<any>;
359
362
  }
360
363
 
361
364
  /**
@@ -36,6 +36,7 @@ class ExplorerService extends Reflector {
36
36
  requestArgIndex;
37
37
  options;
38
38
  metadataKey;
39
+ returnProxyValueFromRequestScope;
39
40
  exceptionsFilterClass;
40
41
  contextCreatorClass;
41
42
  exceptionsFilter;
@@ -54,7 +55,8 @@ class ExplorerService extends Reflector {
54
55
  isRequestScopeSupported = false,
55
56
  options = { guards: true, filters: true, interceptors: true, callback: undefined },
56
57
  requestContextArgIndex = 0,
57
- metadataKey = ROUTE_ARGS_METADATA
58
+ metadataKey = ROUTE_ARGS_METADATA,
59
+ returnProxyValueFromRequestScope = false
58
60
  } = this.getSettings();
59
61
  this.options = options;
60
62
  this.type = contextType;
@@ -63,6 +65,7 @@ class ExplorerService extends Reflector {
63
65
  this.contextCreatorClass = contextCreatorClass;
64
66
  this.withRequestScope = isRequestScopeSupported;
65
67
  this.exceptionsFilterClass = exceptionsFilterClass;
68
+ this.returnProxyValueFromRequestScope = returnProxyValueFromRequestScope;
66
69
  this.contextCreator = this.contextCreatorClass.fromContainer(container, this.contextCreatorClass, this.exceptionsFilterClass);
67
70
  this.exceptionsFilter = new this.exceptionsFilterClass(this.container, this.container.applicationConfig);
68
71
  this.wrappers = this.discoveryService.getProviders().filter((wrapper) => {
@@ -86,8 +89,11 @@ class ExplorerService extends Reflector {
86
89
  getContextArgForRequest(args) {
87
90
  return this.paramsFactory.exchangeKeyForValue(this.requestArgIndex, undefined, args);
88
91
  }
92
+ getOriginalArgsForHandler(args) {
93
+ return args;
94
+ }
89
95
  createRequestScopeContextCallback(wrapper, methodName) {
90
- const { instance } = wrapper;
96
+ const instance = wrapper.instance;
91
97
  const moduleKey = this.contextCreator.getContextModuleKey(instance.constructor);
92
98
  const moduleRef = this.container.getModuleByKey(moduleKey);
93
99
  const collection = moduleRef.injectables;
@@ -97,14 +103,20 @@ class ExplorerService extends Reflector {
97
103
  const contextArg = this.getContextArgForRequest(args);
98
104
  const contextId = this.container.getContextId(contextArg, isTreeDurable);
99
105
  const contextInstance = await new Injector().loadPerContext(instance, moduleRef, collection, contextId);
100
- await this.createContextCallback(contextInstance, contextInstance[methodName], methodName, contextId, wrapper.id)(...args);
106
+ const proxy = this.createContextCallback(contextInstance, contextInstance[methodName], methodName, contextId, wrapper.id);
107
+ const originalArgs = this.getOriginalArgsForHandler(args);
108
+ const result = await proxy(...originalArgs);
109
+ if (this.returnProxyValueFromRequestScope)
110
+ return result;
101
111
  } catch (err) {
102
112
  let exceptionFilter = this.exceptionFiltersCache.get(instance[methodName]);
103
113
  if (!exceptionFilter) {
104
114
  exceptionFilter = this.exceptionsFilter.create(instance, instance[methodName], moduleKey);
105
115
  this.exceptionFiltersCache.set(instance[methodName], exceptionFilter);
106
116
  }
107
- const host = new ExecutionContextHost(args);
117
+ const originalArgs = this.getOriginalArgsForHandler(args);
118
+ const host = new ExecutionContextHost(originalArgs);
119
+ host.setType(this.type);
108
120
  exceptionFilter.next(err, host);
109
121
  }
110
122
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venok/integration",
3
- "version": "2.1.0",
3
+ "version": "2.2.0-next.2",
4
4
  "description": "",
5
5
  "author": "shiz-ceo",
6
6
  "type": "module",
@@ -34,7 +34,7 @@
34
34
  "test": "bun test ./test/"
35
35
  },
36
36
  "peerDependencies": {
37
- "@venok/core": "2.0.1",
37
+ "@venok/core": "2.1.0",
38
38
  "uuid": "^13.0.0",
39
39
  "reflect-metadata": "^0.2.2",
40
40
  "rxjs": "^7.8.1"