-
Notifications
You must be signed in to change notification settings - Fork 71
Allow defining remote method without isStatic flag #173
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
Conversation
db48529
to
b814032
Compare
ed88078
to
31750fe
Compare
default: true | ||
default: function(answers) { | ||
return !answers.methodName.match(/^prototype\.(.*)$/); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation - L101 and L102 are indented by one extra level.
@0candy could you please describe in pull request description what exactly are you changing here? I am mostly able to get that by reading the code, however other people and especially our users may not. |
As I commented in strongloop/loopback-workspace#273, I would like to preserve the current workspace API, i.e. a remote prototype method should still have the name without |
31750fe
to
fb1f66a
Compare
var definition = common.readJsonSync('common/models/car.json'); | ||
var methods = definition.methods || {}; | ||
expect(methods).to.have.property('prototype.myRemote'); | ||
expect(methods['prototype.myRemote']).to.eql({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true when the project is using LoopBack 3.0, i.e. when common.createDummyProject
creates a LB 3.0 project. However, since 3.0 was not released yet, I think we are using LB 2.0 and thus the entry should use the old convention (name + isStatic). Am I missing something?
The implementation itself looks good to me, however the tests are suspicious. Let's figure out the loopback-workspace part fist and then come back to generator-loopback. |
The change in generator-loopback was that either methods of defining the remote method should work. Only loopback-workspace distinguishes between LB 2.0 and 3.0. |
67806a5
to
a9448c7
Compare
* @returns {String|Boolean} | ||
*/ | ||
exports.checkRemoteMethodName = function(name) { | ||
if (name.match(/\./) && !name.match(/^prototype\.(.*)$/)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is .
character allowed after prototype.
? I believe the current code allows that.
I think you need to change the second regexp to /^prototype\.([^.]*)$/
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the \.
after prototype include the .
character?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the test case to add to your unit-tests:
testValidationRejectsValue(validateRemoteMethodName, 'prototype.dotted.method');
type: 'confirm', | ||
default: true | ||
default: function(answers) { | ||
return !answers.methodName.match(/^prototype\.(.*)$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we allow methodName
to start with prototype.
prefix, then I think we need to remove that prefix before we pass the name to ModelMethod
constructor. See strongloop/loopback-workspace#273 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we allow
methodName
to start withprototype.
prefix, then I think we need to remove that prefix before we pass the name toModelMethod
constructor. See strongloop/loopback-workspace#273 (comment)
@0candy ^^^ thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, hence I removed the prefix before passing the name to the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see, the prefix is removed here: https://github.com/strongloop/generator-loopback/pull/173/files#diff-1162a393eb1e8979663fc397b9fbacbeR113
✅
@0candy could you please add a unit-test to verify that the generator correctly handles the case where the user enters |
a9448c7
to
15ec7ee
Compare
* @returns {String|Boolean} | ||
*/ | ||
exports.validateRemoteMethodName = function(name) { | ||
if (name.match(/\./) && !name.match(/^prototype\.(.*)$/)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the
\.
after prototype include the.
character?
Here is the test case to add to your unit-tests:
testValidationRejectsValue(validateRemoteMethodName, 'prototype.dotted.method');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, sorry. I misunderstood. Thought you said it doesn't allow prototype.
, but you meant any other .
after prototype.
. Fixed.
@0candy I don't see that test case in the unit-tests. It makes me wonder, what is the reason behind that decision? We it perhaps left out by a mistake? |
*/ | ||
exports.validateRemoteMethodName = function(name) { | ||
if (name.match(/\./) && !name.match(/^prototype\.([^.]*)$/)) { | ||
return 'Name cannot contain special characters . ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I think "special characters ." is not grammatically correct. How about the following?
'Name cannot contain "." characters except the dot in "prototype." prefix'
One more nitpick, the patch LGTM otherwise. Please squash the commits before landing, no further review is needed. |
Oh, and please make sure CI builds are passing, they are all red ATM. |
49afc41
to
0ca7f26
Compare
CI is all failing on master right now. |
Yeoman's latest release has a breaking change in prompts. We probably have to update our code. The latest version of yeoman-environment 1.6.1 is breaking the unit test. The promptModule is causing problems. |
@0candy Please let me know when you got this working. The fails are also making me cautious of merging #180 (comment) |
0ca7f26
to
6959163
Compare
Connect to https://github.com/strongloop-internal/scrum-loopback/issues/813
prototype.
and false otherwise.prototype.
otherwise.
is still invalid.