Skip to content

Commit

Permalink
Release 2.0.0-rc.9.1
Browse files Browse the repository at this point in the history
- Fix: #90
- Fix: #89
  • Loading branch information
Jonathan Casarrubias committed Aug 17, 2016
1 parent 23c8c67 commit ee08cef
Show file tree
Hide file tree
Showing 15 changed files with 1,026 additions and 444 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This file is created to keep history of the LoopBack SDK Builder, it does not co

## Release 2.0.0-rc.9

- Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/90
- Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/89

## Release 2.0.0-rc.9

- Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/88
- Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/87
- Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/85
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ You don't have to manually write any static code.

````sh
$ cd to/api/project
$ npm install --save-dev loopback-sdk-builder@2.0.0-rc.9
$ npm install --save-dev loopback-sdk-builder@2.0.0-rc.9.1
````

# LoopBack SDK CLI Options
Expand Down
29 changes: 21 additions & 8 deletions lib/angular2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,33 @@ module.exports = function generate(ctx) {
* @method buildServiceImports
* @description
* Define import statement for those model who are related to other scopes
* IMPORTANT: This method have a very specific flow, changing it may create
* multiple issues on multiple different use cases.
*/
function buildServiceImports(model) {
let output = [` ${capitalize(model.name)}`];
let loaded = {}; loaded[model.name] = true;
getModelRelations(model).forEach((relationName, i) => {
let targetClass = model.sharedClass.ctor.relations[relationName].targetClass;
// It is imperative to check first for through models, else we may miss some
// Through Models. This is because multiple relationships to the same model may have
// different Through models, in the next validation we avoid duplicating models, which
// can lead to miss some through models.
if (
model.sharedClass.ctor.relations[relationName].modelThrough &&
model.sharedClass.ctor.relations[relationName].modelThrough.sharedClass.name !== 'Model'
) {
let through = capitalize(model.sharedClass.ctor.relations[relationName].modelThrough.sharedClass.name);
if (!loaded[through]) {
loaded[through] = true;
output.push(` ${through}`);
}
}
// Now and after the through model was included is the right time to verify if the current model
// was loaded by another relationship, this way we don't duplicate the class during imports'
if (!loaded[targetClass]) {
loaded[targetClass] = true;
output.push(` ${targetClass}`);
if (model.sharedClass.ctor.relations[relationName].modelThrough &&
model.sharedClass.ctor.relations[relationName].modelThrough.sharedClass.name !== 'Model')
output.push(` ${capitalize(model.sharedClass.ctor.relations[relationName]
.modelThrough.sharedClass.name)}`);
}
});
output.push(' LoopBackFilter');
Expand Down Expand Up @@ -421,9 +435,8 @@ function capitalize(string) {
}

function getModelRelations(model) {
return Object.keys(model.sharedClass.ctor.relations).filter(relationName => {
return model.sharedClass.ctor.relations[relationName].targetClass &&
model.sharedClass.ctor.relations[relationName].targetClass !== model.name
}
return Object.keys(model.sharedClass.ctor.relations).filter(relationName =>
model.sharedClass.ctor.relations[relationName].targetClass &&
model.sharedClass.ctor.relations[relationName].targetClass !== model.name
);
}
8 changes: 3 additions & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,17 @@ exports.describeModels = function describeModels(app) {
console.error('Skipping %j as it is not a LoopBack model', name);
return;
}

// The URL of prototype methods include sharedCtor parameters like ":id"
// Because all $resource methods are static (non-prototype) in ngResource,
// the sharedCtor parameters should be added to the parameters
// of prototype methods.
c.methods.forEach(function fixArgsOfPrototypeMethods(method, key) {
if (method.name.match(/(^createMany)/)) return;
if (method.name.match(/(^createMany)/)) return
if (method.name.match(/(^create$|__create__)/)) {
var createMany = Object.create(method);
createMany.name = method.name.replace(/create/g, 'createMany');
createMany.isReturningArray = function () { return true; };
c.methods.splice(key + 1, 0, createMany);
c.methods.push(createMany);
}
var ctor = method.restClass.ctor;
if (!ctor || method.sharedMethod.isStatic) return;
Expand All @@ -55,7 +54,6 @@ exports.describeModels = function describeModels(app) {
}
});
}

if (!method.accepts) return;

// Any extra http action arguments in the path need to be added to the
Expand All @@ -76,7 +74,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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "loopback-sdk-builder",
"version": "2.0.0-rc.9",
"version": "2.0.0-rc.9.1",
"description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack",
"bin": {
"lb-ng": "bin/lb-ng",
Expand Down
8 changes: 4 additions & 4 deletions tests/angular2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/core": "2.0.0-rc.4",
"@angular/http": "^2.0.0-rc.4",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/router": "3.0.0-alpha.8",
Expand All @@ -36,10 +36,10 @@
"reflect-metadata": "0.1.3",
"requirejs": "^2.2.0",
"rxjs": "5.0.0-beta.6",
"serve-favicon": "^2.0.1",
"socket.io-client": "^1.4.8",
"serve-favicon": "2.0.1",
"socket.io-client": "1.4.8",
"systemjs": "0.19.26",
"zone.js": "^0.6.12"
"zone.js": "0.6.12"
},
"devDependencies": {
"angular-cli": "0.0.*",
Expand Down
Loading

0 comments on commit ee08cef

Please sign in to comment.