Skip to content

Commit

Permalink
Release 2.1.0-rc.3 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Casarrubias committed Dec 12, 2016
1 parent 93f2fc3 commit bda7c9d
Show file tree
Hide file tree
Showing 29 changed files with 147 additions and 148 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@

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-rc.3

- Milestone Details: https://github.com/mean-expert-official/loopback-sdk-builder/milestone/25

- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/243
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/249
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/250
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/240
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/237
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/246

## Release 2.1.0-rc.2

- Milestone Details: https://github.com/mean-expert-official/loopback-sdk-builder/milestone/24

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

## Release 2.1.0-rc.1

- Milestone Details: https://github.com/mean-expert-official/loopback-sdk-builder/milestone/21

- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/232
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/231
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/228
Expand Down
2 changes: 1 addition & 1 deletion bin/lb-sdk
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var argv = optimist
.default('w', 'disabled')
.default('v', 'disabled')
.default('f', 'disabled')
.alias({ u: 'url', m: 'module-name', l: 'library', i: 'io', d: 'driver', w: 'wipe', v: 'default-values', v: 'fireloop-only' })
.alias({ u: 'url', m: 'module-name', l: 'library', i: 'io', d: 'driver', w: 'wipe', v: 'default-values', f: 'fireloop-only' })
.demand(1)
.argv;
/**
Expand Down
119 changes: 77 additions & 42 deletions lib/angular2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module.exports = function generate(ctx) {
{
template: './shared/models/base.ejs',
output: '/models/BaseModels.ts',
params: { loadAccessToken: ctx.loadAccessToken }
params: { loadAccessToken: ctx.loadAccessToken, buildServiceDI }
},
{
template: './shared/services/core/auth.ejs',
Expand Down Expand Up @@ -150,53 +150,48 @@ module.exports = function generate(ctx) {
template: './shared/storage/internal.storage.ts',
output: '/storage/internal.storage.ts',
params: {}
},
{
template: './shared/storage/cookie.node.ts',
output: '/storage/cookie.node.ts',
params: {}
},
{
}
];
// Add Browser Specific Code
if (ctx.driver.match(/ng2web|ng2universal/)) {
schema.push({
template: './shared/storage/cookie.browser.ts',
output: '/storage/cookie.browser.ts',
params: {}
},
{
});
}
// Add Server Specific Code
if (ctx.driver === 'ng2universal') {
schema.push({
template: './shared/storage/cookie.node.ts',
output: '/storage/cookie.node.ts',
params: {}
});
}
// Add NativeScript Specific Code
if (ctx.driver === 'ng2native') {
schema.push({
template: './shared/storage/storage.native.ts',
output: '/storage/storage.native.ts',
params: {}
}
];
});
}
/**
* REALTIME MODULE SUPPORT
*/
if (ctx.isIo === 'enabled') {
// Add generic code to any environment
schema = schema.concat([
{
template: './shared/sockets/connections.ts',
output: '/sockets/socket.connections.ts',
params: {}
},
{
template: './shared/sockets/socket.browser.ts',
output: '/sockets/socket.browser.ts',
params: {}
},
{
template: './shared/sockets/socket.driver.ts',
output: '/sockets/socket.driver.ts',
params: {}
},
{
template: './shared/sockets/socket.native.ts',
output: '/sockets/socket.native.ts',
params: {}
},
{
template: './shared/sockets/socket.node.ts',
output: '/sockets/socket.node.ts',
params: {}
},
{
template: './shared/services/core/io.ejs',
output: '/services/core/io.service.ts',
Expand All @@ -218,6 +213,30 @@ module.exports = function generate(ctx) {
params: {}
}
]);
// Add Browser Specific Code
if (ctx.driver.match(/ng2web|ng2universal/)) {
schema.push({
template: './shared/sockets/socket.browser.ts',
output: '/sockets/socket.browser.ts',
params: {}
});
}
// Add Server Specific Code
if (ctx.driver === 'ng2universal') {
schema.push({
template: './shared/sockets/socket.node.ts',
output: '/sockets/socket.node.ts',
params: {}
});
}
// Add NativeScript Specific Code
if (ctx.driver === 'ng2native') {
schema.push({
template: './shared/sockets/socket.native.ts',
output: '/sockets/socket.native.ts',
params: {}
});
}
}
/**
* SDK DYNAMIC FILES
Expand Down Expand Up @@ -387,7 +406,7 @@ module.exports = function generate(ctx) {
* IMPORTANT: This method have a very specific flow, changing it may create
* multiple issues on multiple different use cases.
*/
function buildServiceImports(model, loadAccessToken) {
function buildServiceImports(model, loadAccessToken, isIo) {
let modelName = capitalize(model.name);
let imports = [
{ module: 'Injectable, Inject, Optional', from: '@angular/core'},
Expand All @@ -396,7 +415,6 @@ module.exports = function generate(ctx) {
{ module: 'BaseLoopBackApi', from: '../core/base.service'},
{ module: 'LoopBackConfig', from: '../../lb.config'},
{ module: 'LoopBackAuth', from: '../core/auth.service'},
{ module: 'SocketConnections', from: '../../sockets/socket.connections' },
{
module: `LoopBackFilter, ${model.isUser ? `SDKToken${ (loadAccessToken && model.isUser) ? ', AccessToken' : '' }` : '' }`,
from: '../../models/BaseModels'
Expand All @@ -408,6 +426,9 @@ module.exports = function generate(ctx) {
{ module: 'rxjs/add/operator/map' },
{ module: modelName, from: `../../models/${modelName}`},
];
if (isIo === 'enabled') {
imports.push({ module: 'SocketConnections', from: '../../sockets/socket.connections' });
}
let loaded = {}; loaded[model.name] = true;
getModelRelations(model).forEach((relationName, i) => {
let targetClass = model.sharedClass.ctor.relations[relationName].targetClass;
Expand Down Expand Up @@ -450,8 +471,6 @@ module.exports = function generate(ctx) {
{ module: 'LoggerService', from: './services/custom/logger.service'},
{ module: 'SDKModels', from: './services/custom/SDKModels'},
{ module: 'InternalStorage', from: './storage/internal.storage'},
{ module: 'SocketDriver', from: './sockets/socket.driver'},
{ module: 'SocketConnections', from: './sockets/socket.connections'},
{ module: 'HttpModule', from: '@angular/http'},
{ module: 'CommonModule', from: '@angular/common'},
{ module: 'NgModule, ModuleWithProviders', from: '@angular/core'}
Expand All @@ -460,23 +479,33 @@ module.exports = function generate(ctx) {
switch (driver) {
case 'ng2web':
imports.push({ module: 'CookieBrowser', from: './storage/cookie.browser'});
imports.push({ module: 'SocketBrowser', from: './sockets/socket.browser'});
if (isIo === 'enabled') {
imports.push({ module: 'SocketBrowser', from: './sockets/socket.browser'});
}
break;
case 'ng2universal':
imports.push({ module: 'CookieBrowser', from: './storage/cookie.browser'});
imports.push({ module: 'CookieNode', from: './storage/cookie.node'});
imports.push({ module: 'SocketBrowser', from: './sockets/socket.browser'});
imports.push({ module: 'SocketNode', from: './sockets/socket.node'});
if (isIo === 'enabled') {
imports.push({ module: 'SocketBrowser', from: './sockets/socket.browser'});
imports.push({ module: 'SocketNode', from: './sockets/socket.node'});
}
break;
case 'ng2native':
imports.push({ module: 'StorageNative', from: './storage/storage.native'});
imports.push({ module: 'SocketNative', from: './sockets/socket.native'});
if (isIo === 'enabled') {
imports.push({ module: 'SocketNative', from: './sockets/socket.native'});
}
break;
}


if (isIo === 'enabled') {
imports.push({ module: 'RealTime', from: './services/core/real.time'});
imports = imports.concat([
{ module: 'SocketDriver', from: './sockets/socket.driver'},
{ module: 'SocketConnections', from: './sockets/socket.connections'},
{ module: 'RealTime', from: './services/core/real.time'}
]);
}

Object.keys(models).forEach(modelName => {
Expand All @@ -499,19 +528,25 @@ module.exports = function generate(ctx) {
case 'browser':
if (driver === 'ng2web' || driver === 'ng2universal') {
imports.push('{ provide: InternalStorage, useClass: CookieBrowser }');
imports.push('{ provide: SocketDriver, useClass: SocketBrowser }');
if (isIo === 'enabled') {
imports.push('{ provide: SocketDriver, useClass: SocketBrowser }');
}
}
break;
case 'node':
if (driver === 'ng2universal') {
imports.push('{ provide: InternalStorage, useClass: CookieNode }');
imports.push('{ provide: SocketDriver, useClass: SocketNode }');
if (isIo === 'enabled') {
imports.push('{ provide: SocketDriver, useClass: SocketNode }');
}
}
break;
case 'ng2native':
case 'nativescript':
if (driver === 'ng2native') {
imports.push('{ provide: InternalStorage, useClass: StorageNative }');
imports.push('{ provide: SocketDriver, useClass: SocketNative }');
if (isIo === 'enabled') {
imports.push('{ provide: SocketDriver, useClass: SocketNative }');
}
}
break;
}
Expand Down Expand Up @@ -549,7 +584,7 @@ module.exports = function generate(ctx) {
* @method buildBaseServiceImports
* @description
* Define import statement for the SDK Module
*/
**/
function buildBaseServiceImports(isIo) {
let imports = [
{ module: 'Injectable, Inject, Optional', from: '@angular/core'},
Expand All @@ -559,7 +594,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/index'},
{ module: 'LoopBackFilter, AccessToken', from: '../../models/BaseModels'},
{ module: 'SDKModels', from: '../custom/SDKModels'},
{ module: 'Observable', from: 'rxjs/Observable' },
{ module: 'ErrorObservable', from: 'rxjs/observable/ErrorObservable' },
Expand Down
33 changes: 7 additions & 26 deletions lib/angular2/shared/services/core/base.ejs
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
/* tslint:disable */
import { Injectable, Inject, Optional } from '@angular/core';
import { Http, Headers, Request } from '@angular/http';
import { NgModule, ModuleWithProviders } from '@angular/core';
import { JSONSearchParams } from './search.params';
import { ErrorHandler } from './error.service';
import { LoopBackAuth } from './auth.service';
import { LoopBackConfig } from '../../lb.config';
import { LoopBackFilter, SDKToken, AccessToken } from '../../models/BaseModels';
import { SDKModels } from '../custom/SDKModels';
import { Observable } from 'rxjs/Observable';
import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import { Subject } from 'rxjs/Subject';
import { SocketConnections } from '../../sockets/socket.connections';
<%- buildBaseServiceImports(isIo) %>
// Making Sure EventSource Type is available to avoid compilation issues.
declare var EventSource: any;
/**
Expand All @@ -34,12 +20,7 @@ export abstract class BaseLoopBackApi {
protected model: any;

constructor(
@Inject(Http) protected http: Http,
@Inject(SocketConnections) protected connections: SocketConnections,
@Inject(SDKModels) protected models: SDKModels,
@Inject(LoopBackAuth) protected auth: LoopBackAuth,
@Inject(JSONSearchParams) protected searchParams: JSONSearchParams,
@Optional() @Inject(ErrorHandler) protected errorHandler: ErrorHandler
<%- buildServiceDI(isIo) %>
) {
this.model = this.models.get(this.getModelName());
}
Expand All @@ -58,8 +39,8 @@ export abstract class BaseLoopBackApi {
url : string,
routeParams : any = {},
urlParams : any = {},
postBody : any = {},
isio : boolean = false
postBody : any = {}<% if (isIo === 'enabled') { %>,
isio : boolean = false<% } %>
): Observable<any> {

let headers = new Headers();
Expand All @@ -80,7 +61,7 @@ export abstract class BaseLoopBackApi {
routeParams[key] + "$1"
);
}

<% if (isIo === 'enabled') { %>
if (isio) {
if (requestUrl.match(/fk/)) {
let arr = requestUrl.split('/'); arr.pop();
Expand All @@ -95,7 +76,7 @@ export abstract class BaseLoopBackApi {
socket.on(event, (res: any) => subject.next(res));
return subject.asObservable();
}

<% } %>
// 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
Expand Down Expand Up @@ -124,7 +105,7 @@ export abstract class BaseLoopBackApi {
});
return this.http.request(request)
.map((res: any) => (res.text() != "" ? res.json() : {}))
.catch(this.errorHandler.handleError);
.catch((e) => this.errorHandler.handleError(e));
}
/**
* @method create
Expand Down
7 changes: 5 additions & 2 deletions lib/angular2/shared/services/core/error.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
//import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
import 'rxjs/add/observable/throw';
/**
* Default error handler
*/
@Injectable()
export class ErrorHandler {
public handleError(error: Response): ErrorObservable {
// ErrorObservable when rxjs version < rc.5
// ErrorObservable<string> when rxjs version = rc.5
// I'm leaving any for now to avoid breaking apps using both versions
public handleError(error: Response): any {
return Observable.throw(error.json().error || 'Server error');
}
}
2 changes: 1 addition & 1 deletion lib/angular2/shared/services/custom/service.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* tslint:disable */
<%- buildServiceImports(model, loadAccessToken) %>
<%- buildServiceImports(model, loadAccessToken, isIo) %>


/**
Expand Down
Loading

0 comments on commit bda7c9d

Please sign in to comment.