pl-api: improve types

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2026-02-27 18:49:26 +01:00
parent 92174134ac
commit 13983b6e7d
4 changed files with 25 additions and 9 deletions

View File

@ -6,6 +6,8 @@ import { type Features, getFeatures } from './features';
import request, { getNextLink, getPrevLink, type RequestBody } from './request';
import type { Instance } from './entities/instance';
import type { StreamingEvent } from './entities/streaming-event';
import type { StreamingParams } from './params/streaming';
import type { Response as PlApiResponse } from './request';
import type { PaginatedResponse } from './responses';
@ -31,10 +33,10 @@ class PlApiBaseClient {
public features: Features = getFeatures(this.#instance);
/** @internal */
socket?: {
listen: (listener: any, stream?: string) => number;
unlisten: (listener: any) => void;
subscribe: (stream: string, params?: { list?: string; tag?: string }) => void;
unsubscribe: (stream: string, params?: { list?: string; tag?: string }) => void;
listen: (listener: (event: StreamingEvent) => void, stream?: string) => number;
unlisten: (listener: (event: StreamingEvent) => void) => void;
subscribe: (stream: string, params?: StreamingParams) => void;
unsubscribe: (stream: string, params?: StreamingParams) => void;
close: () => void;
};
/** @internal */

View File

@ -55,13 +55,12 @@ const streaming = (client: PlApiBaseClient) => ({
};
client.socket = {
listen: (listener: (event: StreamingEvent) => any, stream?: string) =>
listeners.push({ listener, stream }),
unlisten: (listener: (event: StreamingEvent) => any) =>
listen: (listener, stream) => listeners.push({ listener, stream }),
unlisten: (listener) =>
(listeners = listeners.filter((value) => value.listener !== listener)),
subscribe: (stream: string, { list, tag }: { list?: string; tag?: string } = {}) =>
subscribe: (stream, { list, tag } = {}) =>
enqueue(() => ws.send(JSON.stringify({ type: 'subscribe', stream, list, tag }))),
unsubscribe: (stream: string, { list, tag }: { list?: string; tag?: string } = {}) =>
unsubscribe: (stream, { list, tag } = {}) =>
enqueue(() => ws.send(JSON.stringify({ type: 'unsubscribe', stream, list, tag }))),
close: () => {
ws.close();

View File

@ -22,5 +22,6 @@ export * from './scheduled-statuses';
export * from './search';
export * from './settings';
export * from './statuses';
export * from './streaming';
export * from './timelines';
export * from './trends';

View File

@ -0,0 +1,14 @@
/**
* @category Request params
*/
interface StreamingParams {
/** When stream is set to `list`, use this parameter to specify the list ID. */
list?: string;
/** When stream is set to `hashtag` or `hashtag:local`, use this parameter to specify the tag name. */
tag?: string;
group?: string;
/** Domain name of the instance. Required when `stream` is `public:remote` or `public:remote:media`. */
instance?: string;
}
export { type StreamingParams };