Skip to content

Commit

Permalink
Change TS types to use type declarations from PN JS SDK instead of co…
Browse files Browse the repository at this point in the history
…mmunity driven @types/pubnub
  • Loading branch information
wkal-pubnub committed Jan 7, 2025
1 parent 1ba266d commit 145ace4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
1 change: 0 additions & 1 deletion js-chat/package_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-commonjs": "28.0.1",
"@types/jest": "29.5.0",
"@types/pubnub": "7.4.2",
"babel-jest": "29.5.0",
"dotenv": "16.0.3",
"jest": "29.5.0",
Expand Down
84 changes: 42 additions & 42 deletions src/jsMain/resources/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/// <reference types="pubnub" />
import PubNub from "pubnub";
import { GetMembershipsParametersv2, GetChannelMembersParameters, ObjectCustom, SetMembershipsParameters, ChannelMetadataObject, PublishParameters, SendFileParameters } from "pubnub";
import { AppContext, Publish, FileSharing, Signal, Subscription, History } from "pubnub";
type MembershipFields = Pick<Membership, "channel" | "user" | "custom" | "updated" | "eTag">;
declare class Membership {
private chat;
readonly channel: Channel;
readonly user: User;
readonly custom: ObjectCustom | null | undefined;
readonly custom: AppContext.CustomData | null | undefined;
readonly updated: string;
readonly eTag: string;
update({ custom }: {
custom: ObjectCustom;
custom: AppContext.CustomData;
}): Promise<Membership>;
/*
* Updates
Expand All @@ -33,7 +33,7 @@ declare class User {
readonly externalId?: string;
readonly profileUrl?: string;
readonly email?: string;
readonly custom?: ObjectCustom;
readonly custom?: AppContext.CustomData;
readonly status?: string;
readonly type?: string;
readonly updated?: string;
Expand All @@ -57,7 +57,7 @@ declare class User {
/*
* Memberships
*/
getMemberships(params?: Omit<GetMembershipsParametersv2, "include" | "uuid">): Promise<{
getMemberships(params?: Omit<AppContext.GetMembershipsParameters, "include" | "uuid">): Promise<{
page: {
next: string | undefined;
prev: string | undefined;
Expand All @@ -79,7 +79,7 @@ declare class User {
mute: boolean;
reason: string | number | boolean | undefined;
}>;
getChannelsRestrictions(params?: Pick<PubNub.GetChannelMembersParameters, "limit" | "page" | "sort">): Promise<{
getChannelsRestrictions(params?: Pick<AppContext.GetMembersParameters, "limit" | "page" | "sort">): Promise<{
page: {
next: string | undefined;
prev: string | undefined;
Expand All @@ -97,7 +97,7 @@ declare class User {
* Other
*/
/** @deprecated */
DEPRECATED_report(reason: string): Promise<PubNub.SignalResponse>;
DEPRECATED_report(reason: string): Promise<Signal.SignalResponse>;
}
type EventFields<T extends EventType> = Pick<Event<T>, "timetoken" | "type" | "payload" | "channelId" | "userId">;
declare class Event<T extends EventType> {
Expand Down Expand Up @@ -241,26 +241,26 @@ type MessageReferencedChannels = {
name: string;
};
};
type MessageDraftOptions = Omit<PublishParameters, "message" | "channel">;
type SendTextOptionParams = Omit<PublishParameters, "message" | "channel"> & {
type MessageDraftOptions = Omit<Publish.PublishParameters, "message" | "channel">;
type SendTextOptionParams = Omit<Publish.PublishParameters, "message" | "channel"> & {
mentionedUsers?: MessageMentionedUsers;
referencedChannels?: MessageReferencedChannels;
textLinks?: TextLink[];
quotedMessage?: Message;
files?: FileList | File[] | SendFileParameters["file"][];
files?: FileList | File[] | FileSharing.SendFileParameters<any>["file"][];
};
type EnhancedMessageEvent = PubNub.MessageEvent & {
type EnhancedMessageEvent = Subscription.MessageEvent & {
userMetadata?: {
[key: string]: any;
};
};
type MessageDTOParams = PubNub.FetchMessagesResponse["channels"]["channel"][0] | EnhancedMessageEvent;
type MessageDTOParams = History.FetchMessagesResponse["channels"]["channel"][0] | EnhancedMessageEvent;
type ThreadMessageDTOParams = MessageDTOParams & {
parentChannelId: string;
};
type MembershipResponse = Awaited<ReturnType<User["getMemberships"]>>;
type OptionalAllBut<T, K extends keyof T> = Partial<T> & Pick<T, K>;
type ChannelDTOParams = OptionalAllBut<ChannelMetadataObject<ObjectCustom>, "id"> & {
type ChannelDTOParams = OptionalAllBut<AppContext.ChannelMetadataObject<AppContext.CustomData>, "id"> & {
status?: string | null;
type?: ChannelType | null | string;
};
Expand Down Expand Up @@ -394,11 +394,11 @@ declare class Message {
/*
* Other
*/
forward(channelId: string): Promise<PubNub.PublishResponse>;
forward(channelId: string): Promise<Publish.PublishResponse>;
pin(): Promise<void>;
/** @deprecated */
DEPRECATED_report(reason: string): Promise<PubNub.SignalResponse>;
report(reason: string): Promise<PubNub.SignalResponse>;
DEPRECATED_report(reason: string): Promise<Signal.SignalResponse>;
report(reason: string): Promise<Signal.SignalResponse>;
/**
* Threads
*/
Expand Down Expand Up @@ -427,13 +427,13 @@ export declare class MessageDraftV2 {
get value(): string;
quotedMessage: Message | undefined;
readonly config: MessageDraftConfig;
files?: FileList | File[] | SendFileParameters["file"][];
files?: FileList | File[] | FileSharing.SendFileParameters<any>["file"][];
addQuote(message: Message): void;
removeQuote(): void;
addLinkedText(params: AddLinkedTextParams): void;
removeLinkedText(positionInInput: number): void;
getMessagePreview(): MixedTextTypedElement[];
send(params?: MessageDraftOptions): Promise<PubNub.PublishResponse>;
send(params?: MessageDraftOptions): Promise<Publish.PublishResponse>;
addChangeListener(listener: (p0: MessageDraftState) => void): void;
removeChangeListener(listener: (p0: MessageDraftState) => void): void;
insertText(offset: number, text: string): void;
Expand Down Expand Up @@ -463,7 +463,7 @@ declare class MessageDraft {
value: string;
quotedMessage: Message | undefined;
readonly config: MessageDraftConfig;
files?: FileList | File[] | SendFileParameters["file"][];
files?: FileList | File[] | FileSharing.SendFileParameters<any>["file"][];
onChange(text: string): Promise<{
users: {
nameOccurrenceIndex: number;
Expand Down Expand Up @@ -497,7 +497,7 @@ declare class Channel {
protected chat: Chat;
readonly id: string;
readonly name?: string;
readonly custom?: ObjectCustom;
readonly custom?: AppContext.CustomData;
readonly description?: string;
readonly updated?: string;
readonly status?: string;
Expand All @@ -513,9 +513,9 @@ declare class Channel {
static streamUpdatesOn(channels: Channel[], callback: (channels: Channel[]) => unknown): () => void;
streamUpdates(callback: (channel: Channel) => unknown): () => void;
sendText(text: string, options?: SendTextOptionParams): Promise<unknown>;
forwardMessage(message: Message): Promise<PubNub.PublishResponse>;
startTyping(): Promise<PubNub.SignalResponse | undefined>;
stopTyping(): Promise<PubNub.SignalResponse | undefined>;
forwardMessage(message: Message): Promise<Publish.PublishResponse>;
startTyping(): Promise<Signal.SignalResponse | undefined>;
stopTyping(): Promise<Signal.SignalResponse | undefined>;
getTyping(callback: (typingUserIds: string[]) => unknown): () => void;
/*
* Streaming messages
Expand All @@ -539,14 +539,14 @@ declare class Channel {
isMore: boolean;
}>;
getMessage(timetoken: string): Promise<Message>;
join(callback: (message: Message) => void, params?: Omit<SetMembershipsParameters<ObjectCustom>, "channels" | "include" | "filter"> & {
custom?: ObjectCustom;
join(callback: (message: Message) => void, params?: Omit<AppContext.SetMembershipsParameters<AppContext.CustomData>, "channels" | "include" | "filter"> & {
custom?: AppContext.CustomData;
}): Promise<{
membership: Membership;
disconnect: () => void;
}>;
leave(): Promise<boolean>;
getMembers(params?: Omit<GetChannelMembersParameters, "channel" | "include">): Promise<{
getMembers(params?: Omit<AppContext.GetMembersParameters, "channel" | "include">): Promise<{
page: {
next: string | undefined;
prev: string | undefined;
Expand All @@ -570,7 +570,7 @@ declare class Channel {
streamReadReceipts(callback: (receipts: {
[key: string]: string[];
}) => unknown): Promise<() => void>;
getFiles(params?: Omit<PubNub.ListFilesParameters, "channel">): Promise<{
getFiles(params?: Omit<FileSharing.ListFilesParameters, "channel">): Promise<{
files: {
name: string;
id: string;
Expand All @@ -582,7 +582,7 @@ declare class Channel {
deleteFile(params: {
id: string;
name: string;
}): Promise<PubNub.DeleteFileResponse>;
}): Promise<FileSharing.DeleteFileResponse>;
/**
* Moderation restrictions
*/
Expand All @@ -596,7 +596,7 @@ declare class Channel {
mute: boolean;
reason: string | number | boolean | undefined;
}>;
getUsersRestrictions(params?: Pick<PubNub.GetChannelMembersParameters, "limit" | "page" | "sort">): Promise<{
getUsersRestrictions(params?: Pick<AppContext.GetMembersParameters, "limit" | "page" | "sort">): Promise<{
page: {
next: string | undefined;
prev: string | undefined;
Expand Down Expand Up @@ -649,13 +649,13 @@ type ChatConfig = {
};
authKey?: string;
};
type ChatConstructor = Partial<ChatConfig> & PubNub.PubnubConfig;
type ChatConstructor = Partial<ChatConfig> & PubNub.PubNubConfiguration;
declare class Chat {
readonly sdk: PubNub;
readonly config: ChatConfig;
private user;
static init(params: ChatConstructor): Promise<Chat>;
emitEvent(event: EmitEventParams): Promise<PubNub.SignalResponse>;
emitEvent(event: EmitEventParams): Promise<Signal.SignalResponse>;
listenForEvents<T extends EventType>(event: GenericEventParams<T> & {
callback: (event: Event<T>) => unknown;
}): () => void;
Expand All @@ -679,7 +679,7 @@ declare class Chat {
createUser(id: string, data: Omit<UserFields, "id">): Promise<User>;
updateUser(id: string, data: Omit<UserFields, "id">): Promise<User>;
deleteUser(id: string, params?: DeleteParameters): Promise<true | User>;
getUsers(params?: Omit<PubNub.GetAllMetadataParameters, "include">): Promise<{
getUsers(params?: Omit<AppContext.GetAllMetadataParameters<AppContext.UUIDMetadataObject<AppContext.CustomData>>, "include">): Promise<{
users: User[];
page: {
next: string | undefined;
Expand All @@ -692,7 +692,7 @@ declare class Chat {
*/
getChannel(id: string): Promise<Channel | null>;
updateChannel(id: string, data: Omit<ChannelFields, "id">): Promise<Channel>;
getChannels(params?: Omit<PubNub.GetAllMetadataParameters, "include">): Promise<{
getChannels(params?: Omit<AppContext.GetAllMetadataParameters<AppContext.ChannelMetadataObject<AppContext.CustomData>>, "include">): Promise<{
channels: Channel[];
page: {
next: string | undefined;
Expand All @@ -706,7 +706,7 @@ declare class Chat {
*/
createPublicConversation({ channelId, channelData }?: {
channelId?: string;
channelData?: PubNub.ChannelMetadata<PubNub.ObjectCustom>;
channelData?: AppContext.SetChannelMetadataParameters<AppContext.CustomData>;
}): Promise<Channel>;
/**
* Presence
Expand All @@ -717,9 +717,9 @@ declare class Chat {
createDirectConversation({ user, channelId, channelData, membershipData }: {
user: User;
channelId?: string;
channelData?: PubNub.ChannelMetadata<PubNub.ObjectCustom>;
membershipData?: Omit<PubNub.SetMembershipsParameters<PubNub.ObjectCustom>, "channels" | "include" | "filter"> & {
custom?: PubNub.ObjectCustom;
channelData?: AppContext.SetChannelMetadataParameters<AppContext.CustomData>;
membershipData?: Omit<AppContext.SetMembershipsParameters<AppContext.CustomData>, "channels" | "include" | "filter"> & {
custom?: AppContext.CustomData;
};
}): Promise<{
channel: Channel;
Expand All @@ -729,9 +729,9 @@ declare class Chat {
createGroupConversation({ users, channelId, channelData, membershipData }: {
users: User[];
channelId?: string;
channelData?: PubNub.ChannelMetadata<PubNub.ObjectCustom>;
membershipData?: Omit<PubNub.SetMembershipsParameters<PubNub.ObjectCustom>, "channels" | "include" | "filter"> & {
custom?: PubNub.ObjectCustom;
channelData?: AppContext.SetChannelMetadataParameters<AppContext.CustomData>;
membershipData?: Omit<AppContext.SetMembershipsParameters<AppContext.CustomData>, "channels" | "include" | "filter"> & {
custom?: AppContext.CustomData;
};
}): Promise<{
channel: Channel;
Expand All @@ -757,12 +757,12 @@ declare class Chat {
enhancedMentionsData: UserMentionData[];
isMore: boolean;
}>;
getUnreadMessagesCounts(params?: Omit<GetMembershipsParametersv2, "include">): Promise<{
getUnreadMessagesCounts(params?: Omit<AppContext.GetMembershipsParameters, "include">): Promise<{
channel: Channel;
membership: Membership;
count: number;
}[]>;
markAllMessagesAsRead(params?: Omit<GetMembershipsParametersv2, "include">): Promise<{
markAllMessagesAsRead(params?: Omit<AppContext.GetMembershipsParameters, "include">): Promise<{
page: {
next: string | undefined;
prev: string | undefined;
Expand Down

0 comments on commit 145ace4

Please sign in to comment.