mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-13 05:20:25 +00:00
Add channelgroup type definitions to pubnub types (#38371)
* add type definitions for channelgroup methods to pubnub type definitions * fix the code formatting after husky configs butchered it * add tests * check in auto-formatted code
This commit is contained in:
Vendored
+124
-30
@@ -19,6 +19,8 @@ declare class Pubnub {
|
||||
|
||||
static generateUUID(): string;
|
||||
|
||||
channelGroups: Pubnub.ChannelGroups;
|
||||
|
||||
setUUID(uuid: string): void;
|
||||
|
||||
getUUID(): string;
|
||||
@@ -31,25 +33,30 @@ declare class Pubnub {
|
||||
|
||||
publish(
|
||||
params: Pubnub.PublishParameters,
|
||||
callback: (status: Pubnub.PublishStatus, response: Pubnub.PublishResponse) => void
|
||||
callback: (
|
||||
status: Pubnub.PublishStatus,
|
||||
response: Pubnub.PublishResponse,
|
||||
) => void,
|
||||
): void;
|
||||
|
||||
publish(
|
||||
params: Pubnub.PublishParameters
|
||||
): Promise<Pubnub.PublishResponse>;
|
||||
publish(params: Pubnub.PublishParameters): Promise<Pubnub.PublishResponse>;
|
||||
|
||||
fire(
|
||||
params: Pubnub.FireParameters,
|
||||
callback: (status: Pubnub.PublishStatus, response: Pubnub.PublishResponse) => void
|
||||
callback: (
|
||||
status: Pubnub.PublishStatus,
|
||||
response: Pubnub.PublishResponse,
|
||||
) => void,
|
||||
): void;
|
||||
|
||||
fire(
|
||||
params: Pubnub.FireParameters
|
||||
): Promise<Pubnub.PublishResponse>;
|
||||
fire(params: Pubnub.FireParameters): Promise<Pubnub.PublishResponse>;
|
||||
|
||||
history(
|
||||
params: Pubnub.HistoryParameters,
|
||||
callback: (status: Pubnub.HistoryStatus, response: Pubnub.HistoryResponse) => void
|
||||
callback: (
|
||||
status: Pubnub.HistoryStatus,
|
||||
response: Pubnub.HistoryResponse,
|
||||
) => void,
|
||||
): void;
|
||||
|
||||
subscribe(params: Pubnub.SubscribeParameters): void;
|
||||
@@ -66,48 +73,50 @@ declare class Pubnub {
|
||||
|
||||
hereNow(
|
||||
params: Pubnub.HereNowParameters,
|
||||
callback: (status: Pubnub.HereNowStatus, response: Pubnub.HereNowResponse) => void
|
||||
callback: (
|
||||
status: Pubnub.HereNowStatus,
|
||||
response: Pubnub.HereNowResponse,
|
||||
) => void,
|
||||
): void;
|
||||
|
||||
hereNow(
|
||||
params: Pubnub.HereNowParameters
|
||||
): Promise<Pubnub.HereNowResponse>;
|
||||
hereNow(params: Pubnub.HereNowParameters): Promise<Pubnub.HereNowResponse>;
|
||||
|
||||
whereNow(
|
||||
params: Pubnub.WhereNowParameters,
|
||||
callback: (status: Pubnub.WhereNowStatus, response: Pubnub.WhereNowResponse) => void
|
||||
callback: (
|
||||
status: Pubnub.WhereNowStatus,
|
||||
response: Pubnub.WhereNowResponse,
|
||||
) => void,
|
||||
): void;
|
||||
|
||||
whereNow(
|
||||
params: Pubnub.WhereNowParameters
|
||||
): Promise<Pubnub.WhereNowResponse>;
|
||||
whereNow(params: Pubnub.WhereNowParameters): Promise<Pubnub.WhereNowResponse>;
|
||||
|
||||
getState(
|
||||
params: Pubnub.GetStateParameters,
|
||||
callback: (status: Pubnub.GetStateStatus, state: Pubnub.GetStateResponse) => void
|
||||
callback: (
|
||||
status: Pubnub.GetStateStatus,
|
||||
state: Pubnub.GetStateResponse,
|
||||
) => void,
|
||||
): void;
|
||||
|
||||
getState(
|
||||
params: Pubnub.GetStateParameters
|
||||
): Promise<Pubnub.GetStateResponse>;
|
||||
getState(params: Pubnub.GetStateParameters): Promise<Pubnub.GetStateResponse>;
|
||||
|
||||
setState(
|
||||
params: Pubnub.SetStateParameters,
|
||||
callback: (status: Pubnub.SetStateStatus, state: Pubnub.SetStateResponse) => void
|
||||
callback: (
|
||||
status: Pubnub.SetStateStatus,
|
||||
state: Pubnub.SetStateResponse,
|
||||
) => void,
|
||||
): void;
|
||||
|
||||
setState(
|
||||
params: Pubnub.SetStateParameters
|
||||
): Promise<Pubnub.SetStateResponse>;
|
||||
setState(params: Pubnub.SetStateParameters): Promise<Pubnub.SetStateResponse>;
|
||||
|
||||
grant(
|
||||
params: Pubnub.GrantParameters,
|
||||
callback: (status: Pubnub.GrantStatus, response: {}) => void
|
||||
callback: (status: Pubnub.GrantStatus, response: {}) => void,
|
||||
): void;
|
||||
|
||||
grant(
|
||||
params: Pubnub.GrantParameters
|
||||
): Promise<{}>;
|
||||
grant(params: Pubnub.GrantParameters): Promise<{}>;
|
||||
|
||||
encrypt(
|
||||
data: string,
|
||||
@@ -118,8 +127,10 @@ declare class Pubnub {
|
||||
decrypt(
|
||||
data: string | object,
|
||||
customCipherKey?: string,
|
||||
options?: Pubnub.CryptoParameters
|
||||
options?: Pubnub.CryptoParameters,
|
||||
): any;
|
||||
|
||||
time(): Promise<Pubnub.FetchTimeResponse>;
|
||||
}
|
||||
|
||||
declare namespace Pubnub {
|
||||
@@ -269,6 +280,84 @@ declare namespace Pubnub {
|
||||
channelGroups?: string[];
|
||||
}
|
||||
|
||||
// channelGroups
|
||||
interface ChannelGroups {
|
||||
addChannels(
|
||||
params: AddChannelParameters,
|
||||
callback: (status: ChannelGroupStatus) => void
|
||||
): void;
|
||||
|
||||
addChannels(
|
||||
params: AddChannelParameters
|
||||
): Promise<{}>;
|
||||
|
||||
removeChannels(
|
||||
params: RemoveChannelParameters,
|
||||
callback: (status: ChannelGroupStatus) => void
|
||||
): void;
|
||||
|
||||
removeChannels(
|
||||
params: RemoveChannelParameters
|
||||
): Promise<{}>;
|
||||
|
||||
listChannels(
|
||||
params: ListChannelsParameters,
|
||||
callback: (status: ChannelGroupStatus, response: ListChannelsResponse) => void
|
||||
): void;
|
||||
|
||||
listChannels(
|
||||
params: ListChannelsParameters
|
||||
): Promise<ListChannelsResponse>;
|
||||
|
||||
listGroups(
|
||||
callback: (status: ChannelGroupStatus, response: ListAllGroupsResponse) => void
|
||||
): void;
|
||||
|
||||
listGroups(): Promise<ListAllGroupsResponse>;
|
||||
|
||||
deleteGroup(
|
||||
params: DeleteGroupParameters,
|
||||
callback: (status: ChannelGroupStatus) => void
|
||||
): void;
|
||||
|
||||
deleteGroup(
|
||||
params: DeleteGroupParameters
|
||||
): Promise<{}>;
|
||||
}
|
||||
|
||||
interface AddChannelParameters {
|
||||
channels: string[];
|
||||
channelGroup: string;
|
||||
}
|
||||
|
||||
interface RemoveChannelParameters {
|
||||
channels: string[];
|
||||
channelGroup: string;
|
||||
}
|
||||
|
||||
interface ListChannelsParameters {
|
||||
channelGroup: string;
|
||||
}
|
||||
|
||||
interface DeleteGroupParameters {
|
||||
channelGroup: string;
|
||||
}
|
||||
|
||||
interface ListAllGroupsResponse {
|
||||
groups: string[];
|
||||
}
|
||||
|
||||
interface ListChannelsResponse {
|
||||
channels: string[];
|
||||
}
|
||||
|
||||
interface ChannelGroupStatus {
|
||||
error: boolean;
|
||||
errorData?: Error;
|
||||
operation: string; // see Pubnub.Operations
|
||||
statusCode?: number;
|
||||
}
|
||||
|
||||
// addListener
|
||||
interface ListenerParameters {
|
||||
status?(statusEvent: StatusEvent): void;
|
||||
@@ -383,6 +472,11 @@ declare namespace Pubnub {
|
||||
mode?: string;
|
||||
}
|
||||
|
||||
// fetch time
|
||||
interface FetchTimeResponse {
|
||||
timetoken: number;
|
||||
}
|
||||
|
||||
interface Categories {
|
||||
PNNetworkUpCategory: string;
|
||||
PNNetworkDownCategory: string;
|
||||
|
||||
@@ -115,3 +115,48 @@ const mySecret = {
|
||||
pubnub.decrypt(mySecret, undefined, cryptoOptions);
|
||||
pubnub.decrypt('mySecretString', undefined, cryptoOptions);
|
||||
pubnub.encrypt('egrah5rwgrehwqh5eh3hwfwef', undefined, cryptoOptions);
|
||||
|
||||
pubnub.time().then(response => console.log(response));
|
||||
|
||||
const channelGroup = 'channel-group-1';
|
||||
const channels = ['channel-1'];
|
||||
|
||||
pubnub.channelGroups
|
||||
.addChannels({ channelGroup, channels })
|
||||
.then(response => console.log(response));
|
||||
|
||||
pubnub.channelGroups
|
||||
.listChannels({ channelGroup })
|
||||
.then(response => console.log(response));
|
||||
|
||||
pubnub.channelGroups.listGroups().then(response => console.log(response));
|
||||
|
||||
pubnub.channelGroups
|
||||
.removeChannels({ channelGroup, channels })
|
||||
.then(response => console.log(response));
|
||||
|
||||
pubnub.channelGroups
|
||||
.deleteGroup({ channelGroup })
|
||||
.then(response => console.log(response));
|
||||
|
||||
pubnub.channelGroups.addChannels({ channelGroup, channels }, status =>
|
||||
console.log(status),
|
||||
);
|
||||
|
||||
pubnub.channelGroups.listChannels({ channelGroup }, (status, response) => {
|
||||
console.log(status);
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
pubnub.channelGroups.listGroups((status, response) => {
|
||||
console.log(status);
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
pubnub.channelGroups.removeChannels({ channelGroup, channels }, status =>
|
||||
console.log(status),
|
||||
);
|
||||
|
||||
pubnub.channelGroups.deleteGroup({ channelGroup }, status =>
|
||||
console.log(status),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user