Skip to content

Commit

Permalink
update README; add a few more types
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Nov 7, 2020
1 parent d7b25a9 commit e073b4d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Development status: Unstable. Versioning: while mwn is in version 0, changes may be made to the public interface with a change in the minor version number.

Documentation given below is incomplete. There are a number of additional classes such as `bot.title`, `bot.wikitext`, `bot.page`, etc that provide useful functionality but aren't documented.
Documentation given below is incomplete. There are a number of additional classes such as `bot.title`, `bot.wikitext`, `bot.page`, etc that provide useful functionality but aren't documented. You can learn about these by looking through the source code.

Amongst the major highlights are `batchOperation` and `seriesBatchOperation` which allow you run a large number of tasks with control over concurrency and sleep time between tasks. Failing actions can be automatically retried.

Expand Down Expand Up @@ -52,6 +52,19 @@ If you're migrating from mwbot, note that:

### Documentation

Importing mwn:

In JavaScript:
```js
const {mwn} = require('mwn');
```
Note: Prior to mwn v0.8.0, import was via `const mwn = require('mwn');`

In TypeScript:
```ts
import {mwn} from 'mwn';
```

Create a new bot instance:
```js
const bot = new mwn({
Expand Down Expand Up @@ -208,11 +221,6 @@ Parse the contents of a given page
bot.parseTitle('Page name', additionalOptions);
```

Rollback a user:
```js
bot.rollback('Page title', 'user', additionalOptions);
```

Upload a file from your system to the wiki:
```js
bot.upload('File title', '/path/to/file', 'comment', customParams);
Expand Down
2 changes: 1 addition & 1 deletion build/api_params.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MwnDate } from "./bot";
import type { MwnDate } from "./bot";
declare type timestamp = MwnDate | string;
declare type namespace = number;
declare type limit = number | 'max';
Expand Down
8 changes: 3 additions & 5 deletions build/bot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ export declare class mwn {
* @returns {Promise<ApiPage>}
*/
read(titles: string | string[] | number | number[], options?: ApiParams): Promise<ApiPage | ApiPage[]>;
readGen(titles: string[], options?: ApiParams): AsyncGenerator<any, void, unknown>;
readGen(titles: string[], options?: ApiParams): AsyncGenerator<ApiPage>;
/**
* @param {string|number|MwnTitle} title - Page title or page ID or MwnTitle object
* @param {Function} transform - Callback that prepares the edit. It takes one
Expand Down Expand Up @@ -750,9 +750,7 @@ export declare class mwn {
* @param {number} [limit=Infinity]
* @yields {Object} a single page of the response
*/
continuedQueryGen(query?: ApiParams, limit?: number): AsyncGenerator<{
continue: {};
}, void, unknown>;
continuedQueryGen(query?: ApiParams, limit?: number): AsyncGenerator<ApiResponse>;
/**
* Function for using API action=query with more than 50/500 items in multi-
* input fields.
Expand Down Expand Up @@ -786,7 +784,7 @@ export declare class mwn {
* @param {string} [batchFieldName=titles]
* @param {number} [batchSize]
*/
massQueryGen(query: ApiParams, batchFieldName?: string, batchSize?: number): AsyncGenerator<any, void, unknown>;
massQueryGen(query: ApiParams, batchFieldName?: string, batchSize?: number): AsyncGenerator<ApiResponse>;
/**
* Execute an asynchronous function on a large number of pages (or other arbitrary
* items). Designed for working with promises.
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"scripts": {
"bump": "node bump-version.js",
"build": "npx tsc",
"commit": "npm run build && git commit",
"test": "nyc --reporter=lcov --reporter=text mocha tests/",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"test-ts": "ts-mocha -p tsconfig.json tests/ts/*"
Expand Down
2 changes: 1 addition & 1 deletion src/api_params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {MwnDate} from "./bot";
import type {MwnDate} from "./bot";

type timestamp = MwnDate | string
type namespace = number
Expand Down
6 changes: 3 additions & 3 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ export class mwn {
});
}

async *readGen(titles: string[], options?: ApiParams) {
async *readGen(titles: string[], options?: ApiParams): AsyncGenerator<ApiPage> {
let massQueryResponses = this.massQueryGen({
action: 'query',
...makeTitles(titles),
Expand Down Expand Up @@ -1750,7 +1750,7 @@ export class mwn {
* @param {number} [limit=Infinity]
* @yields {Object} a single page of the response
*/
async *continuedQueryGen(query?: ApiParams, limit = Infinity) {
async *continuedQueryGen(query?: ApiParams, limit = Infinity): AsyncGenerator<ApiResponse> {
let response = { continue: {} };
for (let i = 0; i < limit; i++) {
if (response.continue) {
Expand Down Expand Up @@ -1826,7 +1826,7 @@ export class mwn {
* @param {string} [batchFieldName=titles]
* @param {number} [batchSize]
*/
async *massQueryGen(query: ApiParams, batchFieldName: string = 'titles', batchSize?: number) {
async *massQueryGen(query: ApiParams, batchFieldName: string = 'titles', batchSize?: number): AsyncGenerator<ApiResponse> {
let batchValues = query[batchFieldName];
if (!Array.isArray(batchValues)) {
throw new Error(`massQuery: batch field in query must be an array`);
Expand Down

0 comments on commit e073b4d

Please sign in to comment.