Skip to content

Commit

Permalink
mw.Upload: Update promise types
Browse files Browse the repository at this point in the history
to be based on `mw.Api.PromiseBase` instead of `JQuery.PromiseBase`
  • Loading branch information
Derugon committed Dec 26, 2024
1 parent 0b75da6 commit d050e22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
18 changes: 9 additions & 9 deletions mw/Api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ interface RollbackInfo {
title: string;
}

interface FinishUpload {
export interface FinishUpload {
/**
* Call this function to finish the upload.
*
Expand Down Expand Up @@ -231,15 +231,15 @@ declare global {
* @param {ApiUploadParams} data Other upload options, see `action=upload` API docs for more
* @param {number} [chunkSize] Size (in bytes) per chunk (default: 5MB)
* @param {number} [chunkRetries] Amount of times to retry a failed chunk (default: 1)
* @returns {Api.Promise.Upload}
* @returns {Upload.Promise}
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#chunkedUpload
*/
chunkedUpload(
file: File,
data: ApiUploadParams,
chunkSize?: number,
chunkRetries?: number
): Api.Promise.Upload;
): Upload.Promise;

/**
* Upload a file to the stash, in chunks.
Expand All @@ -251,7 +251,7 @@ declare global {
* @param {ApiUploadParams} [data]
* @param {number} [chunkSize] Size (in bytes) per chunk (default: 5MB)
* @param {number} [chunkRetries] Amount of times to retry a failed chunk (default: 1)
* @returns {Api.Promise.Upload<[FinishUpload]>} Promise that resolves with a
* @returns {Upload.Promise<[FinishUpload]>} Promise that resolves with a
* function that should be called to finish the upload.
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#chunkedUploadToStash
*/
Expand All @@ -260,7 +260,7 @@ declare global {
data?: ApiUploadParams,
chunkSize?: number,
chunkRetries?: number
): Api.Promise.Upload<[FinishUpload]>;
): Upload.Promise<[FinishUpload]>;

/**
* Create a new page.
Expand Down Expand Up @@ -683,10 +683,10 @@ declare global {
*
* @param {File|Blob|HTMLInputElement} file HTML `input type=file` element with a file already inside of it, or a File object.
* @param {ApiUploadParams} data Other upload options, see `action=upload` API docs for more
* @returns {Api.Promise.Upload}
* @returns {Upload.Promise}
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#upload
*/
upload(file: File | Blob | HTMLInputElement, data: ApiUploadParams): Api.Promise.Upload;
upload(file: File | Blob | HTMLInputElement, data: ApiUploadParams): Upload.Promise;

/**
* Finish an upload in the stash.
Expand Down Expand Up @@ -721,14 +721,14 @@ declare global {
* ```
* @param {File|HTMLInputElement} file
* @param {ApiUploadParams} [data]
* @returns {Api.Promise.Upload<[FinishUpload]>} Promise that resolves with a
* @returns {Upload.Promise<[FinishUpload]>} Promise that resolves with a
* function that should be called to finish the upload.
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#uploadToStash
*/
uploadToStash(
file: File | HTMLInputElement,
data?: ApiUploadParams
): Api.Promise.Upload<[FinishUpload]>;
): Upload.Promise<[FinishUpload]>;

/**
* Convenience method for `action=watch`.
Expand Down
17 changes: 10 additions & 7 deletions mw/Upload.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApiResponse } from "./Api";
import { ApiResponse, FinishUpload } from "./Api";

declare global {
namespace mw {
Expand Down Expand Up @@ -62,10 +62,13 @@ declare global {
/**
* Finish a stash upload.
*
* @returns {JQuery.Promise<ApiResponse>}
* @returns {Api.Promise<[ApiResponse], Api.RejectArgTuple | [string, ApiResponse]>}
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Upload.html#finishStashUpload
*/
finishStashUpload(): JQuery.Promise<ApiResponse>;
finishStashUpload(): Api.Promise<
[ApiResponse],
Api.RejectArgTuple | [string, ApiResponse]
>;

/**
* Get the mw.Api instance used by this Upload object.
Expand Down Expand Up @@ -217,18 +220,18 @@ declare global {
/**
* Upload the file directly.
*
* @returns {JQuery.Promise<ApiResponse>}
* @returns {Upload.Promise}
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Upload.html#upload
*/
upload(): JQuery.Promise<ApiResponse>;
upload(): Upload.Promise;

/**
* Upload the file to the stash to be completed later.
*
* @returns {JQuery.Promise<ApiResponse>}
* @returns {Upload.Promise<[FinishUpload]>}
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Upload.html#uploadToStash
*/
uploadToStash(): JQuery.Promise<ApiResponse>;
uploadToStash(): Upload.Promise<[FinishUpload]>;
}

namespace Upload {
Expand Down

0 comments on commit d050e22

Please sign in to comment.