From e073b4de7c280c61397ee4031763fd0ba61a43d9 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Sat, 7 Nov 2020 21:39:49 +0530 Subject: [PATCH] update README; add a few more types --- README.md | 20 ++++++++++++++------ build/api_params.d.ts | 2 +- build/bot.d.ts | 8 +++----- package.json | 1 - src/api_params.ts | 2 +- src/bot.ts | 6 +++--- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 6c890d1..80a1a7d 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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({ @@ -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); diff --git a/build/api_params.d.ts b/build/api_params.d.ts index 0e6ea8a..d103836 100644 --- a/build/api_params.d.ts +++ b/build/api_params.d.ts @@ -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'; diff --git a/build/bot.d.ts b/build/bot.d.ts index 97dfe11..917bf84 100644 --- a/build/bot.d.ts +++ b/build/bot.d.ts @@ -553,7 +553,7 @@ export declare class mwn { * @returns {Promise} */ read(titles: string | string[] | number | number[], options?: ApiParams): Promise; - readGen(titles: string[], options?: ApiParams): AsyncGenerator; + readGen(titles: string[], options?: ApiParams): AsyncGenerator; /** * @param {string|number|MwnTitle} title - Page title or page ID or MwnTitle object * @param {Function} transform - Callback that prepares the edit. It takes one @@ -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; /** * Function for using API action=query with more than 50/500 items in multi- * input fields. @@ -786,7 +784,7 @@ export declare class mwn { * @param {string} [batchFieldName=titles] * @param {number} [batchSize] */ - massQueryGen(query: ApiParams, batchFieldName?: string, batchSize?: number): AsyncGenerator; + massQueryGen(query: ApiParams, batchFieldName?: string, batchSize?: number): AsyncGenerator; /** * Execute an asynchronous function on a large number of pages (or other arbitrary * items). Designed for working with promises. diff --git a/package.json b/package.json index 572b0d1..57ac3a7 100644 --- a/package.json +++ b/package.json @@ -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/*" diff --git a/src/api_params.ts b/src/api_params.ts index be81adb..eeffa62 100644 --- a/src/api_params.ts +++ b/src/api_params.ts @@ -1,4 +1,4 @@ -import {MwnDate} from "./bot"; +import type {MwnDate} from "./bot"; type timestamp = MwnDate | string type namespace = number diff --git a/src/bot.ts b/src/bot.ts index 66422bf..d3be63a 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1245,7 +1245,7 @@ export class mwn { }); } - async *readGen(titles: string[], options?: ApiParams) { + async *readGen(titles: string[], options?: ApiParams): AsyncGenerator { let massQueryResponses = this.massQueryGen({ action: 'query', ...makeTitles(titles), @@ -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 { let response = { continue: {} }; for (let i = 0; i < limit; i++) { if (response.continue) { @@ -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 { let batchValues = query[batchFieldName]; if (!Array.isArray(batchValues)) { throw new Error(`massQuery: batch field in query must be an array`);