From 3adda4984f1bab3cc5c2ae2b34263c9c5e53dc17 Mon Sep 17 00:00:00 2001 From: JerrysShan <1670303003@qq.com> Date: Wed, 1 Jun 2022 18:20:05 +0800 Subject: [PATCH 1/2] chore: open trigger extend --- src/trigger/index.ts | 14 +++++++------- src/types.ts | 10 ++++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/trigger/index.ts b/src/trigger/index.ts index 02e46aa..fd4d26a 100644 --- a/src/trigger/index.ts +++ b/src/trigger/index.ts @@ -1,11 +1,11 @@ import { ExecutionContainer, Inject } from '@artus/injection'; import { Input, Context, MiddlewareInput, Pipeline, Output } from '@artus/pipeline'; import { ArtusInjectEnum } from '../constant'; -import { Application } from '../types'; +import { Application, TriggerType } from '../types'; import { DefineTrigger } from './decorator'; @DefineTrigger() -export default class Trigger { +export default class Trigger implements TriggerType { private pipeline: Pipeline; @Inject(ArtusInjectEnum.Application) @@ -21,14 +21,14 @@ export default class Trigger { this.pipeline.use(middleware); } - async initContext(input: Input): Promise { - const ctx = new Context(input, new Output()); - ctx.container = new ExecutionContainer(ctx, this.app.getContainer()) + async initContext(input: Input, output: Output): Promise { + const ctx = new Context(input, output); + ctx.container = new ExecutionContainer(ctx, this.app.getContainer()); return ctx; } - async startPipeline(input: Input = new Input()): Promise { - const ctx = await this.initContext(input); + async startPipeline(input: Input = new Input(), output = new Output()): Promise { + const ctx = await this.initContext(input, output); await this.pipeline.run(ctx); return ctx; } diff --git a/src/types.ts b/src/types.ts index 4cdeb13..5ca1935 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,7 @@ import { Container } from '@artus/injection'; +import { BaseContext } from '@artus/pipeline'; import { HookFunction } from './lifecycle'; import { Manifest } from './loader'; -import Trigger from './trigger'; export interface ApplicationLifecycle { configWillLoad?: HookFunction; @@ -20,7 +20,7 @@ export interface Application { manifest?: Manifest; config?: Record; - get trigger(): Trigger; + get trigger(): TriggerType; load(manifest: Manifest): Promise; run(): Promise; @@ -30,4 +30,10 @@ export interface Application { getContainer(): Container; } +export interface TriggerType { + use(...args): Promise; + initContext(...args): Promise; + startPipeline(...args): Promise; +} + export * from './loader/types'; From dd4e01b36e26c9ac08d90929a5ed6cd0217bbf7a Mon Sep 17 00:00:00 2001 From: JerrysShan <1670303003@qq.com> Date: Wed, 1 Jun 2022 19:22:35 +0800 Subject: [PATCH 2/2] chore: update trigger type --- src/application.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/application.ts b/src/application.ts index 3ce379e..7df5f30 100644 --- a/src/application.ts +++ b/src/application.ts @@ -4,7 +4,7 @@ import { ArtusInjectEnum } from './constant'; import { ArtusStdError, ExceptionHandler } from './exception'; import { HookFunction, LifecycleManager } from './lifecycle'; import { LoaderFactory, Manifest } from './loader'; -import { Application, ApplicationInitOptions } from './types'; +import { Application, ApplicationInitOptions, TriggerType } from './types'; import Trigger from './trigger'; import ConfigurationHandler from './configuration'; import { ArtusLogger, Logger } from './logger'; @@ -42,7 +42,7 @@ export class ArtusApplication implements Application { return this.container.get(ArtusInjectEnum.Packages); } - get trigger(): Trigger { + get trigger(): TriggerType { return this.container.get(ArtusInjectEnum.Trigger); } @@ -117,6 +117,4 @@ export class ArtusApplication implements Application { } } -export { - Application -}; +export { Application };