Skip to content

Commit

Permalink
Release 2.1.0-beta.5
Browse files Browse the repository at this point in the history
- Fix: #137
- Fix: #136
- Fix: #135
- Fix: #134
- Fix: #125
  • Loading branch information
Jonathan Casarrubias committed Oct 3, 2016
1 parent 963dd12 commit 6500398
Show file tree
Hide file tree
Showing 22 changed files with 480 additions and 372 deletions.
16 changes: 15 additions & 1 deletion lib/angular2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ module.exports = function generate(ctx) {
buildRouteParams: buildRouteParams,
buildMethodParams: buildMethodParams,
buildServiceImports: buildServiceImports,
normalizeMethodName: normalizeMethodName
normalizeMethodName: normalizeMethodName,
buildObservableType: buildObservableType
}
}
]);
Expand Down Expand Up @@ -294,6 +295,17 @@ module.exports = function generate(ctx) {
? basicType : `Array<${basicType}>`;
return finalType;
}
/**
* @method buildObservableType
* @description
* Define observable type
*/
function buildObservableType(modelName, methodName) {
let type = 'any';
if (methodName.match(/(^createMany$|^find)/g)) type = `Array<${modelName}>`;
if (methodName.match(/(^create$|upsert|^findById$|^findOne$)/g)) type = modelName;
return type;
}
/**
* @method buildServiceImports
* @description
Expand All @@ -316,6 +328,7 @@ module.exports = function generate(ctx) {
{ module: 'JSONSearchParams', from: '../core/search.params'},
{ module: 'ErrorHandler', from: '../core/error.service'},
{ module: 'Subject', from: 'rxjs/Subject'},
{ module: 'Observable', from: 'rxjs/Observable'},
{ module: 'rxjs/add/operator/map' },
{ module: modelName, from: `../../models/${modelName}`},
];
Expand Down Expand Up @@ -394,6 +407,7 @@ module.exports = function generate(ctx) {
{ module: 'LoopBackAuth', from: './auth.service'},
{ module: 'LoopBackConfig', from: '../../lb.config'},
{ module: 'AccessToken', from: '../../models'},
{ module: 'ErrorObservable', from: 'rxjs/observable/ErrorObservable' },
{ module: 'rxjs/add/operator/catch' },
{ module: 'rxjs/add/operator/map' },
];
Expand Down
1 change: 1 addition & 0 deletions lib/angular2/shared/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ export * from './lb.config';
<% if ( isIo === 'enabled' ){ -%>export * from './sockets/index';
<% }
-%>

13 changes: 6 additions & 7 deletions lib/angular2/shared/models/flref.ejs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';
import { LoopBackConfig } from '../lb.config';
import { AccessToken, LoopBackFilter } from './index';
import { SocketConnections } from '../sockets/socket.connections';
import { LoopBackFilter } from './index';

export class FireLoopRef<T> {

Expand All @@ -19,7 +17,7 @@ export class FireLoopRef<T> {
this.socket = socket;
return this;
}

public upsert(data: any): Observable<T> {
let id: number = Math.floor(Math.random() * 100800) *
Math.floor(Math.random() * 100700) *
Expand All @@ -44,8 +42,9 @@ export class FireLoopRef<T> {
event = `${this.name}.${event}`;
if (this.observables[event]) { return this.observables[event]; }
let subject: Subject<T> = new Subject<T>();
if (event.match(/(value)/))
this.pull(event, filter, subject);
if (event.match(/(value)/)) {
this.pull(event, filter, subject);
}
// Listen for broadcast announces
this.socket.on(
// When there is a broadcast announce
Expand Down Expand Up @@ -80,4 +79,4 @@ export class FireLoopRef<T> {
// TODO ADD UNLIMITED LEVELS
}
}
}
}
3 changes: 2 additions & 1 deletion lib/angular2/shared/models/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export * from './<%- modelName %>';
export * from './BaseModels';
<% if ( isIo === 'enabled' ){ -%>export * from './FireLoopRef';
<% }
-%>
-%>

19 changes: 14 additions & 5 deletions lib/angular2/shared/services/custom/service.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class <%-: modelName %>Api extends BaseLoopBackApi {
ngdocForMethod(modelName, methodName, action, httpVerb, fullPath);
if (methodName === 'createChangeStream') { -%>
public createChangeStream() {
public createChangeStream(): Observable<any> {
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
<%-: fullPath | q %>;
let subject = new Subject();
Expand Down Expand Up @@ -68,7 +68,7 @@ export class <%-: modelName %>Api extends BaseLoopBackApi {
return (param.http && param.http.source === 'path') || (param.arg && param.arg.match(/(id|fk|file|container)/));
});
-%>
public <%- normalizeMethodName(methodName) %>(<%- buildMethodParams(model, methodName, action.accepts) %>) {
public <%- normalizeMethodName(methodName) %>(<%- buildMethodParams(model, methodName, action.accepts) %>): Observable<<%- buildObservableType(modelName, methodName) %>> {
let method: string = <%-: httpVerb | q %>;
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
<%-: fullPath | q %>;
Expand All @@ -92,7 +92,7 @@ if (model.isUser && methodName === 'login') { %>
);
return result;
<%
} else if (methodName.match(/(^create$|upsert|findById|findOne)/g)) { %>;
} else if (methodName.match(/(^create$|upsert|^findById$|^findOne$)/g)) { %>;
return result.map((instance: <%- modelName %>) => new <%-: modelName %>(instance));<%
} else if (methodName.match(/(^createMany$|^find)/g)) { %>;
return result.map((instances: Array<<%- modelName %>>) =>
Expand All @@ -110,15 +110,24 @@ if (model.isUser && methodName === 'login') { %>
httpVerb !== 'HEAD'){
-%>
public on<%- normalizeMethodName(methodName, true) %>(<%- buildMethodParams(model, methodName, action.accepts, true) %>) {
public on<%- normalizeMethodName(methodName, true) %>(<%- buildMethodParams(model, methodName, action.accepts, true) %>): Observable<<%- buildObservableType(modelName, methodName) %>> {
let method: string = <%-: httpVerb | q %>;
let url: string = "/" + LoopBackConfig.getApiVersion() +
<%-: fullPath | q %>;
let routeParams: any = {<%- buildRouteParams(routeParams.filter(function(param) { return param.arg !== 'fk'; })) %>};
let postBody: any = {};
let urlParams: any = {};
let result = this.request(method, url, routeParams, urlParams, postBody, true);
return result;
<%
if (methodName.match(/(^create$|upsert|^findById$|^findOne$)/g)) { %>
return result.map((instance: <%- modelName %>) => new <%-: modelName %>(instance));<%
} else if (methodName.match(/(^createMany$|^find)/g)) { %>;
return result.map((instances: Array<<%- modelName %>>) =>
instances.map((instance: <%- modelName %>) => new <%-: modelName %>(instance))
);<%
} else { %>;
return result;<%
} %>
}
<% }} -%>
<% }); // model.methods.foreach -%>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mean-expert/loopback-sdk-builder",
"version": "2.1.0-beta.4",
"version": "2.1.0-beta.5",
"description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack",
"bin": {
"lb-sdk": "bin/lb-sdk"
Expand Down
2 changes: 1 addition & 1 deletion tests/angular2/src/app/room-service.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('Service: Room Service', () => {
});
})
));

/**
It can not be tested for now because a strange Angular 2 error (No info available)
This is tested running the Test Application using ng serve instead.
Expand Down
2 changes: 1 addition & 1 deletion tests/angular2/src/app/shared/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ export class SDKModule {
export * from './models/index';
export * from './services/index';
export * from './lb.config';
export * from './sockets/index';
export * from './sockets/index';
13 changes: 6 additions & 7 deletions tests/angular2/src/app/shared/sdk/models/FireLoopRef.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';
import { LoopBackConfig } from '../lb.config';
import { AccessToken, LoopBackFilter } from './index';
import { SocketConnections } from '../sockets/socket.connections';
import { LoopBackFilter } from './index';

export class FireLoopRef<T> {

Expand All @@ -19,7 +17,7 @@ export class FireLoopRef<T> {
this.socket = socket;
return this;
}

public upsert(data: any): Observable<T> {
let id: number = Math.floor(Math.random() * 100800) *
Math.floor(Math.random() * 100700) *
Expand All @@ -44,8 +42,9 @@ export class FireLoopRef<T> {
event = `${this.name}.${event}`;
if (this.observables[event]) { return this.observables[event]; }
let subject: Subject<T> = new Subject<T>();
if (event.match(/(value)/))
this.pull(event, filter, subject);
if (event.match(/(value)/)) {
this.pull(event, filter, subject);
}
// Listen for broadcast announces
this.socket.on(
// When there is a broadcast announce
Expand Down Expand Up @@ -80,4 +79,4 @@ export class FireLoopRef<T> {
// TODO ADD UNLIMITED LEVELS
}
}
}
}
2 changes: 1 addition & 1 deletion tests/angular2/src/app/shared/sdk/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export * from './RoomAccount';
export * from './Storage';
export * from './Core';
export * from './BaseModels';
export * from './FireLoopRef';
export * from './FireLoopRef';
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 { ErrorObservable } from 'rxjs/observable/ErrorObservable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import { Subject } from 'rxjs/Subject';
Expand Down
Loading

0 comments on commit 6500398

Please sign in to comment.