Skip to content

Commit

Permalink
Release 2.0.3 🚀
Browse files Browse the repository at this point in the history
- Fixed Lint issues
- Fix: #99
  • Loading branch information
Jonathan Casarrubias committed Aug 26, 2016
1 parent b89a66d commit 7e9ab3c
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This file is created to keep history of the LoopBack SDK Builder, it does not consider or keeps any history of its parent module `loopback-sdk-angular`.

## Release 2.0.3

- Fixed Lint issues
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/99


## Release 2.0.2

- Hot Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/98
Expand Down
2 changes: 1 addition & 1 deletion lib/angular2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ module.exports = function generate(ctx) {
function buildUrlParams(model, methodName, urlParams) {
let output = [''];
// filter params that should not go over url query string
urlParams = urlParams.filter(param => !param.arg.match(/(id|fk|data|options|credentials)/g));
urlParams = urlParams.filter(param => (param.arg && !param.arg.match(/(id|fk|data|options|credentials)/g)));
if (model.isUser && methodName === 'logout')
output.push(` urlParams.access_token = this.auth.getAccessTokenId();`);
if (urlParams && urlParams.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/angular2/shared/sdk.module.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ export class SDKModule {
]
};
}
}
}
2 changes: 1 addition & 1 deletion lib/angular2/shared/services/custom/service.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class <%-: modelName %>Api extends BaseLoopBackApi {
}
// SET ROUTE PARAMS
var routeParams = action.accepts.filter(function(param) {
return (param.http && param.http.source === 'path') || (param.arg.match(/(id|fk|file|container)/));
return (param.http && param.http.source === 'path') || (param.arg && param.arg.match(/(id|fk|file|container)/));
});
-%>
public <%- normalizeMethodName(methodName) %>(<%- buildMethodParams(model, methodName, action.accepts) %>) {
Expand Down
20 changes: 14 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exports.describeModels = function describeModels(app) {
// Tell SDK to blacklist specific methods
c.sharedClass.ctor.settings.sdk.blacklist = Object.assign(
{}, // Will we want to add methods to blacklist by default???
c.sharedClass.ctor.settings.sdk.blacklist ||  {}
c.sharedClass.ctor.settings.sdk.blacklist || {}
);
if (!c.ctor) {
// Skip classes that don't have a shared ctor
Expand All @@ -33,6 +33,16 @@ exports.describeModels = function describeModels(app) {
// the sharedCtor parameters should be added to the parameters
// of prototype methods.
c.methods.forEach(function fixArgsOfPrototypeMethods(method, key) {
// Fix for REST DataSource with invalid param configuration
if (method.name === 'invoke' && method.sharedMethod.isStatic) {
method.accepts.forEach((param) => {
if (!param.arg && param.name) {
param.arg = param.name;
param.http = { source: 'body' };
}
});
}
// Add CreateMany Support
if (method.name.match(/(^createMany)/)) return
if (method.name.match(/(^create$|__create__)/)) {
var createMany = Object.create(method);
Expand All @@ -44,18 +54,17 @@ exports.describeModels = function describeModels(app) {
if (!ctor || method.sharedMethod.isStatic) return;
method.accepts = ctor.accepts.concat(method.accepts);
var loaded = {};
// clean duplicated params
// Clean duplicated params from diff sources
if (method.name.match(/createMany/)) {
method.accepts.forEach((param, index, arr) => {
if (loaded[param.arg]) {
arr.splice(index, 1);
} else {
} else  {
loaded[param.arg] = true;
}
});
}
if (!method.accepts) return;

// Any extra http action arguments in the path need to be added to the
// angular resource actions as params
method.accepts.forEach(function findResourceParams(arg) {
Expand All @@ -74,7 +83,7 @@ exports.describeModels = function describeModels(app) {
c.properties = c.sharedClass.ctor.definition.properties;

c.isUser = c.sharedClass.ctor.prototype instanceof app.loopback.User ||
c.sharedClass.ctor.prototype === app.loopback.User.prototype;
c.sharedClass.ctor.prototype === app.loopback.User.prototype;
models[name] = c;
});

Expand Down Expand Up @@ -131,7 +140,6 @@ function buildScopeMethod(models, modelName, method) {
'Warning: scope %s.%s targets class %j, which is not exposed ' +
'\nvia remoting. The Angular code for this scope won\'t be generated.',
modelName, scopeName, targetClass);
console.log(modelName, scopeName, targetClass);
modelClass.scopes[scopeName] = null;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mean-expert/loopback-sdk-builder",
"version": "2.0.2",
"version": "2.0.3",
"description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack",
"bin": {
"lb-sdk": "bin/lb-sdk"
Expand Down
3 changes: 3 additions & 0 deletions tests/angular2/common/models/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(Core) {

};
14 changes: 14 additions & 0 deletions tests/angular2/common/models/core.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Core",
"plural": "cores",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
32 changes: 32 additions & 0 deletions tests/angular2/loopback/datasources.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,37 @@
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "./loopback/storage"
},
"corezoid": {
"name": "corezoid",
"crud": false,
"connector": "rest",
"options": {
"headers": {
"accept": "application/json",
"content-type": "application/json"
},
"strictSSL": false
},
"operations": [
{
"template": {
"method": "POST",
"url": "https://www.corezoid.com/api/1/json/{path}",
"query": {},
"responsePath": "$",
"body": "{body}",
"options": {
"useQuerystring": false
}
},
"functions": {
"run": [
"path",
"body"
]
}
}
]
}
}
4 changes: 4 additions & 0 deletions tests/angular2/loopback/model-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,9 @@
"Storage": {
"dataSource": "storage",
"public": true
},
"Core": {
"dataSource": "corezoid",
"public": true
}
}
13 changes: 7 additions & 6 deletions tests/angular2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@
"@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",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"ts-helpers": "^1.1.1",
"zone.js": "0.6.12",
"compression": "^1.0.3",
"config-chain": "^1.1.10",
"core-js": "^2.4.0",
"cors": "^2.5.2",
"es6-shim": "^0.35.0",
"helmet": "^1.3.0",
Expand All @@ -37,8 +33,13 @@
"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",
"socket.io-client": "1.4.8"
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"socket.io-client": "1.4.8",
"ts-helpers": "^1.1.1",
"zone.js": "0.6.12"
},
"devDependencies": {
"@types/jasmine": "^2.2.30",
Expand Down
11 changes: 0 additions & 11 deletions tests/angular2/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Component } from '@angular/core';
import { Room } from './shared/sdk/models';
import { RoomApi } from './shared/sdk/services';

@Component({
selector: 'app-root',
Expand All @@ -10,13 +8,4 @@ import { RoomApi } from './shared/sdk/services';

export class AppComponent {
title = 'app works!';
/*
constructor(private roomApi: RoomApi) {
let room: Room = new Room();
room.name = 'My Room';
this.roomApi.create(room).subscribe((instance: Room) => {
console.log(instance);
});
}
*/
}
2 changes: 1 addition & 1 deletion tests/angular2/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, ApplicationRef } from '@angular/core';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
Expand Down
6 changes: 4 additions & 2 deletions tests/angular2/src/app/shared/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {
CategoryApi,
AccountApi,
RoomAccountApi,
StorageApi
StorageApi,
CoreApi
} from './services/index';
export const API_PROVIDERS: any[] = [
HTTP_PROVIDERS,
Expand All @@ -52,7 +53,8 @@ export const API_PROVIDERS: any[] = [
CategoryApi,
AccountApi,
RoomAccountApi,
StorageApi
StorageApi,
CoreApi
];
export * from './models/index';
export * from './services/index';
Expand Down
12 changes: 12 additions & 0 deletions tests/angular2/src/app/shared/sdk/models/Core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* tslint:disable */

export interface CoreInterface {
id?: number;
}

export class Core implements CoreInterface {
id: number;
constructor(instance?: Core) {
Object.assign(this, instance);
}
}
1 change: 1 addition & 0 deletions tests/angular2/src/app/shared/sdk/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export * from './Category';
export * from './Account';
export * from './RoomAccount';
export * from './Storage';
export * from './Core';
export * from './BaseModels';
8 changes: 5 additions & 3 deletions tests/angular2/src/app/shared/sdk/sdk.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ import {
CategoryApi,
AccountApi,
RoomAccountApi,
StorageApi
StorageApi,
CoreApi
} from './services/index';

@NgModule({
Expand Down Expand Up @@ -81,8 +82,9 @@ export class SDKModule {
CategoryApi,
AccountApi,
RoomAccountApi,
StorageApi
StorageApi,
CoreApi
]
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ export abstract class BaseLoopBackApi {
.map(res => (res.text() != "" ? res.json() : {}))
.catch(this.errorHandler.handleError);
}
}
}
Loading

0 comments on commit 7e9ab3c

Please sign in to comment.