Skip to content

Commit

Permalink
chore: open trigger extend (#94)
Browse files Browse the repository at this point in the history
* chore: open trigger extend

* chore: update trigger type

Co-authored-by: hyj1991 <[email protected]>
  • Loading branch information
JerrysShan and hyj1991 authored Jun 23, 2022
1 parent 5aa712d commit 5d82d3b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -117,6 +117,4 @@ export class ArtusApplication implements Application {
}
}

export {
Application
};
export { Application };
14 changes: 7 additions & 7 deletions src/trigger/index.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -21,14 +21,14 @@ export default class Trigger {
this.pipeline.use(middleware);
}

async initContext(input: Input): Promise<Context> {
const ctx = new Context(input, new Output());
ctx.container = new ExecutionContainer(ctx, this.app.getContainer())
async initContext(input: Input, output: Output): Promise<Context> {
const ctx = new Context(input, output);
ctx.container = new ExecutionContainer(ctx, this.app.getContainer());
return ctx;
}

async startPipeline(input: Input = new Input()): Promise<Context> {
const ctx = await this.initContext(input);
async startPipeline(input: Input = new Input(), output = new Output()): Promise<Context> {
const ctx = await this.initContext(input, output);
await this.pipeline.run(ctx);
return ctx;
}
Expand Down
10 changes: 8 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,7 +20,7 @@ export interface Application {
manifest?: Manifest;
config?: Record<string, any>;

get trigger(): Trigger;
get trigger(): TriggerType;

load(manifest: Manifest): Promise<this>;
run(): Promise<void>;
Expand All @@ -30,4 +30,10 @@ export interface Application {
getContainer(): Container;
}

export interface TriggerType {
use(...args): Promise<void>;
initContext(...args): Promise<BaseContext>;
startPipeline(...args): Promise<BaseContext>;
}

export * from './loader/types';

0 comments on commit 5d82d3b

Please sign in to comment.