-
Notifications
You must be signed in to change notification settings - Fork 683
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
Add UPWARD specification, guide, tests, reference implementation #248
Conversation
5d3af8b
to
fadb5f7
Compare
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.
Left a first batch of feedback. Lots of files in this one.
packages/upward-js/bin/server
Outdated
if (mapping.hasOwnProperty(lowered)) { | ||
return mapping[lowered]; | ||
} | ||
if (value.match(/^\d*\.?\d+$/)) { |
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.
Consider adding a comment either explaining the regex or giving an example.
packages/upward-js/lib/Context.js
Outdated
'latin-1', | ||
'base64', | ||
'hex', | ||
...Array.from({ length: 600 }, (_, i) => (i + 100).toString()) |
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.
Nice. 👍
packages/upward-js/lib/Context.js
Outdated
} | ||
|
||
get(path) { | ||
return constants.get(prop) || dotLookup(this._data, path); |
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 dotLookup
a global or something? I don't see it defined or imported. Perhaps you meant this.depend
, which is defined below but appears to be unused?
return value => | ||
allowed.includes(value) | ||
? undefined | ||
: `must be one of: ${allowed.join()}`; |
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.
In the passing case, why does this return undefined
, rather than ''
like all the rest of these tests?
errors.push({ | ||
name, | ||
errors: itemErrors | ||
}); |
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.
It doesn't look like errors
is defined at this point, so errors.push
looks wrong to me here. Did you mean report.errors.push()
?
ad2be63
to
6b92359
Compare
Noting that I have to back-merge my integration branch into this. |
66ea456
to
5fd2d40
Compare
Closes #28. |
f3647c2
to
94383b6
Compare
return x; | ||
}, rejectPreload); | ||
} catch (e) { | ||
rejectPreload(); |
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.
It looks like rejectPreload
accepts a single argument, e
. It's not being called with any arguments here, though. Did you mean to pass e
to it?
mod => mod.resource.includes('/node_modules/') | ||
: // Top-level modules injected by a downstream "issuer" are not | ||
// entry points in production. | ||
mod => !mod.issuer; |
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.
Comments helping make this file understandable. 👍
// apply their changes synchronously. Use a proxy function to add a | ||
// middleware which lazy loads UPWARD when it's time. | ||
let upwardMiddleware; | ||
let upwardMiddlewarePromise = new Promise((resolve, reject) => {}); |
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 variable, upwardMiddlewarePromise
, appears to be unused. Is this dead code? How is this supposed to work?
: res.json() | ||
); | ||
}; | ||
}; |
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.
Clean and understandable. 👍
Tests would be good.
} | ||
} | ||
|
||
module.exports = Context; |
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.
Can you explain what this file is doing?
@@ -0,0 +1,101 @@ | |||
const debug = require('debug')('upward-js:ContextPath'); | |||
const illegalPathChars = /(^[\.\[\]])|[^\.\w\$\/]/; |
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.
Consider adding a comment either explaining the regex or giving an example.
|
||
const readFile = promisify(fsReadFile); | ||
class IOAdapter { | ||
static default(upwardPath) { |
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 like this idea. 👍
debug( | ||
`returning middleware from visitor.downward() instead of object` | ||
); | ||
return passedMiddleware; |
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.
So if any one of the requests returns a middleware, this error is thrown and caught, and only the middleware is returned. All the other requests are thrown out?
} | ||
getResolverFor(defined, propertyName) { | ||
let Resolver; | ||
for (Resolver of ResolverList) { |
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.
The scoping of Resolver
is misleading here.
Resolver
is declared as a mutable variable prior to thefor...of
block- On each loop iteration,
Resolver
is reassigned andResolver.recognize()
is always called - On each loop iteration, there may be an early return
The only time this arrangement is useful is if the code following the for...of
block is interested in the value of Resolver
after the loop has completed. Otherwise, we would expect to see for (const Resolver of ResolverList) {}
.
However, the code following the for...of
block ("subsequent code") is not interested in the value of Resolver
. In fact, the subsequent code always reassigns Resolver
before ever reading its value. This is counterintuitive because Resolver
appears to have been specifically declared such that it is meaningful, yet it isn't.
My recommendation:
getResolverFor(defined, propertyName) {
for (const Resolver of ResolverList) {
// ...
}
const definedResolver = defined.resolver
const Resolver = definedResolver
? ResolversByType[definedResolver]
: ResolverList.find(({ telltale }) => defined.hasOwnProperty(telltale))
if (Resolver) {
return new Resolver(this)
} else {
this.getResolverFailure = definedResolver
? 'Unrecognized resolver type...'
: 'Unrecognized configuration...'
}
}
Generated by 🚫 dangerJS |
This PR is a:
[x] New feature
[ ] Enhancement/Optimization
[ ] Refactor
[ ] Bugfix
[ ] Test for existing code
[x] Documentation
Summary
When this pull request is merged, it will add the UPWARD specification, guide, test suite, and reference implementation in JavaScript. See the README in this pull request for details.