@ukwhatn/wikidot 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -30
- package/dist/index.cjs +206 -215
- package/dist/index.d.cts +56 -4
- package/dist/index.d.ts +56 -4
- package/dist/index.js +2169 -238
- package/package.json +1 -1
- package/dist/shared/index-7dqqxq7x.js +0 -105
- package/dist/shared/index-f2eh3ykk.js +0 -172
- package/dist/shared/index-kka6e8cb.js +0 -627
- package/dist/shared/index-ytknx2hn.js +0 -980
package/README.md
CHANGED
|
@@ -17,30 +17,40 @@ wikidot-tsは、Wikidot APIを操作するためのTypeScriptライブラリで
|
|
|
17
17
|
## インストール
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
bun add wikidot
|
|
20
|
+
bun add @ukwhatn/wikidot
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
または
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
npm install wikidot
|
|
26
|
+
npm install @ukwhatn/wikidot
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
## 基本的な使い方
|
|
30
30
|
|
|
31
|
+
このライブラリは`neverthrow`のResult型を使用します。すべての非同期メソッドは`WikidotResultAsync<T>`を返し、`isOk()`で成功を確認後、`.value`で値を取得します。
|
|
32
|
+
|
|
31
33
|
### クライアントの作成
|
|
32
34
|
|
|
33
35
|
```typescript
|
|
34
|
-
import { Client } from 'wikidot
|
|
36
|
+
import { Client } from '@ukwhatn/wikidot';
|
|
35
37
|
|
|
36
38
|
// ログインなしでアクセス(公開情報のみ)
|
|
37
|
-
const
|
|
39
|
+
const clientResult = await Client.create();
|
|
40
|
+
if (!clientResult.isOk()) {
|
|
41
|
+
throw new Error('クライアントの作成に失敗しました');
|
|
42
|
+
}
|
|
43
|
+
const client = clientResult.value;
|
|
38
44
|
|
|
39
45
|
// ログインしてアクセス
|
|
40
|
-
const
|
|
46
|
+
const authClientResult = await Client.create({
|
|
41
47
|
username: 'your_username',
|
|
42
48
|
password: 'your_password',
|
|
43
49
|
});
|
|
50
|
+
if (!authClientResult.isOk()) {
|
|
51
|
+
throw new Error('ログインに失敗しました');
|
|
52
|
+
}
|
|
53
|
+
const authClient = authClientResult.value;
|
|
44
54
|
```
|
|
45
55
|
|
|
46
56
|
### サイトの取得
|
|
@@ -48,10 +58,11 @@ const authenticatedClient = await Client.create({
|
|
|
48
58
|
```typescript
|
|
49
59
|
// サイトを取得
|
|
50
60
|
const siteResult = await client.site.get('scp-jp');
|
|
51
|
-
if (siteResult.isOk()) {
|
|
52
|
-
|
|
53
|
-
console.log(`サイト: ${site.title}`);
|
|
61
|
+
if (!siteResult.isOk()) {
|
|
62
|
+
throw new Error('サイトの取得に失敗しました');
|
|
54
63
|
}
|
|
64
|
+
const site = siteResult.value;
|
|
65
|
+
console.log(`サイト: ${site.title}`);
|
|
55
66
|
```
|
|
56
67
|
|
|
57
68
|
### ページの操作
|
|
@@ -59,19 +70,21 @@ if (siteResult.isOk()) {
|
|
|
59
70
|
```typescript
|
|
60
71
|
// ページを検索
|
|
61
72
|
const pagesResult = await site.pages.search({ category: 'scp', tags: ['safe'] });
|
|
62
|
-
if (pagesResult.isOk()) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
if (!pagesResult.isOk()) {
|
|
74
|
+
throw new Error('ページの検索に失敗しました');
|
|
75
|
+
}
|
|
76
|
+
for (const page of pagesResult.value) {
|
|
77
|
+
console.log(`${page.fullname}: ${page.title}`);
|
|
66
78
|
}
|
|
67
79
|
|
|
68
80
|
// 単一ページを取得
|
|
69
81
|
const pageResult = await site.page.get('scp-001');
|
|
70
|
-
if (pageResult.isOk()) {
|
|
71
|
-
|
|
72
|
-
console.log(`タイトル: ${page.title}`);
|
|
73
|
-
console.log(`レーティング: ${page.rating}`);
|
|
82
|
+
if (!pageResult.isOk()) {
|
|
83
|
+
throw new Error('ページの取得に失敗しました');
|
|
74
84
|
}
|
|
85
|
+
const page = pageResult.value;
|
|
86
|
+
console.log(`タイトル: ${page.title}`);
|
|
87
|
+
console.log(`レーティング: ${page.rating}`);
|
|
75
88
|
```
|
|
76
89
|
|
|
77
90
|
### フォーラムの操作
|
|
@@ -79,36 +92,39 @@ if (pageResult.isOk()) {
|
|
|
79
92
|
```typescript
|
|
80
93
|
// フォーラムカテゴリを取得
|
|
81
94
|
const categoriesResult = await site.forum.getCategories();
|
|
82
|
-
if (categoriesResult.isOk()) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
95
|
+
if (!categoriesResult.isOk()) {
|
|
96
|
+
throw new Error('フォーラムカテゴリの取得に失敗しました');
|
|
97
|
+
}
|
|
98
|
+
for (const category of categoriesResult.value) {
|
|
99
|
+
console.log(`カテゴリ: ${category.title}`);
|
|
86
100
|
}
|
|
87
101
|
|
|
88
102
|
// スレッドに返信(要ログイン)
|
|
89
103
|
const threadResult = await site.forum.getThread(12345);
|
|
90
|
-
if (threadResult.isOk()) {
|
|
91
|
-
|
|
92
|
-
await thread.reply('返信内容', 'Re: タイトル');
|
|
104
|
+
if (!threadResult.isOk()) {
|
|
105
|
+
throw new Error('スレッドの取得に失敗しました');
|
|
93
106
|
}
|
|
107
|
+
const thread = threadResult.value;
|
|
108
|
+
await thread.reply('返信内容', 'Re: タイトル');
|
|
94
109
|
```
|
|
95
110
|
|
|
96
111
|
### プライベートメッセージ(要ログイン)
|
|
97
112
|
|
|
98
113
|
```typescript
|
|
99
114
|
// 受信箱を取得
|
|
100
|
-
const inboxResult = await client.
|
|
101
|
-
if (inboxResult.isOk()) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
115
|
+
const inboxResult = await client.privateMessage.inbox();
|
|
116
|
+
if (!inboxResult.isOk()) {
|
|
117
|
+
throw new Error('受信箱の取得に失敗しました');
|
|
118
|
+
}
|
|
119
|
+
for (const message of inboxResult.value) {
|
|
120
|
+
console.log(`From: ${message.sender.name}, Subject: ${message.subject}`);
|
|
105
121
|
}
|
|
106
122
|
|
|
107
123
|
// メッセージを送信
|
|
108
|
-
await client.
|
|
124
|
+
await client.privateMessage.send(recipientUser, '件名', '本文');
|
|
109
125
|
|
|
110
126
|
// メッセージを検索
|
|
111
|
-
const searchResult = await client.
|
|
127
|
+
const searchResult = await client.privateMessage.search('検索クエリ', 'all');
|
|
112
128
|
```
|
|
113
129
|
|
|
114
130
|
## エラーハンドリング
|