-
Notifications
You must be signed in to change notification settings - Fork 59
[DX-1204] Mark v1 callback API as deprecated #2226
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
35d1243
DX-1204: add hint field to ErrorInfo and detectV1Callback helper
umair-ably 30075df
DX-1204: throw on v1 callback shape in 14 method families
umair-ably f6b39ef
DX-1204: add @deprecated v1 overloads to ably.d.ts
umair-ably 7fecab1
DX-1204: add v1 callback runtime tests
umair-ably 71ea4f3
DX-1204: address review feedback on v1 callback guard
umair-ably cafc0f5
DX-1204: use error code 40025 (API no longer supported) for v1 callbacks
umair-ably File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,6 +263,38 @@ export function isErrorInfoOrPartialErrorInfo(err: unknown): err is ErrorInfo | | |
| return typeof err == 'object' && err !== null && (err instanceof ErrorInfo || err instanceof PartialErrorInfo); | ||
| } | ||
|
|
||
| /** | ||
| * Detect a v1-style trailing callback on a public method's args list and throw a | ||
| * steering error. v2 removed callback support from these methods, but agents trained | ||
| * on v1 docs keep passing callbacks — without this check, the callback is silently | ||
| * swallowed and the call hangs (subscribe) or no-ops (publish). | ||
| * | ||
| * Apply only to methods whose v1 form accepted a Node-style (err, result) callback | ||
| * and which are promise-only in v2. Do not apply to APIs that legitimately accept a | ||
| * trailing function (e.g. ClientOptions.authCallback). | ||
| * | ||
| * Fires when the trailing arg is a function AND either: | ||
| * - `args.length > v2TrailingFnArity` (the trailing fn is beyond the arity at | ||
| * which v2 legitimately ends in a function), or | ||
| * - the second-to-last arg is also a function — none of the v2 forms take two | ||
| * trailing functions, so e.g. `subscribe(listener, callback)` is always v1 | ||
| * even though it matches the arity of `subscribe(event, listener)`. | ||
| * | ||
| * @param v2TrailingFnArity - The arity at which v2 legitimately ends in a function | ||
| * (e.g. `subscribe(event, listener)` → 2). For methods where v2 never ends in a | ||
| * function (`authorize`, `publish`, `requestToken`, ...), pass 0. | ||
| */ | ||
| export function detectV1Callback(args: ArrayLike<unknown>, v2TrailingFnArity: number): void { | ||
| const n = args.length; | ||
| if (typeof args[n - 1] !== 'function') return; | ||
| if (n <= v2TrailingFnArity && typeof args[n - 2] !== 'function') return; | ||
| const err = new ErrorInfo('v1 callback signature is no longer supported.', 40025, 400); | ||
| err.hint = | ||
| 'v2 uses Promises — drop the trailing callback and `await` the returned promise. ' + | ||
| 'See https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md'; | ||
| throw err; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be calling out "go and use the Promise signature" explicitly rather than "dont use a callback" |
||
| } | ||
|
|
||
| export function inspectError(err: unknown): string { | ||
| if ( | ||
| err instanceof Error || | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.