Skip to content

Commit

Permalink
Release 2.1.0-beta.11 🚀
Browse files Browse the repository at this point in the history
- Fix: #157
- Fix: #155
- Fix: #154
- Fix: #153
- Fix: #151
- Fix: #147
  • Loading branch information
Jonathan Casarrubias committed Oct 18, 2016
1 parent adaca80 commit bd24246
Show file tree
Hide file tree
Showing 23 changed files with 193 additions and 81 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "6"
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

This file is created to keep history of the LoopBack SDK Builder, it does not consider or keeps any history of its parent module `loopback-sdk-angular`.

## Release 2.1.0-beta.11

- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/157
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/155
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/154
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/153
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/151
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/147

## Release 2.1.0-beta.10

- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/142
Expand Down
1 change: 1 addition & 0 deletions bin/lb-sdk
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ console.log(chalk.green('* CONTRIBUTORS
console.log(chalk.green('* João Ribeiro <http://jonnybgod.ghost.io> *'));
console.log(chalk.green('* Nikolay Matiushenkov <https://github.com/mnvx> *'));
console.log(chalk.green('* Sylvain Dumont <https://www.weboaks.com> *'));
console.log(chalk.green('* Yonggang Luo <https://github.com/lygstate> *'));
console.log(chalk.green('* *'));
console.log(chalk.green('* ORIGINALLY FORKED FROM *'));
console.log(chalk.green('* Miroslav Bajtos\' <[email protected]> *'));
Expand Down
2 changes: 1 addition & 1 deletion lib/angular2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ module.exports = function generate(ctx) {
* Testing if the param is route type
*/
function paramIsRoute(param) {
return (param.http && param.http.source === 'path') || (param.arg && param.arg.match(/(id|fk|file|container)/));
return (param.http && param.http.source === 'path') || (param.arg && param.arg.match(/(^id$|fk|file|container)/));
}
/**
* @method paramIsFunction
Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "@mean-expert/loopback-sdk-builder",
"version": "2.1.0-beta.10",
"version": "2.1.0-beta.11",
"description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack",
"bin": {
"lb-sdk": "bin/lb-sdk"
},
"main": "index.js",
"scripts": {
"prepublish": "",
"test": "npm run test:angular2",
"pretest": "cd tests/angular2 && npm install",
"test:angular2": "cd tests/angular2 && ng lint && npm run test"
"test": "npm run load:api & npm run test:angular2",
"pretest": "cd tests/angular2 && npm install && npm install ../../ && npm run build:sdk",
"load:api": "cd tests/angular2 && NODE_ENV=test node loopback/server",
"test:angular2": "cd tests/angular2 && ng lint && ng test"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -44,6 +45,11 @@
"name": "Sylvain Dumont",
"email": "[email protected]",
"url": "https://www.weboaks.com"
},
{
"name": "Yonggang Luo",
"email": "[email protected]",
"url": "https://github.com/lygstate"
}
],
"license": "MIT",
Expand Down
34 changes: 34 additions & 0 deletions tests/angular2/.github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# How to contribute

I'm really glad you're reading this, volunteer developers to help this project are always welcome.

If you haven't already, follow me ([@johncasarrubias](irc://chat.freenode.net/opengovernment) on twitter). I want you to keep informed about new features and tutorials.

Here are some important resources:

* [MEAN Expert Blog](http://mean.expert) tutorials about the MEAN Stack.
* [WIKI](https://github.com/mean-expert-official/loopback-sdk-builder/wiki) official wiki documentation.
* [Angular 2 Testing](https://angular.io/docs/ts/latest/guide/testing.html) official documentation for testing environment.
* Bugs? [GitHub Issues](https://github.com/mean-expert-official/loopback-sdk-builder/issues) is where to report them

## Testing

Tests are being created and excecuted by using the Angular-CLI Tool, please refer to the official documentation.

````sh
$ cd to/loopback-sdk-builder
$ npm test
````

## Submitting changes

Please send a [GitHub Pull Request](https://github.com/mean-expert-official/loopback-sdk-builder/pull/new/master) with a clear list of what you've done (read more about [pull requests](http://help.github.com/pull-requests/)). When you send a pull request, we will love you forever if you include RSpec examples. We can always use more test coverage. Please follow our coding conventions (below) and make sure all of your commits are atomic (one feature per commit).

Always write a clear log message for your commits. One-line messages are fine for small changes, but bigger changes should look like this:

$ git commit -m "A brief summary of the commit
>
> A paragraph describing what changed and its impact."

Thanks,
Jonathan Casarrubias, [MEAN Expert](http://mean.expert).
33 changes: 27 additions & 6 deletions tests/angular2/common/models/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,42 @@ module.exports = function (Room) {
}
);

Room.greetPost = greet;

// We receive 3 copies of the body from loopback, not sure why
// I would expect body.a, body.b and body.c in 1 object param.
Room.greetPost = (b1, b2, b3, next) => {
next(null, `${b1.a}:${b2.b}:${b3.c}`);
};

Room.remoteMethod(
'greetPost',
{
accepts: [
{ arg: 'a', type: 'string' },
{ arg: 'b', type: 'string' },
{ arg: 'c', type: 'string' }
{ arg: 'a', type: 'object', http: { source: 'body' }},
{ arg: 'b', type: 'object', http: { source: 'body' }},
{ arg: 'c', type: 'object', http: { source: 'body' }}
],
returns: { arg: 'greeting', type: 'string' },
returns: { arg: 'greeting', type: 'object' },
http: { path: '/who', verb: 'post' }
}
);

Room.singleParamPost = function (body, next) {
next(null, body);
};

Room.remoteMethod(
'singleParamPost',
{
accepts: {
arg: 'param',
type: 'object',
http: { source: 'body' }
},
returns: { arg: 'param', type: 'object', root: true },
http: { path: '/single-param-post', verb: 'post' }
}
);

Room.greetGet = greet;

Room.remoteMethod(
Expand Down
3 changes: 2 additions & 1 deletion tests/angular2/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = function (config) {
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-phantomjs-launcher'),
require('karma-remap-istanbul'),
require('angular-cli/plugins/karma')
],
Expand All @@ -32,7 +33,7 @@ module.exports = function (config) {
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
browsers: ['PhantomJS'],
singleRun: false
});
};
Empty file.
7 changes: 5 additions & 2 deletions tests/angular2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"lint": "tslint \"src/**/*.ts\"",
"pree2e": "webdriver-manager update",
"e2e": "protractor",
"test": "node loopback/server.js & ng test",
"build:sdk": "./node_modules/.bin/lb-sdk loopback/server.js src/app/shared/sdk -i enabled"
"test": "ng test --watch false",
"build:sdk": "./node_modules/.bin/lb-sdk loopback/server.js src/app/shared/sdk -i enabled -w enabled"
},
"private": true,
"dependencies": {
Expand All @@ -21,6 +21,7 @@
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"@mean-expert/loopback-component-realtime": "^1.0.0-beta.5",
"@types/socket.io-client": "^1.4.27",
"compression": "^1.0.3",
"config-chain": "^1.1.10",
Expand Down Expand Up @@ -51,7 +52,9 @@
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"phantomjs": "^2.1.7",
"protractor": "4.0.5",
"ts-node": "1.2.1",
"tslint": "3.13.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/angular2/src/app/access/access.routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ const accessRoutes: Routes = [
}
];

export const accessRouting: ModuleWithProviders = RouterModule.forChild(accessRoutes);
export const accessRouting: ModuleWithProviders = RouterModule.forChild(accessRoutes);
4 changes: 2 additions & 2 deletions tests/angular2/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export class AppComponent {
) {
this.logger.info('LoopBack SDK Builder - Test Application');
// Simple IO Test
//this.realTime.IO.emit('hello', 'world');
//this.realTime.IO.on('hello').subscribe((msg: any) => this.logger.info('REALTIME: ', msg));
// this.realTime.IO.emit('hello', 'world');
// this.realTime.IO.on('hello').subscribe((msg: any) => this.logger.info('REALTIME: ', msg));
// Simple FireLoop set and get examples.
let RoomReference: FireLoopRef<Room> = this.realTime.FireLoop.ref<Room>(Room);
// This will get the list of results and fire every time there is new data.
Expand Down
1 change: 0 additions & 1 deletion tests/angular2/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { SDKModule } from './shared/sdk/index';
import { routing, appRoutingProviders } from './app.routing';
Expand Down
1 change: 0 additions & 1 deletion tests/angular2/src/app/app.routing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { RoomComponent } from './room/room.component';
import { AuthGuard } from './shared/auth.guard';

const appRoutes: Routes = [
Expand Down
10 changes: 10 additions & 0 deletions tests/angular2/src/app/room-service.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ describe('Service: Room Service', () => {
})
));

it('should fetch filter as object from single-param post method',
async(inject([RoomApi], (roomApi: RoomApi) => {
let param = { child: 'filtered' };
return roomApi.singleParamPost(param).subscribe((result: { child: string, param: undefined }) => {
expect(result.param).toBe(undefined);
expect(result.child).toBe(param.child);
});
})
));

it('should include multiple layers',
async(inject([RoomApi, MessageApi], (roomApi: RoomApi, messageApi: MessageApi) => {
let room: Room = new Room({ name: Date.now().toString() });
Expand Down
2 changes: 1 addition & 1 deletion tests/angular2/src/app/room/room.routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ const roomRoutes: Routes = [
}
];

export const roomRouting: ModuleWithProviders = RouterModule.forChild(roomRoutes);
export const roomRouting: ModuleWithProviders = RouterModule.forChild(roomRoutes);
67 changes: 33 additions & 34 deletions tests/angular2/src/app/shared/sdk/services/core/base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ErrorHandler } from './error.service';
import { LoopBackAuth } from './auth.service';
import { LoopBackConfig } from '../../lb.config';
import { AccessToken } from '../../models';
import { Observable } from 'rxjs/Observable';
import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
Expand All @@ -29,9 +30,9 @@ export abstract class BaseLoopBackApi {
protected path: string;

constructor(
@Inject(Http) protected http: Http,
@Inject(LoopBackAuth) protected auth: LoopBackAuth,
@Inject(JSONSearchParams) protected searchParams: JSONSearchParams,
@Inject(Http) protected http: Http,
@Inject(LoopBackAuth) protected auth: LoopBackAuth,
@Inject(JSONSearchParams) protected searchParams: JSONSearchParams,
@Optional() @Inject(ErrorHandler) protected errorHandler: ErrorHandler
) {}

Expand All @@ -49,8 +50,9 @@ export abstract class BaseLoopBackApi {
url : string,
routeParams : any = {},
urlParams : any = {},
postBody : any = null, isio : boolean = false
) {
postBody : any = null,
isio : boolean = false
): Observable<any> {

let headers = new Headers();
headers.append('Content-Type', 'application/json');
Expand Down Expand Up @@ -84,33 +86,30 @@ export abstract class BaseLoopBackApi {
let socket: any = SocketConnections.getHandler(LoopBackConfig.getPath(), token);
socket.on(event, (res: any) => subject.next(res));
return subject.asObservable();
} else { // Body fix for built in remote methods using "data", "options" or "credentials
// that are the actual body, Custom remote method properties are different and need
// to be wrapped into a body object
let body: any;
if (
typeof postBody === 'object' &&
(postBody.data || postBody.credentials || postBody.options) &&
Object.keys(postBody).length === 1
) {
body = postBody.data ? postBody.data :
postBody.options ? postBody.options :
postBody.credentials;
} else {
body = postBody;
}
this.searchParams.setJSON(urlParams);
let request: Request = new Request({
headers : headers,
method : method,
url : urlParams.filter ? `${requestUrl}?filter=${ encodeURI(JSON.stringify(urlParams.filter))}`
: requestUrl,
search : !urlParams.filter && Object.keys(urlParams).length > 0
? this.searchParams.getURLSearchParams() : null,
body : body ? JSON.stringify(body) : undefined
});
return this.http.request(request)
.map((res: any) => (res.text() != "" ? res.json() : {}))
.catch(this.errorHandler.handleError);
} }
}

// Body fix for built in remote methods using "data", "options" or "credentials
// that are the actual body, Custom remote method properties are different and need
// to be wrapped into a body object
let body: any;
let postBodyKeys = typeof postBody === 'object' ? Object.keys(postBody) : []
if (postBodyKeys.length === 1) {
body = postBody[postBodyKeys[0]]
} else {
body = postBody;
}
this.searchParams.setJSON(urlParams);
let request: Request = new Request({
headers : headers,
method : method,
url : urlParams.filter ? `${requestUrl}?filter=${ encodeURI(JSON.stringify(urlParams.filter))}`
: requestUrl,
search : !urlParams.filter && Object.keys(urlParams).length > 0
? this.searchParams.getURLSearchParams() : null,
body : body ? JSON.stringify(body) : undefined
});
return this.http.request(request)
.map((res: any) => (res.text() != "" ? res.json() : {}))
.catch(this.errorHandler.handleError);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
import 'rxjs/add/observable/throw';
/**
* Default error handler
*/
@Injectable()
export class ErrorHandler {
public handleError(error: Response) {
public handleError(error: Response): ErrorObservable {
return Observable.throw(error.json().error || 'Server error');
}
}
5 changes: 2 additions & 3 deletions tests/angular2/src/app/shared/sdk/services/custom/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1669,11 +1669,10 @@ export class AccountApi extends BaseLoopBackApi {
let method: string = "GET";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/Accounts/confirm";
let routeParams: any = {
uid: uid
};
let routeParams: any = {};
let postBody: any = {};
let urlParams: any = {};
if (uid) urlParams.uid = uid;
if (token) urlParams.token = token;
if (redirect) urlParams.redirect = redirect;
let result = this.request(method, url, routeParams, urlParams, postBody);
Expand Down
2 changes: 0 additions & 2 deletions tests/angular2/src/app/shared/sdk/services/custom/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export class CoreApi extends BaseLoopBackApi {
body: body
};
let urlParams: any = {};
if (body) urlParams.body = body;
let result = this.request(method, url, routeParams, urlParams, postBody);
return result;
}
Expand Down Expand Up @@ -90,7 +89,6 @@ export class CoreApi extends BaseLoopBackApi {
request: request
};
let urlParams: any = {};
if (request) urlParams.request = request;
let result = this.request(method, url, routeParams, urlParams, postBody);
return result;
}
Expand Down
Loading

0 comments on commit bd24246

Please sign in to comment.