From a6ecd9dd816f06528570d97e0ad37739b70ec05b Mon Sep 17 00:00:00 2001 From: Jonathan Casarrubias Date: Fri, 30 Sep 2016 11:44:05 -0500 Subject: [PATCH] Release 2.1.0-beta.1 :rocket: - Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/127 - Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/124 - Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/122 - Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/112 - Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/31 --- .vscode/settings.json | 4 + CHANGELOG.md | 8 ++ LICENSE.md | 12 ++- README.md | 7 ++ .../drivers/nativescript2/socket.driver.ejs | 6 +- lib/angular2/index.js | 25 +++-- lib/angular2/shared/index.ejs | 86 +++++++++------ lib/angular2/shared/models/base.ejs | 1 + lib/angular2/shared/models/model.ejs | 3 +- lib/angular2/shared/sdk.module.ejs | 61 ----------- lib/angular2/shared/services/core/auth.ejs | 1 + .../shared/services/core/fireloop.ejs | 99 +++++++++++++++++ lib/angular2/shared/services/core/index.ejs | 1 + lib/angular2/shared/services/core/io.ejs | 30 ++++++ .../shared/services/core/realtime.ejs | 22 ++++ package.json | 2 +- tests/angular2/README.md | 2 +- tests/angular2/angular-cli.json | 9 +- tests/angular2/karma.conf.js | 7 +- tests/angular2/loopback/boot/test.js | 7 ++ tests/angular2/loopback/component-config.json | 5 +- tests/angular2/loopback/model-config.json | 2 +- tests/angular2/package.json | 40 +++---- .../src/app/access/access.component.css | 0 .../{+access => access}/access.component.html | 0 .../{+access => access}/access.component.ts | 17 ++- .../angular2/src/app/access/access.module.ts | 15 +++ .../angular2/src/app/access/access.routing.ts | 12 +++ tests/angular2/src/app/app.component.spec.ts | 37 ------- tests/angular2/src/app/app.component.ts | 39 ++++++- tests/angular2/src/app/app.module.ts | 10 +- tests/angular2/src/app/app.routing.ts | 14 ++- .../src/app/room-service.service.spec.ts | 18 +++- .../angular2/src/app/room/room.component.css | 0 .../app/{+room => room}/room.component.html | 0 .../src/app/{+room => room}/room.component.ts | 0 tests/angular2/src/app/room/room.module.ts | 15 +++ tests/angular2/src/app/room/room.routing.ts | 14 +++ tests/angular2/src/app/shared/sdk/index.ts | 101 +++++++++++------- .../src/app/shared/sdk/models/Account.ts | 3 +- .../sdk/models/ApplicationCredential.ts | 3 +- .../src/app/shared/sdk/models/BaseModels.ts | 1 + .../src/app/shared/sdk/models/Category.ts | 3 +- .../src/app/shared/sdk/models/Core.ts | 3 +- .../src/app/shared/sdk/models/Like.ts | 3 +- .../src/app/shared/sdk/models/Room.ts | 3 +- .../src/app/shared/sdk/models/RoomAccount.ts | 3 +- .../src/app/shared/sdk/models/Storage.ts | 3 +- .../src/app/shared/sdk/models/User.ts | 3 +- .../app/shared/sdk/models/UserCredential.ts | 3 +- .../src/app/shared/sdk/models/UserIdentity.ts | 3 +- .../angular2/src/app/shared/sdk/sdk.module.ts | 84 --------------- .../shared/sdk/services/core/auth.service.ts | 1 + .../app/shared/sdk/services/core/fireloop.ts | 99 +++++++++++++++++ .../src/app/shared/sdk/services/core/index.ts | 1 + .../shared/sdk/services/core/io.service.ts | 30 ++++++ .../app/shared/sdk/services/core/real.time.ts | 22 ++++ .../app/shared/sdk/services/custom/Account.ts | 65 +++++++++-- .../services/custom/ApplicationCredential.ts | 36 ++++++- .../shared/sdk/services/custom/Category.ts | 42 +++++++- .../app/shared/sdk/services/custom/Like.ts | 36 ++++++- .../app/shared/sdk/services/custom/Room.ts | 77 ++++++++++--- .../shared/sdk/services/custom/RoomAccount.ts | 36 ++++++- .../app/shared/sdk/services/custom/User.ts | 36 ++++++- .../sdk/services/custom/UserCredential.ts | 36 ++++++- .../sdk/services/custom/UserIdentity.ts | 36 ++++++- .../src/environments/environment.dev.ts | 3 - .../angular2/src/environments/environment.ts | 8 +- tests/angular2/src/test.ts | 4 +- tests/angular2/src/tsconfig.json | 1 - 70 files changed, 1039 insertions(+), 380 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 lib/angular2/shared/sdk.module.ejs create mode 100644 lib/angular2/shared/services/core/fireloop.ejs create mode 100644 lib/angular2/shared/services/core/io.ejs create mode 100644 lib/angular2/shared/services/core/realtime.ejs create mode 100644 tests/angular2/loopback/boot/test.js create mode 100644 tests/angular2/src/app/access/access.component.css rename tests/angular2/src/app/{+access => access}/access.component.html (100%) rename tests/angular2/src/app/{+access => access}/access.component.ts (53%) create mode 100644 tests/angular2/src/app/access/access.module.ts create mode 100644 tests/angular2/src/app/access/access.routing.ts delete mode 100644 tests/angular2/src/app/app.component.spec.ts create mode 100644 tests/angular2/src/app/room/room.component.css rename tests/angular2/src/app/{+room => room}/room.component.html (100%) rename tests/angular2/src/app/{+room => room}/room.component.ts (100%) create mode 100644 tests/angular2/src/app/room/room.module.ts create mode 100644 tests/angular2/src/app/room/room.routing.ts delete mode 100644 tests/angular2/src/app/shared/sdk/sdk.module.ts create mode 100644 tests/angular2/src/app/shared/sdk/services/core/fireloop.ts create mode 100644 tests/angular2/src/app/shared/sdk/services/core/io.service.ts create mode 100644 tests/angular2/src/app/shared/sdk/services/core/real.time.ts delete mode 100644 tests/angular2/src/environments/environment.dev.ts diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..54d3eb09 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "typescript.tsdk": "node_modules/typescript/lib" +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 003543b8..bf9bedec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ 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.1 + +- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/127 +- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/124 +- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/122 +- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/112 +- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/31 + ## Release 2.0.10 - Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/121 diff --git a/LICENSE.md b/LICENSE.md index c8e73848..6481ed9e 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,12 @@ -Copyright (c) 2016 Jonathan Casarrubias <@johncasarrubias> +#Art and Graphics License +Copyright (c) 2016 MEAN Expert - Jonathan Casarrubias <@johncasarrubias> + +All Rights Reserved + +MEAN Expert, LoopBack SDK Builder, SDK Builder Mascot and The FireLoop.io name and Logos are protected by copyright and distributed under licenses restricting copying, distribution and decompilation. + +#Software MTI License +Copyright (c) 2016 MEAN Expert - Jonathan Casarrubias <@johncasarrubias> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: @@ -6,4 +14,4 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -[MIT License](http://opensource.org/licenses/MIT) +[MIT License](http://opensource.org/licenses/MIT) \ No newline at end of file diff --git a/README.md b/README.md index 2e821654..780738f8 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,13 @@ $ npm install --save-dev @mean-expert/loopback-sdk-builder [LINK TO FEATURES](https://github.com/mean-expert-official/loopback-sdk-builder/wiki#features) +# FireLoop API (NEW) + +Are you willing to build pure and modern Real-Time applications?? Then [CHECK THIS OUT](https://github.com/mean-expert-official/loopback-sdk-builder/wiki/8.-(NEW)-FireLoop-API) + +![FireLoop.io](https://storage.googleapis.com/mean-expert-images/fireloop-logo.png) + + # Contact Discuss features and ask questions on [@johncasarrubias at Twitter](https://twitter.com/johncasarrubias). diff --git a/lib/angular2/drivers/nativescript2/socket.driver.ejs b/lib/angular2/drivers/nativescript2/socket.driver.ejs index cfbee939..9f17f398 100644 --- a/lib/angular2/drivers/nativescript2/socket.driver.ejs +++ b/lib/angular2/drivers/nativescript2/socket.driver.ejs @@ -1,7 +1,9 @@ /* tslint:disable */ -var SocketIO = require('nativescript-socket.io'); +var SocketIO = require('nativescript-socketio'); export class SocketDriver { static connect(url: any, options: any) { - return SocketIO.connect(url, options); + let socketIO: any = new SocketIO(url, options) + socketIO.connect(); + return socketIO; } } diff --git a/lib/angular2/index.js b/lib/angular2/index.js index 79b336c9..d062c02d 100644 --- a/lib/angular2/index.js +++ b/lib/angular2/index.js @@ -59,15 +59,6 @@ module.exports = function generate(ctx) { buildModuleImports: buildModuleImports } }, - { - template: './shared/sdk.module.ejs', - output: '/sdk.module.ts', - params: { - isIo: ctx.isIo, - models: ctx.models, - buildModuleImports: buildModuleImports - } - }, { template: './shared/models/index.ejs', output: '/models/index.ts', @@ -88,6 +79,21 @@ module.exports = function generate(ctx) { output: '/services/core/index.ts', params: {} }, + { + template: './shared/services/core/io.ejs', + output: '/services/core/io.service.ts', + params: {} + }, + { + template: './shared/services/core/realtime.ejs', + output: '/services/core/real.time.ts', + params: {} + }, + { + template: './shared/services/core/fireloop.ejs', + output: '/services/core/fireloop.ts', + params: {} + }, /** * SDK CONFIG */ @@ -345,6 +351,7 @@ module.exports = function generate(ctx) { let imports = [ { module: 'JSONSearchParams', from: './services/core/search.params'}, { module: 'ErrorHandler', from: './services/core/error.service'}, + { module: 'RealTime', from: './services/core/real.time'}, { module: 'LoopBackAuth', from: './services/core/auth.service'}, { module: 'LoggerService', from: './services/custom/logger.service'}, ]; diff --git a/lib/angular2/shared/index.ejs b/lib/angular2/shared/index.ejs index 7b760a8a..33e5314a 100644 --- a/lib/angular2/shared/index.ejs +++ b/lib/angular2/shared/index.ejs @@ -1,47 +1,69 @@ /** -* @module SDK Index +* @module SDKModule * @author Jonathan Casarrubias * @license MTI 2016 Jonathan Casarrubias * @description -* The SDK Index is automatically built by the LoopBack SDK Builder. +* The SDKModule is a generated Software Development Kit automatically built by +* the LoopBack SDK Builder open source module. * -* The SDK Index will temporally keep providing access to everything in the SDK -* including services. This is because will maintain backwards compatibility for those -* Applications below Angular 2 RC 5 version that does not support NgModule just yet. +* The SDKModule provides Angular 2 >= RC.5 support, which means that NgModules +* can import this Software Development Kit as follows: * -* IMPORTANT NOTE: * -* If your application is equal or above RC 5 It is recommended to import the SDK -* Module located in ./sdk.module.ts and follow the instructions. +* APP Route Module Context +* ============================================================================ +* import { NgModule } from '@angular/core'; +* import { BrowserModule } from '@angular/platform-browser'; +* // App Root +* import { AppComponent } from './app.component'; +* // Feature Modules +* import { SDKModule } from './shared/sdk/sdk.module'; +* // Import Routing +* import { routing } from './app.routing'; +* @NgModule({ +* imports: [ +* BrowserModule, +* routing, +* SDKModule.forRoot() +* ], +* declarations: [ AppComponent ], +* bootstrap: [ AppComponent ] +* }) +* export class AppModule { } * -* Also, It is recommended for you to start upgrading your application in order to -* support NgModules before backwards support is also dropped by Angular. -* -* READ: https://angular.io/docs/ts/latest/cookbook/rc4-to-rc5.html#!#5-cleanup -**/ -<%- buildModuleImports(models, true) %> -/** -* IMPORTANT: API_PROVIDERS WILL BE DEPRECATED WHEN ANGULAR 2 IS STABLE -* PLEASE MIGRATE YOUR PROJECT AS SOON AS POSSIBLE. -* ONCE ANGULAR 2 IS STABLE I WON'T KEEP SUPPORTING API PROVIDERS. -* USER NGMODULE INSTEAD LOCATED IN ./sdk.module.ts **/ -export const API_PROVIDERS: any[] = [ - LoopBackAuth, - ErrorHandler, - LoggerService, - JSONSearchParams,<% -Object.keys(models).forEach(function(modelName, i, arr) { - modelName = modelName[0].toUpperCase() + modelName.slice(1); -%> - <%- modelName %>Api<%= i < arr.length -1 ? ',' : '' %><% -});%> -]; +<%- buildModuleImports(models, false) %> + +@NgModule({ + imports: [ CommonModule, HttpModule ], + declarations: [ ], + exports: [ ], + providers: [ ] +}) + +export class SDKModule { + static forRoot(): ModuleWithProviders { + return { + ngModule: SDKModule, + providers: [ + RealTime, + LoopBackAuth, + ErrorHandler, + LoggerService, + JSONSearchParams,<% + Object.keys(models).forEach(function(modelName, i, arr) { + modelName = modelName[0].toUpperCase() + modelName.slice(1); + %> + <%- modelName %>Api<%= i < arr.length -1 ? ',' : '' %><% + });%> + ] + }; + } +} + export * from './models/index'; export * from './services/index'; export * from './lb.config'; -export * from './sdk.module'; <% if ( isIo === 'enabled' ){ -%>export * from './sockets/index'; <% } -%> - diff --git a/lib/angular2/shared/models/base.ejs b/lib/angular2/shared/models/base.ejs index 596819dc..f148b29f 100644 --- a/lib/angular2/shared/models/base.ejs +++ b/lib/angular2/shared/models/base.ejs @@ -2,6 +2,7 @@ <% if (!loadAccessToken) { %> import 'AccessToken' from './AccessToken'; <% } %> +declare var Object: any; export interface LoopBackFilter { fields?: any; include?: any; diff --git a/lib/angular2/shared/models/model.ejs b/lib/angular2/shared/models/model.ejs index 987f8fd2..24c72b18 100644 --- a/lib/angular2/shared/models/model.ejs +++ b/lib/angular2/shared/models/model.ejs @@ -1,12 +1,13 @@ /* tslint:disable */ <%- buildModelImports(model) %> +declare var Object: any; export interface <%- modelName %>Interface { <%- buildModelProperties(model, true) %> } export class <%- modelName %> implements <%- modelName %>Interface { <%- buildModelProperties(model) %> - constructor(instance?: <%- modelName %>) { + constructor(instance?: <%- modelName %>Interface) { Object.assign(this, instance); } } diff --git a/lib/angular2/shared/sdk.module.ejs b/lib/angular2/shared/sdk.module.ejs deleted file mode 100644 index 8325c85d..00000000 --- a/lib/angular2/shared/sdk.module.ejs +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @module SDKModule -* @author Jonathan Casarrubias -* @license MTI 2016 Jonathan Casarrubias -* @description -* The SDKModule is a generated Software Development Kit automatically built by -* the LoopBack SDK Builder open source module. -* -* The SDKModule provides Angular 2 >= RC.5 support, which means that NgModules -* can import this Software Development Kit as follows: -* -* -* APP Route Module Context -* ============================================================================ -* import { NgModule } from '@angular/core'; -* import { BrowserModule } from '@angular/platform-browser'; -* // App Root -* import { AppComponent } from './app.component'; -* // Feature Modules -* import { SDKModule } from './shared/sdk/sdk.module'; -* // Import Routing -* import { routing } from './app.routing'; -* @NgModule({ -* imports: [ -* BrowserModule, -* routing, -* SDKModule.forRoot() -* ], -* declarations: [ AppComponent ], -* bootstrap: [ AppComponent ] -* }) -* export class AppModule { } -* -**/ -<%- buildModuleImports(models, false) %> - -@NgModule({ - imports: [ CommonModule, HttpModule ], - declarations: [ ], - exports: [ ], - providers: [ ] -}) - -export class SDKModule { - static forRoot(): ModuleWithProviders { - return { - ngModule: SDKModule, - providers: [ - LoopBackAuth, - ErrorHandler, - LoggerService, - JSONSearchParams,<% - Object.keys(models).forEach(function(modelName, i, arr) { - modelName = modelName[0].toUpperCase() + modelName.slice(1); - %> - <%- modelName %>Api<%= i < arr.length -1 ? ',' : '' %><% - });%> - ] - }; - } -} diff --git a/lib/angular2/shared/services/core/auth.ejs b/lib/angular2/shared/services/core/auth.ejs index 6046d4c1..4cf803a0 100644 --- a/lib/angular2/shared/services/core/auth.ejs +++ b/lib/angular2/shared/services/core/auth.ejs @@ -1,4 +1,5 @@ /* tslint:disable */ +declare var Object: any; import { Injectable } from '@angular/core'; import { StorageDriver } from '../../storage/storage.driver'; import { SDKToken<% if (loadAccessToken) { %>, AccessToken<% } %> } from '../../models/BaseModels'; diff --git a/lib/angular2/shared/services/core/fireloop.ejs b/lib/angular2/shared/services/core/fireloop.ejs new file mode 100644 index 00000000..f4dbc2bd --- /dev/null +++ b/lib/angular2/shared/services/core/fireloop.ejs @@ -0,0 +1,99 @@ +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'; + +class Reference { + + private instance: any; + private socket: any; + private name: string; + private parent: Reference; + private childs: any = {}; + private observables: any = {}; + + constructor(name: string, socket: any, parent: Reference = null) { + this.name = name; + this.parent = parent; + this.socket = socket; + return this; + } + + public upsert(data: any): Observable { + let id: number = Math.floor(Math.random() * 100800) * + Math.floor(Math.random() * 100700) * + Math.floor(Math.random() * 198500); + let request: any = { + event: `${this.name}.upsert`, + data : { + id : id, + data : data, + parent : this.parent && this.parent.instance ? this.parent.instance : null + } + }; + let subject: Subject = new Subject(); + 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 { + event = `${this.name}.${event}`; + if (this.observables[event]) { return this.observables[event]; } + let subject: Subject = new Subject(); + if (event.match(/(value)/)) + this.pull(event, filter, subject); + // Listen for broadcast announces + this.socket.on( + // When there is a broadcast announce + `${event}.broadcast.announce`, + // We send a request containing the filtering options + () => this.socket.emit(`${event}.broadcast.request`, filter) + ); + // Once processed our request will return a unique result + this.socket.on(`${event}.broadcast`, (res: any) => subject.next(res)); + this.observables[event] = subject.asObservable(); + return this.observables[event]; + } + + private pull(event: string, filter: any, subject: Subject): void { + this.socket.emit(`${event}.pull.request`, filter); + this.socket.on(`${event}.pull.requested`, (res: any) => subject.next(res)); + } + + public make(instance: any): Reference { + this.instance = instance; + return this; + } + + public child(name: string): Reference { + 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); + 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]; + } +} diff --git a/lib/angular2/shared/services/core/index.ejs b/lib/angular2/shared/services/core/index.ejs index 0a3ff76a..c3d4b7ec 100644 --- a/lib/angular2/shared/services/core/index.ejs +++ b/lib/angular2/shared/services/core/index.ejs @@ -3,3 +3,4 @@ export * from './auth.service'; export * from './error.service'; export * from './search.params'; export * from './base.service'; +export * from './real.time'; diff --git a/lib/angular2/shared/services/core/io.ejs b/lib/angular2/shared/services/core/io.ejs new file mode 100644 index 00000000..785e90dd --- /dev/null +++ b/lib/angular2/shared/services/core/io.ejs @@ -0,0 +1,30 @@ +import { Subject } from 'rxjs/Subject'; +import { Observable } from 'rxjs/Observable'; +import { AccessToken } from '../../models'; +import { LoopBackConfig } from '../../lb.config'; +import { SocketConnections } from '../../sockets/socket.connections'; + +export class IO { + + private socket: any; + private observables: any = {}; + + constructor(token: AccessToken) { + this.socket = SocketConnections.getHandler(LoopBackConfig.getPath(), token); + } + + emit(event: string, data: any): void { + this.socket.emit('ME:RT:1://event', { + event : event, + data : data + }); + } + + on(event: string): Observable { + if (this.observables[event]) { return this.observables[event]; } + let subject: Subject = new Subject(); + this.socket.on(event, (res: any) => subject.next(res)); + this.observables[event] = subject.asObservable(); + return this.observables[event]; + } +} diff --git a/lib/angular2/shared/services/core/realtime.ejs b/lib/angular2/shared/services/core/realtime.ejs new file mode 100644 index 00000000..6ddd8fb3 --- /dev/null +++ b/lib/angular2/shared/services/core/realtime.ejs @@ -0,0 +1,22 @@ +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'; + +@Injectable() +export class RealTime { + + public IO: IO; + public FireLoop: FireLoop; + + constructor( + @Inject(LoopBackAuth) protected auth: LoopBackAuth, + @Inject(JSONSearchParams) protected searchParams: JSONSearchParams + ) { + let token: AccessToken = this.auth.getToken(); + this.IO = new IO(token); + this.FireLoop = new FireLoop(token); + } +} diff --git a/package.json b/package.json index 2ed52fb0..6e334499 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mean-expert/loopback-sdk-builder", - "version": "2.0.10", + "version": "2.1.0-beta.1", "description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack", "bin": { "lb-sdk": "bin/lb-sdk" diff --git a/tests/angular2/README.md b/tests/angular2/README.md index d5b26ddf..9fe99d27 100644 --- a/tests/angular2/README.md +++ b/tests/angular2/README.md @@ -1,6 +1,6 @@ # Angular2 -This project was generated with [angular-cli](https://github.com/angular/angular-cli) version 1.0.0-beta.11-webpack.8. +This project was generated with [angular-cli](https://github.com/angular/angular-cli) version 1.0.0-beta.15. ## Development server Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. diff --git a/tests/angular2/angular-cli.json b/tests/angular2/angular-cli.json index 89d1efef..2bce67d1 100644 --- a/tests/angular2/angular-cli.json +++ b/tests/angular2/angular-cli.json @@ -1,6 +1,6 @@ { "project": { - "version": "1.0.0-beta.11-webpack.8", + "version": "1.0.0-beta.15", "name": "angular2" }, "apps": [ @@ -20,8 +20,8 @@ "scripts": [], "environments": { "source": "environments/environment.ts", - "prod": "environments/environment.prod.ts", - "dev": "environments/environment.dev.ts" + "dev": "environments/environment.ts", + "prod": "environments/environment.prod.ts" } } ], @@ -39,7 +39,6 @@ }, "defaults": { "styleExt": "css", - "prefixInterfaces": false, - "lazyRoutePrefix": "+" + "prefixInterfaces": false } } diff --git a/tests/angular2/karma.conf.js b/tests/angular2/karma.conf.js index 945ec5b3..e28922ac 100644 --- a/tests/angular2/karma.conf.js +++ b/tests/angular2/karma.conf.js @@ -3,7 +3,7 @@ module.exports = function (config) { config.set({ - basePath: './', + basePath: '', frameworks: ['jasmine', 'angular-cli'], plugins: [ require('karma-jasmine'), @@ -23,7 +23,10 @@ module.exports = function (config) { lcovonly: './coverage/coverage.lcov' } }, - angularCliConfig: './angular-cli.json', + angularCli: { + config: './angular-cli.json', + environment: 'dev' + }, reporters: ['progress', 'karma-remap-istanbul'], port: 9876, colors: true, diff --git a/tests/angular2/loopback/boot/test.js b/tests/angular2/loopback/boot/test.js new file mode 100644 index 00000000..9c70e8ec --- /dev/null +++ b/tests/angular2/loopback/boot/test.js @@ -0,0 +1,7 @@ +module.exports = function(app) { + app.on('started', () => { + app.mx.IO.on('Test.set', (msg) => { + console.log('FIRELOOP', msg); + }); + }) +}; diff --git a/tests/angular2/loopback/component-config.json b/tests/angular2/loopback/component-config.json index e7983e70..8a642b49 100644 --- a/tests/angular2/loopback/component-config.json +++ b/tests/angular2/loopback/component-config.json @@ -2,7 +2,8 @@ "loopback-component-explorer": { "mountPath": "/explorer" }, - "loopback-component-pubsub": { - "auth": true + "@mean-expert/loopback-component-realtime": { + "debug": true, + "auth": false } } diff --git a/tests/angular2/loopback/model-config.json b/tests/angular2/loopback/model-config.json index cbbe8856..5292a55d 100644 --- a/tests/angular2/loopback/model-config.json +++ b/tests/angular2/loopback/model-config.json @@ -11,7 +11,7 @@ "loopback/server/mixins", "../common/mixins", "./mixins", - "../node_modules/loopback-component-pubsub/mixins" + "../node_modules/@mean-expert/loopback-component-realtime/dist/mixins" ] }, "User": { diff --git a/tests/angular2/package.json b/tests/angular2/package.json index 60ce77e7..781b901b 100644 --- a/tests/angular2/package.json +++ b/tests/angular2/package.json @@ -9,24 +9,21 @@ "pree2e": "webdriver-manager update", "e2e": "protractor", "test": "node loopback/server.js & ng test", - "build:sdk": "npm install ../../ && ./node_modules/.bin/lb-sdk loopback/server.js src/app/shared/sdk -i enabled" + "build:sdk": "./node_modules/.bin/lb-sdk loopback/server.js src/app/shared/sdk -i enabled" }, "private": true, "dependencies": { - "@angular/common": "2.0.0-rc.5", - "@angular/compiler": "2.0.0-rc.5", - "@angular/core": "2.0.0-rc.5", - "@angular/forms": "0.3.0", - "@angular/http": "2.0.0-rc.5", - "@angular/platform-browser": "2.0.0-rc.5", - "@angular/platform-browser-dynamic": "2.0.0-rc.5", - "@angular/router": "3.0.0-rc.1", - "core-js": "^2.4.0", - "rxjs": "5.0.0-beta.11", - "ts-helpers": "^1.1.1", - "zone.js": "0.6.12", + "@angular/common": "2.0.0", + "@angular/compiler": "2.0.0", + "@angular/core": "2.0.0", + "@angular/forms": "2.0.0", + "@angular/http": "2.0.0", + "@angular/platform-browser": "2.0.0", + "@angular/platform-browser-dynamic": "2.0.0", + "@angular/router": "3.0.0", "compression": "^1.0.3", "config-chain": "^1.1.10", + "core-js": "^2.4.1", "cors": "^2.5.2", "es6-shim": "^0.35.0", "helmet": "^1.3.0", @@ -34,23 +31,26 @@ "loopback-boot": "^2.6.5", "loopback-component-explorer": "^2.4.0", "loopback-component-passport": "^2.1.0", - "loopback-component-pubsub": "^1.0.18", "loopback-component-storage": "^1.9.0", "loopback-connector-rest": "^2.0.0", - "loopback-datasource-juggler": "^2.39.0" + "loopback-datasource-juggler": "^2.39.0", + "rxjs": "5.0.0-beta.12", + "ts-helpers": "^1.1.1", + "zone.js": "^0.6.23" }, "devDependencies": { "@types/jasmine": "^2.2.30", "@types/socket.io-client": "^1.4.26", - "angular-cli": "1.0.0-beta.11-webpack.8", + "angular-cli": "1.0.0-beta.15", "codelyzer": "~0.0.26", "jasmine-core": "2.4.1", "jasmine-spec-reporter": "2.5.0", - "karma": "0.13.22", - "karma-chrome-launcher": "0.2.3", - "karma-jasmine": "0.3.8", + "karma": "1.2.0", + "karma-chrome-launcher": "^2.0.0", + "karma-cli": "^1.0.1", + "karma-jasmine": "^1.0.2", "karma-remap-istanbul": "^0.2.1", - "protractor": "4.0.3", + "protractor": "4.0.5", "ts-node": "1.2.1", "tslint": "3.13.0", "typescript": "2.0.0" diff --git a/tests/angular2/src/app/access/access.component.css b/tests/angular2/src/app/access/access.component.css new file mode 100644 index 00000000..e69de29b diff --git a/tests/angular2/src/app/+access/access.component.html b/tests/angular2/src/app/access/access.component.html similarity index 100% rename from tests/angular2/src/app/+access/access.component.html rename to tests/angular2/src/app/access/access.component.html diff --git a/tests/angular2/src/app/+access/access.component.ts b/tests/angular2/src/app/access/access.component.ts similarity index 53% rename from tests/angular2/src/app/+access/access.component.ts rename to tests/angular2/src/app/access/access.component.ts index 5f1cb04b..31826c7f 100644 --- a/tests/angular2/src/app/+access/access.component.ts +++ b/tests/angular2/src/app/access/access.component.ts @@ -5,20 +5,29 @@ import { Router } from '@angular/router'; @Component({ selector: 'app-access', - templateUrl: 'access.component.html' + template: ` +

Register or Log In an Account

+
+ + + + + or +
+` }) export class AccessComponent implements OnInit { - private account: Account = new Account(); - private rememberMe: boolean = false; + public account: Account = new Account(); + public rememberMe: boolean = false; constructor( private accountApi: AccountApi, private router: Router ) { } - ngOnInit() { } + ngOnInit() {} register() { this.accountApi.create(this.account).subscribe((account: Account) => this.login()); diff --git a/tests/angular2/src/app/access/access.module.ts b/tests/angular2/src/app/access/access.module.ts new file mode 100644 index 00000000..a39873a1 --- /dev/null +++ b/tests/angular2/src/app/access/access.module.ts @@ -0,0 +1,15 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { AccessComponent } from './access.component'; +import { accessRouting } from './access.routing'; +import { FormsModule } from '@angular/forms'; + +@NgModule({ + imports: [ + FormsModule, + CommonModule, + accessRouting + ], + declarations: [ AccessComponent ] +}) +export class AccessModule { } diff --git a/tests/angular2/src/app/access/access.routing.ts b/tests/angular2/src/app/access/access.routing.ts new file mode 100644 index 00000000..96f560e5 --- /dev/null +++ b/tests/angular2/src/app/access/access.routing.ts @@ -0,0 +1,12 @@ +import { ModuleWithProviders } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; +import { AccessComponent } from './access.component'; + +const accessRoutes: Routes = [ + { + path: '', + component: AccessComponent + } +]; + +export const accessRouting: ModuleWithProviders = RouterModule.forChild(accessRoutes); \ No newline at end of file diff --git a/tests/angular2/src/app/app.component.spec.ts b/tests/angular2/src/app/app.component.spec.ts deleted file mode 100644 index b38efbc5..00000000 --- a/tests/angular2/src/app/app.component.spec.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* tslint:disable:no-unused-variable */ - -import { TestBed, async } from '@angular/core/testing'; -import { AppComponent } from './app.component'; -import { SDKModule } from './shared/sdk/sdk.module'; - -describe('App: LoopBack SDK Builder Test Application', () => { - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [ - AppComponent - ], - imports: [ - SDKModule.forRoot() - ] - }); - }); - - it('should create the app', async(() => { - let fixture = TestBed.createComponent(AppComponent); - let app = fixture.debugElement.componentInstance; - expect(app).toBeTruthy(); - })); - - it(`should have as title 'LoopBack SDK Builder Test Application'`, async(() => { - let fixture = TestBed.createComponent(AppComponent); - let app = fixture.debugElement.componentInstance; - expect(app.title).toEqual('LoopBack SDK Builder Test Application'); - })); - - it('should render title in a h1 tag', async(() => { - let fixture = TestBed.createComponent(AppComponent); - fixture.detectChanges(); - let compiled = fixture.debugElement.nativeElement; - expect(compiled.querySelector('h1').textContent).toContain('LoopBack SDK Builder Test Application'); - })); -}); diff --git a/tests/angular2/src/app/app.component.ts b/tests/angular2/src/app/app.component.ts index 800fbd3e..6949a787 100644 --- a/tests/angular2/src/app/app.component.ts +++ b/tests/angular2/src/app/app.component.ts @@ -1,15 +1,52 @@ import { Component } from '@angular/core'; import { LoggerService } from './shared/sdk/services'; +import { RealTime } from './shared/sdk/services'; +import { Room } from './shared/sdk/models'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) + export class AppComponent { + title = 'LoopBack SDK Builder Test Application'; - constructor(private logger: LoggerService) { + constructor( + private logger: LoggerService, + private realTime: RealTime + ) { 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)); + // Simple FireLoop set and get examples. + let RoomReference = this.realTime.FireLoop.ref('Room'); + // This will get the list of results and fire every time there is new data. +// RoomReference.on('value', { limit: 2 }).subscribe((rooms: Array) => this.logger.info(rooms)); + /* RoomReference.on('child_added', { + limit: 2, + order: 'id DESC' + }).subscribe((room: Room) => this.logger.info(room)); + RoomReference.on('child_changed', { + limit: 2, + order: 'id DESC' + }).subscribe((room: Room) => this.logger.info(room));*/ + // 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' }) + ].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) + ); + MessageReference.upsert({ text : 'Hello Child Reference' }).subscribe((res: any) => console.log(res.text)); + })); } } diff --git a/tests/angular2/src/app/app.module.ts b/tests/angular2/src/app/app.module.ts index b712e001..cf5e1582 100644 --- a/tests/angular2/src/app/app.module.ts +++ b/tests/angular2/src/app/app.module.ts @@ -1,9 +1,9 @@ import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; +import { HttpModule } from '@angular/http'; import { AppComponent } from './app.component'; -import { SDKModule } from './shared/sdk/sdk.module'; +import { SDKModule } from './shared/sdk'; import { routing, appRoutingProviders } from './app.routing'; @NgModule({ @@ -12,7 +12,6 @@ import { routing, appRoutingProviders } from './app.routing'; ], imports: [ BrowserModule, - CommonModule, FormsModule, SDKModule.forRoot(), routing @@ -21,7 +20,4 @@ import { routing, appRoutingProviders } from './app.routing'; entryComponents : [ AppComponent ], bootstrap : [ AppComponent ] }) - -export class AppModule { - -} +export class AppModule { } diff --git a/tests/angular2/src/app/app.routing.ts b/tests/angular2/src/app/app.routing.ts index d38b4282..1ac415f6 100644 --- a/tests/angular2/src/app/app.routing.ts +++ b/tests/angular2/src/app/app.routing.ts @@ -1,13 +1,17 @@ import { ModuleWithProviders } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; -import { AccessComponent } from './+access/access.component'; -import { RoomComponent } from './+room/room.component'; +import { RoomComponent } from './room/room.component'; import { AuthGuard } from './shared/auth.guard'; const appRoutes: Routes = [ - { path: 'access', component: AccessComponent }, - { path: 'room', component: RoomComponent, canActivate: [ AuthGuard ] }, - { path: '**', component: RoomComponent, canActivate: [ AuthGuard ] } + { + path: 'access', + loadChildren: 'app/access/access.module#AccessModule' + }, + { + path: 'room', + loadChildren: 'app/room/room.module#RoomModule' + } ]; export const appRoutingProviders: any[] = [ diff --git a/tests/angular2/src/app/room-service.service.spec.ts b/tests/angular2/src/app/room-service.service.spec.ts index 39eb7325..75d7c01e 100644 --- a/tests/angular2/src/app/room-service.service.spec.ts +++ b/tests/angular2/src/app/room-service.service.spec.ts @@ -3,7 +3,7 @@ import { TestBed, async, inject } from '@angular/core/testing'; import { SDKModule } from './shared/sdk'; import { Room } from './shared/sdk/models'; -import { RoomApi } from './shared/sdk/services'; +import { RoomApi, RealTime } from './shared/sdk/services'; describe('Service: Room Service', () => { beforeEach(() => { @@ -110,4 +110,20 @@ describe('Service: Room Service', () => { }); }) )); + + /** + It can not be tested for now because a strange Angular 2 error (No info available) + This is tested running the Test Application using ng serve instead. + it('should set data using FireLoop API', + async(inject([RealTime], (realTime: RealTime) => { + let room: Room = new Room(); + room.name = 'FireLoop Room'; + let ref: any = realTime.FireLoop.ref('Room'); + return ref.set(room).subscribe((result: Room) => { + expect(result.id).toBeTruthy(); + expect(result.name).toBe(room.name); + }); + }) + )); + **/ }); diff --git a/tests/angular2/src/app/room/room.component.css b/tests/angular2/src/app/room/room.component.css new file mode 100644 index 00000000..e69de29b diff --git a/tests/angular2/src/app/+room/room.component.html b/tests/angular2/src/app/room/room.component.html similarity index 100% rename from tests/angular2/src/app/+room/room.component.html rename to tests/angular2/src/app/room/room.component.html diff --git a/tests/angular2/src/app/+room/room.component.ts b/tests/angular2/src/app/room/room.component.ts similarity index 100% rename from tests/angular2/src/app/+room/room.component.ts rename to tests/angular2/src/app/room/room.component.ts diff --git a/tests/angular2/src/app/room/room.module.ts b/tests/angular2/src/app/room/room.module.ts new file mode 100644 index 00000000..5f0f0b69 --- /dev/null +++ b/tests/angular2/src/app/room/room.module.ts @@ -0,0 +1,15 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { RoomComponent } from './room.component'; +import { roomRouting } from './room.routing'; +import { FormsModule } from '@angular/forms'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + roomRouting + ], + declarations: [RoomComponent] +}) +export class RoomModule { } diff --git a/tests/angular2/src/app/room/room.routing.ts b/tests/angular2/src/app/room/room.routing.ts new file mode 100644 index 00000000..4757d677 --- /dev/null +++ b/tests/angular2/src/app/room/room.routing.ts @@ -0,0 +1,14 @@ +import { ModuleWithProviders } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; +import { RoomComponent } from './room.component'; +import { AuthGuard } from '../shared/auth.guard'; + +const roomRoutes: Routes = [ + { + path: '', + component: RoomComponent, + canActivate: [ AuthGuard ] + } +]; + +export const roomRouting: ModuleWithProviders = RouterModule.forChild(roomRoutes); \ No newline at end of file diff --git a/tests/angular2/src/app/shared/sdk/index.ts b/tests/angular2/src/app/shared/sdk/index.ts index 79229652..7653139c 100644 --- a/tests/angular2/src/app/shared/sdk/index.ts +++ b/tests/angular2/src/app/shared/sdk/index.ts @@ -1,28 +1,45 @@ /** -* @module SDK Index +* @module SDKModule * @author Jonathan Casarrubias * @license MTI 2016 Jonathan Casarrubias * @description -* The SDK Index is automatically built by the LoopBack SDK Builder. +* The SDKModule is a generated Software Development Kit automatically built by +* the LoopBack SDK Builder open source module. * -* The SDK Index will temporally keep providing access to everything in the SDK -* including services. This is because will maintain backwards compatibility for those -* Applications below Angular 2 RC 5 version that does not support NgModule just yet. +* The SDKModule provides Angular 2 >= RC.5 support, which means that NgModules +* can import this Software Development Kit as follows: * -* IMPORTANT NOTE: * -* If your application is equal or above RC 5 It is recommended to import the SDK -* Module located in ./sdk.module.ts and follow the instructions. +* APP Route Module Context +* ============================================================================ +* import { NgModule } from '@angular/core'; +* import { BrowserModule } from '@angular/platform-browser'; +* // App Root +* import { AppComponent } from './app.component'; +* // Feature Modules +* import { SDKModule } from './shared/sdk/sdk.module'; +* // Import Routing +* import { routing } from './app.routing'; +* @NgModule({ +* imports: [ +* BrowserModule, +* routing, +* SDKModule.forRoot() +* ], +* declarations: [ AppComponent ], +* bootstrap: [ AppComponent ] +* }) +* export class AppModule { } * -* Also, It is recommended for you to start upgrading your application in order to -* support NgModules before backwards support is also dropped by Angular. -* -* READ: https://angular.io/docs/ts/latest/cookbook/rc4-to-rc5.html#!#5-cleanup **/ import { JSONSearchParams } from './services/core/search.params'; import { ErrorHandler } from './services/core/error.service'; +import { RealTime } from './services/core/real.time'; import { LoopBackAuth } from './services/core/auth.service'; import { LoggerService } from './services/custom/logger.service'; +import { HttpModule } from '@angular/http'; +import { CommonModule } from '@angular/common'; +import { NgModule, ModuleWithProviders } from '@angular/core'; import { UserApi } from './services/custom/User'; import { RoomApi } from './services/custom/Room'; import { LikeApi } from './services/custom/Like'; @@ -34,31 +51,41 @@ import { AccountApi } from './services/custom/Account'; import { RoomAccountApi } from './services/custom/RoomAccount'; import { StorageApi } from './services/custom/Storage'; import { CoreApi } from './services/custom/Core'; -/** -* IMPORTANT: API_PROVIDERS WILL BE DEPRECATED WHEN ANGULAR 2 IS STABLE -* PLEASE MIGRATE YOUR PROJECT AS SOON AS POSSIBLE. -* ONCE ANGULAR 2 IS STABLE I WON'T KEEP SUPPORTING API PROVIDERS. -* USER NGMODULE INSTEAD LOCATED IN ./sdk.module.ts -**/ -export const API_PROVIDERS: any[] = [ - LoopBackAuth, - ErrorHandler, - LoggerService, - JSONSearchParams, - UserApi, - RoomApi, - LikeApi, - ApplicationCredentialApi, - UserCredentialApi, - UserIdentityApi, - CategoryApi, - AccountApi, - RoomAccountApi, - StorageApi, - CoreApi -]; + +@NgModule({ + imports: [ CommonModule, HttpModule ], + declarations: [ ], + exports: [ ], + providers: [ ] +}) + +export class SDKModule { + static forRoot(): ModuleWithProviders { + return { + ngModule: SDKModule, + providers: [ + RealTime, + LoopBackAuth, + ErrorHandler, + LoggerService, + JSONSearchParams, + UserApi, + RoomApi, + LikeApi, + ApplicationCredentialApi, + UserCredentialApi, + UserIdentityApi, + CategoryApi, + AccountApi, + RoomAccountApi, + StorageApi, + CoreApi + ] + }; + } +} + export * from './models/index'; export * from './services/index'; export * from './lb.config'; -export * from './sdk.module'; -export * from './sockets/index'; +export * from './sockets/index'; \ No newline at end of file diff --git a/tests/angular2/src/app/shared/sdk/models/Account.ts b/tests/angular2/src/app/shared/sdk/models/Account.ts index 695159e7..c5aaab75 100644 --- a/tests/angular2/src/app/shared/sdk/models/Account.ts +++ b/tests/angular2/src/app/shared/sdk/models/Account.ts @@ -3,6 +3,7 @@ import { Room, } from '../index'; +declare var Object: any; export interface AccountInterface { realm?: string; username?: string; @@ -35,7 +36,7 @@ export class Account implements AccountInterface { accessTokens: Array; rooms: Array; administrations: Array; - constructor(instance?: Account) { + constructor(instance?: AccountInterface) { Object.assign(this, instance); } } diff --git a/tests/angular2/src/app/shared/sdk/models/ApplicationCredential.ts b/tests/angular2/src/app/shared/sdk/models/ApplicationCredential.ts index b05ffd14..20e52847 100644 --- a/tests/angular2/src/app/shared/sdk/models/ApplicationCredential.ts +++ b/tests/angular2/src/app/shared/sdk/models/ApplicationCredential.ts @@ -1,5 +1,6 @@ /* tslint:disable */ +declare var Object: any; export interface ApplicationCredentialInterface { provider?: string; authScheme?: string; @@ -18,7 +19,7 @@ export class ApplicationCredential implements ApplicationCredentialInterface { modified: any; userId: any; id: number; - constructor(instance?: ApplicationCredential) { + constructor(instance?: ApplicationCredentialInterface) { Object.assign(this, instance); } } diff --git a/tests/angular2/src/app/shared/sdk/models/BaseModels.ts b/tests/angular2/src/app/shared/sdk/models/BaseModels.ts index 6178f58f..f8ed96a0 100644 --- a/tests/angular2/src/app/shared/sdk/models/BaseModels.ts +++ b/tests/angular2/src/app/shared/sdk/models/BaseModels.ts @@ -1,5 +1,6 @@ /* tslint:disable */ +declare var Object: any; export interface LoopBackFilter { fields?: any; include?: any; diff --git a/tests/angular2/src/app/shared/sdk/models/Category.ts b/tests/angular2/src/app/shared/sdk/models/Category.ts index cb5b9087..1d041a51 100644 --- a/tests/angular2/src/app/shared/sdk/models/Category.ts +++ b/tests/angular2/src/app/shared/sdk/models/Category.ts @@ -3,6 +3,7 @@ import { Room } from '../index'; +declare var Object: any; export interface CategoryInterface { name?: string; id?: number; @@ -13,7 +14,7 @@ export class Category implements CategoryInterface { name: string; id: number; rooms: Array; - constructor(instance?: Category) { + constructor(instance?: CategoryInterface) { Object.assign(this, instance); } } diff --git a/tests/angular2/src/app/shared/sdk/models/Core.ts b/tests/angular2/src/app/shared/sdk/models/Core.ts index e3cdf322..b261a6dc 100644 --- a/tests/angular2/src/app/shared/sdk/models/Core.ts +++ b/tests/angular2/src/app/shared/sdk/models/Core.ts @@ -1,12 +1,13 @@ /* tslint:disable */ +declare var Object: any; export interface CoreInterface { id?: number; } export class Core implements CoreInterface { id: number; - constructor(instance?: Core) { + constructor(instance?: CoreInterface) { Object.assign(this, instance); } } diff --git a/tests/angular2/src/app/shared/sdk/models/Like.ts b/tests/angular2/src/app/shared/sdk/models/Like.ts index 9a6319de..a9cf0325 100644 --- a/tests/angular2/src/app/shared/sdk/models/Like.ts +++ b/tests/angular2/src/app/shared/sdk/models/Like.ts @@ -3,6 +3,7 @@ import { Room } from '../index'; +declare var Object: any; export interface LikeInterface { set: boolean; id?: number; @@ -19,7 +20,7 @@ export class Like implements LikeInterface { messageId: number; room: Room; message: any; - constructor(instance?: Like) { + constructor(instance?: LikeInterface) { Object.assign(this, instance); } } diff --git a/tests/angular2/src/app/shared/sdk/models/Room.ts b/tests/angular2/src/app/shared/sdk/models/Room.ts index 183d702c..07567f0d 100644 --- a/tests/angular2/src/app/shared/sdk/models/Room.ts +++ b/tests/angular2/src/app/shared/sdk/models/Room.ts @@ -5,6 +5,7 @@ import { Account, } from '../index'; +declare var Object: any; export interface RoomInterface { name: string; id?: number; @@ -23,7 +24,7 @@ export class Room implements RoomInterface { categories: Array; accounts: Array; admins: Array; - constructor(instance?: Room) { + constructor(instance?: RoomInterface) { Object.assign(this, instance); } } diff --git a/tests/angular2/src/app/shared/sdk/models/RoomAccount.ts b/tests/angular2/src/app/shared/sdk/models/RoomAccount.ts index 042b28b3..a8458580 100644 --- a/tests/angular2/src/app/shared/sdk/models/RoomAccount.ts +++ b/tests/angular2/src/app/shared/sdk/models/RoomAccount.ts @@ -4,6 +4,7 @@ import { Room } from '../index'; +declare var Object: any; export interface RoomAccountInterface { id?: number; accountId?: number; @@ -18,7 +19,7 @@ export class RoomAccount implements RoomAccountInterface { roomId: number; account: Account; room: Room; - constructor(instance?: RoomAccount) { + constructor(instance?: RoomAccountInterface) { Object.assign(this, instance); } } diff --git a/tests/angular2/src/app/shared/sdk/models/Storage.ts b/tests/angular2/src/app/shared/sdk/models/Storage.ts index 4e26dbaa..132d90c5 100644 --- a/tests/angular2/src/app/shared/sdk/models/Storage.ts +++ b/tests/angular2/src/app/shared/sdk/models/Storage.ts @@ -1,12 +1,13 @@ /* tslint:disable */ +declare var Object: any; export interface StorageInterface { id?: number; } export class Storage implements StorageInterface { id: number; - constructor(instance?: Storage) { + constructor(instance?: StorageInterface) { Object.assign(this, instance); } } diff --git a/tests/angular2/src/app/shared/sdk/models/User.ts b/tests/angular2/src/app/shared/sdk/models/User.ts index 6f444445..9bb5054c 100644 --- a/tests/angular2/src/app/shared/sdk/models/User.ts +++ b/tests/angular2/src/app/shared/sdk/models/User.ts @@ -1,5 +1,6 @@ /* tslint:disable */ +declare var Object: any; export interface UserInterface { realm?: string; username?: string; @@ -28,7 +29,7 @@ export class User implements UserInterface { lastUpdated: any; id: number; accessTokens: Array; - constructor(instance?: User) { + constructor(instance?: UserInterface) { Object.assign(this, instance); } } diff --git a/tests/angular2/src/app/shared/sdk/models/UserCredential.ts b/tests/angular2/src/app/shared/sdk/models/UserCredential.ts index 10d7f910..fdecafe9 100644 --- a/tests/angular2/src/app/shared/sdk/models/UserCredential.ts +++ b/tests/angular2/src/app/shared/sdk/models/UserCredential.ts @@ -1,5 +1,6 @@ /* tslint:disable */ +declare var Object: any; export interface UserCredentialInterface { provider?: string; authScheme?: string; @@ -22,7 +23,7 @@ export class UserCredential implements UserCredentialInterface { modified: any; userId: any; id: number; - constructor(instance?: UserCredential) { + constructor(instance?: UserCredentialInterface) { Object.assign(this, instance); } } diff --git a/tests/angular2/src/app/shared/sdk/models/UserIdentity.ts b/tests/angular2/src/app/shared/sdk/models/UserIdentity.ts index 7d80cba2..74f8f714 100644 --- a/tests/angular2/src/app/shared/sdk/models/UserIdentity.ts +++ b/tests/angular2/src/app/shared/sdk/models/UserIdentity.ts @@ -3,6 +3,7 @@ import { User } from '../index'; +declare var Object: any; export interface UserIdentityInterface { provider?: string; authScheme?: string; @@ -27,7 +28,7 @@ export class UserIdentity implements UserIdentityInterface { userId: number; id: number; user: User; - constructor(instance?: UserIdentity) { + constructor(instance?: UserIdentityInterface) { Object.assign(this, instance); } } diff --git a/tests/angular2/src/app/shared/sdk/sdk.module.ts b/tests/angular2/src/app/shared/sdk/sdk.module.ts deleted file mode 100644 index 0624904b..00000000 --- a/tests/angular2/src/app/shared/sdk/sdk.module.ts +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @module SDKModule -* @author Jonathan Casarrubias -* @license MTI 2016 Jonathan Casarrubias -* @description -* The SDKModule is a generated Software Development Kit automatically built by -* the LoopBack SDK Builder open source module. -* -* The SDKModule provides Angular 2 >= RC.5 support, which means that NgModules -* can import this Software Development Kit as follows: -* -* -* APP Route Module Context -* ============================================================================ -* import { NgModule } from '@angular/core'; -* import { BrowserModule } from '@angular/platform-browser'; -* // App Root -* import { AppComponent } from './app.component'; -* // Feature Modules -* import { SDKModule } from './shared/sdk/sdk.module'; -* // Import Routing -* import { routing } from './app.routing'; -* @NgModule({ -* imports: [ -* BrowserModule, -* routing, -* SDKModule.forRoot() -* ], -* declarations: [ AppComponent ], -* bootstrap: [ AppComponent ] -* }) -* export class AppModule { } -* -**/ -import { JSONSearchParams } from './services/core/search.params'; -import { ErrorHandler } from './services/core/error.service'; -import { LoopBackAuth } from './services/core/auth.service'; -import { LoggerService } from './services/custom/logger.service'; -import { HttpModule } from '@angular/http'; -import { CommonModule } from '@angular/common'; -import { NgModule, ModuleWithProviders } from '@angular/core'; -import { UserApi } from './services/custom/User'; -import { RoomApi } from './services/custom/Room'; -import { LikeApi } from './services/custom/Like'; -import { ApplicationCredentialApi } from './services/custom/ApplicationCredential'; -import { UserCredentialApi } from './services/custom/UserCredential'; -import { UserIdentityApi } from './services/custom/UserIdentity'; -import { CategoryApi } from './services/custom/Category'; -import { AccountApi } from './services/custom/Account'; -import { RoomAccountApi } from './services/custom/RoomAccount'; -import { StorageApi } from './services/custom/Storage'; -import { CoreApi } from './services/custom/Core'; - -@NgModule({ - imports: [ CommonModule, HttpModule ], - declarations: [ ], - exports: [ ], - providers: [ ] -}) - -export class SDKModule { - static forRoot(): ModuleWithProviders { - return { - ngModule: SDKModule, - providers: [ - LoopBackAuth, - ErrorHandler, - LoggerService, - JSONSearchParams, - UserApi, - RoomApi, - LikeApi, - ApplicationCredentialApi, - UserCredentialApi, - UserIdentityApi, - CategoryApi, - AccountApi, - RoomAccountApi, - StorageApi, - CoreApi - ] - }; - } -} diff --git a/tests/angular2/src/app/shared/sdk/services/core/auth.service.ts b/tests/angular2/src/app/shared/sdk/services/core/auth.service.ts index 4b527bbb..1c306c7d 100644 --- a/tests/angular2/src/app/shared/sdk/services/core/auth.service.ts +++ b/tests/angular2/src/app/shared/sdk/services/core/auth.service.ts @@ -1,4 +1,5 @@ /* tslint:disable */ +declare var Object: any; import { Injectable } from '@angular/core'; import { StorageDriver } from '../../storage/storage.driver'; import { SDKToken, AccessToken } from '../../models/BaseModels'; diff --git a/tests/angular2/src/app/shared/sdk/services/core/fireloop.ts b/tests/angular2/src/app/shared/sdk/services/core/fireloop.ts new file mode 100644 index 00000000..f4dbc2bd --- /dev/null +++ b/tests/angular2/src/app/shared/sdk/services/core/fireloop.ts @@ -0,0 +1,99 @@ +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'; + +class Reference { + + private instance: any; + private socket: any; + private name: string; + private parent: Reference; + private childs: any = {}; + private observables: any = {}; + + constructor(name: string, socket: any, parent: Reference = null) { + this.name = name; + this.parent = parent; + this.socket = socket; + return this; + } + + public upsert(data: any): Observable { + let id: number = Math.floor(Math.random() * 100800) * + Math.floor(Math.random() * 100700) * + Math.floor(Math.random() * 198500); + let request: any = { + event: `${this.name}.upsert`, + data : { + id : id, + data : data, + parent : this.parent && this.parent.instance ? this.parent.instance : null + } + }; + let subject: Subject = new Subject(); + 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 { + event = `${this.name}.${event}`; + if (this.observables[event]) { return this.observables[event]; } + let subject: Subject = new Subject(); + if (event.match(/(value)/)) + this.pull(event, filter, subject); + // Listen for broadcast announces + this.socket.on( + // When there is a broadcast announce + `${event}.broadcast.announce`, + // We send a request containing the filtering options + () => this.socket.emit(`${event}.broadcast.request`, filter) + ); + // Once processed our request will return a unique result + this.socket.on(`${event}.broadcast`, (res: any) => subject.next(res)); + this.observables[event] = subject.asObservable(); + return this.observables[event]; + } + + private pull(event: string, filter: any, subject: Subject): void { + this.socket.emit(`${event}.pull.request`, filter); + this.socket.on(`${event}.pull.requested`, (res: any) => subject.next(res)); + } + + public make(instance: any): Reference { + this.instance = instance; + return this; + } + + public child(name: string): Reference { + 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); + 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]; + } +} diff --git a/tests/angular2/src/app/shared/sdk/services/core/index.ts b/tests/angular2/src/app/shared/sdk/services/core/index.ts index 0a3ff76a..c3d4b7ec 100644 --- a/tests/angular2/src/app/shared/sdk/services/core/index.ts +++ b/tests/angular2/src/app/shared/sdk/services/core/index.ts @@ -3,3 +3,4 @@ export * from './auth.service'; export * from './error.service'; export * from './search.params'; export * from './base.service'; +export * from './real.time'; diff --git a/tests/angular2/src/app/shared/sdk/services/core/io.service.ts b/tests/angular2/src/app/shared/sdk/services/core/io.service.ts new file mode 100644 index 00000000..785e90dd --- /dev/null +++ b/tests/angular2/src/app/shared/sdk/services/core/io.service.ts @@ -0,0 +1,30 @@ +import { Subject } from 'rxjs/Subject'; +import { Observable } from 'rxjs/Observable'; +import { AccessToken } from '../../models'; +import { LoopBackConfig } from '../../lb.config'; +import { SocketConnections } from '../../sockets/socket.connections'; + +export class IO { + + private socket: any; + private observables: any = {}; + + constructor(token: AccessToken) { + this.socket = SocketConnections.getHandler(LoopBackConfig.getPath(), token); + } + + emit(event: string, data: any): void { + this.socket.emit('ME:RT:1://event', { + event : event, + data : data + }); + } + + on(event: string): Observable { + if (this.observables[event]) { return this.observables[event]; } + let subject: Subject = new Subject(); + this.socket.on(event, (res: any) => subject.next(res)); + this.observables[event] = subject.asObservable(); + return this.observables[event]; + } +} diff --git a/tests/angular2/src/app/shared/sdk/services/core/real.time.ts b/tests/angular2/src/app/shared/sdk/services/core/real.time.ts new file mode 100644 index 00000000..6ddd8fb3 --- /dev/null +++ b/tests/angular2/src/app/shared/sdk/services/core/real.time.ts @@ -0,0 +1,22 @@ +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'; + +@Injectable() +export class RealTime { + + public IO: IO; + public FireLoop: FireLoop; + + constructor( + @Inject(LoopBackAuth) protected auth: LoopBackAuth, + @Inject(JSONSearchParams) protected searchParams: JSONSearchParams + ) { + let token: AccessToken = this.auth.getToken(); + this.IO = new IO(token); + this.FireLoop = new FireLoop(token); + } +} diff --git a/tests/angular2/src/app/shared/sdk/services/custom/Account.ts b/tests/angular2/src/app/shared/sdk/services/custom/Account.ts index 9347023c..e3e5a153 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/Account.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/Account.ts @@ -240,7 +240,7 @@ export class AccountApi extends BaseLoopBackApi { * This usually means the response is a `Account` object.) * */ - public updateByIdRooms(id: any, fk: any, data: Room = undefined) { + public updateByIdRooms(id: any, fk: any, data: any = undefined) { let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Accounts/:id/rooms/:fk"; @@ -289,7 +289,7 @@ export class AccountApi extends BaseLoopBackApi { * This usually means the response is a `Account` object.) * */ - public linkRooms(id: any, fk: any, data: RoomAccount = undefined) { + public linkRooms(id: any, fk: any, data: any = undefined) { let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Accounts/:id/rooms/rel/:fk"; @@ -478,7 +478,7 @@ export class AccountApi extends BaseLoopBackApi { * This usually means the response is a `Account` object.) * */ - public updateByIdAdministrations(id: any, fk: any, data: Room = undefined) { + public updateByIdAdministrations(id: any, fk: any, data: any = undefined) { let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Accounts/:id/administrations/:fk"; @@ -816,7 +816,7 @@ export class AccountApi extends BaseLoopBackApi { * This usually means the response is a `Account` object.) * */ - public createRooms(id: any, data: Room = undefined) { + public createRooms(id: any, data: any = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Accounts/:id/rooms"; @@ -958,7 +958,7 @@ export class AccountApi extends BaseLoopBackApi { * This usually means the response is a `Account` object.) * */ - public createAdministrations(id: any, data: Room = undefined) { + public createAdministrations(id: any, data: any = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Accounts/:id/administrations"; @@ -1109,7 +1109,7 @@ export class AccountApi extends BaseLoopBackApi { * */ public upsert(data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Accounts"; let routeParams: any = {}; @@ -1122,7 +1122,7 @@ export class AccountApi extends BaseLoopBackApi { } public onUpsert() { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = "/" + LoopBackConfig.getApiVersion() + "/Accounts"; let routeParams: any = {}; @@ -1172,6 +1172,49 @@ export class AccountApi extends BaseLoopBackApi { return result; } + /** + * Update an existing model instance or insert a new one into the data source based on the where criteria. + * + * @param object where Criteria to match model instances + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Account` object.) + * + */ + public upsertWithWhere(where: any = undefined, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Accounts/upsertWithWhere"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + if (where) urlParams.where = where; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instance: Account) => new Account(instance)); + } + + public onUpsertWithWhere(where: any = undefined) { + let method: string = "POST"; + let url: string = "/" + LoopBackConfig.getApiVersion() + + "/Accounts/upsertWithWhere"; + let routeParams: any = {}; + let postBody: any = {}; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody, true); + return result; + } + /** * Check whether a model instance exists in the data source. * @@ -1452,7 +1495,7 @@ export class AccountApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Accounts/:id"; let routeParams: any = { @@ -1467,7 +1510,7 @@ export class AccountApi extends BaseLoopBackApi { } public onUpdateAttributes(id: any) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = "/" + LoopBackConfig.getApiVersion() + "/Accounts/:id"; let routeParams: any = { @@ -1702,7 +1745,7 @@ export class AccountApi extends BaseLoopBackApi { * This usually means the response is a `Account` object.) * */ - public createManyRooms(id: any, data: Array = undefined) { + public createManyRooms(id: any, data: Array = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Accounts/:id/rooms"; @@ -1748,7 +1791,7 @@ export class AccountApi extends BaseLoopBackApi { * This usually means the response is a `Account` object.) * */ - public createManyAdministrations(id: any, data: Array = undefined) { + public createManyAdministrations(id: any, data: Array = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Accounts/:id/administrations"; diff --git a/tests/angular2/src/app/shared/sdk/services/custom/ApplicationCredential.ts b/tests/angular2/src/app/shared/sdk/services/custom/ApplicationCredential.ts index a59a9abd..4737d9ed 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/ApplicationCredential.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/ApplicationCredential.ts @@ -75,7 +75,7 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { * */ public upsert(data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/ApplicationCredentials"; let routeParams: any = {}; @@ -116,6 +116,38 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { return result; } + /** + * Update an existing model instance or insert a new one into the data source based on the where criteria. + * + * @param object where Criteria to match model instances + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `ApplicationCredential` object.) + * + */ + public upsertWithWhere(where: any = undefined, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/ApplicationCredentials/upsertWithWhere"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + if (where) urlParams.where = where; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instance: ApplicationCredential) => new ApplicationCredential(instance)); + } + /** * Check whether a model instance exists in the data source. * @@ -359,7 +391,7 @@ export class ApplicationCredentialApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/ApplicationCredentials/:id"; let routeParams: any = { diff --git a/tests/angular2/src/app/shared/sdk/services/custom/Category.ts b/tests/angular2/src/app/shared/sdk/services/custom/Category.ts index 7766f654..f2be7606 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/Category.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/Category.ts @@ -107,7 +107,7 @@ export class CategoryApi extends BaseLoopBackApi { * This usually means the response is a `Category` object.) * */ - public updateByIdRooms(id: any, fk: any, data: Room = undefined) { + public updateByIdRooms(id: any, fk: any, data: any = undefined) { let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Categories/:id/rooms/:fk"; @@ -264,7 +264,7 @@ export class CategoryApi extends BaseLoopBackApi { * This usually means the response is a `Category` object.) * */ - public createRooms(id: any, data: Room = undefined) { + public createRooms(id: any, data: any = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Categories/:id/rooms"; @@ -378,7 +378,7 @@ export class CategoryApi extends BaseLoopBackApi { * */ public upsert(data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Categories"; let routeParams: any = {}; @@ -419,6 +419,38 @@ export class CategoryApi extends BaseLoopBackApi { return result; } + /** + * Update an existing model instance or insert a new one into the data source based on the where criteria. + * + * @param object where Criteria to match model instances + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Category` object.) + * + */ + public upsertWithWhere(where: any = undefined, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Categories/upsertWithWhere"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + if (where) urlParams.where = where; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instance: Category) => new Category(instance)); + } + /** * Check whether a model instance exists in the data source. * @@ -662,7 +694,7 @@ export class CategoryApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Categories/:id"; let routeParams: any = { @@ -723,7 +755,7 @@ export class CategoryApi extends BaseLoopBackApi { * This usually means the response is a `Category` object.) * */ - public createManyRooms(id: any, data: Array = undefined) { + public createManyRooms(id: any, data: Array = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Categories/:id/rooms"; diff --git a/tests/angular2/src/app/shared/sdk/services/custom/Like.ts b/tests/angular2/src/app/shared/sdk/services/custom/Like.ts index af517c10..d4f2e0e9 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/Like.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/Like.ts @@ -136,7 +136,7 @@ export class LikeApi extends BaseLoopBackApi { * */ public upsert(data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/likes"; let routeParams: any = {}; @@ -177,6 +177,38 @@ export class LikeApi extends BaseLoopBackApi { return result; } + /** + * Update an existing model instance or insert a new one into the data source based on the where criteria. + * + * @param object where Criteria to match model instances + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Like` object.) + * + */ + public upsertWithWhere(where: any = undefined, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/likes/upsertWithWhere"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + if (where) urlParams.where = where; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instance: Like) => new Like(instance)); + } + /** * Check whether a model instance exists in the data source. * @@ -420,7 +452,7 @@ export class LikeApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/likes/:id"; let routeParams: any = { diff --git a/tests/angular2/src/app/shared/sdk/services/custom/Room.ts b/tests/angular2/src/app/shared/sdk/services/custom/Room.ts index ff98e8bc..00c6daa5 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/Room.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/Room.ts @@ -242,7 +242,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public updateByIdLikes(id: any, fk: any, data: Like = undefined) { + public updateByIdLikes(id: any, fk: any, data: any = undefined) { let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/likes/:fk"; @@ -361,7 +361,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public updateByIdCategories(id: any, fk: any, data: Category = undefined) { + public updateByIdCategories(id: any, fk: any, data: any = undefined) { let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/categories/:fk"; @@ -599,7 +599,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public updateByIdAccounts(id: any, fk: any, data: Account = undefined) { + public updateByIdAccounts(id: any, fk: any, data: any = undefined) { let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/accounts/:fk"; @@ -648,7 +648,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public linkAccounts(id: any, fk: any, data: RoomAccount = undefined) { + public linkAccounts(id: any, fk: any, data: any = undefined) { let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/accounts/rel/:fk"; @@ -837,7 +837,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public updateByIdAdmins(id: any, fk: any, data: Account = undefined) { + public updateByIdAdmins(id: any, fk: any, data: any = undefined) { let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/admins/:fk"; @@ -1175,7 +1175,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public createLikes(id: any, data: Like = undefined) { + public createLikes(id: any, data: any = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/likes"; @@ -1317,7 +1317,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public createCategories(id: any, data: Category = undefined) { + public createCategories(id: any, data: any = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/categories"; @@ -1459,7 +1459,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public createAccounts(id: any, data: Account = undefined) { + public createAccounts(id: any, data: any = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/accounts"; @@ -1601,7 +1601,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public createAdmins(id: any, data: Account = undefined) { + public createAdmins(id: any, data: any = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/admins"; @@ -1752,7 +1752,7 @@ export class RoomApi extends BaseLoopBackApi { * */ public upsert(data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms"; let routeParams: any = {}; @@ -1765,7 +1765,7 @@ export class RoomApi extends BaseLoopBackApi { } public onUpsert() { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = "/" + LoopBackConfig.getApiVersion() + "/rooms"; let routeParams: any = {}; @@ -1815,6 +1815,49 @@ export class RoomApi extends BaseLoopBackApi { return result; } + /** + * Update an existing model instance or insert a new one into the data source based on the where criteria. + * + * @param object where Criteria to match model instances + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `Room` object.) + * + */ + public upsertWithWhere(where: any = undefined, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/rooms/upsertWithWhere"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + if (where) urlParams.where = where; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instance: Room) => new Room(instance)); + } + + public onUpsertWithWhere(where: any = undefined) { + let method: string = "POST"; + let url: string = "/" + LoopBackConfig.getApiVersion() + + "/rooms/upsertWithWhere"; + let routeParams: any = {}; + let postBody: any = {}; + let urlParams: any = {}; + let result = this.request(method, url, routeParams, urlParams, postBody, true); + return result; + } + /** * Check whether a model instance exists in the data source. * @@ -2095,7 +2138,7 @@ export class RoomApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id"; let routeParams: any = { @@ -2110,7 +2153,7 @@ export class RoomApi extends BaseLoopBackApi { } public onUpdateAttributes(id: any) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = "/" + LoopBackConfig.getApiVersion() + "/rooms/:id"; let routeParams: any = { @@ -2332,7 +2375,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public createManyLikes(id: any, data: Array = undefined) { + public createManyLikes(id: any, data: Array = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/likes"; @@ -2378,7 +2421,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public createManyCategories(id: any, data: Array = undefined) { + public createManyCategories(id: any, data: Array = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/categories"; @@ -2424,7 +2467,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public createManyAccounts(id: any, data: Array = undefined) { + public createManyAccounts(id: any, data: Array = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/accounts"; @@ -2470,7 +2513,7 @@ export class RoomApi extends BaseLoopBackApi { * This usually means the response is a `Room` object.) * */ - public createManyAdmins(id: any, data: Array = undefined) { + public createManyAdmins(id: any, data: Array = undefined) { let method: string = "POST"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/rooms/:id/admins"; diff --git a/tests/angular2/src/app/shared/sdk/services/custom/RoomAccount.ts b/tests/angular2/src/app/shared/sdk/services/custom/RoomAccount.ts index 1bd6d421..bd277b27 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/RoomAccount.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/RoomAccount.ts @@ -137,7 +137,7 @@ export class RoomAccountApi extends BaseLoopBackApi { * */ public upsert(data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/room-accounts"; let routeParams: any = {}; @@ -178,6 +178,38 @@ export class RoomAccountApi extends BaseLoopBackApi { return result; } + /** + * Update an existing model instance or insert a new one into the data source based on the where criteria. + * + * @param object where Criteria to match model instances + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `RoomAccount` object.) + * + */ + public upsertWithWhere(where: any = undefined, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/room-accounts/upsertWithWhere"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + if (where) urlParams.where = where; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instance: RoomAccount) => new RoomAccount(instance)); + } + /** * Check whether a model instance exists in the data source. * @@ -421,7 +453,7 @@ export class RoomAccountApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/room-accounts/:id"; let routeParams: any = { diff --git a/tests/angular2/src/app/shared/sdk/services/custom/User.ts b/tests/angular2/src/app/shared/sdk/services/custom/User.ts index fd556077..8c4ac5dd 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/User.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/User.ts @@ -284,7 +284,7 @@ export class UserApi extends BaseLoopBackApi { * */ public upsert(data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Users"; let routeParams: any = {}; @@ -325,6 +325,38 @@ export class UserApi extends BaseLoopBackApi { return result; } + /** + * Update an existing model instance or insert a new one into the data source based on the where criteria. + * + * @param object where Criteria to match model instances + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `User` object.) + * + */ + public upsertWithWhere(where: any = undefined, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/Users/upsertWithWhere"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + if (where) urlParams.where = where; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instance: User) => new User(instance)); + } + /** * Check whether a model instance exists in the data source. * @@ -568,7 +600,7 @@ export class UserApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/Users/:id"; let routeParams: any = { diff --git a/tests/angular2/src/app/shared/sdk/services/custom/UserCredential.ts b/tests/angular2/src/app/shared/sdk/services/custom/UserCredential.ts index 832abb3b..bdef0325 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/UserCredential.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/UserCredential.ts @@ -75,7 +75,7 @@ export class UserCredentialApi extends BaseLoopBackApi { * */ public upsert(data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/UserCredentials"; let routeParams: any = {}; @@ -116,6 +116,38 @@ export class UserCredentialApi extends BaseLoopBackApi { return result; } + /** + * Update an existing model instance or insert a new one into the data source based on the where criteria. + * + * @param object where Criteria to match model instances + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `UserCredential` object.) + * + */ + public upsertWithWhere(where: any = undefined, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/UserCredentials/upsertWithWhere"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + if (where) urlParams.where = where; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instance: UserCredential) => new UserCredential(instance)); + } + /** * Check whether a model instance exists in the data source. * @@ -359,7 +391,7 @@ export class UserCredentialApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/UserCredentials/:id"; let routeParams: any = { diff --git a/tests/angular2/src/app/shared/sdk/services/custom/UserIdentity.ts b/tests/angular2/src/app/shared/sdk/services/custom/UserIdentity.ts index d682353d..8367ad01 100644 --- a/tests/angular2/src/app/shared/sdk/services/custom/UserIdentity.ts +++ b/tests/angular2/src/app/shared/sdk/services/custom/UserIdentity.ts @@ -106,7 +106,7 @@ export class UserIdentityApi extends BaseLoopBackApi { * */ public upsert(data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/UserIdentities"; let routeParams: any = {}; @@ -147,6 +147,38 @@ export class UserIdentityApi extends BaseLoopBackApi { return result; } + /** + * Update an existing model instance or insert a new one into the data source based on the where criteria. + * + * @param object where Criteria to match model instances + * + * @param object data Request data. + * + * This method expects a subset of model properties as request parameters. + * + * @returns object An empty reference that will be + * populated with the actual data once the response is returned + * from the server. + * + * + * (The remote method definition does not provide any description. + * This usually means the response is a `UserIdentity` object.) + * + */ + public upsertWithWhere(where: any = undefined, data: any = undefined) { + let method: string = "POST"; + let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + + "/UserIdentities/upsertWithWhere"; + let routeParams: any = {}; + let postBody: any = { + data: data + }; + let urlParams: any = {}; + if (where) urlParams.where = where; + let result = this.request(method, url, routeParams, urlParams, postBody); + return result.map((instance: UserIdentity) => new UserIdentity(instance)); + } + /** * Check whether a model instance exists in the data source. * @@ -390,7 +422,7 @@ export class UserIdentityApi extends BaseLoopBackApi { * */ public updateAttributes(id: any, data: any = undefined) { - let method: string = "PATCH"; + let method: string = "PUT"; let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() + "/UserIdentities/:id"; let routeParams: any = { diff --git a/tests/angular2/src/environments/environment.dev.ts b/tests/angular2/src/environments/environment.dev.ts deleted file mode 100644 index ffe8aed7..00000000 --- a/tests/angular2/src/environments/environment.dev.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const environment = { - production: false -}; diff --git a/tests/angular2/src/environments/environment.ts b/tests/angular2/src/environments/environment.ts index 5c54e150..00313f16 100644 --- a/tests/angular2/src/environments/environment.ts +++ b/tests/angular2/src/environments/environment.ts @@ -1,7 +1,7 @@ -// The file for the current environment will overwrite this one during build. -// Different environments can be found in ./environment.{dev|prod}.ts, and -// you can create your own and use it with the --env flag. -// The build system defaults to the dev environment. +// The file contents for the current environment will overwrite these during build. +// The build system defaults to the dev environment which uses `environment.ts`, but if you do +// `ng build --env=prod` then `environment.prod.ts` will be used instead. +// The list of which env maps to which file can be found in `angular-cli.json`. export const environment = { production: false diff --git a/tests/angular2/src/test.ts b/tests/angular2/src/test.ts index a85e8bb7..7727c8e6 100644 --- a/tests/angular2/src/test.ts +++ b/tests/angular2/src/test.ts @@ -1,13 +1,15 @@ import './polyfills.ts'; import 'zone.js/dist/long-stack-trace-zone'; +import 'zone.js/dist/proxy.js'; +import 'zone.js/dist/sync-test'; import 'zone.js/dist/jasmine-patch'; import 'zone.js/dist/async-test'; import 'zone.js/dist/fake-async-test'; -import 'zone.js/dist/sync-test'; // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. declare var __karma__: any; +declare var require: any; // Prevent Karma from running prematurely. __karma__.loaded = function () {}; diff --git a/tests/angular2/src/tsconfig.json b/tests/angular2/src/tsconfig.json index 06ca7b86..7f33f7f0 100644 --- a/tests/angular2/src/tsconfig.json +++ b/tests/angular2/src/tsconfig.json @@ -3,7 +3,6 @@ "declaration": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, - "noImplicitAny": true, "lib": ["es6", "dom"], "mapRoot": "./", "module": "es6",