diff --git a/packages/di/src/decorators/inject.ts b/packages/di/src/decorators/inject.ts index 57234767f7a..a52cdb4b803 100644 --- a/packages/di/src/decorators/inject.ts +++ b/packages/di/src/decorators/inject.ts @@ -1,6 +1,7 @@ import {decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType} from "@tsed/core"; import {DI_PARAM_OPTIONS, INJECTABLE_PROP} from "../constants/constants"; import type {InjectablePropertyOptions} from "../interfaces/InjectableProperties"; +import {getContext} from "../utils/runInContext"; export function injectProperty(target: any, propertyKey: string, options: Partial) { Store.from(target).merge(INJECTABLE_PROP, { @@ -84,3 +85,27 @@ export function Inject(symbol?: any, onGet = (bean: any) => bean): Function { } }; } + +/** + * Inject a context like PlatformContext or any BaseContext. + * + * ```typescript + * @Injectable() + * export class MyService { + * @InjectContext() + * ctx?: Context; + * } + * ``` + * + * @returns {Function} + * @decorator + */ +export function InjectContext(): PropertyDecorator { + return (target: any, propertyKey: string): any | void => { + injectProperty(target, propertyKey, { + resolver() { + return () => getContext(); + } + }); + }; +} diff --git a/packages/di/src/index.ts b/packages/di/src/index.ts index c73a00cdd77..4768b5e0e66 100644 --- a/packages/di/src/index.ts +++ b/packages/di/src/index.ts @@ -47,6 +47,7 @@ export * from "./services/DIConfiguration"; export * from "./services/DILogger"; export * from "./services/DITest"; export * from "./services/InjectorService"; +export * from "./utils/runInContext"; export * from "./utils/colors"; export * from "./utils/createContainer"; export * from "./utils/getConfiguration"; diff --git a/packages/di/src/services/DITest.ts b/packages/di/src/services/DITest.ts index 9bb7e60e32f..2bda4cc6967 100644 --- a/packages/di/src/services/DITest.ts +++ b/packages/di/src/services/DITest.ts @@ -6,6 +6,7 @@ import {OnInit} from "../interfaces/OnInit"; import {TokenProvider} from "../interfaces/TokenProvider"; import {setLoggerLevel} from "../utils/setLoggerLevel"; import {InjectorService} from "./InjectorService"; +import {DIContext} from "../domain/DIContext"; export interface DITestInvokeOptions { token?: TokenProvider; @@ -124,6 +125,14 @@ export class DITest { return DITest.injector.get(target, options)!; } + static createDIContext() { + return new DIContext({ + id: "id", + injector: DITest.injector, + logger: DITest.injector.logger + }); + } + protected static configure(settings: Partial = {}): Partial { return { ...settings, diff --git a/packages/di/src/services/InjectorService.spec.ts b/packages/di/src/services/InjectorService.spec.ts index 12f2d08fb1e..8179efad88f 100644 --- a/packages/di/src/services/InjectorService.spec.ts +++ b/packages/di/src/services/InjectorService.spec.ts @@ -49,12 +49,6 @@ describe("InjectorService", () => { expect(new InjectorService().has(Test)).to.be.false; }); }); - describe("runInContext()", () => { - it("should return true", () => { - const injector = new InjectorService(); - injector.runInContext({} as any, () => {}); - }); - }); describe("get()", () => { it("should return element", () => { diff --git a/packages/di/src/services/InjectorService.ts b/packages/di/src/services/InjectorService.ts index ddc828ae833..be8373999a0 100644 --- a/packages/di/src/services/InjectorService.ts +++ b/packages/di/src/services/InjectorService.ts @@ -27,13 +27,11 @@ import {ResolvedInvokeOptions} from "../interfaces/ResolvedInvokeOptions"; import {ProviderScope} from "../domain/ProviderScope"; import {DILogger} from "../interfaces/DILogger"; import {TokenProvider} from "../interfaces/TokenProvider"; -import {ProviderOpts} from "../interfaces/ProviderOpts"; import {InvokeOptions} from "../interfaces/InvokeOptions"; import {InjectableProperties, InjectablePropertyOptions, InjectablePropertyValue} from "../interfaces/InjectableProperties"; import {InjectablePropertyType} from "../domain/InjectablePropertyType"; import {InterceptorContext} from "../interfaces/InterceptorContext"; import {InterceptorMethods} from "../interfaces/InterceptorMethods"; -import {DIContext} from "../domain/DIContext"; /** * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`. @@ -501,16 +499,6 @@ export class InjectorService extends Container { }; } - /** - * Allow handler hack for AsyncHookContext plugin. - * @param ctx - * @param cb - * @protected - */ - runInContext(ctx: DIContext, cb: any) { - return cb(); - } - async lazyInvoke(token: TokenProvider) { let instance = this.getInstance(token); diff --git a/packages/di/src/utils/runInContext.ts b/packages/di/src/utils/runInContext.ts new file mode 100644 index 00000000000..8e08cdd00a6 --- /dev/null +++ b/packages/di/src/utils/runInContext.ts @@ -0,0 +1,17 @@ +import {AsyncLocalStorage} from "async_hooks"; +import {DIContext} from "../domain/DIContext"; + +let store: AsyncLocalStorage; + +export function getAsyncStore() { + store = store || new AsyncLocalStorage(); + return store; +} + +export function getContext() { + return store?.getStore(); +} + +export function runInContext(ctx: DIContext, cb: any) { + return getAsyncStore().run(ctx, cb); +} diff --git a/packages/di/test/integration/inject-context.spec.ts b/packages/di/test/integration/inject-context.spec.ts new file mode 100644 index 00000000000..905b32676b7 --- /dev/null +++ b/packages/di/test/integration/inject-context.spec.ts @@ -0,0 +1,26 @@ +import {DIContext, DITest, Injectable, InjectContext, runInContext} from "@tsed/di"; +import {expect} from "chai"; + +@Injectable() +class MyService { + @InjectContext() + $ctx: DIContext; + + get() { + return this.$ctx.id; + } +} + +describe("InjectContext", () => { + beforeEach(() => DITest.create()); + afterEach(() => DITest.reset()); + + it("should inject context", () => { + const ctx = DITest.createDIContext(); + const service = DITest.get(MyService); + + const result = runInContext(ctx, () => service.get()); + + expect(result).to.equal("id"); + }); +}); diff --git a/packages/platform/common/src/services/PlatformHandler.ts b/packages/platform/common/src/services/PlatformHandler.ts index f44907d6025..a9ed7dfe2ee 100644 --- a/packages/platform/common/src/services/PlatformHandler.ts +++ b/packages/platform/common/src/services/PlatformHandler.ts @@ -1,5 +1,5 @@ import {AnyToPromiseStatus, isFunction, isStream} from "@tsed/core"; -import {Inject, Injectable, InjectorService, Provider, ProviderScope} from "@tsed/di"; +import {Inject, Injectable, InjectorService, Provider, ProviderScope, runInContext} from "@tsed/di"; import {$log} from "@tsed/logger"; import {ArgScope, HandlerWithScope, PlatformParams} from "@tsed/platform-params"; import {PlatformResponseFilter} from "@tsed/platform-response-filter"; @@ -135,7 +135,7 @@ export class PlatformHandler { const resolver = new AnyToPromiseWithCtx({$ctx, err}); - return this.injector.runInContext($ctx, async () => { + return runInContext($ctx, async () => { try { const {state, data, status, headers} = await resolver.call(handler); diff --git a/packages/platform/common/src/services/PlatformTest.ts b/packages/platform/common/src/services/PlatformTest.ts index f0fdf307a39..184c8b1faca 100644 --- a/packages/platform/common/src/services/PlatformTest.ts +++ b/packages/platform/common/src/services/PlatformTest.ts @@ -7,7 +7,6 @@ import {PlatformApplication} from "./PlatformApplication"; import {getConfiguration} from "../utils/getConfiguration"; import {PlatformAdapter, PlatformBuilderSettings} from "./PlatformAdapter"; import accepts from "accepts"; -import {FakeAdapter} from "./FakeAdapter"; /** * @platform diff --git a/packages/platform/platform-serverless/src/builder/PlatformServerlessHandler.ts b/packages/platform/platform-serverless/src/builder/PlatformServerlessHandler.ts index 0fe7518adf9..b280a1144c2 100644 --- a/packages/platform/platform-serverless/src/builder/PlatformServerlessHandler.ts +++ b/packages/platform/platform-serverless/src/builder/PlatformServerlessHandler.ts @@ -1,5 +1,5 @@ import {AnyPromiseResult, AnyToPromise, isSerializable} from "@tsed/core"; -import {BaseContext, Inject, Injectable, InjectorService, LazyInject, ProviderScope, TokenProvider} from "@tsed/di"; +import {BaseContext, Inject, Injectable, InjectorService, LazyInject, ProviderScope, runInContext, TokenProvider} from "@tsed/di"; import {serialize} from "@tsed/json-mapper"; import {DeserializerPipe, PlatformParams, ValidationPipe} from "@tsed/platform-params"; import type {PlatformExceptions} from "@tsed/platform-exceptions"; @@ -29,7 +29,7 @@ export class PlatformServerlessHandler { return async ($ctx: ServerlessContext) => { await this.injector.emit("$onRequest", $ctx); - await this.injector.runInContext($ctx, async () => { + await runInContext($ctx as any, async () => { try { const resolver = new AnyToPromise(); const handler = await promisedHandler; diff --git a/packages/third-parties/async-hook-context/.mocharc.js b/packages/third-parties/async-hook-context/.mocharc.js deleted file mode 100644 index 93a7052f64a..00000000000 --- a/packages/third-parties/async-hook-context/.mocharc.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - ...require("@tsed/mocha-config")(), - spec: ["{src,test}/**/*.spec.ts"], - exclude: [] -}; diff --git a/packages/third-parties/async-hook-context/.npmignore b/packages/third-parties/async-hook-context/.npmignore deleted file mode 100644 index 7f50c0fb80c..00000000000 --- a/packages/third-parties/async-hook-context/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -src -test -tsconfig.compile.json -tsconfig.json diff --git a/packages/third-parties/async-hook-context/.nycrc b/packages/third-parties/async-hook-context/.nycrc deleted file mode 100644 index 60081c0a654..00000000000 --- a/packages/third-parties/async-hook-context/.nycrc +++ /dev/null @@ -1,26 +0,0 @@ -{ - "include": [ - "src/**/*.ts" - ], - "exclude": [ - "**/*.d.ts", - "node_modules", - "**/interfaces/**", - "**/index.ts" - ], - "extension": [ - ".ts" - ], - "require": [], - "reporter": [ - "text-summary", - "html", - "lcov", - "json" - ], - "check-coverage": true, - "statements": 95.65, - "branches": 72.22, - "functions": 100, - "lines": 95 -} diff --git a/packages/third-parties/async-hook-context/package.json b/packages/third-parties/async-hook-context/package.json deleted file mode 100644 index 3a50a481cc3..00000000000 --- a/packages/third-parties/async-hook-context/package.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "@tsed/async-hook-context", - "version": "7.0.0-beta.7", - "description": "Add Async Hook context support in Ts.ED", - "private": false, - "source": "./src/index.ts", - "main": "./lib/cjs/index.js", - "module": "./lib/esm/index.js", - "typings": "./lib/types/index.d.ts", - "exports": { - "types": "./lib/types/index.d.ts", - "import": "./lib/esm/index.js", - "require": "./lib/cjs/index.js", - "default": "./lib/esm/index.js" - }, - "scripts": { - "build": "yarn run build:esm && yarn run build:cjs", - "build:cjs": "tsc --build tsconfig.compile.json", - "build:esm": "tsc --build tsconfig.compile.esm.json", - "test": "cross-env NODE_ENV=test nyc mocha" - }, - "keywords": [ - "AsyncHooks", - "Express", - "Koa", - "TypeScript", - "typescript", - "Decorator", - "decorators", - "decorator", - "express", - "koa", - "Controller", - "Inject", - "ioc", - "di" - ], - "dependencies": { - "tslib": "2.3.1" - }, - "devDependencies": { - "@tsed/core": "7.0.0-beta.7", - "@tsed/di": "7.0.0-beta.7" - }, - "peerDependencies": {} -} \ No newline at end of file diff --git a/packages/third-parties/async-hook-context/readme.md b/packages/third-parties/async-hook-context/readme.md deleted file mode 100644 index 450b9409a6f..00000000000 --- a/packages/third-parties/async-hook-context/readme.md +++ /dev/null @@ -1,137 +0,0 @@ -

- Ts.ED logo -

- -
-

@tsed/async-hook-context

- -[![Build & Release](https://github.com/tsedio/tsed/workflows/Build%20&%20Release/badge.svg)](https://github.com/tsedio/tsed/actions?query=workflow%3A%22Build+%26+Release%22) -[![PR Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/tsedio/tsed/blob/master/CONTRIBUTING.md) -[![Coverage Status](https://coveralls.io/repos/github/tsedio/tsed/badge.svg?branch=production)](https://coveralls.io/github/tsedio/tsed?branch=production) -[![npm version](https://badge.fury.io/js/%40tsed%2Fcommon.svg)](https://badge.fury.io/js/%40tsed%2Fcommon) -[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) -[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) -[![backers](https://opencollective.com/tsed/tiers/badge.svg)](https://opencollective.com/tsed) - -
- -
- Website -   •   - Getting started -   •   - Slack -   •   - Twitter -
- -
- -Add [Async Hook context](https://nodejs.org/api/async_hooks.html#async_hooks_class_asynclocalstorage) support in Ts.ED. - -## Usage - -Ts.ED provide an injectable [RequestContext] to get all request and response information during a request. -But, you have to inject the context from your controller and forward context instance manually to the service. - -```typescript -@Injectable() -export class CustomRepository { - async findById(id: string, ctx: PlatformContext) { - ctx.logger.info("Where are in the repository"); - return { - id, - headers: this.$ctx?.request.headers - }; - } -} - -@Controller("/async-hooks") -export class AsyncHookCtrl { - @Inject() - repository: CustomRepository; - - @Get("/:id") - async get(@PathParams("id") id: string, @Context() ctx: PlatformContext) { - return this.repository.findById(id, ctx); - } -} -``` - -With this package, you can inject directly the PlatformContext in the service without injecting it in the controller: - -```typescript -@Injectable() -export class CustomRepository { - @InjectContext() - $ctx?: PlatformContext; - - async findById(id: string) { - this.ctx?.logger.info("Where are in the repository"); - - return { - id, - headers: this.$ctx?.request.headers - }; - } -} - -@Controller("/async-hooks") -export class AsyncHookCtrl { - @Inject() - repository: CustomRepository; - - @Get("/:id") - async get(@PathParams("id") id: string) { - return this.repository.findById(id); - } -} -``` - -## Installation - -Async Hook context required Node.js at least v13.10.0. ` - -Install the `@tsed/async-hook-context`: - -```bash -npm install --save @tsed/async-hook-context -``` - -Then import `@tsed/async-hook-context` in your Server: - -```typescript -import {Configuration} from "@tsed/common"; -import "@tsed/async-hook-context"; - -@Configuration({}) -export class Server {} -``` - -## Contributors - -Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html) - - - -## Backers - -Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)] - - - -## Sponsors - -Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)] - -## License - -The MIT License (MIT) - -Copyright (c) 2016 - 2021 Romain Lenzotti - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/third-parties/async-hook-context/src/decorators/injectContext.ts b/packages/third-parties/async-hook-context/src/decorators/injectContext.ts deleted file mode 100644 index ad11d5c4159..00000000000 --- a/packages/third-parties/async-hook-context/src/decorators/injectContext.ts +++ /dev/null @@ -1,26 +0,0 @@ -import {injectProperty} from "@tsed/di"; -import {isPromise} from "@tsed/core"; -import {PlatformAsyncHookContext} from "../services/PlatformAsyncHookContext"; - -export function InjectContext(): PropertyDecorator { - return (target: any, propertyKey: string): any | void => { - let bean: any; - - injectProperty(target, propertyKey, { - resolver(injector, locals, invokeOptions) { - if (!bean) { - bean = injector.invoke(PlatformAsyncHookContext, locals, invokeOptions); - } - - // istanbul ignore next - if (isPromise(bean)) { - bean.then((result: any) => { - bean = result; - }); - } - - return () => (bean as PlatformAsyncHookContext).getContext(); - } - }); - }; -} diff --git a/packages/third-parties/async-hook-context/src/index.ts b/packages/third-parties/async-hook-context/src/index.ts deleted file mode 100644 index 592372e720e..00000000000 --- a/packages/third-parties/async-hook-context/src/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./decorators/injectContext"; -export * from "./services/PlatformAsyncHookContext"; diff --git a/packages/third-parties/async-hook-context/src/services/PlatformAsyncHookContext.ts b/packages/third-parties/async-hook-context/src/services/PlatformAsyncHookContext.ts deleted file mode 100644 index fd98460f407..00000000000 --- a/packages/third-parties/async-hook-context/src/services/PlatformAsyncHookContext.ts +++ /dev/null @@ -1,44 +0,0 @@ -import {Inject, Injectable, InjectorService, BaseContext} from "@tsed/di"; -import {Logger} from "@tsed/logger"; -import {AsyncLocalStorage} from "async_hooks"; - -let store: AsyncLocalStorage; - -@Injectable() -export class PlatformAsyncHookContext { - @Inject() - protected logger: Logger; - - @Inject() - protected injector: InjectorService; - - static getStore() { - store = store || new AsyncLocalStorage(); - return store; - } - - static run(ctx: BaseContext, cb: any) { - return PlatformAsyncHookContext.getStore().run(ctx, cb); - } - - getContext() { - return store?.getStore(); - } - - run = (ctx: BaseContext, cb: any) => { - return PlatformAsyncHookContext.run(ctx, cb); - }; - - $onInit() { - /* istanbul ignore */ - if (AsyncLocalStorage) { - PlatformAsyncHookContext.getStore(); - // override - this.injector.runInContext = this.run; - } else { - this.logger.warn( - `AsyncLocalStorage is not available for your Node.js version (${process.versions.node}). Please upgrade your version at least to v13.10.0.` - ); - } - } -} diff --git a/packages/third-parties/async-hook-context/test/app/Server.ts b/packages/third-parties/async-hook-context/test/app/Server.ts deleted file mode 100644 index 216d6363a8f..00000000000 --- a/packages/third-parties/async-hook-context/test/app/Server.ts +++ /dev/null @@ -1,47 +0,0 @@ -import "@tsed/ajv"; -import {PlatformApplication} from "@tsed/common"; -import {Configuration, Inject} from "@tsed/di"; -import bodyParser from "body-parser"; -import compress from "compression"; -import cookieParser from "cookie-parser"; -import {Application} from "express"; -import session from "express-session"; -import methodOverride from "method-override"; -import "../../src"; - -export const rootDir = __dirname; - -@Configuration({ - port: 8081, - disableComponentScan: true, - logger: { - // level: "" - } -}) -export class Server { - @Inject() - app: PlatformApplication; - - $beforeRoutesInit() { - this.app - .use(cookieParser()) - .use(compress({})) - .use(methodOverride()) - .use(bodyParser.json()) - .use( - bodyParser.urlencoded({ - extended: true - }) - ) - .use( - session({ - secret: "keyboard cat", // change secret key - resave: false, - saveUninitialized: true, - cookie: { - secure: false // set true if HTTPS is enabled - } - }) - ); - } -} diff --git a/packages/third-parties/async-hook-context/test/async-hook-context.integration.spec.ts b/packages/third-parties/async-hook-context/test/async-hook-context.integration.spec.ts deleted file mode 100644 index 5f3f4cfd482..00000000000 --- a/packages/third-parties/async-hook-context/test/async-hook-context.integration.spec.ts +++ /dev/null @@ -1,70 +0,0 @@ -import {Controller, Get, Inject, Injectable, PathParams, PlatformContext, PlatformTest} from "@tsed/common"; -import {PlatformExpress} from "@tsed/platform-express"; -import {PlatformTestUtils} from "@tsed/platform-test-utils"; -import {expect} from "chai"; -import faker from "@faker-js/faker"; -import SuperTest from "supertest"; -import {InjectContext} from "../src"; -import {rootDir, Server} from "./app/Server"; - -@Injectable() -export class CustomRepository { - @InjectContext() - $ctx?: PlatformContext; - - async findById(id: string) { - return { - id, - agentId: this.$ctx?.request.get("x-agent-id") - }; - } -} - -@Controller("/async-hooks") -export class AsyncHookCtrl { - @Inject() - repository: CustomRepository; - - @Get("/:id") - async get(@PathParams("id") id: string) { - return this.repository.findById(id); - } -} - -const utils = PlatformTestUtils.create({ - rootDir, - platform: PlatformExpress, - server: Server -}); - -describe("AsyncHookContext", () => { - let request: SuperTest.SuperTest; - - before( - utils.bootstrap({ - mount: { - "/rest": [AsyncHookCtrl] - } - }) - ); - after(utils.reset); - - before(() => { - request = SuperTest(PlatformTest.callback()); - }); - - describe("GET /rest/async-hooks/1", () => { - it("should the agentId from context request headers", async () => { - const agentId = faker.datatype.uuid(); - const id = faker.datatype.uuid(); - const {body} = await request.get(`/rest/async-hooks/${id}`).set("x-agent-id", agentId).expect(200); - - if (require("async_hooks").AsyncLocalStorage) { - expect(body).to.deep.eq({ - id, - agentId - }); - } - }); - }); -}); diff --git a/packages/third-parties/async-hook-context/tsconfig.compile.esm.json b/packages/third-parties/async-hook-context/tsconfig.compile.esm.json deleted file mode 100644 index 06456ae6499..00000000000 --- a/packages/third-parties/async-hook-context/tsconfig.compile.esm.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "./tsconfig.compile.json", - "compilerOptions": { - "baseUrl": ".", - "module": "ES2020", - "rootDir": "src", - "outDir": "./lib/esm", - "declaration": true, - "declarationDir": "./lib/types" - }, - "exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"] -} diff --git a/packages/third-parties/async-hook-context/tsconfig.compile.json b/packages/third-parties/async-hook-context/tsconfig.compile.json deleted file mode 100644 index 97476d245bb..00000000000 --- a/packages/third-parties/async-hook-context/tsconfig.compile.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../../tsconfig.compile.json", - "compilerOptions": { - "rootDir": "src", - "outDir": "lib/cjs", - "declaration": false - }, - "exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"] -} diff --git a/packages/third-parties/formio/src/components/AlterActions.ts b/packages/third-parties/formio/src/components/AlterActions.ts index 2a29e56ac3d..993d2e4ff97 100644 --- a/packages/third-parties/formio/src/components/AlterActions.ts +++ b/packages/third-parties/formio/src/components/AlterActions.ts @@ -1,4 +1,4 @@ -import {Inject, InjectorService, Provider} from "@tsed/di"; +import {Inject, InjectorService, Provider, runInContext} from "@tsed/di"; import {EndpointMetadata} from "@tsed/schema"; import {FormioActionInfo} from "@tsed/formio-types"; import {PlatformParams} from "@tsed/platform-params"; @@ -83,7 +83,7 @@ export class AlterActions implements AlterHook { $ctx.set("ACTION_CTX", {handler, method, setActionItemMessage, action}); $ctx.endpoint = EndpointMetadata.get(provider.useClass, "resolve"); - await this.injector.runInContext($ctx, async () => { + await runInContext($ctx, async () => { try { const resolver = new AnyToPromise(); const handler = await promisedHandler;