Skip to content

Commit

Permalink
Merge pull request #6 from moegirlwiki/dragon-fish/refactor-lyla
Browse files Browse the repository at this point in the history
refactor!: rewrite with lyla-fetch
  • Loading branch information
dragon-fish authored Jul 12, 2023
2 parents c02bb43 + e52760f commit 615050f
Show file tree
Hide file tree
Showing 16 changed files with 475 additions and 256 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ dist
# TernJS port file
.tern-port

lib
lib
debug
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ const api = new MediaWikiApi('https://zh.moegirl.org.cn/api.php')
**在浏览器中直接使用/Use directly in the browser**

```js
import('https://unpkg.com/wiki-saikou').then(() => {
const { MediaWikiApi } = globalThis.WikiSaikou
import('https://unpkg.com/wiki-saikou?module').then(({ MediaWikiApi }) => {
const api = new MediaWikiApi('https://zh.moegirl.org.cn/api.php')
// ...
})
Expand All @@ -66,25 +65,25 @@ Below is the documentation of MediaWikiApi.

**Main methods**:

#### `new MediaWikiApi(baseURL?: string, options?: AxiosRequestConfig)`
#### `new MediaWikiApi(baseURL?: string, options?: LylaRequestOptions)`

- `baseURL`: API endpoint of your target wiki site (e.g. https://mediawiki.org/w/api.php)
- **Not required but with conditions**: If you are using it in the browser environment, and the website runs MediaWiki. The instance will automatically use the API endpoint of current wiki.
- `options`: {AxiosRequestConfig}
- `options`: {LylaRequestOptions}

#### `login(username: string, password: string): Promise<{ result: 'Success' | 'Failed'; lguserid: number; lgusername: string }>`

Login your account.

#### `get<T = any>(params: MwApiParams, options?: AxiosRequestConfig): Promise<AxiosResponse<T>>`
#### `get<T = any>(params: MwApiParams, options?: LylaRequestOptions): Promise<LylaResponseWith<T>>`

Make `GET` request

#### `post<T = any>(body: MwApiParams, options?: AxiosRequestConfig): Promise<AxiosResponse<T>>`
#### `post<T = any>(body: MwApiParams, options?: LylaRequestOptions): Promise<LylaResponseWith<T>>`

Make `POST` request

#### `postWithToken<T = any>(tokenType: MwTokenName, body: MwApiParams, options?: AxiosRequestConfig): Promise<AxiosResponse<T>>`
#### `postWithToken<T = any>(tokenType: MwTokenName, body: MwApiParams, options?: LylaRequestOptions): Promise<LylaResponseWith<T>>`

Make `POST` request with specified token.

Expand All @@ -101,20 +100,20 @@ type MwTokenName =
### Auxiliary utilities
#### `get ajax` {AxiosInstance}
#### `get request` {AxiosInstance}
Get `AxiosInstance` of current MediaWikiApi instance
Get `Lyla` instance of current MediaWikiApi instance
#### `MediaWikiApi.adjustParamValue(params: MwApiParams): Record<string: string>` (static)
#### `MediaWikiApi.normalizeParamValue(params: MwApiParams[keyof MwApiParams]): string | File | undefined` (static)
Adjust input params to standard MediaWiki request params.
Normalize input params to standard MediaWiki request params.
- `string[] → string`: `['foo', 'bar', 'baz'] → 'foo|bar|baz`
- `false → undefined`: remove false items

#### `MediaWikiApi.createAxiosInstance(payload: { baseURL: string; params: MwApiParams; options: AxiosRequestConfig })` (static)
#### `MediaWikiApi.createLylaInstance(baseURL: string, options?: LylaRequestOptions): Lyla` (static)

Create your own axios instance.
Create your own Lyla instance.

**Warning: The instance created by this method does not include responsive getters/setters (described below) and the out of box cookie controls.**

Expand Down
13 changes: 0 additions & 13 deletions debug/index.cjs

This file was deleted.

13 changes: 0 additions & 13 deletions debug/index.mjs

This file was deleted.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "wiki-saikou",
"version": "1.4.1",
"version": "2.0.0",
"description": "The library provides the out of box accessing to MediaWiki API in both browsers & Node.js, and the syntax is very similar to vanilla `new mw.Api()`. TypeScript definition included~",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"browser": "./dist/index.umd.js",
"module": "./dist/index.mjs",
"files": [
"dist",
"lib"
Expand Down Expand Up @@ -40,8 +41,8 @@
},
"homepage": "https://github.com/moegirlwiki/wiki-saikou#readme",
"dependencies": {
"@vue/reactivity": "^3.3.4",
"axios": "^1.4.0"
"@lylajs/core": "^1.2.0",
"@vue/reactivity": "^3.3.4"
},
"devDependencies": {
"@types/chai": "^4.3.5",
Expand All @@ -50,6 +51,7 @@
"@types/node": "^18.16.19",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"dotenv": "^16.3.1",
"esbuild-register": "^3.4.2",
"mocha": "^10.2.0",
"rimraf": "^5.0.1",
Expand Down
81 changes: 16 additions & 65 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 615050f

Please sign in to comment.