Skip to content

Commit

Permalink
Merge pull request #8 from moegirlwiki/Dragon-Fish/refactor-fexios
Browse files Browse the repository at this point in the history
refactor: replace lyla with fexios
  • Loading branch information
dragon-fish authored Jul 21, 2023
2 parents 615050f + d78ced6 commit 5e17eb3
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 347 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ The library provides the out of box accessing to MediaWiki API in both browsers
- With unit tests
- User authentication supports out of the box \*(also applicable to Node.js!)

## 开箱即用/Out of box
## 开箱即用 Out of box

**安装/installation**
**安装 Installation**

```sh
# Via pnpm:
Expand All @@ -42,7 +42,7 @@ const api = new MediaWikiApi('https://zh.moegirl.org.cn/api.php')
// ...
```

**在浏览器中直接使用/Use directly in the browser**
**在浏览器中直接使用 Use directly in the browser**

```js
import('https://unpkg.com/wiki-saikou?module').then(({ MediaWikiApi }) => {
Expand All @@ -53,7 +53,7 @@ import('https://unpkg.com/wiki-saikou?module').then(({ MediaWikiApi }) => {

Then use it just like the `new mw.Api()`

## 使用方法/Usage
## 使用方法 Usage

You can find some sample code snippets [here](test/).

Expand All @@ -65,7 +65,7 @@ Below is the documentation of MediaWikiApi.

**Main methods**:

#### `new MediaWikiApi(baseURL?: string, options?: LylaRequestOptions)`
#### `new MediaWikiApi(baseURL?: string, options?: Partial<FexiosConfigs>)`

- `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.
Expand All @@ -75,15 +75,15 @@ Below is the documentation of MediaWikiApi.

Login your account.

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

Make `GET` request

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

Make `POST` request

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

Make `POST` request with specified token.

Expand All @@ -98,11 +98,11 @@ type MwTokenName =
| 'watch'
```
### Auxiliary utilities
### 工具函数 Auxiliary utilities
#### `get request` {AxiosInstance}
#### `get request` {Fexios}
Get `Lyla` instance of current MediaWikiApi instance
Get `Fexios` instance of current MediaWikiApi instance
#### `MediaWikiApi.normalizeParamValue(params: MwApiParams[keyof MwApiParams]): string | File | undefined` (static)
Expand All @@ -111,9 +111,9 @@ Normalize input params to standard MediaWiki request params.
- `string[] → string`: `['foo', 'bar', 'baz'] → 'foo|bar|baz`
- `false → undefined`: remove false items

#### `MediaWikiApi.createLylaInstance(baseURL: string, options?: LylaRequestOptions): Lyla` (static)
#### `MediaWikiApi.createRequestHandler(baseURL: string, options?: Partial<FexiosRequestOptions>): Fexios` (static)

Create your own Lyla instance.
Create your own Fexios 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
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wiki-saikou",
"version": "2.0.0",
"version": "3.0.0-rc.1",
"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",
Expand Down Expand Up @@ -32,7 +32,9 @@
"node",
"api-wrapper",
"typescript",
"axios"
"fetch",
"fetch-api",
"fexios"
],
"author": "Dragon-Fish <[email protected]>",
"license": "MIT",
Expand All @@ -41,8 +43,9 @@
},
"homepage": "https://github.com/moegirlwiki/wiki-saikou#readme",
"dependencies": {
"@lylajs/core": "^1.2.0",
"@vue/reactivity": "^3.3.4"
"@vue/reactivity": "^3.3.4",
"fexios": "^1.3.0",
"tslib": "^2.6.0"
},
"devDependencies": {
"@types/chai": "^4.3.5",
Expand All @@ -56,7 +59,6 @@
"mocha": "^10.2.0",
"rimraf": "^5.0.1",
"ts-mocha": "^10.0.0",
"tslib": "^2.6.0",
"tsup": "^7.1.0",
"tsx": "^3.12.7",
"typescript": "^5.1.6",
Expand Down
23 changes: 12 additions & 11 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 5e17eb3

Please sign in to comment.