Skip to content
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

Print the list of registered routes #12

Open
amitguptagwl opened this issue Oct 19, 2018 · 12 comments
Open

Print the list of registered routes #12

amitguptagwl opened this issue Oct 19, 2018 · 12 comments
Labels
assigned first-timers-only Only for developers who are starting open source development good first issue Good for newcomers help wanted Extra attention is needed

Comments

@amitguptagwl
Copy link
Member

It can be a good user experience if the library can return the list of registered routes. They can be useful for debugging purpose as well.

@amitguptagwl amitguptagwl added help wanted Extra attention is needed good first issue Good for newcomers first-timers-only Only for developers who are starting open source development labels Oct 19, 2018
@lucasheim
Copy link

Can I try to tackle this issue? Do you have more details about the method name for this and what should I return? An object with all routes, each formatted like the ones on find?

@amitguptagwl
Copy link
Member Author

amitguptagwl commented Oct 25, 2018 via email

@amitguptagwl
Copy link
Member Author

@lucasheim are you working on this issue?

@lucasheim
Copy link

I'm not @amitguptagwl. It's been hard for me to find some time recently.

@amitguptagwl
Copy link
Member Author

no problem

@amitguptagwl amitguptagwl added the unassigned this issue is free to be picked by anyone label Dec 27, 2018
@jadach1
Copy link

jadach1 commented Feb 11, 2019

Hi, can I please be assigned this issue, I would like to try to tackle it.

@amitguptagwl amitguptagwl added assigned and removed unassigned this issue is free to be picked by anyone labels Feb 11, 2019
@jadach1
Copy link

jadach1 commented Feb 13, 2019

Hi I have a question regarding a closed PR from October 2018 which is relevant to this issue

#13

It seems that someone was trying to work on the issue with the router lists and tried to merge their PR but the PR was closed because of lack of features or functionality ? I am not quite sure but I would like to not make the same mistakes going further, so any clarification would be great ! Thank you.

@amitguptagwl
Copy link
Member Author

  1. The PR you mentioned was based on the assumption that someone may use the added code in the PR to print the list of routes.
  2. It was not handling the case for versioned routes.

Expected output

{
  "GET" : [
         "/this/is/static",
         { "/this/is/static/with/versions" : [ '1.2.3', '*' ] } 
         "/this/is/{dynamic}"
  ]
}

The goal is to print the routes without revealing the internal complexity of the application. Though we can prepare the list at the time of adding/deleting the route, printing routes is generally one-time operation hence I was avoiding to store it in a variable. However, this option can be considered to reduce complexity.

@jadach1
Copy link

jadach1 commented Feb 13, 2019

Thanks for your reply, a few new questions, I see inside of the letsRoute.js file there is a function commented out as shown below on line 541:

/*
Anumargak.prototype.print = function(){
var urlTree = {

}

for(var i=0; i < httpMethods.length; i++){
    this.staticRoutes [ httpMethods[i] ]
}

}
*/

Is this what you are trying to request to be completed, or is that something different ?


Second questions, there are 34 different OBJECTS inside of the staticRoutes and dynamicRoutes objects as shown below:
ACL,BIND,CHECKOUT,CONNECT,COPY,DELETE,GET,HEAD,LINK,LOCK,M-SEARCH,MERGE,MKACTIVITY,MKCALENDAR,MKCOL,MOVE,NOTIFY,OPTIONS,PATCH,POST,PROPFIND,PROPPATCH,PURGE,PUT,REBIND,REPORT,SEARCH,SOURCE,SUBSCRIBE,TRACE,UNBIND,UNLINK,UNLOCK,UNSUBSCRIBE

As of right now I am under the assumption that you only want to print the properties from the GET objects as per your example above. However, there are also objects within those objects which brings up the question which data from those sub objects would you like to have displayed for the user ? It is my understanding that you want it to be as clean and user friendly as possible.

As an example if I do a crude console.log[this.staticRoute.GET] it will print

{ '/':
{ data: { handler: [Function], store: undefined },
verMap: undefined,
params: undefined },
'/a':
{ data: { handler: [Function], store: undefined },
verMap: undefined,
params: undefined },
'/login/as/admin':
{ data: { handler: undefined, store: undefined },
verMap: undefined,
params: { role: 'admin' } },
'/login/as/user':
{ data: { handler: undefined, store: undefined },
verMap: undefined,
params: { role: 'user' } },
'/login/as/staff':
{ data: { handler: undefined, store: undefined },
verMap: undefined,
params: { role: 'staff' } },
'/some/route':
{ data: undefined,
verMap: SemVerStore { tree: [Node] },
params: undefined } }

I am guessing the verMap is where the version will be stored, my question is, is there any other data from those sub objects you want to be displayed for the user ?

The above example you provided will give me a starting point but I would like to know exactly what you are looking for.

Thank you.

@amitguptagwl
Copy link
Member Author

I believe most of the things are self-explainable. However, there is nothing wrong to verify them.

  1. The commented print method in the code can be used for this purpose.
  2. If a user registers routes only with GET method then it should print only GET> But you should iterate through all to know which method has the routes.
  3. In the log, you must have noticed that the URLs(routes) are the key of the object that we want to print. But in case if you've gone through the rest code, you must have noticed that the route used to register and the route actually being saved is a little bit different. So I'll suggest you collect the data at the time of registering the route. This will be a simple approach.

Further, we can think to print a route as follow,

  "GET" : [
         "this: : {
               "is" : {
                    "static",
                    "with" : {
                          "versions" : [ '1.2.3', '*' ] 
                     },
                     "{dynamic}"
               }
          }
  ]
}

@jadach1
Copy link

jadach1 commented Feb 22, 2019

Hi, I submitted a PR but it is failing on a test

  1. Anumargak events should emit not-found and request event when the route is not registered
    Message:
    TypeError: Cannot read property 'version' of undefined
    Stack:
    at
    at Anumargak.on (C:\Users\Jacob\OSD600\anumargak\src\letsRoute.js:51:18)
    at UserContext. (C:\Users\Jacob\OSD600\anumargak\tests\event_test.js:53:16)
    at
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)

mainly because I am trying to access the version property of objects which don't have a version on them and regardless of what I do ( check to see if there is a version before saving ) it will always fail that test case.
I took your advice on collecting the data of the routes when they are being registered in the prorotype.on method but I do not know how to get around this particular problem, if you have any idea of how to approach this that would be great. My alternative would be to print from the staticRoutes and dynamicRoutes objects.

@amitguptagwl
Copy link
Member Author

Sure.. I'll check it tomorrow. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assigned first-timers-only Only for developers who are starting open source development good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants