Skip to content

Commit a17a685

Browse files
author
Adrien LESÉNÉCHAL
committed
mw.api: Rename Response to UnknownResponse
We may add API response types later. In the same way as with `mw.Api.Params` and `mw.Api.UnknownParams`, we may want to use `mw.Api.Response` as an interface with common response parameters (e.g. `warnings`, `continue`).
1 parent 2956e76 commit a17a685

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

mw/Api.d.ts

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ declare global {
6565
*
6666
* @param {Api.UnknownParams} parameters Parameters to the API. See also {@link mw.Api.Options.parameters}.
6767
* @param {JQuery.AjaxSettings} [ajaxOptions] Parameters to pass to jQuery.ajax. See also {@link mw.Api.Options.ajax}.
68-
* @returns {JQuery.Promise<Api.Response>} A promise that settles when the API response is processed.
68+
* @returns {JQuery.Promise<Api.UnknownResponse>} A promise that settles when the API response is processed.
6969
* Has an 'abort' method which can be used to abort the request.
7070
*
7171
* - On success, resolves to `( result, jqXHR )` where `result` is the parsed API response.
@@ -92,7 +92,7 @@ declare global {
9292
ajax(
9393
parameters: Api.UnknownParams,
9494
ajaxOptions?: JQuery.AjaxSettings
95-
): JQuery.Promise<Api.Response>;
95+
): JQuery.Promise<Api.UnknownResponse>;
9696

9797
/**
9898
* Extend an API parameter object with an assertion that the user won't change.
@@ -148,15 +148,15 @@ declare global {
148148
* @param {ApiUploadParams} data Other upload options, see `action=upload` API docs for more
149149
* @param {number} [chunkSize] Size (in bytes) per chunk (default: 5MB)
150150
* @param {number} [chunkRetries] Amount of times to retry a failed chunk (default: 1)
151-
* @returns {JQuery.Promise<Api.Response>}
151+
* @returns {JQuery.Promise<Api.UnknownResponse>}
152152
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#chunkedUpload
153153
*/
154154
chunkedUpload(
155155
file: File,
156156
data: ApiUploadParams,
157157
chunkSize?: number,
158158
chunkRetries?: number
159-
): JQuery.Promise<Api.Response>;
159+
): JQuery.Promise<Api.UnknownResponse>;
160160

161161
/**
162162
* Upload a file to the stash, in chunks.
@@ -273,13 +273,13 @@ declare global {
273273
*
274274
* @param {Api.UnknownParams} parameters
275275
* @param {JQuery.AjaxSettings} [ajaxOptions]
276-
* @returns {JQuery.Promise<Api.Response>}
276+
* @returns {JQuery.Promise<Api.UnknownResponse>}
277277
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#get
278278
*/
279279
get(
280280
parameters: Api.UnknownParams,
281281
ajaxOptions?: JQuery.AjaxSettings
282-
): JQuery.Promise<Api.Response>;
282+
): JQuery.Promise<Api.UnknownResponse>;
283283

284284
/**
285285
* Get the categories that a particular page on the wiki belongs to.
@@ -339,11 +339,11 @@ declare global {
339339
* mw.notify( api.getErrorMessage( data ), { type: 'error' } );
340340
* } );
341341
* ```
342-
* @param {Api.Response} data API response indicating an error
342+
* @param {Api.UnknownResponse} data API response indicating an error
343343
* @returns {JQuery} Error messages, each wrapped in a `<div>`
344344
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#getErrorMessage
345345
*/
346-
getErrorMessage(data: Api.Response): JQuery;
346+
getErrorMessage(data: Api.UnknownResponse): JQuery;
347347

348348
/**
349349
* Get a set of messages.
@@ -436,10 +436,10 @@ declare global {
436436
/**
437437
* @param {string} username
438438
* @param {string} password
439-
* @returns {JQuery.Promise<Api.Response>} See {@link post()}
439+
* @returns {JQuery.Promise<Api.UnknownResponse>} See {@link post()}
440440
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#login
441441
*/
442-
login(username: string, password: string): JQuery.Promise<Api.Response>;
442+
login(username: string, password: string): JQuery.Promise<Api.UnknownResponse>;
443443

444444
/**
445445
* Post a new section to the page.
@@ -448,15 +448,15 @@ declare global {
448448
* @param {string} header
449449
* @param {string} message Wikitext message
450450
* @param {ApiEditPageParams} additionalParams Additional API parameters
451-
* @returns {JQuery.Promise<Api.Response>} See {@link postWithEditToken}
451+
* @returns {JQuery.Promise<Api.UnknownResponse>} See {@link postWithEditToken}
452452
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#newSection
453453
*/
454454
newSection(
455455
title: Title.Like,
456456
header: string,
457457
message: string,
458458
additionalParams?: ApiEditPageParams
459-
): JQuery.Promise<Api.Response>;
459+
): JQuery.Promise<Api.UnknownResponse>;
460460

461461
/**
462462
* Convenience method for `action=parse`.
@@ -474,26 +474,26 @@ declare global {
474474
*
475475
* @param {Api.UnknownParams} parameters
476476
* @param {JQuery.AjaxSettings} [ajaxOptions]
477-
* @returns {JQuery.Promise<Api.Response>}
477+
* @returns {JQuery.Promise<Api.UnknownResponse>}
478478
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#post
479479
*/
480480
post(
481481
parameters: Api.UnknownParams,
482482
ajaxOptions?: JQuery.AjaxSettings
483-
): JQuery.Promise<Api.Response>;
483+
): JQuery.Promise<Api.UnknownResponse>;
484484

485485
/**
486486
* Post to API with csrf token. If we have no token, get one and try to post. If we have a cached token try using that, and if it fails, blank out the cached token and start over.
487487
*
488488
* @param {Api.UnknownParams} params API parameters
489489
* @param {JQuery.AjaxSettings} [ajaxOptions]
490-
* @returns {JQuery.Promise<Api.Response>} See {@link post}
490+
* @returns {JQuery.Promise<Api.UnknownResponse>} See {@link post}
491491
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#postWithEditToken
492492
*/
493493
postWithEditToken(
494494
params: Api.UnknownParams,
495495
ajaxOptions?: JQuery.AjaxSettings
496-
): JQuery.Promise<Api.Response>;
496+
): JQuery.Promise<Api.UnknownResponse>;
497497

498498
/**
499499
* Post to API with the specified type of token. If we have no token, get one and try to post.
@@ -512,25 +512,25 @@ declare global {
512512
* @param {string} tokenType The name of the token, like `options` or `edit`.
513513
* @param {Api.UnknownParams} params API parameters
514514
* @param {JQuery.AjaxSettings} [ajaxOptions]
515-
* @returns {JQuery.Promise<Api.Response>} See {@link post()}
515+
* @returns {JQuery.Promise<Api.UnknownResponse>} See {@link post()}
516516
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#postWithToken
517517
*/
518518
postWithToken(
519519
tokenType: Api.TokenType,
520520
params: Api.UnknownParams,
521521
ajaxOptions?: JQuery.AjaxSettings
522-
): JQuery.Promise<Api.Response>;
522+
): JQuery.Promise<Api.UnknownResponse>;
523523
/** @deprecated Use `postWithToken('csrf', params)` instead */
524524
postWithToken(
525525
tokenType: Api.LegacyTokenType,
526526
params: Api.UnknownParams,
527527
ajaxOptions?: JQuery.AjaxSettings
528-
): JQuery.Promise<Api.Response>;
528+
): JQuery.Promise<Api.UnknownResponse>;
529529
postWithToken(
530530
tokenType: string,
531531
params: Api.UnknownParams,
532532
ajaxOptions?: JQuery.AjaxSettings
533-
): JQuery.Promise<Api.Response>;
533+
): JQuery.Promise<Api.UnknownResponse>;
534534

535535
/**
536536
* Convenience method for `action=rollback`.
@@ -554,10 +554,10 @@ declare global {
554554
*
555555
* @param {string} name
556556
* @param {string|null} value
557-
* @returns {JQuery.Promise<Api.Response>}
557+
* @returns {JQuery.Promise<Api.UnknownResponse>}
558558
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#saveOption
559559
*/
560-
saveOption(name: string, value: string | null): JQuery.Promise<Api.Response>;
560+
saveOption(name: string, value: string | null): JQuery.Promise<Api.UnknownResponse>;
561561

562562
/**
563563
* Asynchronously save the values of user options using the {@link https://www.mediawiki.org/wiki/Special:MyLanguage/API:Options Options API}.
@@ -575,10 +575,12 @@ declare global {
575575
* would fail anyway. See T214963.
576576
*
577577
* @param {Object.<string, string|null>} options Options as a `{ name: value, … }` object
578-
* @returns {JQuery.Promise<Api.Response>}
578+
* @returns {JQuery.Promise<Api.UnknownResponse>}
579579
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#saveOptions
580580
*/
581-
saveOptions(options: Record<string, string | null>): JQuery.Promise<Api.Response>;
581+
saveOptions(
582+
options: Record<string, string | null>
583+
): JQuery.Promise<Api.UnknownResponse>;
582584

583585
/**
584586
* Convenience method for `action=watch&unwatch=1`.
@@ -602,23 +604,26 @@ declare global {
602604
*
603605
* @param {File|Blob|HTMLInputElement} file HTML `input type=file` element with a file already inside of it, or a File object.
604606
* @param {ApiUploadParams} data Other upload options, see `action=upload` API docs for more
605-
* @returns {JQuery.Promise<Api.Response>}
607+
* @returns {JQuery.Promise<Api.UnknownResponse>}
606608
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#upload
607609
*/
608610
upload(
609611
file: File | Blob | HTMLInputElement,
610612
data: ApiUploadParams
611-
): JQuery.Promise<Api.Response>;
613+
): JQuery.Promise<Api.UnknownResponse>;
612614

613615
/**
614616
* Finish an upload in the stash.
615617
*
616618
* @param {string} filekey
617619
* @param {ApiUploadParams} data
618-
* @returns {JQuery.Promise<Api.Response>}
620+
* @returns {JQuery.Promise<Api.UnknownResponse>}
619621
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#uploadFromStash
620622
*/
621-
uploadFromStash(filekey: string, data: ApiUploadParams): JQuery.Promise<Api.Response>;
623+
uploadFromStash(
624+
filekey: string,
625+
data: ApiUploadParams
626+
): JQuery.Promise<Api.UnknownResponse>;
622627

623628
/**
624629
* Upload a file to the stash.
@@ -759,7 +764,7 @@ declare global {
759764
timestamp: string;
760765
}
761766

762-
type Response = Record<string, any>; // it will always be a JSON object, the rest is uncertain ...
767+
type UnknownResponse = Record<string, any>; // it will always be a JSON object, the rest is uncertain ...
763768

764769
namespace Response {
765770
type Edit = Edit.Failure | Edit.NoChange | Edit.Changed;
@@ -879,7 +884,7 @@ declare global {
879884

880885
/** @deprecated Use {@link mw.Api.Options} instead. Note that `ApiOptions` is strictly equivalent to `Required<mw.Api.Options>` as properties are now optional for consistency. */
881886
export type ApiOptions = Required<mw.Api.Options>;
882-
/** @deprecated Use {@link mw.Api.Response} instead */
883-
export type ApiResponse = mw.Api.Response;
887+
/** @deprecated Use {@link mw.Api.UnknownResponse} instead */
888+
export type ApiResponse = mw.Api.UnknownResponse;
884889

885890
export {};

mw/searchSuggest.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ declare global {
2424
* @param {ResponseFunction} response
2525
* @param {string|number} [limit]
2626
* @param {string|number|string[]|number[]} [namespace]
27-
* @returns {JQuery.Promise<ApiResponse>}
27+
* @returns {JQuery.Promise<Api.UnknownResponse>}
2828
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.searchSuggest.html#.request
2929
*/
3030
function request(
@@ -33,7 +33,7 @@ declare global {
3333
response: ResponseFunction,
3434
limit?: number | "max",
3535
namespace?: number | number[]
36-
): JQuery.Promise<Api.Response>;
36+
): JQuery.Promise<Api.UnknownResponse>;
3737

3838
/**
3939
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.searchSuggest.html#~ResponseFunction

0 commit comments

Comments
 (0)