Skip to content

Commit

Permalink
Release 2.0.9 🚀
Browse files Browse the repository at this point in the history
- Fix: #114
- Fix: #88
  • Loading branch information
Jonathan Casarrubias committed Sep 8, 2016
1 parent 10035dd commit 3029592
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 64 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

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.0.9

- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/114
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/88

## Release 2.0.8

- Hot Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/111
Expand Down
2 changes: 1 addition & 1 deletion lib/angular2/drivers/nativescript2/socket.driver.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* tslint:disable */
var SocketIO = require('nativescript-socket.io');
export class SocketDriver {
static connect(url, options) {
static connect(url: any, options: any) {
return SocketIO.connect(url, options);
}
}
2 changes: 1 addition & 1 deletion lib/angular2/drivers/ng4web/socket.driver.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* tslint:disable */
import * as io from 'socket.io-client';
export class SocketDriver {
static connect(url, options) {
static connect(url: any, options: any) {
return io(url, options);
}
}
4 changes: 4 additions & 0 deletions lib/angular2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ module.exports = function generate(ctx) {
{ module: 'ErrorHandler', from: './error.service'},
{ module: 'LoopBackAuth', from: './auth.service'},
{ module: 'LoopBackConfig', from: '../../lb.config'},
{ module: 'AccessToken', from: '../../models'},
{ module: 'rxjs/add/operator/catch' },
{ module: 'rxjs/add/operator/map' },
];
Expand Down Expand Up @@ -445,6 +446,9 @@ module.exports = function generate(ctx) {
} else {
value = !param.required ? ' = undefined' : '';
}
if (methodName.match(/createMany/) && param.arg === 'data') {
type = `Array<${type}>`;
}
output.push(`${param.arg}: ${type}${value}`);
});

Expand Down
12 changes: 6 additions & 6 deletions lib/angular2/shared/services/core/base.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export abstract class BaseLoopBackApi {
}
let event: string = (`[${method}]${requestUrl}`).replace(/\?/, '');
let subject: Subject<any> = new Subject<any>();
let socket: any = SocketConnections.getHandler(LoopBackConfig.getPath(), {
id: this.auth.getAccessTokenId(),
userId: this.auth.getCurrentUserId()
});
socket.on(event, res => subject.next(res));
let token: AccessToken = new AccessToken();
token.id = this.auth.getAccessTokenId();
token.userId = this.auth.getCurrentUserId();
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
Expand All @@ -101,7 +101,7 @@ export abstract class BaseLoopBackApi {
body : body ? JSON.stringify(body) : undefined
});
return this.http.request(request)
.map(res => (res.text() != "" ? res.json() : {}))
.map((res: any) => (res.text() != "" ? res.json() : {}))
.catch(this.errorHandler.handleError);
<% if ( isIo === 'enabled' ){ -%> }<% } -%>
}
Expand Down
2 changes: 1 addition & 1 deletion lib/angular2/shared/services/custom/service.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class <%-: modelName %>Api extends BaseLoopBackApi {
<%-: fullPath | q %>;
let subject = new Subject();
if (typeof EventSource !== 'undefined') {
let emit = (msg) => subject.next(JSON.parse(msg.data));
let emit = (msg: any) => subject.next(JSON.parse(msg.data));
var source = new EventSource(url);
source.addEventListener('data', emit);
source.onerror = emit;
Expand Down
19 changes: 10 additions & 9 deletions lib/angular2/shared/sockets/connections.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
* Angular 2 for web and NativeScript 2.
**/
import { SocketDriver } from './socket.driver';
import { AccessToken } from '../models';
export class SocketConnections {
private static connections = {};
private static configured = false;
static getHandler(url, token: { id: any, userId: any }) {
private static connections: any = {};
private static configured: boolean = false;
static getHandler(url: string, token: AccessToken) {
if (!SocketConnections.connections[url]) {
console.log('Creating a new connection with: ', url);
let config = { log: false, secure: false, forceWebsockets: true };
let config: any = { log: false, secure: false, forceWebsockets: true };
SocketConnections.connections[url] = SocketDriver.connect(url, config);
SocketConnections.connections[url].on('connect', () => {
if (!SocketConnections.configured)
SocketConnections.setupConnection(url, token, config);
});
let forceConfig = setInterval(() => {
let forceConfig: any = setInterval(() => {
if (!SocketConnections.configured && SocketConnections.connections[url].connected) {
console.info('Forcing IO Configuration');
SocketConnections.setupConnection(url, token, config);
Expand All @@ -36,14 +37,14 @@ export class SocketConnections {
return SocketConnections.connections[url];
}

private static setupConnection(url, token, config): void {
private static setupConnection(url: string, token: AccessToken, config: any): void {
SocketConnections.configured = true;
console.log('Connected to %s', url);
SocketConnections.connections[url].emit('authentication', token);
SocketConnections.connections[url].on('unauthorized', res => console.error('Unauthenticated', res));
SocketConnections.connections[url].on('unauthorized', (res: any) => console.error('Unauthenticated', res));
setInterval(() => SocketConnections.connections[url].emit('lb-ping'), 15000);
SocketConnections.connections[url].on('lb-pong', data => console.info('Heartbeat: ', data));
SocketConnections.connections[url].on('disconnect', data => {
SocketConnections.connections[url].on('lb-pong', (data: any) => console.info('Heartbeat: ', data));
SocketConnections.connections[url].on('disconnect', (data: any) => {
console.info('Unexpected disconnection from IO - Socket IO will try to reconnect');
});
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mean-expert/loopback-sdk-builder",
"version": "2.0.8",
"version": "2.0.9",
"description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack",
"bin": {
"lb-sdk": "bin/lb-sdk"
Expand All @@ -10,7 +10,7 @@
"prepublish": "",
"test": "npm run test:angular2",
"pretest": "cd tests/angular2 && npm install",
"test:angular2": "cd tests/angular2 && npm run test"
"test:angular2": "cd tests/angular2 && ng lint && npm run test"
},
"repository": {
"type": "git",
Expand Down
13 changes: 7 additions & 6 deletions tests/angular2/src/app/shared/sdk/services/core/base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { JSONSearchParams } from './search.params';
import { ErrorHandler } from './error.service';
import { LoopBackAuth } from './auth.service';
import { LoopBackConfig } from '../../lb.config';
import { AccessToken } from '../../models';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import { Subject } from 'rxjs/Subject';
Expand Down Expand Up @@ -76,11 +77,11 @@ export abstract class BaseLoopBackApi {
}
let event: string = (`[${method}]${requestUrl}`).replace(/\?/, '');
let subject: Subject<any> = new Subject<any>();
let socket: any = SocketConnections.getHandler(LoopBackConfig.getPath(), {
id: this.auth.getAccessTokenId(),
userId: this.auth.getCurrentUserId()
});
socket.on(event, res => subject.next(res));
let token: AccessToken = new AccessToken();
token.id = this.auth.getAccessTokenId();
token.userId = this.auth.getCurrentUserId();
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
Expand All @@ -106,7 +107,7 @@ export abstract class BaseLoopBackApi {
body : body ? JSON.stringify(body) : undefined
});
return this.http.request(request)
.map(res => (res.text() != "" ? res.json() : {}))
.map((res: any) => (res.text() != "" ? res.json() : {}))
.catch(this.errorHandler.handleError);
} }
}
10 changes: 5 additions & 5 deletions tests/angular2/src/app/shared/sdk/services/custom/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ export class AccountApi extends BaseLoopBackApi {
"/Accounts/change-stream";
let subject = new Subject();
if (typeof EventSource !== 'undefined') {
let emit = (msg) => subject.next(JSON.parse(msg.data));
let emit = (msg: any) => subject.next(JSON.parse(msg.data));
var source = new EventSource(url);
source.addEventListener('data', emit);
source.onerror = emit;
Expand Down Expand Up @@ -1657,7 +1657,7 @@ export class AccountApi extends BaseLoopBackApi {
* This usually means the response is a `Account` object.)
* </em>
*/
public createManyAccessTokens(id: any, data: any = undefined) {
public createManyAccessTokens(id: any, data: Array<any> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/Accounts/:id/accessTokens";
Expand Down Expand Up @@ -1703,7 +1703,7 @@ export class AccountApi extends BaseLoopBackApi {
* This usually means the response is a `Account` object.)
* </em>
*/
public createManyRooms(id: any, data: Room = undefined) {
public createManyRooms(id: any, data: Array<Room> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/Accounts/:id/rooms";
Expand Down Expand Up @@ -1749,7 +1749,7 @@ export class AccountApi extends BaseLoopBackApi {
* This usually means the response is a `Account` object.)
* </em>
*/
public createManyAdministrations(id: any, data: Room = undefined) {
public createManyAdministrations(id: any, data: Array<Room> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/Accounts/:id/administrations";
Expand Down Expand Up @@ -1793,7 +1793,7 @@ export class AccountApi extends BaseLoopBackApi {
* This usually means the response is a `Account` object.)
* </em>
*/
public createMany(data: any = undefined) {
public createMany(data: Array<any> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/Accounts";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export class ApplicationCredentialApi extends BaseLoopBackApi {
"/ApplicationCredentials/change-stream";
let subject = new Subject();
if (typeof EventSource !== 'undefined') {
let emit = (msg) => subject.next(JSON.parse(msg.data));
let emit = (msg: any) => subject.next(JSON.parse(msg.data));
var source = new EventSource(url);
source.addEventListener('data', emit);
source.onerror = emit;
Expand All @@ -418,7 +418,7 @@ export class ApplicationCredentialApi extends BaseLoopBackApi {
* This usually means the response is a `ApplicationCredential` object.)
* </em>
*/
public createMany(data: any = undefined) {
public createMany(data: Array<any> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/ApplicationCredentials";
Expand Down
6 changes: 3 additions & 3 deletions tests/angular2/src/app/shared/sdk/services/custom/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ export class CategoryApi extends BaseLoopBackApi {
"/Categories/change-stream";
let subject = new Subject();
if (typeof EventSource !== 'undefined') {
let emit = (msg) => subject.next(JSON.parse(msg.data));
let emit = (msg: any) => subject.next(JSON.parse(msg.data));
var source = new EventSource(url);
source.addEventListener('data', emit);
source.onerror = emit;
Expand All @@ -723,7 +723,7 @@ export class CategoryApi extends BaseLoopBackApi {
* This usually means the response is a `Category` object.)
* </em>
*/
public createManyRooms(id: any, data: Room = undefined) {
public createManyRooms(id: any, data: Array<Room> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/Categories/:id/rooms";
Expand Down Expand Up @@ -754,7 +754,7 @@ export class CategoryApi extends BaseLoopBackApi {
* This usually means the response is a `Category` object.)
* </em>
*/
public createMany(data: any = undefined) {
public createMany(data: Array<any> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/Categories";
Expand Down
4 changes: 2 additions & 2 deletions tests/angular2/src/app/shared/sdk/services/custom/Like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ export class LikeApi extends BaseLoopBackApi {
"/likes/change-stream";
let subject = new Subject();
if (typeof EventSource !== 'undefined') {
let emit = (msg) => subject.next(JSON.parse(msg.data));
let emit = (msg: any) => subject.next(JSON.parse(msg.data));
var source = new EventSource(url);
source.addEventListener('data', emit);
source.onerror = emit;
Expand All @@ -479,7 +479,7 @@ export class LikeApi extends BaseLoopBackApi {
* This usually means the response is a `Like` object.)
* </em>
*/
public createMany(data: any = undefined) {
public createMany(data: Array<any> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/likes";
Expand Down
14 changes: 7 additions & 7 deletions tests/angular2/src/app/shared/sdk/services/custom/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2142,7 +2142,7 @@ export class RoomApi extends BaseLoopBackApi {
"/rooms/change-stream";
let subject = new Subject();
if (typeof EventSource !== 'undefined') {
let emit = (msg) => subject.next(JSON.parse(msg.data));
let emit = (msg: any) => subject.next(JSON.parse(msg.data));
var source = new EventSource(url);
source.addEventListener('data', emit);
source.onerror = emit;
Expand Down Expand Up @@ -2286,7 +2286,7 @@ export class RoomApi extends BaseLoopBackApi {
* This usually means the response is a `Room` object.)
* </em>
*/
public createManyMessages(id: any, data: any = undefined) {
public createManyMessages(id: any, data: Array<any> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/rooms/:id/messages";
Expand Down Expand Up @@ -2332,7 +2332,7 @@ export class RoomApi extends BaseLoopBackApi {
* This usually means the response is a `Room` object.)
* </em>
*/
public createManyLikes(id: any, data: Like = undefined) {
public createManyLikes(id: any, data: Array<Like> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/rooms/:id/likes";
Expand Down Expand Up @@ -2378,7 +2378,7 @@ export class RoomApi extends BaseLoopBackApi {
* This usually means the response is a `Room` object.)
* </em>
*/
public createManyCategories(id: any, data: Category = undefined) {
public createManyCategories(id: any, data: Array<Category> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/rooms/:id/categories";
Expand Down Expand Up @@ -2424,7 +2424,7 @@ export class RoomApi extends BaseLoopBackApi {
* This usually means the response is a `Room` object.)
* </em>
*/
public createManyAccounts(id: any, data: Account = undefined) {
public createManyAccounts(id: any, data: Array<Account> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/rooms/:id/accounts";
Expand Down Expand Up @@ -2470,7 +2470,7 @@ export class RoomApi extends BaseLoopBackApi {
* This usually means the response is a `Room` object.)
* </em>
*/
public createManyAdmins(id: any, data: Account = undefined) {
public createManyAdmins(id: any, data: Array<Account> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/rooms/:id/admins";
Expand Down Expand Up @@ -2514,7 +2514,7 @@ export class RoomApi extends BaseLoopBackApi {
* This usually means the response is a `Room` object.)
* </em>
*/
public createMany(data: any = undefined) {
public createMany(data: Array<any> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/rooms";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ export class RoomAccountApi extends BaseLoopBackApi {
"/room-accounts/change-stream";
let subject = new Subject();
if (typeof EventSource !== 'undefined') {
let emit = (msg) => subject.next(JSON.parse(msg.data));
let emit = (msg: any) => subject.next(JSON.parse(msg.data));
var source = new EventSource(url);
source.addEventListener('data', emit);
source.onerror = emit;
Expand All @@ -480,7 +480,7 @@ export class RoomAccountApi extends BaseLoopBackApi {
* This usually means the response is a `RoomAccount` object.)
* </em>
*/
public createMany(data: any = undefined) {
public createMany(data: Array<any> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/room-accounts";
Expand Down
6 changes: 3 additions & 3 deletions tests/angular2/src/app/shared/sdk/services/custom/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ export class UserApi extends BaseLoopBackApi {
"/Users/change-stream";
let subject = new Subject();
if (typeof EventSource !== 'undefined') {
let emit = (msg) => subject.next(JSON.parse(msg.data));
let emit = (msg: any) => subject.next(JSON.parse(msg.data));
var source = new EventSource(url);
source.addEventListener('data', emit);
source.onerror = emit;
Expand Down Expand Up @@ -760,7 +760,7 @@ export class UserApi extends BaseLoopBackApi {
* This usually means the response is a `User` object.)
* </em>
*/
public createManyAccessTokens(id: any, data: any = undefined) {
public createManyAccessTokens(id: any, data: Array<any> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/Users/:id/accessTokens";
Expand Down Expand Up @@ -791,7 +791,7 @@ export class UserApi extends BaseLoopBackApi {
* This usually means the response is a `User` object.)
* </em>
*/
public createMany(data: any = undefined) {
public createMany(data: Array<any> = undefined) {
let method: string = "POST";
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
"/Users";
Expand Down
Loading

0 comments on commit 3029592

Please sign in to comment.