-
Notifications
You must be signed in to change notification settings - Fork 756
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
Remove "curried" nested resources and manually specified urlParams #625
Conversation
Verified this is no different with: ```js const urlParams = utils.extractUrlParams(spec.path || ''); if ( !(spec.urlParams || []).every((x, i) => urlParams[i] === x) || (spec.urlParams || []).length !== urlParams.length ) { throw Error( 'mismatch' + JSON.stringify(urlParams) + JSON.stringify(spec.urlParams) ); } ``` inside StripeMethod
|
||
function getRequestOpts(self, requestArgs, spec, overrideData) { | ||
// Extract spec values with defaults. | ||
const commandPath = | ||
typeof spec.path == 'function' |
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 had no path
s specified as functions anymore
@@ -1,14 +1,10 @@ | |||
'use strict'; | |||
|
|||
const utils = require('./utils'); | |||
const OPTIONAL_REGEX = /^optional!/; |
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 had no url params specified as optional anymore
throw new Error( | ||
`Stripe: Argument "${ | ||
urlParams[i] | ||
}" required, but got: ${arg} (on API request to \`${requestMethod} ${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.
this error wasn't as good as the other, combined it.
|
||
if (param == 'id' && typeof arg !== 'string') { | ||
path = self.createResourcePathWithSymbols(spec.path); | ||
const urlData = urlParams.reduce((urlData, param) => { |
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.
Now that we're on Node 6+, we can use "modern" features like .reduce
lib/resources/Disputes.js
Outdated
@@ -8,5 +8,5 @@ module.exports = StripeResource.extend({ | |||
|
|||
includeBasic: ['list', 'retrieve', 'update'], | |||
|
|||
close: stripeMethod({method: 'POST', path: '/{id}/close', urlParams: ['id']}), | |||
close: stripeMethod({method: 'POST', path: '/{id}/close'}), |
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.
Should we break this out onto multiple lines like we do with most of the stripeMethod()
calls? Purely a style thing.
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.
Good call! prettier collapsed them but we can uncollapse.
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.
cc @irace-stripe we may want to try to indicate to prettier-poet that these should break.
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 think <Node.Object entries={} break />
would be a useful API, since prettier generally allows objects to be configured to be broken
lib/resources/Orders.js
Outdated
@@ -8,11 +8,10 @@ module.exports = StripeResource.extend({ | |||
|
|||
includeBasic: ['create', 'list', 'retrieve', 'update'], | |||
|
|||
pay: stripeMethod({method: 'POST', path: '/{id}/pay', urlParams: ['id']}), | |||
pay: stripeMethod({method: 'POST', path: '/{id}/pay'}), |
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.
Same question here on one vs. multiple lines.
a1465f6
to
f650b77
Compare
Let's wait until we reach a decision re. nested resources, but this looks pretty great to me! |
This reverts commit e5eccb8.
1cdba64
to
d58bbf8
Compare
Per internal discussion document, I've reverted my change adding support for |
Per IRL with @ob-stripe merging this. |
* Extract separate resources file (to aid with code generation) * Remove resources that were removed in #625 https://github.com/stripe/stripe-node/pull/625/files#diff-d3dd6c4fd6f915f29d42e4081dc817a8L85
) * Drop support for optional url params * Delete nested resource files * Remove urlData * Extract urlParams from path instead of manual definition Verified this is no different with: ```js const urlParams = utils.extractUrlParams(spec.path || ''); if ( !(spec.urlParams || []).every((x, i) => urlParams[i] === x) || (spec.urlParams || []).length !== urlParams.length ) { throw Error( 'mismatch' + JSON.stringify(urlParams) + JSON.stringify(spec.urlParams) ); } ``` inside StripeMethod * Remove manually specified urlParams * Add a deprecation error message * Revert "Delete nested resource files" This reverts commit d88a3e7. * Fix nested resources for non-curried urlParams and update tests to demonstrate their use * Refactor makeRequest * Revert "Revert "Delete nested resource files"" This reverts commit e5eccb8.
* Extract separate resources file (to aid with code generation) * Remove resources that were removed in #625 https://github.com/stripe/stripe-node/pull/625/files#diff-d3dd6c4fd6f915f29d42e4081dc817a8L85
) * Drop support for optional url params * Delete nested resource files * Remove urlData * Extract urlParams from path instead of manual definition Verified this is no different with: ```js const urlParams = utils.extractUrlParams(spec.path || ''); if ( !(spec.urlParams || []).every((x, i) => urlParams[i] === x) || (spec.urlParams || []).length !== urlParams.length ) { throw Error( 'mismatch' + JSON.stringify(urlParams) + JSON.stringify(spec.urlParams) ); } ``` inside StripeMethod * Remove manually specified urlParams * Add a deprecation error message * Revert "Delete nested resource files" This reverts commit d88a3e7. * Fix nested resources for non-curried urlParams and update tests to demonstrate their use * Refactor makeRequest * Revert "Revert "Delete nested resource files"" This reverts commit e5eccb8.
* Extract separate resources file (to aid with code generation) * Remove resources that were removed in #625 https://github.com/stripe/stripe-node/pull/625/files#diff-d3dd6c4fd6f915f29d42e4081dc817a8L85
) * Drop support for optional url params * Delete nested resource files * Remove urlData * Extract urlParams from path instead of manual definition Verified this is no different with: ```js const urlParams = utils.extractUrlParams(spec.path || ''); if ( !(spec.urlParams || []).every((x, i) => urlParams[i] === x) || (spec.urlParams || []).length !== urlParams.length ) { throw Error( 'mismatch' + JSON.stringify(urlParams) + JSON.stringify(spec.urlParams) ); } ``` inside StripeMethod * Remove manually specified urlParams * Add a deprecation error message * Revert "Delete nested resource files" This reverts commit d88a3e7. * Fix nested resources for non-curried urlParams and update tests to demonstrate their use * Refactor makeRequest * Revert "Revert "Delete nested resource files"" This reverts commit e5eccb8.
* Extract separate resources file (to aid with code generation) * Remove resources that were removed in #625 https://github.com/stripe/stripe-node/pull/625/files#diff-d3dd6c4fd6f915f29d42e4081dc817a8L85
) * Drop support for optional url params * Delete nested resource files * Remove urlData * Extract urlParams from path instead of manual definition Verified this is no different with: ```js const urlParams = utils.extractUrlParams(spec.path || ''); if ( !(spec.urlParams || []).every((x, i) => urlParams[i] === x) || (spec.urlParams || []).length !== urlParams.length ) { throw Error( 'mismatch' + JSON.stringify(urlParams) + JSON.stringify(spec.urlParams) ); } ``` inside StripeMethod * Remove manually specified urlParams * Add a deprecation error message * Revert "Delete nested resource files" This reverts commit d88a3e7. * Fix nested resources for non-curried urlParams and update tests to demonstrate their use * Refactor makeRequest * Revert "Revert "Delete nested resource files"" This reverts commit e5eccb8.
* Extract separate resources file (to aid with code generation) * Remove resources that were removed in #625 https://github.com/stripe/stripe-node/pull/625/files#diff-d3dd6c4fd6f915f29d42e4081dc817a8L85
* Update version to 7 and drop support for Node 4 and Node 5, and Node 7 * Format using Prettier tmp * Alphabetize basic methods * Use 'id' for all single identifier positional arguments * Fix typo * Modernize ES5 to ES6 with lebab (#607) * Add lebab and a script to run it * lebab transform: arrow * lebab transform: arg-rest * lebab transform: arg-spread * lebab transform: obj-method * lebab transform: obj-shorthand * lebab transform: let * lebab transform: template * lebab transform: default-param * lebab transform: destruct-param * lebab transform: includes * Revert "Add lebab and a script to run it" This reverts commit 70fd492. * Revert "lebab transform: destruct-param" because its changes didn't seem good. This reverts commit b56f52d. * Revert "lebab transform: default-param" because it seems dangerous / backwards-incompatible. This reverts commit 7eba992. * Unrelated: mark 8.1 as minimum 8-series version * Add mocha-only script * Use arrows in more places * Loosen some eslint rules I don't love * Remove deprecated methods * Add VSCode and EditorConfig files * Bump dependencies to latest versions * Remove legacy parameter support in invoices.retrieveUpcoming() * Misc. manual formatting (#623) * Misc. manual formatting * Fix some unit tests * Roll back path argument name changes * Misc. manual formatting * Remove "curried" nested resources and manually specified urlParams (#625) * Drop support for optional url params * Delete nested resource files * Remove urlData * Extract urlParams from path instead of manual definition Verified this is no different with: ```js const urlParams = utils.extractUrlParams(spec.path || ''); if ( !(spec.urlParams || []).every((x, i) => urlParams[i] === x) || (spec.urlParams || []).length !== urlParams.length ) { throw Error( 'mismatch' + JSON.stringify(urlParams) + JSON.stringify(spec.urlParams) ); } ``` inside StripeMethod * Remove manually specified urlParams * Add a deprecation error message * Revert "Delete nested resource files" This reverts commit d88a3e7. * Fix nested resources for non-curried urlParams and update tests to demonstrate their use * Refactor makeRequest * Revert "Revert "Delete nested resource files"" This reverts commit e5eccb8. * Extract resources file (to aid with code generation) (#626) * Extract separate resources file (to aid with code generation) * Remove resources that were removed in #625 https://github.com/stripe/stripe-node/pull/625/files#diff-d3dd6c4fd6f915f29d42e4081dc817a8L85 * Update CHANGELOG for 7.0.0 release
r? @ob-stripe
cc @irace-stripe @paulasjes-stripe @robz-stripe @remi-stripe
cc @stripe/api-libraries
This removes support for "curried" url parameters on nested resources, like this:
and along with it, removing the associated resource objects (ie;
stripe.transferReversals
no longer exists) on the grounds that they were not usable outside of the curried case.You can still do this instead:
This applies to all nested resources, namely:
Persons
LoginLinks
SubscriptionScheduleRevisions
ApplicationFeeRefunds
TaxIds
TransferReversals
This means the names of url parameters is no longer meaningful, and can be changed without compatibility concerns. We can even have two url parameters named
id
if we like (though I think that would be less clear).Because of this, and because we no longer have any
path
s specified as a function, I was also able to removeurlParams
from the stripeMethods, inferring them with a regex instead (though their name values are not actually used; only the number of url params is meaningful).Note that we briefly experimented with support for this pattern:
and ultimately decided against it for now; we may reconsider in the future. Thoughts from the community welcome!