Skip to content

Add option to leave out definitions for common modules + namespace models #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

persimmons
Copy link
Contributor

When connecting to several LoopBack APIs from an Angular app, multiple definitions of LoopBackAuth and LoopBackResource will 'step on' each other, resulting in unpredictable behavior.

This change keeps the default behavior consistent, but will omit the module block that generates the LoopBackAuth, LoopBackAuthRequestInterceptor, and LoopBackResource components if a fourth parameter (excludeCommonModules) is set to 'true' when generateServices is called.

This will enable loopback-sdk-angular to more seamlessly be used with multiple-API architectures, without having to manually delete sections of code generated by the SDK.

@slnode
Copy link

slnode commented Apr 11, 2016

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@persimmons
Copy link
Contributor Author

Rebased to match master. Please let me know if there are any desired changes and I'll be happy to accommodate.

@bajtos

@persimmons persimmons force-pushed the feature/optional-common-modules branch from 9fab292 to cb28c8a Compare April 11, 2016 19:08
@bajtos
Copy link
Member

bajtos commented Apr 12, 2016

@slnode ok to test

@bajtos bajtos self-assigned this Apr 12, 2016
@@ -374,7 +380,9 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' &&
},
};
}])

<% } // end if (defineLoopBackAuthRequestInterceptor) %>
defineLoopBackResource: <%= defineLoopBackResource %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what is the purpose of this line?

@bajtos
Copy link
Member

bajtos commented Apr 12, 2016

Hi @keithajackson, thank you for the pull request. Could you please add tests to verify your changes?

If I am reading the code correctly, when defineLoopBackAuthRequestInterceptor is true and defineLoopBackResource is false, the generated code will miss a semicolon at the end:

module
    // ...
   .config(['$httpProvider', function($httpProvider) {
     $httpProvider.interceptors.push('LoopBackAuthRequestInterceptor');
   }])
   .factory('LoopBackAuthRequestInterceptor', ['$q', 'LoopBackAuth',
     function($q, LoopBackAuth) {
       // ...
     }])
//      ^-- missing semicolon

I am proposing to get rid of fine-grained flags defineLoopBack* and use a single flag instead.

var defineLoopBackAuthRequestInterceptor = true;
var defineLoopBackResource = true;

if (excludeCommonModules === "true") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a string? At this abstraction level, we should expect input arguments in the correct type and let callers to figure out how to convert string input into boolean values.

if (excludeCommonModules) {
  // ...
}

@bajtos
Copy link
Member

bajtos commented Jun 13, 2016

@keithajackson hello, what's the status of this pull request? Are you still keen to finish it?

@bajtos bajtos added the waiting label Jun 13, 2016
@persimmons
Copy link
Contributor Author

Hi @bajtos - my apologies for letting this go stale - I'm working on writing tests and catching up to master right now.

I'm running into some difficulty getting the test system up and running and was wondering if you might be able to give me a suggestion of what to try next. I've been following the instructions in DEVELOPING.md to run tests with Karma.

When I run node test.e2e/test-server in a zsh terminal running Node 5.10.1, I get the output: Test server is listening on http://localhost:3033

The second terminal outputs:

[2016-06-17 14:41:37.563] [DEBUG] config - Loading config /Users/kjackson/Code/loopback-sdk-angular/karma.conf.js
17 06 2016 14:41:37.578:ERROR [runner]: There is no server listening on port 9876

I went into the karma.conf.js and changed the port from 9876 to 3033 to match the e2e server and re-ran karma-start.

The terminal running the test server outputs POST /run 404 1.274 ms - 17, but the terminal running karma start has another error:

[2016-06-17 14:42:38.113] [DEBUG] config - Loading config /Users/kjackson/Code/loopback-sdk-angular/karma.conf.js
Cannot POST /run

Does this issue sound familiar? Is there a server or Selenium webdriver I need to be running on port 9876 in addition to the test-server on 3033?

Thank you so much for your time and assistance!

@persimmons persimmons force-pushed the feature/optional-common-modules branch from cb28c8a to 538edd7 Compare June 17, 2016 22:40
@persimmons persimmons changed the title Add option to leave out definitions for common modules Add option to leave out definitions for common modules + namespace models Jun 17, 2016
@persimmons persimmons force-pushed the feature/optional-common-modules branch from 538edd7 to f3afff4 Compare June 17, 2016 22:46
@bajtos
Copy link
Member

bajtos commented Jun 20, 2016

Hey @keithajackson, I am sorry to hear about the difficulties with getting the tests environment set up. Before I dig deeper, I'd like to check whether npm test works for you?

@persimmons
Copy link
Contributor Author

Hi @bajtos!

All right - I think I've figured out the issue, at least on my machine. My npm test fails unless I manually update my installed version of phantomjs to v2.x. The error I get with Phantom is on v1.9 is:

Error: [$injector:modulerr] Failed to instantiate module ng due to:
  TypeError: 'undefined' is not an object (evaluating 'Function.prototype.bind.apply')

It seems connected to this thread related to Angular v1.5 breaking compatibility with Phantom v1.x: angular/angular.js#13794

I've run it in these environments and found the same issue:

  • Node v5.10.1, NPM v3.8.3
  • Node v0.10.45, NPM v2.15.1
  • Node v0.10.45, NPM v2.15.1 (on master)

I'm unblocked on my issue, so I'll continue working on tests - but I would recommend either updating phantomjs to v2.x or locking angular at ~1.4.9 (since angular doesn't comply with semver and minor version changes introduce breaking changes).

@persimmons persimmons force-pushed the feature/optional-common-modules branch 2 times, most recently from 24dcbdc to 8d089fc Compare June 21, 2016 17:07
@persimmons
Copy link
Contributor Author

persimmons commented Jun 21, 2016

Hi @bajtos ,

I've added tests covering the new features, but few builds are failing:

  • default: when I attempt to access the Jenkins server for details, I get an ERR_ADDRESS_UNREACHABLE error.
  • loopback-sdk-angular.dependants:
Set build name.
New build name is '#4244 (origin/master)'
Variable with name 'BUILD_DISPLAY_NAME' already exists, current value: '#4244 (origin/master)', new value: '#4244 (origin/master)'
Notifying upstream projects of job completion
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Triggering a new build of update-commit-status
Finished: FAILURE
  • pr-builder:
Setting commit status on GitHub for https://github.com/strongloop/loopback-sdk-angular/commit/8d089fc41faf2a6f77abd9d67abc40de45319981
Notifying upstream projects of job completion
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Triggering a new build of update-commit-status
Finished: FAILURE
  • dependent-loopback-workspace:
  1) end-to-end empty-server template without explorer "before all" hook: installSandboxPackages:
     Error: timeout of 300000ms exceeded. Ensure the done() callback is being called in this test.
      at [object Object].<anonymous> (node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31)

  2) end-to-end api-server template "before all" hook:
     Error: ENOTEMPTY, rmdir '/mnt/jenkins/workspace/loopback-workspace/1de32925/test/sandbox/node_modules/eslint/node_modules/es6-map/node_modules/es5-ext/test/number'
      at Error (native)

  3) end-to-end notes template "before all" hook: installSandboxPackages:
     Error: timeout of 300000ms exceeded. Ensure the done() callback is being called in this test.
      at [object Object].<anonymous> (node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31)

  4) end-to-end hello-world template "before all" hook:
     Error: ENOTEMPTY, rmdir '/mnt/jenkins/workspace/loopback-workspace/1de32925/test/sandbox/node_modules/eslint/node_modules/escope/node_modules/es6-weak-map/node_modules/es5-ext/math'
      at Error (native)

  5) end-to-end autoupdate "before all" hook: installSandboxPackages:
     Error: timeout of 300000ms exceeded. Ensure the done() callback is being called in this test.
      at [object Object].<anonymous> (node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31)

  6) end-to-end discovery "before all" hook:
     Error: ENOTEMPTY, rmdir '/mnt/jenkins/workspace/loopback-workspace/1de32925/test/sandbox/node_modules/eslint/node_modules/escope/node_modules/es6-weak-map/node_modules/es5-ext/test/array/#'
      at Error (native)

  7) end-to-end testConnection "before all" hook: installSandboxPackages:
     Error: timeout of 300000ms exceeded. Ensure the done() callback is being called in this test.
      at [object Object].<anonymous> (node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31)

  8) end-to-end start/stop/restart "before all" hook:
     Error: ENOTEMPTY, rmdir '/mnt/jenkins/workspace/loopback-workspace/1de32925/test/sandbox/node_modules/eslint/node_modules/escope/node_modules/es6-weak-map/node_modules/es5-ext/math/asinh'
      at Error (native)

Do you have any recommendations for how to address these issues?
Thanks!

@@ -50,10 +50,14 @@ module.exports = function generateServices(app, options) {
apiUrl: arguments[2],
};
}
var oldOptions = options;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, this is unused - please remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes - removed!

@bajtos
Copy link
Member

bajtos commented Jul 27, 2016

Hey @keithajackson, sorry for the long delay. I reviewed your changes, they looks mostly good to me. Please address the comments I left above.

As for failing CI builds, I am afraid our CI system is still not stable and still not visible to public. Just make sure npm test passes on your local machine, we will check CI results ourselves to see if they are related to this patch.

@slnode
Copy link

slnode commented Jul 27, 2016

Can one of the admins verify this patch?

@persimmons persimmons force-pushed the feature/optional-common-modules branch from 7b4b562 to 2f54ee5 Compare July 27, 2016 17:45
@persimmons
Copy link
Contributor Author

@bajtos All comments adressed and code rebased against master - thanks so much for close review! Let me know if you have any other comments you'd like addressed or run into any surprises.

I double-checked test after the update+rebase and it all looks good on my machine.

@bajtos
Copy link
Member

bajtos commented Jul 28, 2016

Thank you for the quick update, @keithajackson!

I run node apidocs/describe-builtin-models.js using master version and the version from your patch. When I compared the outcome, there is one extra empty line:

--- apidocs/loopback-core-master.js 2016-07-28 14:43:03.000000000 +0200
+++ apidocs/loopback-core.js    2016-07-28 14:43:18.000000000 +0200
@@ -6993,6 +6993,7 @@
       }]);


+
   module
   .factory('LoopBackAuth', function() {
     var props = ['accessTokenId', 'currentUserId', 'rememberMe'];

What's your opinion? Do you feel like fixing this small detail, or should we ignore it?

Other than that, the patch LGTM.

Could you please squash all your commits into a single one and provide a descriptive commit message following the 50/72 rule?

@persimmons persimmons force-pushed the feature/optional-common-modules branch from 2f54ee5 to 433e46f Compare July 28, 2016 20:37
@persimmons
Copy link
Contributor Author

@bajtos Fixed! I was able to find the blank line causing the documentation inconsistency and removed it. I've also squashed commits to match the commit style.

Thanks again for your time and thoughtful comments. Let me know if there is anything else I can improve or help with!

@persimmons persimmons force-pushed the feature/optional-common-modules branch from 433e46f to ee43271 Compare July 28, 2016 20:42
When connecting to several LoopBack APIs from an Angular app, multiple
definitions of LoopBackAuth and LoopBackResource will 'step on' each
other, resulting in unpredictable behavior. In addition, if two APIs
have models with the same names, these definitions will override each
other, depending upon whichever API loaded last.

This patch keeps the default behavior consistent, but provides an option
to omit the module block that generates the LoopBackAuth,
LoopBackAuthRequestInterceptor, and LoopBackResource components. It also
provides an option to namespace models with the module name.
@persimmons persimmons force-pushed the feature/optional-common-modules branch from ee43271 to 1c7ec4c Compare July 28, 2016 20:43
@bajtos bajtos removed the waiting label Jul 29, 2016
@bajtos bajtos merged commit 7ae1e3e into strongloop:master Jul 29, 2016
@bajtos
Copy link
Member

bajtos commented Jul 29, 2016

@keithajackson awesome! I have landed the patch, thank you for this great contribution 🎉 👏

@bajtos
Copy link
Member

bajtos commented Jul 29, 2016

Released as [email protected], enjoy 😄

@bajtos bajtos mentioned this pull request Nov 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants