-
Notifications
You must be signed in to change notification settings - Fork 35
feat: support multiple paths in V2 functions #1586
Conversation
⏱ Benchmark resultsComparing with d98dd20 largeDepsEsbuild: 2.8s⬆️ 7.85% increase vs. d98dd20
Legend
largeDepsNft: 9.3s⬆️ 18.07% increase vs. d98dd20
Legend
largeDepsZisi: 16s⬆️ 7.41% increase vs. d98dd20
Legend
|
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.
Some small comments and request for tests but nothing blocking ;)
@@ -262,7 +262,7 @@ describe('V2 API', () => { | |||
}) | |||
|
|||
test('With an invalid pattern', () => { | |||
expect.assertions(4) | |||
expect.assertions(8) |
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.
oof 🫣
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've split this into two tests now.
} | ||
|
||
export const config = { | ||
path: ["/store/:category/products/:product-id", "/super-awesome-campaign"] |
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 we make the second one a named group as well?
- Can we add a test for what if both routes are the same?
- What if I add falsy values like
null
orundefined
to the array? Do we throw type errors if numbers or whatever is provided? (You have a non nullable function but no test cases for it)
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've added more tests to capture this.
const paths = Array.isArray(input) ? input : [input] | ||
const routes = paths.map((path) => getRoute(path, functionName, methods ?? [])).filter(nonNullable) | ||
|
||
return routes |
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 would do return [...new Set(routes)]
to remove duplicates
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.
Done in 9e2cac9.
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.
We can't do it on routes
because it's an array of objects. I've done it on paths
.
} catch { | ||
throw new FunctionBundlingUserError(`'${path}' is not a valid path according to the URLPattern specification`, { | ||
functionName, | ||
runtime: RUNTIME.JAVASCRIPT, | ||
}) | ||
} | ||
} | ||
|
||
export const getRoutes = (input: unknown, functionName: string, methods: string[]): Route[] => { |
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.
NIT: would love a small jsdoc that explains the parameters and the method. So that a tipsy on call engineer at 2am in the morning can understand it as well :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.
Done.
return [] | ||
} | ||
|
||
const getRoute = (path: unknown, functionName: string, methods: string[]): Route | undefined => { |
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.
NIT: small jsdoc would be nice
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.
Done.
@lukasholzer I think I addressed all your feedback. I ended up having to make some changes in the AST parsing, because when processing arrays we were only looking for strings, so any other primitive values were ignored (so we couldn't throw a type error if people tried to use them). This has now been addressed. |
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.
Thanks for the added test cases! 🚀
…-it#1586) * feat: support multiple paths in V2 functions * refactor: remove unnecessary check * refactor: support more primitive types * fix: de-duplicate paths * feat: look for `null`
Summary
Allow an array of strings in the
path
in-source configuration property of V2 functions.The types already allow this, as well as the rest of the infrastructure.