-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): update template for
src/sequence.ts
- Loading branch information
1 parent
35fcbe3
commit 0dadb63
Showing
2 changed files
with
3 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,3 @@ | ||
import {inject} from '@loopback/context'; | ||
import { | ||
FindRoute, | ||
InvokeMethod, | ||
InvokeMiddleware, | ||
ParseParams, | ||
Reject, | ||
RequestContext, | ||
RestBindings, | ||
Send, | ||
SequenceHandler, | ||
} from '@loopback/rest'; | ||
import {MiddlewareSequence} from '@loopback/rest'; | ||
|
||
const SequenceActions = RestBindings.SequenceActions; | ||
|
||
export class MySequence implements SequenceHandler { | ||
/** | ||
* Optional invoker for registered middleware in a chain. | ||
* To be injected via SequenceActions.INVOKE_MIDDLEWARE. | ||
*/ | ||
@inject(SequenceActions.INVOKE_MIDDLEWARE, {optional: true}) | ||
protected invokeMiddleware: InvokeMiddleware = () => false; | ||
|
||
constructor( | ||
@inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute, | ||
@inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams, | ||
@inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod, | ||
@inject(SequenceActions.SEND) public send: Send, | ||
@inject(SequenceActions.REJECT) public reject: Reject, | ||
) {} | ||
|
||
async handle(context: RequestContext) { | ||
try { | ||
const {request, response} = context; | ||
const finished = await this.invokeMiddleware(context); | ||
if (finished) return; | ||
const route = this.findRoute(request); | ||
const args = await this.parseParams(request, route); | ||
const result = await this.invoke(route, args); | ||
this.send(response, result); | ||
} catch (err) { | ||
this.reject(context, err); | ||
} | ||
} | ||
} | ||
export class MySequence extends MiddlewareSequence {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters