feat(cli): Cleanup REST application tooling#774
Conversation
shimks
commented
Dec 5, 2017
- connected to [CLI] Create empty REST API project #723
67eb6a3 to
3bd7a6e
Compare
|
@slnode test please |
| "build:watch": "lb-tsc --watch", | ||
| "clean": "lb-clean", | ||
| <% if (project.prettier && project.tslint) { -%> | ||
| <% if (project.prettier && project.tslint) { -%> |
There was a problem hiding this comment.
No need to change the formatting for this file. Please revert.
| "build:watch": "tsc --outDir dist --target es2017 --watch", | ||
| "clean": "rm -rf dist", | ||
| <% if (project.prettier && project.tslint) { -%> | ||
| <% if (project.prettier && project.tslint) { -%> |
There was a problem hiding this comment.
No need to change the formatting for this file. Please revert.
If you have a build script to do auto-formatting, please exclude template files.
There was a problem hiding this comment.
@raymondfeng With the previous formatting, the indenting on the generated package.json was inconsistent. The indenting is consistent with the new format.
| { | ||
| "$schema": "http://json.schemastore.org/tsconfig", | ||
| <% if (project.loopbackBuild) { -%> | ||
| <% if (project.loopbackBuild) { -%> |
There was a problem hiding this comment.
No need to change the formatting for this file. Please revert.
| { | ||
| "$schema": "http://json.schemastore.org/tslint", | ||
| <% if (project.loopbackBuild) { -%> | ||
| <% if (project.loopbackBuild) { -%> |
There was a problem hiding this comment.
No need to change the formatting for this file. Please revert.
| // Note: arguments and options should be defined in the constructor. | ||
| constructor(args, opts) { | ||
| super(args, opts); | ||
| this._setupGenerator(); |
There was a problem hiding this comment.
Maybe it's better to remove redundant call of this._setupGenerator() in subclasses instead.
| @@ -0,0 +1,3 @@ | |||
| # Datasources | |||
|
|
|||
| This directory contains code for datasources provided by this app. | |||
There was a problem hiding this comment.
I suggest rephrasing to contains config for datasources used by this app.
f306fad to
ec5f7fb
Compare
1741238 to
9c353d9
Compare
| } from '@loopback/rest'; | ||
| import {ServerResponse} from 'http'; | ||
|
|
||
| export class MySequence extends DefaultSequence { |
There was a problem hiding this comment.
We can't extend a Sequence because of DI ... we can't inject new sequence actions if we do this. Below is a sample implementation from log-extension I would suggest using (removing the logging stuff).
class LogSequence implements SequenceHandler {
constructor(
@inject(RestBindings.Http.CONTEXT) public ctx: Context,
@inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
@inject(SequenceActions.PARSE_PARAMS)
protected parseParams: ParseParams,
@inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
@inject(SequenceActions.SEND) protected send: Send,
@inject(SequenceActions.REJECT) protected reject: Reject,
@inject(EXAMPLE_LOG_BINDINGS.LOG_ACTION) protected logger: LogFn,
) { }
async handle(req: ParsedRequest, res: ServerResponse) {
// tslint:disable-next-line:no-any
let args: any = [];
// tslint:disable-next-line:no-any
let result: any;
try {
const route = this.findRoute(req);
args = await this.parseParams(req, route);
result = await this.invoke(route, args);
this.send(res, result);
} catch (err) {
this.reject(res, req, err);
result = err;
}
await this.logger(req, args, result);
}
}There was a problem hiding this comment.
@virkt25 Are you saying @inject doesn't allow inheritance from base classes?
There was a problem hiding this comment.
Yes. I get the following error message
Uncaught Error: Cannot resolve injected arguments for function MySequence: The arguments[0] is not decorated for dependency injection, but a value is not supplied
When I try using the following MySequence (in log-extension acceptance test) ... when I'm trying to inject a custom sequence action.
class MySequence extends DefaultSequence {
constructor(
public ctx: Context,
protected findRoute: FindRoute,
protected parseParams: ParseParams,
protected invoke: InvokeMethod,
public send: Send,
public reject: Reject,
@inject(EXAMPLE_LOG_BINDINGS.LOG_ACTION) protected logger: LogFn,
) {
super(ctx, findRoute, parseParams, invoke, send, reject);
}
// Handle your request routing here:
async handle(req: ParsedRequest, res: ServerResponse) {
let args: any = [];
let result: any;
try {
const route = this.findRoute(req);
args = await this.parseParams(req, route);
result = await this.invoke(route, args);
await this.send(res, result);
} catch (err) {
this.reject(res, req, err);
result = err;
}
await this.logger(req, args, result);
}
}
server.sequence(MySequence);There was a problem hiding this comment.
@raymondfeng I've made a commit with @virkt25 's suggestion in mind, but should I revert it if you're adding in support for inheritance in @inject?
6fbcc7c to
14a494f
Compare
|
@slnode test please |
14a494f to
bf165bf
Compare