diff --git a/CHANGELOG.md b/CHANGELOG.md index d9eb3254..45753725 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ 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.7 + +- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/141 +- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/140 + ## Release 2.1.0-beta.6 - Hot Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/132 diff --git a/lib/angular2/index.js b/lib/angular2/index.js index 7f5b05d5..6d38bd39 100644 --- a/lib/angular2/index.js +++ b/lib/angular2/index.js @@ -80,7 +80,7 @@ module.exports = function generate(ctx) { { template: './shared/services/core/index.ejs', output: '/services/core/index.ts', - params: {} + params: { isIo: ctx.isIo } }, /** * SDK CONFIG @@ -215,6 +215,7 @@ module.exports = function generate(ctx) { buildPostBody: buildPostBody, buildUrlParams: buildUrlParams, buildRouteParams: buildRouteParams, + loadAccessToken: ctx.loadAccessToken, buildMethodParams: buildMethodParams, buildServiceImports: buildServiceImports, normalizeMethodName: normalizeMethodName, @@ -313,7 +314,7 @@ module.exports = function generate(ctx) { * IMPORTANT: This method have a very specific flow, changing it may create * multiple issues on multiple different use cases. */ - function buildServiceImports(model) { + function buildServiceImports(model, loadAccessToken) { let modelName = capitalize(model.name); let imports = [ { module: 'Injectable, Inject, Optional', from: '@angular/core'}, @@ -322,7 +323,7 @@ module.exports = function generate(ctx) { { module: 'LoopBackConfig', from: '../../lb.config'}, { module: 'LoopBackAuth', from: '../core/auth.service'}, { - module: `LoopBackFilter, ${model.isUser ? `SDKToken${ctx.loadAccessToken ? ', AccessToken' : ''}` : '' }`, + module: `LoopBackFilter, ${model.isUser ? `SDKToken${ (loadAccessToken && model.isUser) ? ', AccessToken' : '' }` : '' }`, from: '../../models/BaseModels' }, { module: 'JSONSearchParams', from: '../core/search.params'}, @@ -332,8 +333,6 @@ module.exports = function generate(ctx) { { module: 'rxjs/add/operator/map' }, { module: modelName, from: `../../models/${modelName}`}, ]; - if (!ctx.loadAccessToken && model.isUser) - imports.push({ module: `AccessToken`, from: '../../models/AccessToken' }); let loaded = {}; loaded[model.name] = true; getModelRelations(model).forEach((relationName, i) => { let targetClass = model.sharedClass.ctor.relations[relationName].targetClass; @@ -368,21 +367,19 @@ module.exports = function generate(ctx) { * @description * Define import statement for the SDK Module */ - function buildModuleImports(models, isIndex) { + function buildModuleImports(models, isIo) { 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'}, + { module: 'HttpModule', from: '@angular/http'}, + { module: 'CommonModule', from: '@angular/common'}, + { module: 'NgModule, ModuleWithProviders', from: '@angular/core'} ]; - if (!isIndex) { - imports = imports.concat([ - { module: 'HttpModule', from: '@angular/http'}, - { module: 'CommonModule', from: '@angular/common'}, - { module: 'NgModule, ModuleWithProviders', from: '@angular/core'} - ]); + if (isIo) { + imports.push({ module: 'RealTime', from: './services/core/real.time'}); } Object.keys(models).forEach(modelName => { diff --git a/lib/angular2/shared/index.ejs b/lib/angular2/shared/index.ejs index 4fa7fdaa..df449cfc 100644 --- a/lib/angular2/shared/index.ejs +++ b/lib/angular2/shared/index.ejs @@ -32,7 +32,7 @@ * export class AppModule { } * **/ -<%- buildModuleImports(models, false) %> +<%- buildModuleImports(models, isIo) %> @NgModule({ imports: [ CommonModule, HttpModule ], diff --git a/lib/angular2/shared/models/base.ejs b/lib/angular2/shared/models/base.ejs index f148b29f..077f7460 100644 --- a/lib/angular2/shared/models/base.ejs +++ b/lib/angular2/shared/models/base.ejs @@ -1,6 +1,6 @@ /* tslint:disable */ <% if (!loadAccessToken) { %> -import 'AccessToken' from './AccessToken'; +import { AccessToken } from './AccessToken'; <% } %> declare var Object: any; export interface LoopBackFilter { @@ -33,10 +33,10 @@ export class AccessToken implements AccessTokenInterface { } <% } %> export class SDKToken extends AccessToken { - id:string = null; + id: any = null; ttl: number = null; created: any = null; - userId: string = null; + userId: any = null; user: any = null; rememberMe: boolean = null; constructor(instance?: AccessToken) { diff --git a/lib/angular2/shared/services/core/auth.ejs b/lib/angular2/shared/services/core/auth.ejs index 4cf803a0..e5064de1 100644 --- a/lib/angular2/shared/services/core/auth.ejs +++ b/lib/angular2/shared/services/core/auth.ejs @@ -4,7 +4,7 @@ import { Injectable } from '@angular/core'; import { StorageDriver } from '../../storage/storage.driver'; import { SDKToken<% if (loadAccessToken) { %>, AccessToken<% } %> } from '../../models/BaseModels'; <% if (!loadAccessToken) { %> -import { AccessToken } from '../../models/BaseModels'; +import { AccessToken } from '../../models/AccessToken'; <% } %> /** * @module LoopBackAuth diff --git a/lib/angular2/shared/services/core/index.ejs b/lib/angular2/shared/services/core/index.ejs index c3d4b7ec..b1342a4d 100644 --- a/lib/angular2/shared/services/core/index.ejs +++ b/lib/angular2/shared/services/core/index.ejs @@ -3,4 +3,7 @@ export * from './auth.service'; export * from './error.service'; export * from './search.params'; export * from './base.service'; -export * from './real.time'; +<% if ( isIo === 'enabled' ){ -%>export * from './real.time'; +<% } +-%> + diff --git a/lib/angular2/shared/services/custom/service.ejs b/lib/angular2/shared/services/custom/service.ejs index 8e6c48ae..526a89bc 100644 --- a/lib/angular2/shared/services/custom/service.ejs +++ b/lib/angular2/shared/services/custom/service.ejs @@ -1,5 +1,5 @@ /* tslint:disable */ -<%- buildServiceImports(model) %> +<%- buildServiceImports(model, loadAccessToken) %> // Making Sure EventSource Type is available to avoid compilation issues. declare var EventSource: any; diff --git a/package.json b/package.json index c30632cb..e4c3192a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mean-expert/loopback-sdk-builder", - "version": "2.1.0-beta.6", + "version": "2.1.0-beta.7", "description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack", "bin": { "lb-sdk": "bin/lb-sdk" diff --git a/tests/angular2/package.json b/tests/angular2/package.json index 781b901b..af119edb 100644 --- a/tests/angular2/package.json +++ b/tests/angular2/package.json @@ -21,6 +21,7 @@ "@angular/platform-browser": "2.0.0", "@angular/platform-browser-dynamic": "2.0.0", "@angular/router": "3.0.0", + "@types/socket.io-client": "^1.4.27", "compression": "^1.0.3", "config-chain": "^1.1.10", "core-js": "^2.4.1", @@ -35,6 +36,7 @@ "loopback-connector-rest": "^2.0.0", "loopback-datasource-juggler": "^2.39.0", "rxjs": "5.0.0-beta.12", + "socket.io-client": "^1.4.8", "ts-helpers": "^1.1.1", "zone.js": "^0.6.23" }, diff --git a/tests/angular2/src/app/shared/sdk/index.ts b/tests/angular2/src/app/shared/sdk/index.ts index e86f61e6..ed96bbbe 100644 --- a/tests/angular2/src/app/shared/sdk/index.ts +++ b/tests/angular2/src/app/shared/sdk/index.ts @@ -34,12 +34,12 @@ **/ 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 { RealTime } from './services/core/real.time'; import { UserApi } from './services/custom/User'; import { RoomApi } from './services/custom/Room'; import { MessageApi } from './services/custom/Message'; diff --git a/tests/angular2/src/app/shared/sdk/models/BaseModels.ts b/tests/angular2/src/app/shared/sdk/models/BaseModels.ts index f8ed96a0..e5cd2ed9 100644 --- a/tests/angular2/src/app/shared/sdk/models/BaseModels.ts +++ b/tests/angular2/src/app/shared/sdk/models/BaseModels.ts @@ -31,10 +31,10 @@ export class AccessToken implements AccessTokenInterface { } export class SDKToken extends AccessToken { - id:string = null; + id: any = null; ttl: number = null; created: any = null; - userId: string = null; + userId: any = null; user: any = null; rememberMe: boolean = null; constructor(instance?: AccessToken) {