Skip to content

Commit

Permalink
Release 2.1.0-beta.3 🚀
Browse files Browse the repository at this point in the history
- Fix: #131
- Fix: #130
- Fix: #129
  • Loading branch information
Jonathan Casarrubias committed Sep 30, 2016
1 parent d9b34a1 commit 92d0dca
Show file tree
Hide file tree
Showing 27 changed files with 201 additions and 87 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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-beta.3

- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/131
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/130
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/129

## Release 2.1.0-beta.2

- Hot Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/128
Expand Down
4 changes: 2 additions & 2 deletions bin/lb-sdk
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ var argv = optimist
'\n ./node_modules/.bin/lb-sdk server/server app/shared/sdk -d [ng4web | nativescript2] -i [enabled | disabled]')
.describe('l', 'Client\'s library (angular2, react <todo>, ...)')
.describe('d', 'Platform specific drivers (ng4web, nativescript2, ng2universal <todo>)')
.describe('i', 'Enable PubSub functionality for loopback-component-pubsub')
.describe('i', 'Enable PubSub, IO and FireLoop functionality')
.describe('w', 'Automatically wipe SDK Directory')
.default('l', 'angular2')
.default('d', 'ng4web')
.default('i', 'disabled')
.default('i', 'enabled')
.default('w', 'disabled')
.alias({ u: 'url', m: 'module-name', l: 'library', i: 'io', d: 'driver', w: 'wipe' })
.demand(1)
Expand Down
14 changes: 11 additions & 3 deletions lib/angular2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ module.exports = function generate(ctx) {
{
template: './shared/models/index.ejs',
output: '/models/index.ts',
params: { models: ctx.models }
params: {
isIo: ctx.isIo,
models: ctx.models
}
},
{
template: './shared/services/index.ejs',
Expand Down Expand Up @@ -163,8 +166,13 @@ module.exports = function generate(ctx) {
params: {}
},
{
template: './shared/services/core/fireloop.ejs',
output: '/services/core/fireloop.ts',
template: './shared/models/fireloop.ejs',
output: '/models/FireLoop.ts',
params: {}
},
{
template: './shared/models/flref.ejs',
output: '/models/FireLoopRef.ts',
params: {}
}
]);
Expand Down
20 changes: 20 additions & 0 deletions lib/angular2/shared/models/fireloop.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { LoopBackConfig } from '../lb.config';
import { AccessToken, FireLoopRef } from './index';
import { SocketConnections } from '../sockets/socket.connections';

export class FireLoop {

private socket: any;
private references: any = {};

constructor(token: AccessToken) {
this.socket = SocketConnections.getHandler(LoopBackConfig.getPath(), token);
}

public ref<T>(model: { getModelName(): string }): FireLoopRef<T> {
let name: string = model.getModelName();
if (this.references[name]) { return this.references[name]; }
this.references[name] = new FireLoopRef<T>(name, this.socket);
return this.references[name];
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';
import { LoopBackConfig } from '../../lb.config';
import { AccessToken, LoopBackFilter } from '../../models';
import { SocketConnections } from '../../sockets/socket.connections';
import { LoopBackConfig } from '../lb.config';
import { AccessToken, LoopBackFilter } from './index';
import { SocketConnections } from '../sockets/socket.connections';

class Reference {
export class FireLoopRef<T> {

private instance: any;
private socket: any;
private name: string;
private parent: Reference;
private parent: FireLoopRef<T>;
private childs: any = {};
private observables: any = {};

constructor(name: string, socket: any, parent: Reference = null) {
constructor(name: string, socket: any, parent: FireLoopRef<any> = null) {
this.name = name;
this.parent = parent;
this.socket = socket;
return this;
}

public upsert(data: any): Observable<any> {
public upsert(data: any): Observable<T> {
let id: number = Math.floor(Math.random() * 100800) *
Math.floor(Math.random() * 100700) *
Math.floor(Math.random() * 198500);
Expand All @@ -32,18 +32,18 @@ class Reference {
parent : this.parent && this.parent.instance ? this.parent.instance : null
}
};
let subject: Subject<any> = new Subject<any>();
let subject: Subject<T> = new Subject<T>();
this.socket.emit('ME:RT:1://event', request);
this.socket.on(`${this.name}.value.result.${id}`, (res: any) =>
subject.next(res.error ? Observable.throw(res.error) : res)
);
return subject.asObservable();
}

public on(event: string, filter: LoopBackFilter = { limit: 100 }): Observable<any> {
public on(event: string, filter: LoopBackFilter = { limit: 100 }): Observable<T | T[]> {
event = `${this.name}.${event}`;
if (this.observables[event]) { return this.observables[event]; }
let subject: Subject<any> = new Subject<any>();
let subject: Subject<T> = new Subject<T>();
if (event.match(/(value)/))
this.pull(event, filter, subject);
// Listen for broadcast announces
Expand All @@ -59,41 +59,25 @@ class Reference {
return this.observables[event];
}

private pull(event: string, filter: any, subject: Subject<any>): void {
private pull(event: string, filter: any, subject: Subject<T>): void {
this.socket.emit(`${event}.pull.request`, filter);
this.socket.on(`${event}.pull.requested`, (res: any) => subject.next(res));
}

public make(instance: any): Reference {
public make(instance: any): FireLoopRef<T> {
this.instance = instance;
return this;
}

public child(name: string): Reference {
public child<T>(name: string): FireLoopRef<T> {
if (!this.parent) {
let childName = `${this.name}.${name}`;
if (this.childs[childName]) { return this.childs[childName]; }
this.childs[childName] = new Reference(childName, this.socket, this);
this.childs[childName] = new FireLoopRef<T>(childName, this.socket, this);
return this.childs[childName];
} else {
console.warn('Only 1 child level is supported');
// TODO ADD UNLIMITED LEVELS
}
}
}

export class FireLoop {

private socket: any;
private references: any = {};

constructor(token: AccessToken) {
this.socket = SocketConnections.getHandler(LoopBackConfig.getPath(), token);
}

public ref(name: string): Reference {
if (this.references[name]) { return this.references[name]; }
this.references[name] = new Reference(name, this.socket);
return this.references[name];
}
}
}
3 changes: 3 additions & 0 deletions lib/angular2/shared/models/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
export * from './<%- modelName %>';
<% } // for modelName in models -%>
export * from './BaseModels';
<% if ( isIo === 'enabled' ){ -%>export * from './FireLoopRef';
<% }
-%>
7 changes: 7 additions & 0 deletions lib/angular2/shared/models/model.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ export class <%- modelName %> implements <%- modelName %>Interface {
constructor(instance?: <%- modelName %>Interface) {
Object.assign(this, instance);
}
/**
* The name of the model represented by this $resource,
* i.e. `<%- modelName %>`.
*/
public static getModelName() {
return <%-: modelName | q %>;
}
}
2 changes: 1 addition & 1 deletion lib/angular2/shared/services/core/realtime.ejs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Injectable, Inject } from '@angular/core';
import { IO } from './io.service';
import { FireLoop } from './fireloop';
import { JSONSearchParams } from './search.params';
import { LoopBackAuth } from './auth.service';
import { AccessToken } from '../../models';
import { FireLoop } from '../../models/FireLoop';

@Injectable()
export class RealTime {
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.2",
"version": "2.1.0-beta.3",
"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/loopback/component-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"mountPath": "/explorer"
},
"@mean-expert/loopback-component-realtime": {
"debug": true,
"debug": false,
"auth": false
}
}
34 changes: 19 additions & 15 deletions tests/angular2/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Component } from '@angular/core';
import { LoggerService } from './shared/sdk/services';
import { RealTime } from './shared/sdk/services';
import { Room } from './shared/sdk/models';
import { Room, FireLoopRef } from './shared/sdk/models';
// Hardcoded Message interface, this because Messge models
// Is private, this is only for testing purposes, in real life
// the Message should not be private -if needed in front end-
interface Message { text: string; }

@Component({
selector: 'app-root',
Expand All @@ -19,34 +23,34 @@ export class AppComponent {
) {
this.logger.info('LoopBack SDK Builder - Test Application');
// Simple IO Test
//this.realTime.IO.emit('hello', 'world');
//this.realTime.IO.on('hello').subscribe((msg: any) => this.logger.info('REALTIME: ', msg));
this.realTime.IO.emit('hello', 'world');
this.realTime.IO.on('hello').subscribe((msg: any) => this.logger.info('REALTIME: ', msg));
// Simple FireLoop set and get examples.
let RoomReference = this.realTime.FireLoop.ref('Room');
let RoomReference: FireLoopRef<Room> = this.realTime.FireLoop.ref<Room>(Room);
// This will get the list of results and fire every time there is new data.
// RoomReference.on('value', { limit: 2 }).subscribe((rooms: Array<Room>) => this.logger.info(rooms));
/* RoomReference.on('child_added', {
RoomReference.on('value', { limit: 2 }).subscribe((rooms: Array<Room>) => this.logger.info(rooms));
RoomReference.on('child_added', {
limit: 2,
order: 'id DESC'
}).subscribe((room: Room) => this.logger.info(room));
}).subscribe((room: Room) => this.logger.info(room.name));
RoomReference.on('child_changed', {
limit: 2,
order: 'id DESC'
}).subscribe((room: Room) => this.logger.info(room));*/
}).subscribe((room: Room) => this.logger.info(room.name));
// This will set a new value into the reference
[
new Room({ name: 'Room 1' }),
// new Room({ name: 'Room 2' }),
// new Room({ name: 'Room 3' }),
// new Room({ name: 'Room 4' })
new Room({ name: 'Room 2' }),
new Room({ name: 'Room 3' }),
new Room({ name: 'Room 4' })
].forEach((room: Room) => RoomReference.upsert(room).subscribe((instance: Room) => {
console.log('ROOM IS CREATED');
// Child Feature
let MessageReference = RoomReference.make(instance).child('messages');
MessageReference.on('child_changed').subscribe(
(messages: Array<{ text: string }>) => this.logger.info(messages)
let MessageReference: FireLoopRef<Message> = RoomReference.make(instance).child<Message>('messages');
MessageReference.on('child_created').subscribe(
(messages: Array<Message>) => this.logger.info(messages)
);
MessageReference.upsert({ text : 'Hello Child Reference' }).subscribe((res: any) => console.log(res.text));
MessageReference.upsert({ text : 'Hello Child Reference' }).subscribe((res: Message) => console.log(res.text));
}));
}
}
2 changes: 1 addition & 1 deletion tests/angular2/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { SDKModule } from './shared/sdk';
import { SDKModule } from './shared/sdk/index';
import { routing, appRoutingProviders } from './app.routing';

@NgModule({
Expand Down
7 changes: 7 additions & 0 deletions tests/angular2/src/app/shared/sdk/models/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ export class Account implements AccountInterface {
constructor(instance?: AccountInterface) {
Object.assign(this, instance);
}
/**
* The name of the model represented by this $resource,
* i.e. `Account`.
*/
public static getModelName() {
return "Account";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ export class ApplicationCredential implements ApplicationCredentialInterface {
constructor(instance?: ApplicationCredentialInterface) {
Object.assign(this, instance);
}
/**
* The name of the model represented by this $resource,
* i.e. `ApplicationCredential`.
*/
public static getModelName() {
return "ApplicationCredential";
}
}
7 changes: 7 additions & 0 deletions tests/angular2/src/app/shared/sdk/models/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ export class Category implements CategoryInterface {
constructor(instance?: CategoryInterface) {
Object.assign(this, instance);
}
/**
* The name of the model represented by this $resource,
* i.e. `Category`.
*/
public static getModelName() {
return "Category";
}
}
7 changes: 7 additions & 0 deletions tests/angular2/src/app/shared/sdk/models/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ export class Core implements CoreInterface {
constructor(instance?: CoreInterface) {
Object.assign(this, instance);
}
/**
* The name of the model represented by this $resource,
* i.e. `Core`.
*/
public static getModelName() {
return "Core";
}
}
20 changes: 20 additions & 0 deletions tests/angular2/src/app/shared/sdk/models/FireLoop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { LoopBackConfig } from '../lb.config';
import { AccessToken, FireLoopRef } from './index';
import { SocketConnections } from '../sockets/socket.connections';

export class FireLoop {

private socket: any;
private references: any = {};

constructor(token: AccessToken) {
this.socket = SocketConnections.getHandler(LoopBackConfig.getPath(), token);
}

public ref<T>(model: { getModelName(): string }): FireLoopRef<T> {
let name: string = model.getModelName();
if (this.references[name]) { return this.references[name]; }
this.references[name] = new FireLoopRef<T>(name, this.socket);
return this.references[name];
}
}
Loading

0 comments on commit 92d0dca

Please sign in to comment.