Skip to content

Commit

Permalink
Merge pull request #299 from mean-expert-official/development
Browse files Browse the repository at this point in the history
Release 2.1.0-rc.8
  • Loading branch information
jonathan-casarrubias authored Jan 6, 2017
2 parents 9ddbdb8 + eeb3b78 commit 3983103
Show file tree
Hide file tree
Showing 47 changed files with 1,038 additions and 499 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

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

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

- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/297
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/296
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/295
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/292
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/290
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/288
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/285
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/284

## Release 2.1.0-rc.7

- Milestone Details: https://github.com/mean-expert-official/loopback-sdk-builder/milestone/29?closed=1
Expand Down
25 changes: 12 additions & 13 deletions lib/angular2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,6 @@ module.exports = function generate(ctx) {
modelName: modelName,
plural: ctx.models[modelName].sharedClass.ctor.settings.plural
|| ejs.filters.pluralize(modelName),
buildModelImports: buildModelImports,
buildModelProperties: buildModelProperties,
buildPropertyType: buildPropertyType,
buildPropertyDefaultValue: buildPropertyDefaultValue,
buildRelationType: buildRelationType,
Expand Down Expand Up @@ -427,12 +425,11 @@ 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: 'Observable', from: 'rxjs/Rx'},
{ module: modelName, from: `../../models/${modelName}`},
];
if (isIo === 'enabled') {
imports.push({ module: 'SocketConnections', from: '../../sockets/socket.connections' });
imports.push({ module: 'SocketConnection', from: '../../sockets/socket.connections' });
}
let loaded = {}; loaded[model.name] = true;
getModelRelations(model).forEach((relationName, i) => {
Expand Down Expand Up @@ -510,7 +507,7 @@ module.exports = function generate(ctx) {
if (isIo === 'enabled') {
imports = imports.concat([
{ module: 'SocketDriver', from: './sockets/socket.driver'},
{ module: 'SocketConnections', from: './sockets/socket.connections'},
{ module: 'SocketConnection', from: './sockets/socket.connections'},
{ module: 'RealTime', from: './services/core/real.time'}
]);
}
Expand Down Expand Up @@ -568,7 +565,7 @@ module.exports = function generate(ctx) {
*/
function buildNgProviders(isIo) {
let imports = ['ErrorHandler'];
if (isIo === 'enabled') { imports.push('SocketConnections'); }
if (isIo === 'enabled') { imports.push('SocketConnection'); }
return imports.join(',\n ');
}
/**
Expand All @@ -579,7 +576,7 @@ module.exports = function generate(ctx) {
function buildServiceDI(isIo) {
let dependencies = ['@Inject(Http) protected http: Http'];
if (isIo === 'enabled') {
dependencies.push('@Inject(SocketConnections) protected connections: SocketConnections');
dependencies.push('@Inject(SocketConnection) protected connection: SocketConnection');
}
dependencies = dependencies.concat([
'@Inject(SDKModels) protected models: SDKModels',
Expand Down Expand Up @@ -613,7 +610,7 @@ module.exports = function generate(ctx) {
];

if (isIo === 'enabled') {
imports.push({ module: 'SocketConnections', from: '../../sockets/socket.connections'});
imports.push({ module: 'SocketConnection', from: '../../sockets/socket.connections'});
}

return buildImports(imports);
Expand Down Expand Up @@ -672,7 +669,7 @@ module.exports = function generate(ctx) {
);
if (isIo) params = params.filter(param => !param.arg.match(/(fk|data|options)/));
params.forEach((param, i, arr) => {
let type;
let type, isArray = false;
if (param.type === 'object') {
type = param.arg === 'filter' ? 'LoopBackFilter' : 'any';
} else {
Expand All @@ -685,17 +682,19 @@ module.exports = function generate(ctx) {
let value = '';
// Accept Array on createMany method.
if (methodName.match(/createMany/) && param.arg === 'data') {
type = `Array<${type}>`;
isArray = true;
}
// Set default value, usually will be {}, but on login we include user
// Should not be undefined or will create request issues
if (!param.required && methodName === 'login' && param.arg === 'include') {
type = 'any';
value = " = 'user'";
} else if (type.match(/(any|LoopBackFilter)/)) {
value = !param.required ? ` = ${ isArray ? '[]' : '{}' }`: '';
} else {
value = !param.required ? ` = ${ type.match(/Array/) ? '[]' : '{}' }`: '';
value = !param.required ? ` = ${ isArray ? `new Array<${type}>()` : `new ${type}()` }`: '';
}
output.push(`${param.arg}: ${type}${value}`);
output.push(`${param.arg}: ${type}${ isArray ? '[]' : '' }${value}`);
});

// When login, there is a property not coming from LoopBack that is needed.
Expand Down
87 changes: 71 additions & 16 deletions lib/angular2/shared/models/base.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* tslint:disable */
<% if (!loadAccessToken) { %>
import { AccessToken } from './AccessToken';
import { AccessToken, AccessTokenInterface } from './AccessToken';
export * from './AccessToken';
<% } %>
declare var Object: any;
export interface LoopBackFilter {
Expand All @@ -17,34 +18,88 @@ export interface AccessTokenInterface {
id?: string;
ttl?: number;
issuedAt?: any;
created?: any;
created: any;
userId?: string;
rememberMe?: boolean;
}
export class AccessToken implements AccessTokenInterface {
id:string;
ttl: number;
issuedAt?: any;
created?: any;
userId: string;
user: any;
rememberMe: boolean = null;
constructor(instance?: AccessToken) {
Object.assign(this, instance);
id: string = '';
ttl: number = 1209600;
created: Date = new Date(0);
userId: number = 0;
user: User = null;
constructor(data?: AccessTokenInterface) {
Object.assign(this, data);
}
/**
* The name of the model represented by this $resource,
* i.e. `AccessToken`.
*/
public static getModelName() {
return "AccessToken";
}
/**
* @method factory
* @author Jonathan Casarrubias
* @license MIT
* This method creates an instance of AccessToken for dynamic purposes.
**/
public static factory(data: AccessTokenInterface): AccessToken{
return new AccessToken(data);
}
/**
* @method getModelDefinition
* @author Julien Ledun
* @license MIT
* This method returns an object that represents some of the model
* definitions.
**/
public static getModelDefinition() {
return {
name: 'AccessToken',
plural: 'AccessTokens',
properties: {
id: {
name: 'id',
type: 'string'
},
ttl: {
name: 'ttl',
type: 'number',
default: 1209600
},
created: {
name: 'created',
type: 'Date',
default: new Date(0)
},
userId: {
name: 'userId',
type: 'number'
},
},
relations: {
user: {
name: 'user',
type: 'User',
model: 'User'
},
}
}
}
}
<% } %>
export class SDKToken extends AccessToken {
export class SDKToken implements AccessTokenInterface {
id: any = null;
ttl: number = null;
issuedAt?: any = null;
created?: any = null;
issuedAt: any = null;
created: any = null;
userId: any = null;
user: any = null;
rememberMe: boolean = null;
constructor(instance?: AccessToken) {
super(instance);
constructor(data?: AccessTokenInterface) {
Object.assign(this, data);
}
}

Expand Down
1 change: 0 additions & 1 deletion lib/angular2/shared/models/fireloop.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export class FireLoop {

public ref<T>(model: any): FireLoopRef<T> {
let name: string = model.getModelName();
if (this.references[name]) { return this.references[name]; }
model.models = this.models;
this.references[name] = new FireLoopRef<T>(model, this.socket);
return this.references[name];
Expand Down
82 changes: 71 additions & 11 deletions lib/angular2/shared/models/flref.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Rx';
import { LoopBackFilter, StatFilter } from './index';
import { SocketConnection } from '../sockets/socket.connections';
/**
* @class FireLoopRef<T>
* @author Jonathan Casarrubias <t: johncasarrubias, gh: mean-expert-official>
Expand Down Expand Up @@ -31,7 +32,7 @@ export class FireLoopRef<T> {
**/
constructor(
private model: any,
private socket: any,
private socket: SocketConnection,
private parent: any = null,
private relationship: any = null
) {
Expand All @@ -42,6 +43,21 @@ export class FireLoopRef<T> {
return this;
}
/**
* @method dispose
* @description
* This method is super important to avoid memory leaks in the server.
* This method requires to be called on components destroy
*
* ngOnDestroy() {
* this.someRef.dispose()
* }
**/
public dispose() {
this.operation('dispose', {})
.subscribe()
.unsubscribe();
}
/**
* @method upsert
* @param data
* @description
Expand All @@ -51,7 +67,7 @@ export class FireLoopRef<T> {
return this.operation('upsert', data);
}
/**
* @method upsert
* @method create
* @param data
* @description
* Operation wrapper for create function.
Expand All @@ -60,7 +76,7 @@ export class FireLoopRef<T> {
return this.operation('create', data);
}
/**
* @method upsert
* @method remove
* @param data
* @description
* Operation wrapper for remove function.
Expand All @@ -69,6 +85,37 @@ export class FireLoopRef<T> {
return this.operation('remove', data);
}
/**
* @method remote
* @param method
* @param params
* @description
* This method calls for any remote method. It is flexible enough to
* allow you call either built-in or custom remote methods.
*
* FireLoop provides this interface to enable calling remote methods
* but also to optionally send any defined accept params that will be
* applied within the server.
**/
public remote(method: string, params?: any[], broadcast: Boolean = false): Observable<T> {
return this.operation('remote', { method, params, broadcast });
}
/**
* @method onRemote
* @param method
* @param params
* @description
* This method listen for public .
**/
public onRemote(method: string): Observable<T> {
let event: string = 'remote';
if (!this.relationship) {
event = `${ this.model.getModelName() }.${event}`;
} else {
event = `${ this.parent.model.getModelName() }.${ this.relationship }.${event}`;
}
return this.broadcasts(event, {});
}
/**
* @method on
* @param event
* @param filter
Expand All @@ -81,6 +128,9 @@ export class FireLoopRef<T> {
* - child_removed (Triggers when a child is removed)
**/
public on(event: string, filter: LoopBackFilter = { limit: 100, order: 'id DESC' }): Observable<T | T[]> {
if (event === 'remote') {
throw new Error('The "remote" event is not allowed using "on()" method, use "onRemote()" instead');
}
let request: any;
if (!this.relationship) {
event = `${ this.model.getModelName() }.${event}`;
Expand Down Expand Up @@ -113,8 +163,12 @@ export class FireLoopRef<T> {
* @method make
* @param instance
* @description
* This method will set a model instance into this current FireLoop Reference.
* This method will set a model instance into this a new FireLoop Reference.
* This allows to persiste parentship when creating related instances.
*
* It also allows to have multiple different persisted instance references to same model.
* otherwise if using singleton will replace a previous instance for a new instance, when
* we actually want to have more than 1 instance of same model.
**/
public make(instance: any): FireLoopRef<T> {
let reference: FireLoopRef<T> = new FireLoopRef<T>(this.model, this.socket);
Expand Down Expand Up @@ -165,7 +219,7 @@ export class FireLoopRef<T> {
}
sbj.next(data);
};
this.socket.onZone(nowEvent, pullNow);
this.socket.on(nowEvent, pullNow);
return sbj.asObservable();
}
/**
Expand All @@ -176,12 +230,12 @@ export class FireLoopRef<T> {
**/
private broadcasts(event: string, request: any): Observable<T> {
let sbj: Subject<T> = new Subject<T>();
this.socket.onZone(
this.socket.on(
`${event}.broadcast.announce.${ this.id }`,
(res: T) =>
this.socket.emit(`${event}.broadcast.request.${ this.id }`, request)
);
this.socket.onZone(`${ event }.broadcast.${ this.id }`, (data: any) => sbj.next(data));
this.socket.on(`${ event }.broadcast.${ this.id }`, (data: any) => sbj.next(data));
return sbj.asObservable();
}
/**
Expand All @@ -203,10 +257,16 @@ export class FireLoopRef<T> {
parent: this.parent && this.parent.instance ? this.parent.instance : null
};
this.socket.emit(event, config);
this.socket.onZone(`${ this.model.getModelName() }.value.result.${ this.id }`, (res: any) =>
subject.next(res.error ? Observable.throw(res.error) : res)
);
return subject.asObservable();
this.socket.on(`${ this.model.getModelName() }.value.result.${ this.id }`, (res: any) => {
if (res.error) {
subject.error(res);
} else {
subject.next(res);
}
});
// 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));
}
/**
* @method buildId
Expand Down
Loading

0 comments on commit 3983103

Please sign in to comment.