pl-api: improve types
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -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 */
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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';
|
||||
|
||||
14
packages/pl-api/lib/params/streaming.ts
Normal file
14
packages/pl-api/lib/params/streaming.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user