Skip to content

Commit 6500398

Browse files
author
Jonathan Casarrubias
committed
Release 2.1.0-beta.5
- Fix: #137 - Fix: #136 - Fix: #135 - Fix: #134 - Fix: #125
1 parent 963dd12 commit 6500398

22 files changed

Lines changed: 480 additions & 372 deletions

File tree

lib/angular2/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ module.exports = function generate(ctx) {
217217
buildRouteParams: buildRouteParams,
218218
buildMethodParams: buildMethodParams,
219219
buildServiceImports: buildServiceImports,
220-
normalizeMethodName: normalizeMethodName
220+
normalizeMethodName: normalizeMethodName,
221+
buildObservableType: buildObservableType
221222
}
222223
}
223224
]);
@@ -294,6 +295,17 @@ module.exports = function generate(ctx) {
294295
? basicType : `Array<${basicType}>`;
295296
return finalType;
296297
}
298+
/**
299+
* @method buildObservableType
300+
* @description
301+
* Define observable type
302+
*/
303+
function buildObservableType(modelName, methodName) {
304+
let type = 'any';
305+
if (methodName.match(/(^createMany$|^find)/g)) type = `Array<${modelName}>`;
306+
if (methodName.match(/(^create$|upsert|^findById$|^findOne$)/g)) type = modelName;
307+
return type;
308+
}
297309
/**
298310
* @method buildServiceImports
299311
* @description
@@ -316,6 +328,7 @@ module.exports = function generate(ctx) {
316328
{ module: 'JSONSearchParams', from: '../core/search.params'},
317329
{ module: 'ErrorHandler', from: '../core/error.service'},
318330
{ module: 'Subject', from: 'rxjs/Subject'},
331+
{ module: 'Observable', from: 'rxjs/Observable'},
319332
{ module: 'rxjs/add/operator/map' },
320333
{ module: modelName, from: `../../models/${modelName}`},
321334
];
@@ -394,6 +407,7 @@ module.exports = function generate(ctx) {
394407
{ module: 'LoopBackAuth', from: './auth.service'},
395408
{ module: 'LoopBackConfig', from: '../../lb.config'},
396409
{ module: 'AccessToken', from: '../../models'},
410+
{ module: 'ErrorObservable', from: 'rxjs/observable/ErrorObservable' },
397411
{ module: 'rxjs/add/operator/catch' },
398412
{ module: 'rxjs/add/operator/map' },
399413
];

lib/angular2/shared/index.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ export * from './lb.config';
6767
<% if ( isIo === 'enabled' ){ -%>export * from './sockets/index';
6868
<% }
6969
-%>
70+

lib/angular2/shared/models/flref.ejs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { Subject } from 'rxjs/Subject';
22
import { Observable } from 'rxjs/Observable';
3-
import { LoopBackConfig } from '../lb.config';
4-
import { AccessToken, LoopBackFilter } from './index';
5-
import { SocketConnections } from '../sockets/socket.connections';
3+
import { LoopBackFilter } from './index';
64

75
export class FireLoopRef<T> {
86

@@ -19,7 +17,7 @@ export class FireLoopRef<T> {
1917
this.socket = socket;
2018
return this;
2119
}
22-
20+
2321
public upsert(data: any): Observable<T> {
2422
let id: number = Math.floor(Math.random() * 100800) *
2523
Math.floor(Math.random() * 100700) *
@@ -44,8 +42,9 @@ export class FireLoopRef<T> {
4442
event = `${this.name}.${event}`;
4543
if (this.observables[event]) { return this.observables[event]; }
4644
let subject: Subject<T> = new Subject<T>();
47-
if (event.match(/(value)/))
48-
this.pull(event, filter, subject);
45+
if (event.match(/(value)/)) {
46+
this.pull(event, filter, subject);
47+
}
4948
// Listen for broadcast announces
5049
this.socket.on(
5150
// When there is a broadcast announce
@@ -80,4 +79,4 @@ export class FireLoopRef<T> {
8079
// TODO ADD UNLIMITED LEVELS
8180
}
8281
}
83-
}
82+
}

lib/angular2/shared/models/index.ejs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export * from './<%- modelName %>';
99
export * from './BaseModels';
1010
<% if ( isIo === 'enabled' ){ -%>export * from './FireLoopRef';
1111
<% }
12-
-%>
12+
-%>
13+

lib/angular2/shared/services/custom/service.ejs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class <%-: modelName %>Api extends BaseLoopBackApi {
3434
ngdocForMethod(modelName, methodName, action, httpVerb, fullPath);
3535
3636
if (methodName === 'createChangeStream') { -%>
37-
public createChangeStream() {
37+
public createChangeStream(): Observable<any> {
3838
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
3939
<%-: fullPath | q %>;
4040
let subject = new Subject();
@@ -68,7 +68,7 @@ export class <%-: modelName %>Api extends BaseLoopBackApi {
6868
return (param.http && param.http.source === 'path') || (param.arg && param.arg.match(/(id|fk|file|container)/));
6969
});
7070
-%>
71-
public <%- normalizeMethodName(methodName) %>(<%- buildMethodParams(model, methodName, action.accepts) %>) {
71+
public <%- normalizeMethodName(methodName) %>(<%- buildMethodParams(model, methodName, action.accepts) %>): Observable<<%- buildObservableType(modelName, methodName) %>> {
7272
let method: string = <%-: httpVerb | q %>;
7373
let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
7474
<%-: fullPath | q %>;
@@ -92,7 +92,7 @@ if (model.isUser && methodName === 'login') { %>
9292
);
9393
return result;
9494
<%
95-
} else if (methodName.match(/(^create$|upsert|findById|findOne)/g)) { %>;
95+
} else if (methodName.match(/(^create$|upsert|^findById$|^findOne$)/g)) { %>;
9696
return result.map((instance: <%- modelName %>) => new <%-: modelName %>(instance));<%
9797
} else if (methodName.match(/(^createMany$|^find)/g)) { %>;
9898
return result.map((instances: Array<<%- modelName %>>) =>
@@ -110,15 +110,24 @@ if (model.isUser && methodName === 'login') { %>
110110
httpVerb !== 'HEAD'){
111111
-%>
112112
113-
public on<%- normalizeMethodName(methodName, true) %>(<%- buildMethodParams(model, methodName, action.accepts, true) %>) {
113+
public on<%- normalizeMethodName(methodName, true) %>(<%- buildMethodParams(model, methodName, action.accepts, true) %>): Observable<<%- buildObservableType(modelName, methodName) %>> {
114114
let method: string = <%-: httpVerb | q %>;
115115
let url: string = "/" + LoopBackConfig.getApiVersion() +
116116
<%-: fullPath | q %>;
117117
let routeParams: any = {<%- buildRouteParams(routeParams.filter(function(param) { return param.arg !== 'fk'; })) %>};
118118
let postBody: any = {};
119119
let urlParams: any = {};
120120
let result = this.request(method, url, routeParams, urlParams, postBody, true);
121-
return result;
121+
<%
122+
if (methodName.match(/(^create$|upsert|^findById$|^findOne$)/g)) { %>
123+
return result.map((instance: <%- modelName %>) => new <%-: modelName %>(instance));<%
124+
} else if (methodName.match(/(^createMany$|^find)/g)) { %>;
125+
return result.map((instances: Array<<%- modelName %>>) =>
126+
instances.map((instance: <%- modelName %>) => new <%-: modelName %>(instance))
127+
);<%
128+
} else { %>;
129+
return result;<%
130+
} %>
122131
}
123132
<% }} -%>
124133
<% }); // model.methods.foreach -%>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mean-expert/loopback-sdk-builder",
3-
"version": "2.1.0-beta.4",
3+
"version": "2.1.0-beta.5",
44
"description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack",
55
"bin": {
66
"lb-sdk": "bin/lb-sdk"

tests/angular2/src/app/room-service.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('Service: Room Service', () => {
110110
});
111111
})
112112
));
113-
113+
114114
/**
115115
It can not be tested for now because a strange Angular 2 error (No info available)
116116
This is tested running the Test Application using ng serve instead.

tests/angular2/src/app/shared/sdk/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ export class SDKModule {
8888
export * from './models/index';
8989
export * from './services/index';
9090
export * from './lb.config';
91-
export * from './sockets/index';
91+
export * from './sockets/index';

tests/angular2/src/app/shared/sdk/models/FireLoopRef.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { Subject } from 'rxjs/Subject';
22
import { Observable } from 'rxjs/Observable';
3-
import { LoopBackConfig } from '../lb.config';
4-
import { AccessToken, LoopBackFilter } from './index';
5-
import { SocketConnections } from '../sockets/socket.connections';
3+
import { LoopBackFilter } from './index';
64

75
export class FireLoopRef<T> {
86

@@ -19,7 +17,7 @@ export class FireLoopRef<T> {
1917
this.socket = socket;
2018
return this;
2119
}
22-
20+
2321
public upsert(data: any): Observable<T> {
2422
let id: number = Math.floor(Math.random() * 100800) *
2523
Math.floor(Math.random() * 100700) *
@@ -44,8 +42,9 @@ export class FireLoopRef<T> {
4442
event = `${this.name}.${event}`;
4543
if (this.observables[event]) { return this.observables[event]; }
4644
let subject: Subject<T> = new Subject<T>();
47-
if (event.match(/(value)/))
48-
this.pull(event, filter, subject);
45+
if (event.match(/(value)/)) {
46+
this.pull(event, filter, subject);
47+
}
4948
// Listen for broadcast announces
5049
this.socket.on(
5150
// When there is a broadcast announce
@@ -80,4 +79,4 @@ export class FireLoopRef<T> {
8079
// TODO ADD UNLIMITED LEVELS
8180
}
8281
}
83-
}
82+
}

tests/angular2/src/app/shared/sdk/models/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ export * from './RoomAccount';
1111
export * from './Storage';
1212
export * from './Core';
1313
export * from './BaseModels';
14-
export * from './FireLoopRef';
14+
export * from './FireLoopRef';

0 commit comments

Comments
 (0)