Skip to content

Commit 615050f

Browse files
authored
Merge pull request #6 from moegirlwiki/dragon-fish/refactor-lyla
refactor!: rewrite with lyla-fetch
2 parents c02bb43 + e52760f commit 615050f

File tree

16 files changed

+475
-256
lines changed

16 files changed

+475
-256
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,5 @@ dist
103103
# TernJS port file
104104
.tern-port
105105

106-
lib
106+
lib
107+
debug

README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ const api = new MediaWikiApi('https://zh.moegirl.org.cn/api.php')
4545
**在浏览器中直接使用/Use directly in the browser**
4646

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

6766
**Main methods**:
6867

69-
#### `new MediaWikiApi(baseURL?: string, options?: AxiosRequestConfig)`
68+
#### `new MediaWikiApi(baseURL?: string, options?: LylaRequestOptions)`
7069

7170
- `baseURL`: API endpoint of your target wiki site (e.g. https://mediawiki.org/w/api.php)
7271
- **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.
73-
- `options`: {AxiosRequestConfig}
72+
- `options`: {LylaRequestOptions}
7473

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

7776
Login your account.
7877

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

8180
Make `GET` request
8281

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

8584
Make `POST` request
8685

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

8988
Make `POST` request with specified token.
9089

@@ -101,20 +100,20 @@ type MwTokenName =
101100
102101
### Auxiliary utilities
103102
104-
#### `get ajax` {AxiosInstance}
103+
#### `get request` {AxiosInstance}
105104
106-
Get `AxiosInstance` of current MediaWikiApi instance
105+
Get `Lyla` instance of current MediaWikiApi instance
107106
108-
#### `MediaWikiApi.adjustParamValue(params: MwApiParams): Record<string: string>` (static)
107+
#### `MediaWikiApi.normalizeParamValue(params: MwApiParams[keyof MwApiParams]): string | File | undefined` (static)
109108
110-
Adjust input params to standard MediaWiki request params.
109+
Normalize input params to standard MediaWiki request params.
111110
112111
- `string[] → string`: `['foo', 'bar', 'baz'] → 'foo|bar|baz`
113112
- `false → undefined`: remove false items
114113

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

117-
Create your own axios instance.
116+
Create your own Lyla instance.
118117

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

debug/index.cjs

Lines changed: 0 additions & 13 deletions
This file was deleted.

debug/index.mjs

Lines changed: 0 additions & 13 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "wiki-saikou",
3-
"version": "1.4.1",
3+
"version": "2.0.0",
44
"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~",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",
77
"browser": "./dist/index.umd.js",
8+
"module": "./dist/index.mjs",
89
"files": [
910
"dist",
1011
"lib"
@@ -40,8 +41,8 @@
4041
},
4142
"homepage": "https://github.com/moegirlwiki/wiki-saikou#readme",
4243
"dependencies": {
43-
"@vue/reactivity": "^3.3.4",
44-
"axios": "^1.4.0"
44+
"@lylajs/core": "^1.2.0",
45+
"@vue/reactivity": "^3.3.4"
4546
},
4647
"devDependencies": {
4748
"@types/chai": "^4.3.5",
@@ -50,6 +51,7 @@
5051
"@types/node": "^18.16.19",
5152
"chai": "^4.3.7",
5253
"chai-as-promised": "^7.1.1",
54+
"dotenv": "^16.3.1",
5355
"esbuild-register": "^3.4.2",
5456
"mocha": "^10.2.0",
5557
"rimraf": "^5.0.1",

pnpm-lock.yaml

Lines changed: 16 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)