Skip to content

Commit 3983103

Browse files
Merge pull request #299 from mean-expert-official/development
Release 2.1.0-rc.8
2 parents 9ddbdb8 + eeb3b78 commit 3983103

47 files changed

Lines changed: 1038 additions & 499 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
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`.
44

5+
## Release 2.1.0-rc.8
6+
7+
- Milestone Details: https://github.com/mean-expert-official/loopback-sdk-builder/milestone/30?closed=1
8+
9+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/297
10+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/296
11+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/295
12+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/292
13+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/290
14+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/288
15+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/285
16+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/284
17+
518
## Release 2.1.0-rc.7
619

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

lib/angular2/index.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ module.exports = function generate(ctx) {
265265
modelName: modelName,
266266
plural: ctx.models[modelName].sharedClass.ctor.settings.plural
267267
|| ejs.filters.pluralize(modelName),
268-
buildModelImports: buildModelImports,
269-
buildModelProperties: buildModelProperties,
270268
buildPropertyType: buildPropertyType,
271269
buildPropertyDefaultValue: buildPropertyDefaultValue,
272270
buildRelationType: buildRelationType,
@@ -427,12 +425,11 @@ module.exports = function generate(ctx) {
427425
{ module: 'JSONSearchParams', from: '../core/search.params'},
428426
{ module: 'ErrorHandler', from: '../core/error.service'},
429427
{ module: 'Subject', from: 'rxjs/Subject'},
430-
{ module: 'Observable', from: 'rxjs/Observable'},
431-
{ module: 'rxjs/add/operator/map' },
428+
{ module: 'Observable', from: 'rxjs/Rx'},
432429
{ module: modelName, from: `../../models/${modelName}`},
433430
];
434431
if (isIo === 'enabled') {
435-
imports.push({ module: 'SocketConnections', from: '../../sockets/socket.connections' });
432+
imports.push({ module: 'SocketConnection', from: '../../sockets/socket.connections' });
436433
}
437434
let loaded = {}; loaded[model.name] = true;
438435
getModelRelations(model).forEach((relationName, i) => {
@@ -510,7 +507,7 @@ module.exports = function generate(ctx) {
510507
if (isIo === 'enabled') {
511508
imports = imports.concat([
512509
{ module: 'SocketDriver', from: './sockets/socket.driver'},
513-
{ module: 'SocketConnections', from: './sockets/socket.connections'},
510+
{ module: 'SocketConnection', from: './sockets/socket.connections'},
514511
{ module: 'RealTime', from: './services/core/real.time'}
515512
]);
516513
}
@@ -568,7 +565,7 @@ module.exports = function generate(ctx) {
568565
*/
569566
function buildNgProviders(isIo) {
570567
let imports = ['ErrorHandler'];
571-
if (isIo === 'enabled') { imports.push('SocketConnections'); }
568+
if (isIo === 'enabled') { imports.push('SocketConnection'); }
572569
return imports.join(',\n ');
573570
}
574571
/**
@@ -579,7 +576,7 @@ module.exports = function generate(ctx) {
579576
function buildServiceDI(isIo) {
580577
let dependencies = ['@Inject(Http) protected http: Http'];
581578
if (isIo === 'enabled') {
582-
dependencies.push('@Inject(SocketConnections) protected connections: SocketConnections');
579+
dependencies.push('@Inject(SocketConnection) protected connection: SocketConnection');
583580
}
584581
dependencies = dependencies.concat([
585582
'@Inject(SDKModels) protected models: SDKModels',
@@ -613,7 +610,7 @@ module.exports = function generate(ctx) {
613610
];
614611

615612
if (isIo === 'enabled') {
616-
imports.push({ module: 'SocketConnections', from: '../../sockets/socket.connections'});
613+
imports.push({ module: 'SocketConnection', from: '../../sockets/socket.connections'});
617614
}
618615

619616
return buildImports(imports);
@@ -672,7 +669,7 @@ module.exports = function generate(ctx) {
672669
);
673670
if (isIo) params = params.filter(param => !param.arg.match(/(fk|data|options)/));
674671
params.forEach((param, i, arr) => {
675-
let type;
672+
let type, isArray = false;
676673
if (param.type === 'object') {
677674
type = param.arg === 'filter' ? 'LoopBackFilter' : 'any';
678675
} else {
@@ -685,17 +682,19 @@ module.exports = function generate(ctx) {
685682
let value = '';
686683
// Accept Array on createMany method.
687684
if (methodName.match(/createMany/) && param.arg === 'data') {
688-
type = `Array<${type}>`;
685+
isArray = true;
689686
}
690687
// Set default value, usually will be {}, but on login we include user
691688
// Should not be undefined or will create request issues
692689
if (!param.required && methodName === 'login' && param.arg === 'include') {
693690
type = 'any';
694691
value = " = 'user'";
692+
} else if (type.match(/(any|LoopBackFilter)/)) {
693+
value = !param.required ? ` = ${ isArray ? '[]' : '{}' }`: '';
695694
} else {
696-
value = !param.required ? ` = ${ type.match(/Array/) ? '[]' : '{}' }`: '';
695+
value = !param.required ? ` = ${ isArray ? `new Array<${type}>()` : `new ${type}()` }`: '';
697696
}
698-
output.push(`${param.arg}: ${type}${value}`);
697+
output.push(`${param.arg}: ${type}${ isArray ? '[]' : '' }${value}`);
699698
});
700699

701700
// When login, there is a property not coming from LoopBack that is needed.

lib/angular2/shared/models/base.ejs

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* tslint:disable */
22
<% if (!loadAccessToken) { %>
3-
import { AccessToken } from './AccessToken';
3+
import { AccessToken, AccessTokenInterface } from './AccessToken';
4+
export * from './AccessToken';
45
<% } %>
56
declare var Object: any;
67
export interface LoopBackFilter {
@@ -17,34 +18,88 @@ export interface AccessTokenInterface {
1718
id?: string;
1819
ttl?: number;
1920
issuedAt?: any;
20-
created?: any;
21+
created: any;
2122
userId?: string;
2223
rememberMe?: boolean;
2324
}
2425
2526
export class AccessToken implements AccessTokenInterface {
26-
id:string;
27-
ttl: number;
28-
issuedAt?: any;
29-
created?: any;
30-
userId: string;
31-
user: any;
32-
rememberMe: boolean = null;
33-
constructor(instance?: AccessToken) {
34-
Object.assign(this, instance);
27+
id: string = '';
28+
ttl: number = 1209600;
29+
created: Date = new Date(0);
30+
userId: number = 0;
31+
user: User = null;
32+
constructor(data?: AccessTokenInterface) {
33+
Object.assign(this, data);
34+
}
35+
/**
36+
* The name of the model represented by this $resource,
37+
* i.e. `AccessToken`.
38+
*/
39+
public static getModelName() {
40+
return "AccessToken";
41+
}
42+
/**
43+
* @method factory
44+
* @author Jonathan Casarrubias
45+
* @license MIT
46+
* This method creates an instance of AccessToken for dynamic purposes.
47+
**/
48+
public static factory(data: AccessTokenInterface): AccessToken{
49+
return new AccessToken(data);
50+
}
51+
/**
52+
* @method getModelDefinition
53+
* @author Julien Ledun
54+
* @license MIT
55+
* This method returns an object that represents some of the model
56+
* definitions.
57+
**/
58+
public static getModelDefinition() {
59+
return {
60+
name: 'AccessToken',
61+
plural: 'AccessTokens',
62+
properties: {
63+
id: {
64+
name: 'id',
65+
type: 'string'
66+
},
67+
ttl: {
68+
name: 'ttl',
69+
type: 'number',
70+
default: 1209600
71+
},
72+
created: {
73+
name: 'created',
74+
type: 'Date',
75+
default: new Date(0)
76+
},
77+
userId: {
78+
name: 'userId',
79+
type: 'number'
80+
},
81+
},
82+
relations: {
83+
user: {
84+
name: 'user',
85+
type: 'User',
86+
model: 'User'
87+
},
88+
}
3589
}
90+
}
3691
}
3792
<% } %>
38-
export class SDKToken extends AccessToken {
93+
export class SDKToken implements AccessTokenInterface {
3994
id: any = null;
4095
ttl: number = null;
41-
issuedAt?: any = null;
42-
created?: any = null;
96+
issuedAt: any = null;
97+
created: any = null;
4398
userId: any = null;
4499
user: any = null;
45100
rememberMe: boolean = null;
46-
constructor(instance?: AccessToken) {
47-
super(instance);
101+
constructor(data?: AccessTokenInterface) {
102+
Object.assign(this, data);
48103
}
49104
}
50105

lib/angular2/shared/models/fireloop.ejs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export class FireLoop {
88

99
public ref<T>(model: any): FireLoopRef<T> {
1010
let name: string = model.getModelName();
11-
if (this.references[name]) { return this.references[name]; }
1211
model.models = this.models;
1312
this.references[name] = new FireLoopRef<T>(model, this.socket);
1413
return this.references[name];

lib/angular2/shared/models/flref.ejs

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Subject } from 'rxjs/Subject';
22
import { Observable } from 'rxjs/Rx';
33
import { LoopBackFilter, StatFilter } from './index';
4+
import { SocketConnection } from '../sockets/socket.connections';
45
/**
56
* @class FireLoopRef<T>
67
* @author Jonathan Casarrubias <t: johncasarrubias, gh: mean-expert-official>
@@ -31,7 +32,7 @@ export class FireLoopRef<T> {
3132
**/
3233
constructor(
3334
private model: any,
34-
private socket: any,
35+
private socket: SocketConnection,
3536
private parent: any = null,
3637
private relationship: any = null
3738
) {
@@ -42,6 +43,21 @@ export class FireLoopRef<T> {
4243
return this;
4344
}
4445
/**
46+
* @method dispose
47+
* @description
48+
* This method is super important to avoid memory leaks in the server.
49+
* This method requires to be called on components destroy
50+
*
51+
* ngOnDestroy() {
52+
* this.someRef.dispose()
53+
* }
54+
**/
55+
public dispose() {
56+
this.operation('dispose', {})
57+
.subscribe()
58+
.unsubscribe();
59+
}
60+
/**
4561
* @method upsert
4662
* @param data
4763
* @description
@@ -51,7 +67,7 @@ export class FireLoopRef<T> {
5167
return this.operation('upsert', data);
5268
}
5369
/**
54-
* @method upsert
70+
* @method create
5571
* @param data
5672
* @description
5773
* Operation wrapper for create function.
@@ -60,7 +76,7 @@ export class FireLoopRef<T> {
6076
return this.operation('create', data);
6177
}
6278
/**
63-
* @method upsert
79+
* @method remove
6480
* @param data
6581
* @description
6682
* Operation wrapper for remove function.
@@ -69,6 +85,37 @@ export class FireLoopRef<T> {
6985
return this.operation('remove', data);
7086
}
7187
/**
88+
* @method remote
89+
* @param method
90+
* @param params
91+
* @description
92+
* This method calls for any remote method. It is flexible enough to
93+
* allow you call either built-in or custom remote methods.
94+
*
95+
* FireLoop provides this interface to enable calling remote methods
96+
* but also to optionally send any defined accept params that will be
97+
* applied within the server.
98+
**/
99+
public remote(method: string, params?: any[], broadcast: Boolean = false): Observable<T> {
100+
return this.operation('remote', { method, params, broadcast });
101+
}
102+
/**
103+
* @method onRemote
104+
* @param method
105+
* @param params
106+
* @description
107+
* This method listen for public .
108+
**/
109+
public onRemote(method: string): Observable<T> {
110+
let event: string = 'remote';
111+
if (!this.relationship) {
112+
event = `${ this.model.getModelName() }.${event}`;
113+
} else {
114+
event = `${ this.parent.model.getModelName() }.${ this.relationship }.${event}`;
115+
}
116+
return this.broadcasts(event, {});
117+
}
118+
/**
72119
* @method on
73120
* @param event
74121
* @param filter
@@ -81,6 +128,9 @@ export class FireLoopRef<T> {
81128
* - child_removed (Triggers when a child is removed)
82129
**/
83130
public on(event: string, filter: LoopBackFilter = { limit: 100, order: 'id DESC' }): Observable<T | T[]> {
131+
if (event === 'remote') {
132+
throw new Error('The "remote" event is not allowed using "on()" method, use "onRemote()" instead');
133+
}
84134
let request: any;
85135
if (!this.relationship) {
86136
event = `${ this.model.getModelName() }.${event}`;
@@ -113,8 +163,12 @@ export class FireLoopRef<T> {
113163
* @method make
114164
* @param instance
115165
* @description
116-
* This method will set a model instance into this current FireLoop Reference.
166+
* This method will set a model instance into this a new FireLoop Reference.
117167
* This allows to persiste parentship when creating related instances.
168+
*
169+
* It also allows to have multiple different persisted instance references to same model.
170+
* otherwise if using singleton will replace a previous instance for a new instance, when
171+
* we actually want to have more than 1 instance of same model.
118172
**/
119173
public make(instance: any): FireLoopRef<T> {
120174
let reference: FireLoopRef<T> = new FireLoopRef<T>(this.model, this.socket);
@@ -165,7 +219,7 @@ export class FireLoopRef<T> {
165219
}
166220
sbj.next(data);
167221
};
168-
this.socket.onZone(nowEvent, pullNow);
222+
this.socket.on(nowEvent, pullNow);
169223
return sbj.asObservable();
170224
}
171225
/**
@@ -176,12 +230,12 @@ export class FireLoopRef<T> {
176230
**/
177231
private broadcasts(event: string, request: any): Observable<T> {
178232
let sbj: Subject<T> = new Subject<T>();
179-
this.socket.onZone(
233+
this.socket.on(
180234
`${event}.broadcast.announce.${ this.id }`,
181235
(res: T) =>
182236
this.socket.emit(`${event}.broadcast.request.${ this.id }`, request)
183237
);
184-
this.socket.onZone(`${ event }.broadcast.${ this.id }`, (data: any) => sbj.next(data));
238+
this.socket.on(`${ event }.broadcast.${ this.id }`, (data: any) => sbj.next(data));
185239
return sbj.asObservable();
186240
}
187241
/**
@@ -203,10 +257,16 @@ export class FireLoopRef<T> {
203257
parent: this.parent && this.parent.instance ? this.parent.instance : null
204258
};
205259
this.socket.emit(event, config);
206-
this.socket.onZone(`${ this.model.getModelName() }.value.result.${ this.id }`, (res: any) =>
207-
subject.next(res.error ? Observable.throw(res.error) : res)
208-
);
209-
return subject.asObservable();
260+
this.socket.on(`${ this.model.getModelName() }.value.result.${ this.id }`, (res: any) => {
261+
if (res.error) {
262+
subject.error(res);
263+
} else {
264+
subject.next(res);
265+
}
266+
});
267+
// This event listener will be wiped within socket.connections
268+
this.socket.sharedObservables.sharedOnDisconnect.subscribe(() => subject.complete());
269+
return subject.asObservable().catch((error: any) => Observable.throw(error));
210270
}
211271
/**
212272
* @method buildId

0 commit comments

Comments
 (0)