mixi2-js 1.4.0 → 1.5.0
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 +9 -4
- package/dist/{client-DK9LqeiF.d.cts → event-CgwQm1Mk.d.cts} +148 -26
- package/dist/{client-GWUs7tD3.d.mts → event-LyIxrXkO.d.mts} +148 -26
- package/dist/helpers/index.cjs +212 -5
- package/dist/helpers/index.d.cts +135 -2
- package/dist/helpers/index.d.mts +135 -2
- package/dist/helpers/index.mjs +208 -6
- package/dist/index.cjs +132 -28
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +125 -24
- package/dist/{types-BrJ83qtL.mjs → types-DxrdxgSg.mjs} +35 -1
- package/dist/{types-D9t_NdQ0.cjs → types-cAD9ShMV.cjs} +52 -0
- package/package.json +21 -16
- package/proto/social/mixi/application/const/v1/application_requirement.proto +18 -0
- package/proto/social/mixi/application/const/v1/community_access_level.proto +9 -0
- package/proto/social/mixi/application/const/v1/community_visibility.proto +9 -0
- package/proto/social/mixi/application/const/v1/event_type.proto +7 -0
- package/proto/social/mixi/application/model/v1/application.proto +11 -0
- package/proto/social/mixi/application/model/v1/community.proto +20 -0
- package/proto/social/mixi/application/model/v1/event.proto +15 -0
- package/proto/social/mixi/application/model/v1/post.proto +1 -0
- package/proto/social/mixi/application/model/v1/stamp.proto +11 -0
- package/proto/social/mixi/application/service/application_api/v1/service.proto +178 -0
package/dist/helpers/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
require("../types-cAD9ShMV.cjs");
|
|
3
3
|
//#region src/helpers/address.ts
|
|
4
4
|
/**
|
|
5
5
|
* アクセストークン取得用のエンドポイント URL です。
|
|
@@ -14,6 +14,92 @@ const apiAddress = "application-api.mixi.social";
|
|
|
14
14
|
*/
|
|
15
15
|
const streamAddress = "application-stream.mixi.social";
|
|
16
16
|
//#endregion
|
|
17
|
+
//#region src/helpers/application-pager.ts
|
|
18
|
+
/**
|
|
19
|
+
* getCommunitiesUsingApplication のカーソルページネーションをラップするヘルパー(Plugin 専用)。
|
|
20
|
+
* ページ単位の非同期ジェネレーターと、全件を一括取得する fetchAll() を提供する。
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // ページ単位で処理
|
|
24
|
+
* const pager = new ApplicationPager(client);
|
|
25
|
+
* for await (const page of pager.iteratePages()) {
|
|
26
|
+
* for (const c of page.communitiesUsingApplication) {
|
|
27
|
+
* console.log(c.community?.name);
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* // 全件を一括取得
|
|
32
|
+
* const { communitiesUsingApplication, applicationVersions } = await pager.fetchAll();
|
|
33
|
+
*/
|
|
34
|
+
var ApplicationPager = class {
|
|
35
|
+
client;
|
|
36
|
+
constructor(client) {
|
|
37
|
+
this.client = client;
|
|
38
|
+
}
|
|
39
|
+
async *iteratePages(request, options) {
|
|
40
|
+
let cursor = request?.cursor;
|
|
41
|
+
const maxPages = options?.maxPages ?? Infinity;
|
|
42
|
+
let page = 0;
|
|
43
|
+
while (page < maxPages) {
|
|
44
|
+
const result = await this.client.getCommunitiesUsingApplication({
|
|
45
|
+
...request,
|
|
46
|
+
cursor
|
|
47
|
+
});
|
|
48
|
+
yield {
|
|
49
|
+
communitiesUsingApplication: result.communitiesUsingApplication,
|
|
50
|
+
applicationVersions: result.applicationVersions
|
|
51
|
+
};
|
|
52
|
+
if (!result.nextCursor) break;
|
|
53
|
+
cursor = result.nextCursor;
|
|
54
|
+
page++;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async fetchAll(request) {
|
|
58
|
+
const allCommunities = [];
|
|
59
|
+
const allVersions = [];
|
|
60
|
+
for await (const page of this.iteratePages(request)) {
|
|
61
|
+
allCommunities.push(...page.communitiesUsingApplication);
|
|
62
|
+
allVersions.push(...page.applicationVersions);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
communitiesUsingApplication: allCommunities,
|
|
66
|
+
applicationVersions: allVersions
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/helpers/community-filter.ts
|
|
72
|
+
/**
|
|
73
|
+
* 指定したコミュニティ ID に関連するイベントのみを内部ハンドラに渡すミドルウェア。
|
|
74
|
+
* コミュニティと無関係なイベント(PING など)はそのまま通過する。
|
|
75
|
+
*
|
|
76
|
+
* 複数のコミュニティにインストールされた Plugin で、
|
|
77
|
+
* 特定コミュニティのイベントだけを処理したい場合に有用。
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* const filter = new CommunityFilter(router, ['community-id-1', 'community-id-2']);
|
|
81
|
+
* await watcher.watch(filter);
|
|
82
|
+
*/
|
|
83
|
+
var CommunityFilter = class {
|
|
84
|
+
inner;
|
|
85
|
+
communityIds;
|
|
86
|
+
constructor(handler, communityIds) {
|
|
87
|
+
this.inner = handler;
|
|
88
|
+
this.communityIds = new Set(communityIds);
|
|
89
|
+
}
|
|
90
|
+
async handle(event) {
|
|
91
|
+
const communityId = this.getCommunityId(event);
|
|
92
|
+
if (communityId !== null && !this.communityIds.has(communityId)) return;
|
|
93
|
+
await this.inner.handle(event);
|
|
94
|
+
}
|
|
95
|
+
getCommunityId(event) {
|
|
96
|
+
if (event.postCreatedEvent?.post?.communityId) return event.postCreatedEvent.post.communityId;
|
|
97
|
+
if (event.communityMemberChangedEvent?.community?.communityId) return event.communityMemberChangedEvent.community.communityId;
|
|
98
|
+
if (event.communityPluginManagedEvent?.community?.communityId) return event.communityPluginManagedEvent.community.communityId;
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
//#endregion
|
|
17
103
|
//#region src/helpers/event-deduplicator.ts
|
|
18
104
|
/**
|
|
19
105
|
* 重複したイベントを検出してスキップするミドルウェア。
|
|
@@ -175,14 +261,125 @@ var MediaUploader = class {
|
|
|
175
261
|
const startTime = Date.now();
|
|
176
262
|
while (Date.now() - startTime < this.timeout) {
|
|
177
263
|
const status = await this.client.getPostMediaStatus(mediaId);
|
|
178
|
-
if (status.status ===
|
|
179
|
-
if (status.status ===
|
|
264
|
+
if (status.status === 3) return mediaId;
|
|
265
|
+
if (status.status === 4) throw new Error(`Media upload failed: ${mediaId}`);
|
|
180
266
|
await new Promise((resolve) => setTimeout(resolve, this.pollInterval));
|
|
181
267
|
}
|
|
182
268
|
throw new Error(`Media upload timed out after ${this.timeout}ms: ${mediaId}`);
|
|
183
269
|
}
|
|
184
270
|
};
|
|
185
271
|
//#endregion
|
|
272
|
+
//#region src/helpers/member-event-router.ts
|
|
273
|
+
/**
|
|
274
|
+
* CommunityMemberChangedEvent を参加・退出に分けてルーティングするハンドラ(Plugin 専用)。
|
|
275
|
+
* EventRouter と組み合わせて使用するか、単体で EventHandler として使用できる。
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* const memberRouter = new MemberEventRouter()
|
|
279
|
+
* .onJoined((member, community) => {
|
|
280
|
+
* console.log(`${member.displayName} が ${community.name} に参加しました`);
|
|
281
|
+
* })
|
|
282
|
+
* .onLeft((member, community) => {
|
|
283
|
+
* console.log(`${member.displayName} が ${community.name} から退出しました`);
|
|
284
|
+
* });
|
|
285
|
+
*
|
|
286
|
+
* // EventRouter と組み合わせる場合
|
|
287
|
+
* eventRouter.on(EventType.COMMUNITY_MEMBER_CHANGED, (e) => memberRouter.handle(e));
|
|
288
|
+
*
|
|
289
|
+
* // 単体で使用する場合
|
|
290
|
+
* await watcher.watch(memberRouter);
|
|
291
|
+
*/
|
|
292
|
+
var MemberEventRouter = class {
|
|
293
|
+
joinedListeners = [];
|
|
294
|
+
leftListeners = [];
|
|
295
|
+
onJoined(listener) {
|
|
296
|
+
this.joinedListeners.push(listener);
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
299
|
+
onLeft(listener) {
|
|
300
|
+
this.leftListeners.push(listener);
|
|
301
|
+
return this;
|
|
302
|
+
}
|
|
303
|
+
async handle(event) {
|
|
304
|
+
const e = event.communityMemberChangedEvent;
|
|
305
|
+
if (!e || !e.member || !e.community) return;
|
|
306
|
+
if (e.eventReasonList.includes(6)) for (const l of this.joinedListeners) await l(e.member, e.community, e);
|
|
307
|
+
if (e.eventReasonList.includes(7)) for (const l of this.leftListeners) await l(e.member, e.community, e);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/helpers/member-list-pager.ts
|
|
312
|
+
/**
|
|
313
|
+
* getCommunityMemberList のカーソルページネーションをラップする非同期ジェネレーター(Plugin 専用)。
|
|
314
|
+
* 全メンバーを取得するまでカーソルを自動で追跡する。
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* const pager = new MemberListPager(client);
|
|
318
|
+
* for await (const member of pager.iterate({ communityId: 'xxx' })) {
|
|
319
|
+
* console.log(member.displayName);
|
|
320
|
+
* }
|
|
321
|
+
*
|
|
322
|
+
* // 最大 3 ページまで
|
|
323
|
+
* for await (const member of pager.iterate({ communityId: 'xxx' }, { maxPages: 3 })) {
|
|
324
|
+
* console.log(member.displayName);
|
|
325
|
+
* }
|
|
326
|
+
*/
|
|
327
|
+
var MemberListPager = class {
|
|
328
|
+
client;
|
|
329
|
+
constructor(client) {
|
|
330
|
+
this.client = client;
|
|
331
|
+
}
|
|
332
|
+
async *iterate(request, options) {
|
|
333
|
+
let cursor = request.paginationCursor;
|
|
334
|
+
const maxPages = options?.maxPages ?? Infinity;
|
|
335
|
+
let page = 0;
|
|
336
|
+
while (page < maxPages) {
|
|
337
|
+
const result = await this.client.getCommunityMemberList({
|
|
338
|
+
...request,
|
|
339
|
+
paginationCursor: cursor
|
|
340
|
+
});
|
|
341
|
+
for (const member of result.members) yield member;
|
|
342
|
+
if (!result.nextPaginationCursor) break;
|
|
343
|
+
cursor = result.nextPaginationCursor;
|
|
344
|
+
page++;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/helpers/plugin-managed-router.ts
|
|
350
|
+
/**
|
|
351
|
+
* CommunityPluginManagedEvent をインストール・アンインストールに分けてルーティングするハンドラ(Plugin 専用)。
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* const pluginRouter = new PluginManagedRouter()
|
|
355
|
+
* .onInstalled((community) => {
|
|
356
|
+
* console.log(`Plugin が ${community.name} にインストールされました`);
|
|
357
|
+
* })
|
|
358
|
+
* .onUninstalled((community) => {
|
|
359
|
+
* console.log(`Plugin が ${community.name} からアンインストールされました`);
|
|
360
|
+
* });
|
|
361
|
+
*
|
|
362
|
+
* eventRouter.on(EventType.COMMUNITY_PLUGIN_MANAGED, (e) => pluginRouter.handle(e));
|
|
363
|
+
*/
|
|
364
|
+
var PluginManagedRouter = class {
|
|
365
|
+
installedListeners = [];
|
|
366
|
+
uninstalledListeners = [];
|
|
367
|
+
onInstalled(listener) {
|
|
368
|
+
this.installedListeners.push(listener);
|
|
369
|
+
return this;
|
|
370
|
+
}
|
|
371
|
+
onUninstalled(listener) {
|
|
372
|
+
this.uninstalledListeners.push(listener);
|
|
373
|
+
return this;
|
|
374
|
+
}
|
|
375
|
+
async handle(event) {
|
|
376
|
+
const e = event.communityPluginManagedEvent;
|
|
377
|
+
if (!e || !e.community) return;
|
|
378
|
+
if (e.eventReasonList.includes(9)) for (const l of this.installedListeners) await l(e.community, e);
|
|
379
|
+
if (e.eventReasonList.includes(10)) for (const l of this.uninstalledListeners) await l(e.community, e);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
//#endregion
|
|
186
383
|
//#region src/helpers/post-builder.ts
|
|
187
384
|
/**
|
|
188
385
|
* ポスト作成リクエストをメソッドチェーンで組み立てるビルダー。
|
|
@@ -219,7 +416,7 @@ var PostBuilder = class {
|
|
|
219
416
|
/** センシティブマスクを設定する。 */
|
|
220
417
|
sensitive(caption = "") {
|
|
221
418
|
this.request.postMask = {
|
|
222
|
-
maskType:
|
|
419
|
+
maskType: 1,
|
|
223
420
|
caption
|
|
224
421
|
};
|
|
225
422
|
return this;
|
|
@@ -227,7 +424,7 @@ var PostBuilder = class {
|
|
|
227
424
|
/** ネタバレマスクを設定する。 */
|
|
228
425
|
spoiler(caption = "") {
|
|
229
426
|
this.request.postMask = {
|
|
230
|
-
maskType:
|
|
427
|
+
maskType: 2,
|
|
231
428
|
caption
|
|
232
429
|
};
|
|
233
430
|
return this;
|
|
@@ -237,6 +434,11 @@ var PostBuilder = class {
|
|
|
237
434
|
this.request.postMask = postMask;
|
|
238
435
|
return this;
|
|
239
436
|
}
|
|
437
|
+
/** 投稿先コミュニティ ID を設定する。 */
|
|
438
|
+
community(communityId) {
|
|
439
|
+
this.request.communityId = communityId;
|
|
440
|
+
return this;
|
|
441
|
+
}
|
|
240
442
|
/** 配信設定を設定する。 */
|
|
241
443
|
publishing(type) {
|
|
242
444
|
this.request.publishingType = type;
|
|
@@ -322,10 +524,15 @@ var TextSplitter = class {
|
|
|
322
524
|
}
|
|
323
525
|
};
|
|
324
526
|
//#endregion
|
|
527
|
+
exports.ApplicationPager = ApplicationPager;
|
|
528
|
+
exports.CommunityFilter = CommunityFilter;
|
|
325
529
|
exports.EventDeduplicator = EventDeduplicator;
|
|
326
530
|
exports.EventLogger = EventLogger;
|
|
327
531
|
exports.EventRouter = EventRouter;
|
|
328
532
|
exports.MediaUploader = MediaUploader;
|
|
533
|
+
exports.MemberEventRouter = MemberEventRouter;
|
|
534
|
+
exports.MemberListPager = MemberListPager;
|
|
535
|
+
exports.PluginManagedRouter = PluginManagedRouter;
|
|
329
536
|
exports.PostBuilder = PostBuilder;
|
|
330
537
|
exports.ReasonFilter = ReasonFilter;
|
|
331
538
|
exports.TextSplitter = TextSplitter;
|
package/dist/helpers/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as GetCommunityMemberListRequest, G as PostMask, Z as PostPublishingType, _ as Event, a as ApplicationVersion, c as Community, d as CommunityPluginManagedEvent, g as CreatePostRequest, it as User, k as InitiatePostMediaUploadRequest, m as CommunityUsingApplication, n as Client, t as EventHandler, u as CommunityMemberChangedEvent, v as EventReason, x as GetCommunitiesUsingApplicationRequest, y as EventType } from "../event-CgwQm1Mk.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/helpers/address.d.ts
|
|
4
4
|
/**
|
|
@@ -14,6 +14,58 @@ declare const apiAddress: string;
|
|
|
14
14
|
*/
|
|
15
15
|
declare const streamAddress: string;
|
|
16
16
|
//#endregion
|
|
17
|
+
//#region src/helpers/application-pager.d.ts
|
|
18
|
+
interface ApplicationPagerOptions {
|
|
19
|
+
/** 取得する最大ページ数。デフォルト: 無制限 */
|
|
20
|
+
maxPages?: number;
|
|
21
|
+
}
|
|
22
|
+
interface ApplicationPagerPage {
|
|
23
|
+
communitiesUsingApplication: CommunityUsingApplication[];
|
|
24
|
+
applicationVersions: ApplicationVersion[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* getCommunitiesUsingApplication のカーソルページネーションをラップするヘルパー(Plugin 専用)。
|
|
28
|
+
* ページ単位の非同期ジェネレーターと、全件を一括取得する fetchAll() を提供する。
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // ページ単位で処理
|
|
32
|
+
* const pager = new ApplicationPager(client);
|
|
33
|
+
* for await (const page of pager.iteratePages()) {
|
|
34
|
+
* for (const c of page.communitiesUsingApplication) {
|
|
35
|
+
* console.log(c.community?.name);
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* // 全件を一括取得
|
|
40
|
+
* const { communitiesUsingApplication, applicationVersions } = await pager.fetchAll();
|
|
41
|
+
*/
|
|
42
|
+
declare class ApplicationPager {
|
|
43
|
+
private readonly client;
|
|
44
|
+
constructor(client: Client);
|
|
45
|
+
iteratePages(request?: GetCommunitiesUsingApplicationRequest, options?: ApplicationPagerOptions): AsyncGenerator<ApplicationPagerPage>;
|
|
46
|
+
fetchAll(request?: GetCommunitiesUsingApplicationRequest): Promise<ApplicationPagerPage>;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/helpers/community-filter.d.ts
|
|
50
|
+
/**
|
|
51
|
+
* 指定したコミュニティ ID に関連するイベントのみを内部ハンドラに渡すミドルウェア。
|
|
52
|
+
* コミュニティと無関係なイベント(PING など)はそのまま通過する。
|
|
53
|
+
*
|
|
54
|
+
* 複数のコミュニティにインストールされた Plugin で、
|
|
55
|
+
* 特定コミュニティのイベントだけを処理したい場合に有用。
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const filter = new CommunityFilter(router, ['community-id-1', 'community-id-2']);
|
|
59
|
+
* await watcher.watch(filter);
|
|
60
|
+
*/
|
|
61
|
+
declare class CommunityFilter implements EventHandler {
|
|
62
|
+
private readonly inner;
|
|
63
|
+
private readonly communityIds;
|
|
64
|
+
constructor(handler: EventHandler, communityIds: string[]);
|
|
65
|
+
handle(event: Event): Promise<void>;
|
|
66
|
+
private getCommunityId;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
17
69
|
//#region src/helpers/event-deduplicator.d.ts
|
|
18
70
|
interface EventDeduplicatorOptions {
|
|
19
71
|
/** 記憶する最大イベント数。デフォルト: 1000 */
|
|
@@ -127,6 +179,85 @@ declare class MediaUploader {
|
|
|
127
179
|
waitForReady(mediaId: string): Promise<string>;
|
|
128
180
|
}
|
|
129
181
|
//#endregion
|
|
182
|
+
//#region src/helpers/member-event-router.d.ts
|
|
183
|
+
type MemberListener = (member: User, community: Community, event: CommunityMemberChangedEvent) => void | Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* CommunityMemberChangedEvent を参加・退出に分けてルーティングするハンドラ(Plugin 専用)。
|
|
186
|
+
* EventRouter と組み合わせて使用するか、単体で EventHandler として使用できる。
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* const memberRouter = new MemberEventRouter()
|
|
190
|
+
* .onJoined((member, community) => {
|
|
191
|
+
* console.log(`${member.displayName} が ${community.name} に参加しました`);
|
|
192
|
+
* })
|
|
193
|
+
* .onLeft((member, community) => {
|
|
194
|
+
* console.log(`${member.displayName} が ${community.name} から退出しました`);
|
|
195
|
+
* });
|
|
196
|
+
*
|
|
197
|
+
* // EventRouter と組み合わせる場合
|
|
198
|
+
* eventRouter.on(EventType.COMMUNITY_MEMBER_CHANGED, (e) => memberRouter.handle(e));
|
|
199
|
+
*
|
|
200
|
+
* // 単体で使用する場合
|
|
201
|
+
* await watcher.watch(memberRouter);
|
|
202
|
+
*/
|
|
203
|
+
declare class MemberEventRouter implements EventHandler {
|
|
204
|
+
private readonly joinedListeners;
|
|
205
|
+
private readonly leftListeners;
|
|
206
|
+
onJoined(listener: MemberListener): this;
|
|
207
|
+
onLeft(listener: MemberListener): this;
|
|
208
|
+
handle(event: Event): Promise<void>;
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/helpers/member-list-pager.d.ts
|
|
212
|
+
interface MemberListPagerOptions {
|
|
213
|
+
/** 取得する最大ページ数。デフォルト: 無制限 */
|
|
214
|
+
maxPages?: number;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* getCommunityMemberList のカーソルページネーションをラップする非同期ジェネレーター(Plugin 専用)。
|
|
218
|
+
* 全メンバーを取得するまでカーソルを自動で追跡する。
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* const pager = new MemberListPager(client);
|
|
222
|
+
* for await (const member of pager.iterate({ communityId: 'xxx' })) {
|
|
223
|
+
* console.log(member.displayName);
|
|
224
|
+
* }
|
|
225
|
+
*
|
|
226
|
+
* // 最大 3 ページまで
|
|
227
|
+
* for await (const member of pager.iterate({ communityId: 'xxx' }, { maxPages: 3 })) {
|
|
228
|
+
* console.log(member.displayName);
|
|
229
|
+
* }
|
|
230
|
+
*/
|
|
231
|
+
declare class MemberListPager {
|
|
232
|
+
private readonly client;
|
|
233
|
+
constructor(client: Client);
|
|
234
|
+
iterate(request: GetCommunityMemberListRequest, options?: MemberListPagerOptions): AsyncGenerator<User>;
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/helpers/plugin-managed-router.d.ts
|
|
238
|
+
type PluginManagedListener = (community: Community, event: CommunityPluginManagedEvent) => void | Promise<void>;
|
|
239
|
+
/**
|
|
240
|
+
* CommunityPluginManagedEvent をインストール・アンインストールに分けてルーティングするハンドラ(Plugin 専用)。
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* const pluginRouter = new PluginManagedRouter()
|
|
244
|
+
* .onInstalled((community) => {
|
|
245
|
+
* console.log(`Plugin が ${community.name} にインストールされました`);
|
|
246
|
+
* })
|
|
247
|
+
* .onUninstalled((community) => {
|
|
248
|
+
* console.log(`Plugin が ${community.name} からアンインストールされました`);
|
|
249
|
+
* });
|
|
250
|
+
*
|
|
251
|
+
* eventRouter.on(EventType.COMMUNITY_PLUGIN_MANAGED, (e) => pluginRouter.handle(e));
|
|
252
|
+
*/
|
|
253
|
+
declare class PluginManagedRouter implements EventHandler {
|
|
254
|
+
private readonly installedListeners;
|
|
255
|
+
private readonly uninstalledListeners;
|
|
256
|
+
onInstalled(listener: PluginManagedListener): this;
|
|
257
|
+
onUninstalled(listener: PluginManagedListener): this;
|
|
258
|
+
handle(event: Event): Promise<void>;
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
130
261
|
//#region src/helpers/post-builder.d.ts
|
|
131
262
|
/**
|
|
132
263
|
* ポスト作成リクエストをメソッドチェーンで組み立てるビルダー。
|
|
@@ -153,6 +284,8 @@ declare class PostBuilder {
|
|
|
153
284
|
spoiler(caption?: string): this;
|
|
154
285
|
/** カスタムマスクを設定する。 */
|
|
155
286
|
mask(postMask: PostMask): this;
|
|
287
|
+
/** 投稿先コミュニティ ID を設定する。 */
|
|
288
|
+
community(communityId: string): this;
|
|
156
289
|
/** 配信設定を設定する。 */
|
|
157
290
|
publishing(type: PostPublishingType): this;
|
|
158
291
|
/** CreatePostRequest オブジェクトを構築する。 */
|
|
@@ -210,4 +343,4 @@ declare class TextSplitter {
|
|
|
210
343
|
split(text: string): string[];
|
|
211
344
|
}
|
|
212
345
|
//#endregion
|
|
213
|
-
export { EventDeduplicator, type EventDeduplicatorOptions, EventLogger, type EventLoggerOptions, EventRouter, MediaUploader, type MediaUploaderOptions, PostBuilder, ReasonFilter, TextSplitter, type TextSplitterOptions, type UploadedMedia, apiAddress, maxPostLength, streamAddress, tokenUrl };
|
|
346
|
+
export { ApplicationPager, type ApplicationPagerOptions, type ApplicationPagerPage, CommunityFilter, EventDeduplicator, type EventDeduplicatorOptions, EventLogger, type EventLoggerOptions, EventRouter, MediaUploader, type MediaUploaderOptions, MemberEventRouter, MemberListPager, type MemberListPagerOptions, PluginManagedRouter, PostBuilder, ReasonFilter, TextSplitter, type TextSplitterOptions, type UploadedMedia, apiAddress, maxPostLength, streamAddress, tokenUrl };
|
package/dist/helpers/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as GetCommunityMemberListRequest, G as PostMask, Z as PostPublishingType, _ as Event, a as ApplicationVersion, c as Community, d as CommunityPluginManagedEvent, g as CreatePostRequest, it as User, k as InitiatePostMediaUploadRequest, m as CommunityUsingApplication, n as Client, t as EventHandler, u as CommunityMemberChangedEvent, v as EventReason, x as GetCommunitiesUsingApplicationRequest, y as EventType } from "../event-LyIxrXkO.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/helpers/address.d.ts
|
|
4
4
|
/**
|
|
@@ -14,6 +14,58 @@ declare const apiAddress: string;
|
|
|
14
14
|
*/
|
|
15
15
|
declare const streamAddress: string;
|
|
16
16
|
//#endregion
|
|
17
|
+
//#region src/helpers/application-pager.d.ts
|
|
18
|
+
interface ApplicationPagerOptions {
|
|
19
|
+
/** 取得する最大ページ数。デフォルト: 無制限 */
|
|
20
|
+
maxPages?: number;
|
|
21
|
+
}
|
|
22
|
+
interface ApplicationPagerPage {
|
|
23
|
+
communitiesUsingApplication: CommunityUsingApplication[];
|
|
24
|
+
applicationVersions: ApplicationVersion[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* getCommunitiesUsingApplication のカーソルページネーションをラップするヘルパー(Plugin 専用)。
|
|
28
|
+
* ページ単位の非同期ジェネレーターと、全件を一括取得する fetchAll() を提供する。
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // ページ単位で処理
|
|
32
|
+
* const pager = new ApplicationPager(client);
|
|
33
|
+
* for await (const page of pager.iteratePages()) {
|
|
34
|
+
* for (const c of page.communitiesUsingApplication) {
|
|
35
|
+
* console.log(c.community?.name);
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* // 全件を一括取得
|
|
40
|
+
* const { communitiesUsingApplication, applicationVersions } = await pager.fetchAll();
|
|
41
|
+
*/
|
|
42
|
+
declare class ApplicationPager {
|
|
43
|
+
private readonly client;
|
|
44
|
+
constructor(client: Client);
|
|
45
|
+
iteratePages(request?: GetCommunitiesUsingApplicationRequest, options?: ApplicationPagerOptions): AsyncGenerator<ApplicationPagerPage>;
|
|
46
|
+
fetchAll(request?: GetCommunitiesUsingApplicationRequest): Promise<ApplicationPagerPage>;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/helpers/community-filter.d.ts
|
|
50
|
+
/**
|
|
51
|
+
* 指定したコミュニティ ID に関連するイベントのみを内部ハンドラに渡すミドルウェア。
|
|
52
|
+
* コミュニティと無関係なイベント(PING など)はそのまま通過する。
|
|
53
|
+
*
|
|
54
|
+
* 複数のコミュニティにインストールされた Plugin で、
|
|
55
|
+
* 特定コミュニティのイベントだけを処理したい場合に有用。
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const filter = new CommunityFilter(router, ['community-id-1', 'community-id-2']);
|
|
59
|
+
* await watcher.watch(filter);
|
|
60
|
+
*/
|
|
61
|
+
declare class CommunityFilter implements EventHandler {
|
|
62
|
+
private readonly inner;
|
|
63
|
+
private readonly communityIds;
|
|
64
|
+
constructor(handler: EventHandler, communityIds: string[]);
|
|
65
|
+
handle(event: Event): Promise<void>;
|
|
66
|
+
private getCommunityId;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
17
69
|
//#region src/helpers/event-deduplicator.d.ts
|
|
18
70
|
interface EventDeduplicatorOptions {
|
|
19
71
|
/** 記憶する最大イベント数。デフォルト: 1000 */
|
|
@@ -127,6 +179,85 @@ declare class MediaUploader {
|
|
|
127
179
|
waitForReady(mediaId: string): Promise<string>;
|
|
128
180
|
}
|
|
129
181
|
//#endregion
|
|
182
|
+
//#region src/helpers/member-event-router.d.ts
|
|
183
|
+
type MemberListener = (member: User, community: Community, event: CommunityMemberChangedEvent) => void | Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* CommunityMemberChangedEvent を参加・退出に分けてルーティングするハンドラ(Plugin 専用)。
|
|
186
|
+
* EventRouter と組み合わせて使用するか、単体で EventHandler として使用できる。
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* const memberRouter = new MemberEventRouter()
|
|
190
|
+
* .onJoined((member, community) => {
|
|
191
|
+
* console.log(`${member.displayName} が ${community.name} に参加しました`);
|
|
192
|
+
* })
|
|
193
|
+
* .onLeft((member, community) => {
|
|
194
|
+
* console.log(`${member.displayName} が ${community.name} から退出しました`);
|
|
195
|
+
* });
|
|
196
|
+
*
|
|
197
|
+
* // EventRouter と組み合わせる場合
|
|
198
|
+
* eventRouter.on(EventType.COMMUNITY_MEMBER_CHANGED, (e) => memberRouter.handle(e));
|
|
199
|
+
*
|
|
200
|
+
* // 単体で使用する場合
|
|
201
|
+
* await watcher.watch(memberRouter);
|
|
202
|
+
*/
|
|
203
|
+
declare class MemberEventRouter implements EventHandler {
|
|
204
|
+
private readonly joinedListeners;
|
|
205
|
+
private readonly leftListeners;
|
|
206
|
+
onJoined(listener: MemberListener): this;
|
|
207
|
+
onLeft(listener: MemberListener): this;
|
|
208
|
+
handle(event: Event): Promise<void>;
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/helpers/member-list-pager.d.ts
|
|
212
|
+
interface MemberListPagerOptions {
|
|
213
|
+
/** 取得する最大ページ数。デフォルト: 無制限 */
|
|
214
|
+
maxPages?: number;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* getCommunityMemberList のカーソルページネーションをラップする非同期ジェネレーター(Plugin 専用)。
|
|
218
|
+
* 全メンバーを取得するまでカーソルを自動で追跡する。
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* const pager = new MemberListPager(client);
|
|
222
|
+
* for await (const member of pager.iterate({ communityId: 'xxx' })) {
|
|
223
|
+
* console.log(member.displayName);
|
|
224
|
+
* }
|
|
225
|
+
*
|
|
226
|
+
* // 最大 3 ページまで
|
|
227
|
+
* for await (const member of pager.iterate({ communityId: 'xxx' }, { maxPages: 3 })) {
|
|
228
|
+
* console.log(member.displayName);
|
|
229
|
+
* }
|
|
230
|
+
*/
|
|
231
|
+
declare class MemberListPager {
|
|
232
|
+
private readonly client;
|
|
233
|
+
constructor(client: Client);
|
|
234
|
+
iterate(request: GetCommunityMemberListRequest, options?: MemberListPagerOptions): AsyncGenerator<User>;
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/helpers/plugin-managed-router.d.ts
|
|
238
|
+
type PluginManagedListener = (community: Community, event: CommunityPluginManagedEvent) => void | Promise<void>;
|
|
239
|
+
/**
|
|
240
|
+
* CommunityPluginManagedEvent をインストール・アンインストールに分けてルーティングするハンドラ(Plugin 専用)。
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* const pluginRouter = new PluginManagedRouter()
|
|
244
|
+
* .onInstalled((community) => {
|
|
245
|
+
* console.log(`Plugin が ${community.name} にインストールされました`);
|
|
246
|
+
* })
|
|
247
|
+
* .onUninstalled((community) => {
|
|
248
|
+
* console.log(`Plugin が ${community.name} からアンインストールされました`);
|
|
249
|
+
* });
|
|
250
|
+
*
|
|
251
|
+
* eventRouter.on(EventType.COMMUNITY_PLUGIN_MANAGED, (e) => pluginRouter.handle(e));
|
|
252
|
+
*/
|
|
253
|
+
declare class PluginManagedRouter implements EventHandler {
|
|
254
|
+
private readonly installedListeners;
|
|
255
|
+
private readonly uninstalledListeners;
|
|
256
|
+
onInstalled(listener: PluginManagedListener): this;
|
|
257
|
+
onUninstalled(listener: PluginManagedListener): this;
|
|
258
|
+
handle(event: Event): Promise<void>;
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
130
261
|
//#region src/helpers/post-builder.d.ts
|
|
131
262
|
/**
|
|
132
263
|
* ポスト作成リクエストをメソッドチェーンで組み立てるビルダー。
|
|
@@ -153,6 +284,8 @@ declare class PostBuilder {
|
|
|
153
284
|
spoiler(caption?: string): this;
|
|
154
285
|
/** カスタムマスクを設定する。 */
|
|
155
286
|
mask(postMask: PostMask): this;
|
|
287
|
+
/** 投稿先コミュニティ ID を設定する。 */
|
|
288
|
+
community(communityId: string): this;
|
|
156
289
|
/** 配信設定を設定する。 */
|
|
157
290
|
publishing(type: PostPublishingType): this;
|
|
158
291
|
/** CreatePostRequest オブジェクトを構築する。 */
|
|
@@ -210,4 +343,4 @@ declare class TextSplitter {
|
|
|
210
343
|
split(text: string): string[];
|
|
211
344
|
}
|
|
212
345
|
//#endregion
|
|
213
|
-
export { EventDeduplicator, type EventDeduplicatorOptions, EventLogger, type EventLoggerOptions, EventRouter, MediaUploader, type MediaUploaderOptions, PostBuilder, ReasonFilter, TextSplitter, type TextSplitterOptions, type UploadedMedia, apiAddress, maxPostLength, streamAddress, tokenUrl };
|
|
346
|
+
export { ApplicationPager, type ApplicationPagerOptions, type ApplicationPagerPage, CommunityFilter, EventDeduplicator, type EventDeduplicatorOptions, EventLogger, type EventLoggerOptions, EventRouter, MediaUploader, type MediaUploaderOptions, MemberEventRouter, MemberListPager, type MemberListPagerOptions, PluginManagedRouter, PostBuilder, ReasonFilter, TextSplitter, type TextSplitterOptions, type UploadedMedia, apiAddress, maxPostLength, streamAddress, tokenUrl };
|