Skip to content

Commit

Permalink
Release 2.1.0-rc.13.5 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Casarrubias committed Aug 18, 2017
1 parent 592a4ca commit 7bde747
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 69 deletions.
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-rc.13.5

- Milestone Details: https://github.com/mean-expert-official/loopback-sdk-builder/milestone/47?closed=1

- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/482
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/481
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/480
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/475

## Release 2.1.0-rc.13.4

- Replaces Release 2.1.0-rc.13.3
Expand Down
38 changes: 33 additions & 5 deletions lib/angular2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,31 @@ module.exports = function generate(ctx) {
function paramIsContext(param) {
return (typeof param.http !== 'undefined' && typeof param.http.source !== 'undefined' && param.http.source === 'context');
}
/**
* @method paramIsBody
* @description
* Testing if the param is a http.body or form
*/
function paramIsBody(param) {
return (typeof param.http !== 'undefined' && typeof param.http.source !== 'undefined' && (param.http.source == 'body' || param.http.source == 'form'));
}
/**
* @method paramIsQuery
* @description
* Testing if the param is a http.query or form
*/
function paramIsQuery(param) {
return (
(
typeof param.http === 'undefined' && // Query is default, if http is not defined we treat it as query param
(param.arg && !param.arg.match(/(^id$|fk|^file$|container)/)) // But only if it is not id, fk, file or container
)
||
(
typeof param.http !== 'undefined' && typeof param.http.source !== 'undefined' && param.http.source == 'query'
)
);
}
/**
* @method buildPostBody
* @description
Expand All @@ -786,11 +811,11 @@ module.exports = function generate(ctx) {
if (Array.isArray(postData)) {
postData = postData.filter(param => {
// Filter out route params and function params
if (paramIsRoute(param) || paramIsFunction(param)) {
if (paramIsRoute(param) || paramIsFunction(param) || paramIsContext(param) || paramIsQuery(param)) {
return false
}
// Make sure the param is body or form data
return param.http && (param.http.source == 'body' || param.http.source == 'form')
return paramIsBody(param);
})
if (postData.length > 0) {
output.push('');
Expand Down Expand Up @@ -826,11 +851,11 @@ module.exports = function generate(ctx) {
// filter params that should not go over url query string
urlParams = urlParams.filter(param => {
// Filter out route params and function params
if (paramIsRoute(param) || paramIsFunction(param) || paramIsContext(param)) {
if (paramIsRoute(param) || paramIsFunction(param) || paramIsContext(param) || paramIsBody(param)) {
return false
}
// Filter out body params
return (!param.http || param.http.source != 'body')
return paramIsQuery(param);
});
if (model.isUser && methodName === 'logout')
output.push(` _urlParams.access_token = this.auth.getAccessTokenId();`);
Expand All @@ -850,7 +875,10 @@ module.exports = function generate(ctx) {
let output = [];
if (routeParams) {
routeParams = routeParams.filter((param) => {
return paramIsRoute(param) && !paramIsFunction(param)
if (paramIsQuery(param) || paramIsFunction(param) || paramIsContext(param) || paramIsBody(param)) {
return false
}
return paramIsRoute(param)
});
if (routeParams.length > 0) {
output.push('');
Expand Down
70 changes: 44 additions & 26 deletions lib/angular2/shared/models/flref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export class FireLoopRef<T> {
private instance: any;
// Model Childs
private childs: any = {};
// Disposable Events
private disposable: { [key: string]: any } = {};
/**
* @method constructor
* @param {any} model The model we want to create a reference
Expand All @@ -37,8 +39,8 @@ export class FireLoopRef<T> {
private relationship: string = null
) {
this.socket.emit(
`Subscribe.${ !parent ? model.getModelName() : parent.model.getModelName() }`,
{ id : this.id, scope: model.getModelName(), relationship: relationship }
`Subscribe.${!parent ? model.getModelName() : parent.model.getModelName()}`,
{ id: this.id, scope: model.getModelName(), relationship: relationship }
);
return this;
}
Expand All @@ -54,9 +56,13 @@ export class FireLoopRef<T> {
* }
**/
public dispose(): void {
this.operation('dispose', {})
.subscribe()
.unsubscribe();
const subscription = this.operation('dispose', {}).subscribe(() => {
Object.keys(this.disposable).forEach((channel: string) => {
this.socket.removeListener(channel, this.disposable[channel]);
this.socket.removeAllListeners(channel);
});
subscription.unsubscribe();
});
}
/**
* @method upsert
Expand Down Expand Up @@ -116,9 +122,9 @@ export class FireLoopRef<T> {
public onRemote(method: string): Observable<any> {
let event: string = 'remote';
if (!this.relationship) {
event = `${ this.model.getModelName() }.${event}`;
event = `${this.model.getModelName()}.${event}`;
} else {
event = `${ this.parent.model.getModelName() }.${ this.relationship }.${event}`;
event = `${this.parent.model.getModelName()}.${this.relationship}.${event}`;
}
return this.broadcasts(event, {});
}
Expand All @@ -141,10 +147,10 @@ export class FireLoopRef<T> {
}
let request: any;
if (!this.relationship) {
event = `${ this.model.getModelName() }.${event}`;
event = `${this.model.getModelName()}.${event}`;
request = { filter };
} else {
event = `${ this.parent.model.getModelName() }.${ this.relationship }.${event}`;
event = `${this.parent.model.getModelName()}.${this.relationship}.${event}`;
request = { filter, parent: this.parent.instance };
}
if (event.match(/(value|change|stats)/)) {
Expand Down Expand Up @@ -182,7 +188,7 @@ export class FireLoopRef<T> {
**/
public make(instance: any): FireLoopRef<T> {
let reference: FireLoopRef<T> = new FireLoopRef<T>(this.model, this.socket);
reference.instance = instance;
reference.instance = instance;
return reference;
}
/**
Expand All @@ -200,15 +206,15 @@ export class FireLoopRef<T> {
let settings: any = this.model.getModelDefinition().relations[relationship];
// Verify the relationship actually exists
if (!settings) {
throw new Error(`Invalid model relationship ${ this.model.getModelName() } <-> ${ relationship }, verify your model settings.`);
throw new Error(`Invalid model relationship ${this.model.getModelName()} <-> ${relationship}, verify your model settings.`);
}
// Verify if the relationship model is public
if (settings.model === '') {
throw new Error(`Relationship model is private, cam't use ${ relationship } unless you set your model as public.`);
throw new Error(`Relationship model is private, cam't use ${relationship} unless you set your model as public.`);
}
// Lets get a model reference and add a reference for all of the models
let model: any = this.model.models.get(settings.model);
model.models = this.model.models;
let model: any = this.model.models.get(settings.model);
model.models = this.model.models;
// If everything goes well, we will store a child reference and return it.
this.childs[relationship] = new FireLoopRef<T>(model, this.socket, this, relationship);
return this.childs[relationship];
Expand All @@ -224,8 +230,8 @@ export class FireLoopRef<T> {
private pull(event: string, request: any): Observable<T> {
let sbj: Subject<T> = new Subject<T>();
let that: FireLoopRef<T> = this;
let nowEvent: any = `${event}.pull.requested.${ this.id }`;
this.socket.emit(`${event}.pull.request.${ this.id }`, request);
let nowEvent: any = `${event}.pull.requested.${this.id}`;
this.socket.emit(`${event}.pull.request.${this.id}`, request);
function pullNow(data: any) {
if (that.socket.removeListener) {
that.socket.removeListener(nowEvent, pullNow);
Expand All @@ -246,12 +252,21 @@ export class FireLoopRef<T> {
**/
private broadcasts(event: string, request: any): Observable<T> {
let sbj: Subject<T> = new Subject<T>();
this.socket.on(
`${event}.broadcast.announce.${ this.id }`,
(res: T) =>
this.socket.emit(`${event}.broadcast.request.${ this.id }`, request)
);
this.socket.on(`${ event }.broadcast.${ this.id }`, (data: any) => sbj.next(data));
let channels: { announce: string, broadcast: string } = {
announce: `${event}.broadcast.announce.${this.id}`,
broadcast: `${event}.broadcast.${this.id}`
};
let that = this;
// Announces Handler
this.disposable[channels.announce] = function (res: T) {
that.socket.emit(`${event}.broadcast.request.${that.id}`, request)
};
// Broadcasts Handler
this.disposable[channels.broadcast] = function (data: any) {
sbj.next(data);
};
this.socket.on(channels.announce, this.disposable[channels.announce]);
this.socket.on(channels.broadcast, this.disposable[channels.broadcast]);
return sbj.asObservable();
}
/**
Expand All @@ -264,9 +279,9 @@ export class FireLoopRef<T> {
**/
private operation(event: string, data: any): Observable<T> {
if (!this.relationship) {
event = `${ this.model.getModelName() }.${event}.${ this.id }`;
event = `${this.model.getModelName()}.${event}.${this.id}`;
} else {
event = `${ this.parent.model.getModelName() }.${ this.relationship }.${ event }.${ this.id }`;
event = `${this.parent.model.getModelName()}.${this.relationship}.${event}.${this.id}`;
}
let subject: Subject<T> = new Subject<T>();
let config: { data: any, parent: any } = {
Expand All @@ -276,9 +291,9 @@ export class FireLoopRef<T> {
this.socket.emit(event, config);
let resultEvent: string = '';
if (!this.relationship) {
resultEvent = `${ this.model.getModelName()}.value.result.${ this.id }`;
resultEvent = `${this.model.getModelName()}.value.result.${this.id}`;
} else {
resultEvent = `${ this.parent.model.getModelName() }.${ this.relationship }.value.result.${ this.id }`;
resultEvent = `${this.parent.model.getModelName()}.${this.relationship}.value.result.${this.id}`;
}
this.socket.on(resultEvent, (res: any) => {
if (res.error) {
Expand All @@ -287,6 +302,9 @@ export class FireLoopRef<T> {
subject.next(res);
}
});
if (event.match('dispose')) {
setTimeout(() => subject.next());
}
// This event listener will be wiped within socket.connections
this.socket.sharedObservables.sharedOnDisconnect.subscribe(() => subject.complete());
return subject.asObservable().catch((error: any) => Observable.throw(error));
Expand Down
15 changes: 15 additions & 0 deletions lib/angular2/shared/sockets/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ export class SocketConnection {
this.socket.off(event, handler);
}
}
/**
* @method removeAllListeners
* @param {string} event Event name
* @param {Function} handler Event listener handler
* @return {void}
* @description
* This method will wrap the original "on" method and run it within the Angular Zone
* Note: off is being used since the nativescript socket io client does not provide
* removeListener method, but only provides with off which is provided in any platform.
**/
public removeAllListeners(event: string): void {
if (typeof this.socket.removeAllListeners === 'function') {
this.socket.removeAllListeners(event);
}
}
/**
* @method disconnect
* @return {void}
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-rc.13.4",
"version": "2.1.0-rc.13.5",
"description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack",
"bin": {
"lb-sdk": "bin/lb-sdk"
Expand Down
Loading

0 comments on commit 7bde747

Please sign in to comment.