Skip to content

Commit

Permalink
api: add types (+ submodule)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChlodAlejandro committed May 28, 2024
1 parent 198e33a commit aaf9c78
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "data/types"]
path = data/types
url = https://github.com/ChlodAlejandro/deputy-dispatch-types.git
1 change: 1 addition & 0 deletions data/types
Submodule types added at c97487
6 changes: 2 additions & 4 deletions src/api/Dispatch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { ExpandedRevisionData } from './ExpandedRevisionData';
import Requester from '../util/Requester';
import { deputyVersion } from '../DeputyVersion';
import WikiConfiguration from '../config/WikiConfiguration';

/**
* API communication class
Expand Down Expand Up @@ -51,7 +49,7 @@ export default class Dispatch {
async getEndpoint( endpoint: string ): Promise<URL> {
return new URL(
endpoint.replace( /^\/+/, '' ),
( await window.deputy.getWikiConfig() ).core.dispatchRoot.get()
( await WikiConfiguration.load() ).core.dispatchRoot.get()
.href
.replace( /\/+$/, '' )
);
Expand Down
5 changes: 3 additions & 2 deletions src/api/DispatchAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface DeputyDispatchTaskOptions {
/**
* The rate in milliseconds at which new progress requests are made.
*
* @default 500
* @default 1000
*/
refreshRate?: number;
}
Expand Down Expand Up @@ -54,7 +54,7 @@ export class DeputyDispatchTask<T> extends EventTarget implements DeputyDispatch
}
this.id = id;

this.refreshRate = options.refreshRate ?? 500;
this.refreshRate = options.refreshRate ?? 1000;

// Execute last.
this.promise = this.waitUntilDone();
Expand Down Expand Up @@ -125,6 +125,7 @@ export default class DispatchAsync {
taskOptions: DeputyDispatchTaskOptions = {}
): Promise<DeputyDispatchTask<T>> {
const taskInfo = await fetch( endpoint, {
method: 'POST',
body: JSON.stringify( options ),
headers: {
'Content-Type': 'application/json',
Expand Down
4 changes: 3 additions & 1 deletion src/api/DispatchUser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Dispatch from './Dispatch';
import DispatchAsync, { DeputyDispatchTask } from './DispatchAsync';
import { DispatchUserDeletedPagesResponse } from './types/DispatchTypes';

/**
*
Expand All @@ -20,7 +21,8 @@ export default class DispatchUser {
*
* @param user
*/
async deletedPages( user: string ): Promise<DeputyDispatchTask<any>> {
async deletedPages( user: string ):
Promise<DeputyDispatchTask<DispatchUserDeletedPagesResponse>> {
const endpoint = await Dispatch.i.getEndpoint( 'v1/user/deleted-pages' );
return ( await DispatchAsync.makeRequest( endpoint, {
user,
Expand Down
4 changes: 4 additions & 0 deletions src/api/ExpandedRevisionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export interface RevisionData {
size: number;
comment: string;
tags: string[];

commenthidden?: true;
userhidden?: true;
texthidden?: true;
}

export interface ExpandedRevisionData extends RevisionData {
Expand Down
1 change: 1 addition & 0 deletions src/api/models
13 changes: 13 additions & 0 deletions src/api/types/DispatchTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { DeletedPage } from '../models/DeletedPage';
import type { DeletedRevision } from '../models/DeletedRevision';

export interface DispatchUserDeletedPagesResponse {

pages: DeletedPage[];

}
export interface DispatchUserDeletedRevisionsResponse {

revisions: DeletedRevision[];

}

0 comments on commit aaf9c78

Please sign in to comment.