@supabase/realtime-js
Advanced tools
Comparing version 2.0.0 to 2.1.0
import RealtimeClient, { RealtimeClientOptions, RealtimeMessage, RealtimeRemoveChannelResponse } from './RealtimeClient'; | ||
import RealtimeChannel, { RealtimeChannelOptions, RealtimeChannelSendResponse, RealtimePostgresChangesPayload, REALTIME_LISTEN_TYPES, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_SUBSCRIBE_STATES } from './RealtimeChannel'; | ||
import RealtimeChannel, { RealtimeChannelOptions, RealtimeChannelSendResponse, RealtimePostgresChangesFilter, RealtimePostgresChangesPayload, RealtimePostgresInsertPayload, RealtimePostgresUpdatePayload, RealtimePostgresDeletePayload, REALTIME_LISTEN_TYPES, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_SUBSCRIBE_STATES } from './RealtimeChannel'; | ||
import RealtimePresence, { RealtimePresenceState, RealtimePresenceJoinPayload, RealtimePresenceLeavePayload, REALTIME_PRESENCE_LISTEN_EVENTS } from './RealtimePresence'; | ||
export { RealtimePresence, RealtimeChannel, RealtimeChannelOptions, RealtimeChannelSendResponse, RealtimeClient, RealtimeClientOptions, RealtimeMessage, RealtimePostgresChangesPayload, RealtimePresenceJoinPayload, RealtimePresenceLeavePayload, RealtimePresenceState, RealtimeRemoveChannelResponse, REALTIME_LISTEN_TYPES, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_PRESENCE_LISTEN_EVENTS, REALTIME_SUBSCRIBE_STATES, }; | ||
export { RealtimePresence, RealtimeChannel, RealtimeChannelOptions, RealtimeChannelSendResponse, RealtimeClient, RealtimeClientOptions, RealtimeMessage, RealtimePostgresChangesFilter, RealtimePostgresChangesPayload, RealtimePostgresInsertPayload, RealtimePostgresUpdatePayload, RealtimePostgresDeletePayload, RealtimePresenceJoinPayload, RealtimePresenceLeavePayload, RealtimePresenceState, RealtimeRemoveChannelResponse, REALTIME_LISTEN_TYPES, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_PRESENCE_LISTEN_EVENTS, REALTIME_SUBSCRIBE_STATES, }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export declare const version = "2.0.0"; | ||
export declare const version = "2.1.0"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = '2.0.0'; | ||
exports.version = '2.1.0'; | ||
//# sourceMappingURL=version.js.map |
@@ -24,13 +24,38 @@ import { CHANNEL_STATES } from './lib/constants'; | ||
}; | ||
export declare type RealtimePostgresChangesPayload<T extends { | ||
[key: string]: any; | ||
}> = { | ||
declare type RealtimePostgresChangesPayloadBase = { | ||
schema: string; | ||
table: string; | ||
commit_timestamp: string; | ||
eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}` | `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}` | `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}`; | ||
new: T | {}; | ||
old: Partial<T> | {}; | ||
errors: string[]; | ||
}; | ||
export declare type RealtimePostgresInsertPayload<T extends { | ||
[key: string]: any; | ||
}> = RealtimePostgresChangesPayloadBase & { | ||
eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}`; | ||
new: T; | ||
old: {}; | ||
}; | ||
export declare type RealtimePostgresUpdatePayload<T extends { | ||
[key: string]: any; | ||
}> = RealtimePostgresChangesPayloadBase & { | ||
eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}`; | ||
new: T; | ||
old: Partial<T>; | ||
}; | ||
export declare type RealtimePostgresDeletePayload<T extends { | ||
[key: string]: any; | ||
}> = RealtimePostgresChangesPayloadBase & { | ||
eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}`; | ||
new: {}; | ||
old: Partial<T>; | ||
}; | ||
export declare type RealtimePostgresChangesPayload<T extends { | ||
[key: string]: any; | ||
}> = RealtimePostgresInsertPayload<T> | RealtimePostgresUpdatePayload<T> | RealtimePostgresDeletePayload<T>; | ||
export declare type RealtimePostgresChangesFilter<T extends string> = { | ||
event: T; | ||
schema: string; | ||
table?: string; | ||
filter?: string; | ||
}; | ||
export declare type RealtimeChannelSendResponse = 'ok' | 'timed out' | 'rate limited'; | ||
@@ -54,3 +79,9 @@ export declare enum REALTIME_POSTGRES_CHANGES_LISTEN_EVENT { | ||
} | ||
/** A channel is the basic building block of Realtime | ||
* and narrows the scope of data flow to subscribed clients. | ||
* You can think of a channel as a chatroom where participants are able to see who's online | ||
* and send and receive messages. | ||
**/ | ||
export default class RealtimeChannel { | ||
/** Topic name can be any string. */ | ||
topic: string; | ||
@@ -76,3 +107,6 @@ params: RealtimeChannelOptions; | ||
presence: RealtimePresence; | ||
constructor(topic: string, params: RealtimeChannelOptions, socket: RealtimeClient); | ||
constructor( | ||
/** Topic name can be any string. */ | ||
topic: string, params: RealtimeChannelOptions, socket: RealtimeClient); | ||
/** Subscribe registers your client with the server */ | ||
subscribe(callback?: (status: `${REALTIME_SUBSCRIBE_STATES}`, err?: Error) => void, timeout?: number): RealtimeChannel; | ||
@@ -88,2 +122,3 @@ presenceState(): RealtimePresenceState; | ||
}): Promise<RealtimeChannelSendResponse>; | ||
/** Listen to messages. */ | ||
on(type: `${REALTIME_LISTEN_TYPES.BROADCAST}`, filter: { | ||
@@ -97,12 +132,22 @@ event: string; | ||
on(type: `${REALTIME_LISTEN_TYPES.PRESENCE}`, filter: { | ||
event: `${REALTIME_PRESENCE_LISTEN_EVENTS}`; | ||
}, callback: (payload: RealtimePresenceJoinPayload | RealtimePresenceLeavePayload | undefined) => void): RealtimeChannel; | ||
event: `${REALTIME_PRESENCE_LISTEN_EVENTS.SYNC}`; | ||
}, callback: () => void): RealtimeChannel; | ||
on(type: `${REALTIME_LISTEN_TYPES.PRESENCE}`, filter: { | ||
event: `${REALTIME_PRESENCE_LISTEN_EVENTS.JOIN}`; | ||
}, callback: (payload: RealtimePresenceJoinPayload) => void): RealtimeChannel; | ||
on(type: `${REALTIME_LISTEN_TYPES.PRESENCE}`, filter: { | ||
event: `${REALTIME_PRESENCE_LISTEN_EVENTS.LEAVE}`; | ||
}, callback: (payload: RealtimePresenceLeavePayload) => void): RealtimeChannel; | ||
on<T extends { | ||
[key: string]: any; | ||
}>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: { | ||
event: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT}`; | ||
schema: string; | ||
table?: string; | ||
filter?: string; | ||
}, callback: (payload: RealtimePostgresChangesPayload<T>) => void): RealtimeChannel; | ||
}>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.ALL}`>, callback: (payload: RealtimePostgresChangesPayload<T>) => void): RealtimeChannel; | ||
on<T extends { | ||
[key: string]: any; | ||
}>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}`>, callback: (payload: RealtimePostgresInsertPayload<T>) => void): RealtimeChannel; | ||
on<T extends { | ||
[key: string]: any; | ||
}>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}`>, callback: (payload: RealtimePostgresUpdatePayload<T>) => void): RealtimeChannel; | ||
on<T extends { | ||
[key: string]: any; | ||
}>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}`>, callback: (payload: RealtimePostgresDeletePayload<T>) => void): RealtimeChannel; | ||
send(payload: { | ||
@@ -127,43 +172,4 @@ type: string; | ||
unsubscribe(timeout?: number): Promise<'ok' | 'timed out' | 'error'>; | ||
_push(event: string, payload: { | ||
[key: string]: any; | ||
}, timeout?: number): Push; | ||
/** | ||
* Overridable message hook | ||
* | ||
* Receives all events for specialized message handling before dispatching to the channel callbacks. | ||
* Must return the payload, modified or unmodified. | ||
*/ | ||
_onMessage(_event: string, payload: any, _ref?: string): any; | ||
_isMember(topic: string): boolean; | ||
_joinRef(): string; | ||
_trigger(type: string, payload?: any, ref?: string): void; | ||
_isClosed(): boolean; | ||
_isJoined(): boolean; | ||
_isJoining(): boolean; | ||
_isLeaving(): boolean; | ||
_replyEventName(ref: string): string; | ||
_on(type: string, filter: { | ||
[key: string]: any; | ||
}, callback: Function): this; | ||
_off(type: string, filter: { | ||
[key: string]: any; | ||
}): this; | ||
private static isEqual; | ||
private _rejoinUntilConnected; | ||
/** | ||
* Registers a callback that will be executed when the channel closes. | ||
*/ | ||
private _onClose; | ||
/** | ||
* Registers a callback that will be executed when the channel encounteres an error. | ||
*/ | ||
private _onError; | ||
/** | ||
* Returns `true` if the socket is connected and the channel has been joined. | ||
*/ | ||
private _canPush; | ||
private _rejoin; | ||
private _getPayloadRecords; | ||
} | ||
export {}; | ||
//# sourceMappingURL=RealtimeChannel.d.ts.map |
@@ -64,4 +64,11 @@ "use strict"; | ||
})(REALTIME_SUBSCRIBE_STATES = exports.REALTIME_SUBSCRIBE_STATES || (exports.REALTIME_SUBSCRIBE_STATES = {})); | ||
/** A channel is the basic building block of Realtime | ||
* and narrows the scope of data flow to subscribed clients. | ||
* You can think of a channel as a chatroom where participants are able to see who's online | ||
* and send and receive messages. | ||
**/ | ||
class RealtimeChannel { | ||
constructor(topic, params = { config: {} }, socket) { | ||
constructor( | ||
/** Topic name can be any string. */ | ||
topic, params = { config: {} }, socket) { | ||
this.topic = topic; | ||
@@ -114,2 +121,3 @@ this.params = params; | ||
} | ||
/** Subscribe registers your client with the server */ | ||
subscribe(callback, timeout = this.timeout) { | ||
@@ -263,2 +271,3 @@ var _a, _b; | ||
} | ||
/** @internal */ | ||
_push(event, payload, timeout = this.timeout) { | ||
@@ -283,2 +292,4 @@ if (!this.joinedOnce) { | ||
* Must return the payload, modified or unmodified. | ||
* | ||
* @internal | ||
*/ | ||
@@ -288,8 +299,11 @@ _onMessage(_event, payload, _ref) { | ||
} | ||
/** @internal */ | ||
_isMember(topic) { | ||
return this.topic === topic; | ||
} | ||
/** @internal */ | ||
_joinRef() { | ||
return this.joinPush.ref; | ||
} | ||
/** @internal */ | ||
_trigger(type, payload, ref) { | ||
@@ -355,17 +369,23 @@ var _a, _b; | ||
} | ||
/** @internal */ | ||
_isClosed() { | ||
return this.state === constants_1.CHANNEL_STATES.closed; | ||
} | ||
/** @internal */ | ||
_isJoined() { | ||
return this.state === constants_1.CHANNEL_STATES.joined; | ||
} | ||
/** @internal */ | ||
_isJoining() { | ||
return this.state === constants_1.CHANNEL_STATES.joining; | ||
} | ||
/** @internal */ | ||
_isLeaving() { | ||
return this.state === constants_1.CHANNEL_STATES.leaving; | ||
} | ||
/** @internal */ | ||
_replyEventName(ref) { | ||
return `chan_reply_${ref}`; | ||
} | ||
/** @internal */ | ||
_on(type, filter, callback) { | ||
@@ -386,2 +406,3 @@ const typeLower = type.toLocaleLowerCase(); | ||
} | ||
/** @internal */ | ||
_off(type, filter) { | ||
@@ -396,2 +417,3 @@ const typeLower = type.toLocaleLowerCase(); | ||
} | ||
/** @internal */ | ||
static isEqual(obj1, obj2) { | ||
@@ -408,2 +430,3 @@ if (Object.keys(obj1).length !== Object.keys(obj2).length) { | ||
} | ||
/** @internal */ | ||
_rejoinUntilConnected() { | ||
@@ -417,2 +440,4 @@ this.rejoinTimer.scheduleTimeout(); | ||
* Registers a callback that will be executed when the channel closes. | ||
* | ||
* @internal | ||
*/ | ||
@@ -424,2 +449,4 @@ _onClose(callback) { | ||
* Registers a callback that will be executed when the channel encounteres an error. | ||
* | ||
* @internal | ||
*/ | ||
@@ -431,2 +458,4 @@ _onError(callback) { | ||
* Returns `true` if the socket is connected and the channel has been joined. | ||
* | ||
* @internal | ||
*/ | ||
@@ -436,2 +465,3 @@ _canPush() { | ||
} | ||
/** @internal */ | ||
_rejoin(timeout = this.timeout) { | ||
@@ -445,2 +475,3 @@ if (this._isLeaving()) { | ||
} | ||
/** @internal */ | ||
_getPayloadRecords(payload) { | ||
@@ -447,0 +478,0 @@ const records = { |
@@ -116,30 +116,3 @@ import { CONNECTION_STATE } from './lib/constants'; | ||
setAuth(token: string | null): void; | ||
/** | ||
* Return the next message ref, accounting for overflows | ||
*/ | ||
_makeRef(): string; | ||
/** | ||
* Unsubscribe from channels with the specified topic. | ||
*/ | ||
_leaveOpenTopic(topic: string): void; | ||
/** | ||
* Removes a subscription from the socket. | ||
* | ||
* @param channel An open subscription. | ||
*/ | ||
_remove(channel: RealtimeChannel): void; | ||
/** | ||
* Returns the URL of the websocket. | ||
*/ | ||
private _endPointURL; | ||
private _onConnMessage; | ||
private _onConnOpen; | ||
private _onConnClose; | ||
private _onConnError; | ||
private _triggerChanError; | ||
private _appendParams; | ||
private _flushSendBuffer; | ||
private _sendHeartbeat; | ||
private _throttle; | ||
} | ||
//# sourceMappingURL=RealtimeClient.d.ts.map |
@@ -231,2 +231,4 @@ "use strict"; | ||
* Return the next message ref, accounting for overflows | ||
* | ||
* @internal | ||
*/ | ||
@@ -245,2 +247,4 @@ _makeRef() { | ||
* Unsubscribe from channels with the specified topic. | ||
* | ||
* @internal | ||
*/ | ||
@@ -258,2 +262,4 @@ _leaveOpenTopic(topic) { | ||
* @param channel An open subscription. | ||
* | ||
* @internal | ||
*/ | ||
@@ -265,2 +271,4 @@ _remove(channel) { | ||
* Returns the URL of the websocket. | ||
* | ||
* @internal | ||
*/ | ||
@@ -270,2 +278,3 @@ _endPointURL() { | ||
} | ||
/** @internal */ | ||
_onConnMessage(rawMessage) { | ||
@@ -285,2 +294,3 @@ this.decode(rawMessage.data, (msg) => { | ||
} | ||
/** @internal */ | ||
_onConnOpen() { | ||
@@ -294,2 +304,3 @@ this.log('transport', `connected to ${this._endPointURL()}`); | ||
} | ||
/** @internal */ | ||
_onConnClose(event) { | ||
@@ -302,2 +313,3 @@ this.log('transport', 'close', event); | ||
} | ||
/** @internal */ | ||
_onConnError(error) { | ||
@@ -308,5 +320,7 @@ this.log('transport', error.message); | ||
} | ||
/** @internal */ | ||
_triggerChanError() { | ||
this.channels.forEach((channel) => channel._trigger(constants_1.CHANNEL_EVENTS.error)); | ||
} | ||
/** @internal */ | ||
_appendParams(url, params) { | ||
@@ -320,2 +334,3 @@ if (Object.keys(params).length === 0) { | ||
} | ||
/** @internal */ | ||
_flushSendBuffer() { | ||
@@ -327,2 +342,3 @@ if (this.isConnected() && this.sendBuffer.length > 0) { | ||
} | ||
/** @internal */ | ||
_sendHeartbeat() { | ||
@@ -348,2 +364,3 @@ var _a; | ||
} | ||
/** @internal */ | ||
_throttle(callback, eventsPerSecondLimit = this.eventsPerSecondLimitMs) { | ||
@@ -350,0 +367,0 @@ return () => { |
@@ -58,50 +58,4 @@ import { PresenceOpts, PresenceOnJoinCallback, PresenceOnLeaveCallback } from 'phoenix'; | ||
constructor(channel: RealtimeChannel, opts?: PresenceOpts); | ||
/** | ||
* Used to sync the list of presences on the server with the | ||
* client's state. | ||
* | ||
* An optional `onJoin` and `onLeave` callback can be provided to | ||
* react to changes in the client's local presences across | ||
* disconnects and reconnects with the server. | ||
*/ | ||
private static syncState; | ||
/** | ||
* Used to sync a diff of presence join and leave events from the | ||
* server, as they happen. | ||
* | ||
* Like `syncState`, `syncDiff` accepts optional `onJoin` and | ||
* `onLeave` callbacks to react to a user joining or leaving from a | ||
* device. | ||
*/ | ||
private static syncDiff; | ||
private static map; | ||
/** | ||
* Remove 'metas' key | ||
* Change 'phx_ref' to 'presence_ref' | ||
* Remove 'phx_ref' and 'phx_ref_prev' | ||
* | ||
* @example | ||
* // returns { | ||
* abc123: [ | ||
* { presence_ref: '2', user_id: 1 }, | ||
* { presence_ref: '3', user_id: 2 } | ||
* ] | ||
* } | ||
* RealtimePresence.transformState({ | ||
* abc123: { | ||
* metas: [ | ||
* { phx_ref: '2', phx_ref_prev: '1' user_id: 1 }, | ||
* { phx_ref: '3', user_id: 2 } | ||
* ] | ||
* } | ||
* }) | ||
*/ | ||
private static transformState; | ||
private static cloneDeep; | ||
private onJoin; | ||
private onLeave; | ||
private onSync; | ||
private inPendingSyncState; | ||
} | ||
export {}; | ||
//# sourceMappingURL=RealtimePresence.d.ts.map |
@@ -83,2 +83,4 @@ "use strict"; | ||
* disconnects and reconnects with the server. | ||
* | ||
* @internal | ||
*/ | ||
@@ -122,2 +124,4 @@ static syncState(currentState, newState, onJoin, onLeave) { | ||
* device. | ||
* | ||
* @internal | ||
*/ | ||
@@ -159,2 +163,3 @@ static syncDiff(state, diff, onJoin, onLeave) { | ||
} | ||
/** @internal */ | ||
static map(obj, func) { | ||
@@ -183,2 +188,4 @@ return Object.getOwnPropertyNames(obj).map((key) => func(key, obj[key])); | ||
* }) | ||
* | ||
* @internal | ||
*/ | ||
@@ -203,14 +210,19 @@ static transformState(state) { | ||
} | ||
/** @internal */ | ||
static cloneDeep(obj) { | ||
return JSON.parse(JSON.stringify(obj)); | ||
} | ||
/** @internal */ | ||
onJoin(callback) { | ||
this.caller.onJoin = callback; | ||
} | ||
/** @internal */ | ||
onLeave(callback) { | ||
this.caller.onLeave = callback; | ||
} | ||
/** @internal */ | ||
onSync(callback) { | ||
this.caller.onSync = callback; | ||
} | ||
/** @internal */ | ||
inPendingSyncState() { | ||
@@ -217,0 +229,0 @@ return !this.joinRef || this.joinRef !== this.channel._joinRef(); |
import RealtimeClient, { RealtimeClientOptions, RealtimeMessage, RealtimeRemoveChannelResponse } from './RealtimeClient'; | ||
import RealtimeChannel, { RealtimeChannelOptions, RealtimeChannelSendResponse, RealtimePostgresChangesPayload, REALTIME_LISTEN_TYPES, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_SUBSCRIBE_STATES } from './RealtimeChannel'; | ||
import RealtimeChannel, { RealtimeChannelOptions, RealtimeChannelSendResponse, RealtimePostgresChangesFilter, RealtimePostgresChangesPayload, RealtimePostgresInsertPayload, RealtimePostgresUpdatePayload, RealtimePostgresDeletePayload, REALTIME_LISTEN_TYPES, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_SUBSCRIBE_STATES } from './RealtimeChannel'; | ||
import RealtimePresence, { RealtimePresenceState, RealtimePresenceJoinPayload, RealtimePresenceLeavePayload, REALTIME_PRESENCE_LISTEN_EVENTS } from './RealtimePresence'; | ||
export { RealtimePresence, RealtimeChannel, RealtimeChannelOptions, RealtimeChannelSendResponse, RealtimeClient, RealtimeClientOptions, RealtimeMessage, RealtimePostgresChangesPayload, RealtimePresenceJoinPayload, RealtimePresenceLeavePayload, RealtimePresenceState, RealtimeRemoveChannelResponse, REALTIME_LISTEN_TYPES, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_PRESENCE_LISTEN_EVENTS, REALTIME_SUBSCRIBE_STATES, }; | ||
export { RealtimePresence, RealtimeChannel, RealtimeChannelOptions, RealtimeChannelSendResponse, RealtimeClient, RealtimeClientOptions, RealtimeMessage, RealtimePostgresChangesFilter, RealtimePostgresChangesPayload, RealtimePostgresInsertPayload, RealtimePostgresUpdatePayload, RealtimePostgresDeletePayload, RealtimePresenceJoinPayload, RealtimePresenceLeavePayload, RealtimePresenceState, RealtimeRemoveChannelResponse, REALTIME_LISTEN_TYPES, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_PRESENCE_LISTEN_EVENTS, REALTIME_SUBSCRIBE_STATES, }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export declare const version = "2.0.0"; | ||
export declare const version = "2.1.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export const version = '2.0.0'; | ||
export const version = '2.1.0'; | ||
//# sourceMappingURL=version.js.map |
@@ -24,13 +24,38 @@ import { CHANNEL_STATES } from './lib/constants'; | ||
}; | ||
export declare type RealtimePostgresChangesPayload<T extends { | ||
[key: string]: any; | ||
}> = { | ||
declare type RealtimePostgresChangesPayloadBase = { | ||
schema: string; | ||
table: string; | ||
commit_timestamp: string; | ||
eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}` | `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}` | `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}`; | ||
new: T | {}; | ||
old: Partial<T> | {}; | ||
errors: string[]; | ||
}; | ||
export declare type RealtimePostgresInsertPayload<T extends { | ||
[key: string]: any; | ||
}> = RealtimePostgresChangesPayloadBase & { | ||
eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}`; | ||
new: T; | ||
old: {}; | ||
}; | ||
export declare type RealtimePostgresUpdatePayload<T extends { | ||
[key: string]: any; | ||
}> = RealtimePostgresChangesPayloadBase & { | ||
eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}`; | ||
new: T; | ||
old: Partial<T>; | ||
}; | ||
export declare type RealtimePostgresDeletePayload<T extends { | ||
[key: string]: any; | ||
}> = RealtimePostgresChangesPayloadBase & { | ||
eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}`; | ||
new: {}; | ||
old: Partial<T>; | ||
}; | ||
export declare type RealtimePostgresChangesPayload<T extends { | ||
[key: string]: any; | ||
}> = RealtimePostgresInsertPayload<T> | RealtimePostgresUpdatePayload<T> | RealtimePostgresDeletePayload<T>; | ||
export declare type RealtimePostgresChangesFilter<T extends string> = { | ||
event: T; | ||
schema: string; | ||
table?: string; | ||
filter?: string; | ||
}; | ||
export declare type RealtimeChannelSendResponse = 'ok' | 'timed out' | 'rate limited'; | ||
@@ -54,3 +79,9 @@ export declare enum REALTIME_POSTGRES_CHANGES_LISTEN_EVENT { | ||
} | ||
/** A channel is the basic building block of Realtime | ||
* and narrows the scope of data flow to subscribed clients. | ||
* You can think of a channel as a chatroom where participants are able to see who's online | ||
* and send and receive messages. | ||
**/ | ||
export default class RealtimeChannel { | ||
/** Topic name can be any string. */ | ||
topic: string; | ||
@@ -76,3 +107,6 @@ params: RealtimeChannelOptions; | ||
presence: RealtimePresence; | ||
constructor(topic: string, params: RealtimeChannelOptions, socket: RealtimeClient); | ||
constructor( | ||
/** Topic name can be any string. */ | ||
topic: string, params: RealtimeChannelOptions, socket: RealtimeClient); | ||
/** Subscribe registers your client with the server */ | ||
subscribe(callback?: (status: `${REALTIME_SUBSCRIBE_STATES}`, err?: Error) => void, timeout?: number): RealtimeChannel; | ||
@@ -88,2 +122,3 @@ presenceState(): RealtimePresenceState; | ||
}): Promise<RealtimeChannelSendResponse>; | ||
/** Listen to messages. */ | ||
on(type: `${REALTIME_LISTEN_TYPES.BROADCAST}`, filter: { | ||
@@ -97,12 +132,22 @@ event: string; | ||
on(type: `${REALTIME_LISTEN_TYPES.PRESENCE}`, filter: { | ||
event: `${REALTIME_PRESENCE_LISTEN_EVENTS}`; | ||
}, callback: (payload: RealtimePresenceJoinPayload | RealtimePresenceLeavePayload | undefined) => void): RealtimeChannel; | ||
event: `${REALTIME_PRESENCE_LISTEN_EVENTS.SYNC}`; | ||
}, callback: () => void): RealtimeChannel; | ||
on(type: `${REALTIME_LISTEN_TYPES.PRESENCE}`, filter: { | ||
event: `${REALTIME_PRESENCE_LISTEN_EVENTS.JOIN}`; | ||
}, callback: (payload: RealtimePresenceJoinPayload) => void): RealtimeChannel; | ||
on(type: `${REALTIME_LISTEN_TYPES.PRESENCE}`, filter: { | ||
event: `${REALTIME_PRESENCE_LISTEN_EVENTS.LEAVE}`; | ||
}, callback: (payload: RealtimePresenceLeavePayload) => void): RealtimeChannel; | ||
on<T extends { | ||
[key: string]: any; | ||
}>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: { | ||
event: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT}`; | ||
schema: string; | ||
table?: string; | ||
filter?: string; | ||
}, callback: (payload: RealtimePostgresChangesPayload<T>) => void): RealtimeChannel; | ||
}>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.ALL}`>, callback: (payload: RealtimePostgresChangesPayload<T>) => void): RealtimeChannel; | ||
on<T extends { | ||
[key: string]: any; | ||
}>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}`>, callback: (payload: RealtimePostgresInsertPayload<T>) => void): RealtimeChannel; | ||
on<T extends { | ||
[key: string]: any; | ||
}>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}`>, callback: (payload: RealtimePostgresUpdatePayload<T>) => void): RealtimeChannel; | ||
on<T extends { | ||
[key: string]: any; | ||
}>(type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}`>, callback: (payload: RealtimePostgresDeletePayload<T>) => void): RealtimeChannel; | ||
send(payload: { | ||
@@ -127,43 +172,4 @@ type: string; | ||
unsubscribe(timeout?: number): Promise<'ok' | 'timed out' | 'error'>; | ||
_push(event: string, payload: { | ||
[key: string]: any; | ||
}, timeout?: number): Push; | ||
/** | ||
* Overridable message hook | ||
* | ||
* Receives all events for specialized message handling before dispatching to the channel callbacks. | ||
* Must return the payload, modified or unmodified. | ||
*/ | ||
_onMessage(_event: string, payload: any, _ref?: string): any; | ||
_isMember(topic: string): boolean; | ||
_joinRef(): string; | ||
_trigger(type: string, payload?: any, ref?: string): void; | ||
_isClosed(): boolean; | ||
_isJoined(): boolean; | ||
_isJoining(): boolean; | ||
_isLeaving(): boolean; | ||
_replyEventName(ref: string): string; | ||
_on(type: string, filter: { | ||
[key: string]: any; | ||
}, callback: Function): this; | ||
_off(type: string, filter: { | ||
[key: string]: any; | ||
}): this; | ||
private static isEqual; | ||
private _rejoinUntilConnected; | ||
/** | ||
* Registers a callback that will be executed when the channel closes. | ||
*/ | ||
private _onClose; | ||
/** | ||
* Registers a callback that will be executed when the channel encounteres an error. | ||
*/ | ||
private _onError; | ||
/** | ||
* Returns `true` if the socket is connected and the channel has been joined. | ||
*/ | ||
private _canPush; | ||
private _rejoin; | ||
private _getPayloadRecords; | ||
} | ||
export {}; | ||
//# sourceMappingURL=RealtimeChannel.d.ts.map |
@@ -35,4 +35,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
})(REALTIME_SUBSCRIBE_STATES || (REALTIME_SUBSCRIBE_STATES = {})); | ||
/** A channel is the basic building block of Realtime | ||
* and narrows the scope of data flow to subscribed clients. | ||
* You can think of a channel as a chatroom where participants are able to see who's online | ||
* and send and receive messages. | ||
**/ | ||
export default class RealtimeChannel { | ||
constructor(topic, params = { config: {} }, socket) { | ||
constructor( | ||
/** Topic name can be any string. */ | ||
topic, params = { config: {} }, socket) { | ||
this.topic = topic; | ||
@@ -85,2 +92,3 @@ this.params = params; | ||
} | ||
/** Subscribe registers your client with the server */ | ||
subscribe(callback, timeout = this.timeout) { | ||
@@ -234,2 +242,3 @@ var _a, _b; | ||
} | ||
/** @internal */ | ||
_push(event, payload, timeout = this.timeout) { | ||
@@ -254,2 +263,4 @@ if (!this.joinedOnce) { | ||
* Must return the payload, modified or unmodified. | ||
* | ||
* @internal | ||
*/ | ||
@@ -259,8 +270,11 @@ _onMessage(_event, payload, _ref) { | ||
} | ||
/** @internal */ | ||
_isMember(topic) { | ||
return this.topic === topic; | ||
} | ||
/** @internal */ | ||
_joinRef() { | ||
return this.joinPush.ref; | ||
} | ||
/** @internal */ | ||
_trigger(type, payload, ref) { | ||
@@ -326,17 +340,23 @@ var _a, _b; | ||
} | ||
/** @internal */ | ||
_isClosed() { | ||
return this.state === CHANNEL_STATES.closed; | ||
} | ||
/** @internal */ | ||
_isJoined() { | ||
return this.state === CHANNEL_STATES.joined; | ||
} | ||
/** @internal */ | ||
_isJoining() { | ||
return this.state === CHANNEL_STATES.joining; | ||
} | ||
/** @internal */ | ||
_isLeaving() { | ||
return this.state === CHANNEL_STATES.leaving; | ||
} | ||
/** @internal */ | ||
_replyEventName(ref) { | ||
return `chan_reply_${ref}`; | ||
} | ||
/** @internal */ | ||
_on(type, filter, callback) { | ||
@@ -357,2 +377,3 @@ const typeLower = type.toLocaleLowerCase(); | ||
} | ||
/** @internal */ | ||
_off(type, filter) { | ||
@@ -367,2 +388,3 @@ const typeLower = type.toLocaleLowerCase(); | ||
} | ||
/** @internal */ | ||
static isEqual(obj1, obj2) { | ||
@@ -379,2 +401,3 @@ if (Object.keys(obj1).length !== Object.keys(obj2).length) { | ||
} | ||
/** @internal */ | ||
_rejoinUntilConnected() { | ||
@@ -388,2 +411,4 @@ this.rejoinTimer.scheduleTimeout(); | ||
* Registers a callback that will be executed when the channel closes. | ||
* | ||
* @internal | ||
*/ | ||
@@ -395,2 +420,4 @@ _onClose(callback) { | ||
* Registers a callback that will be executed when the channel encounteres an error. | ||
* | ||
* @internal | ||
*/ | ||
@@ -402,2 +429,4 @@ _onError(callback) { | ||
* Returns `true` if the socket is connected and the channel has been joined. | ||
* | ||
* @internal | ||
*/ | ||
@@ -407,2 +436,3 @@ _canPush() { | ||
} | ||
/** @internal */ | ||
_rejoin(timeout = this.timeout) { | ||
@@ -416,2 +446,3 @@ if (this._isLeaving()) { | ||
} | ||
/** @internal */ | ||
_getPayloadRecords(payload) { | ||
@@ -418,0 +449,0 @@ const records = { |
@@ -116,30 +116,3 @@ import { CONNECTION_STATE } from './lib/constants'; | ||
setAuth(token: string | null): void; | ||
/** | ||
* Return the next message ref, accounting for overflows | ||
*/ | ||
_makeRef(): string; | ||
/** | ||
* Unsubscribe from channels with the specified topic. | ||
*/ | ||
_leaveOpenTopic(topic: string): void; | ||
/** | ||
* Removes a subscription from the socket. | ||
* | ||
* @param channel An open subscription. | ||
*/ | ||
_remove(channel: RealtimeChannel): void; | ||
/** | ||
* Returns the URL of the websocket. | ||
*/ | ||
private _endPointURL; | ||
private _onConnMessage; | ||
private _onConnOpen; | ||
private _onConnClose; | ||
private _onConnError; | ||
private _triggerChanError; | ||
private _appendParams; | ||
private _flushSendBuffer; | ||
private _sendHeartbeat; | ||
private _throttle; | ||
} | ||
//# sourceMappingURL=RealtimeClient.d.ts.map |
@@ -226,2 +226,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
* Return the next message ref, accounting for overflows | ||
* | ||
* @internal | ||
*/ | ||
@@ -240,2 +242,4 @@ _makeRef() { | ||
* Unsubscribe from channels with the specified topic. | ||
* | ||
* @internal | ||
*/ | ||
@@ -253,2 +257,4 @@ _leaveOpenTopic(topic) { | ||
* @param channel An open subscription. | ||
* | ||
* @internal | ||
*/ | ||
@@ -260,2 +266,4 @@ _remove(channel) { | ||
* Returns the URL of the websocket. | ||
* | ||
* @internal | ||
*/ | ||
@@ -265,2 +273,3 @@ _endPointURL() { | ||
} | ||
/** @internal */ | ||
_onConnMessage(rawMessage) { | ||
@@ -280,2 +289,3 @@ this.decode(rawMessage.data, (msg) => { | ||
} | ||
/** @internal */ | ||
_onConnOpen() { | ||
@@ -289,2 +299,3 @@ this.log('transport', `connected to ${this._endPointURL()}`); | ||
} | ||
/** @internal */ | ||
_onConnClose(event) { | ||
@@ -297,2 +308,3 @@ this.log('transport', 'close', event); | ||
} | ||
/** @internal */ | ||
_onConnError(error) { | ||
@@ -303,5 +315,7 @@ this.log('transport', error.message); | ||
} | ||
/** @internal */ | ||
_triggerChanError() { | ||
this.channels.forEach((channel) => channel._trigger(CHANNEL_EVENTS.error)); | ||
} | ||
/** @internal */ | ||
_appendParams(url, params) { | ||
@@ -315,2 +329,3 @@ if (Object.keys(params).length === 0) { | ||
} | ||
/** @internal */ | ||
_flushSendBuffer() { | ||
@@ -322,2 +337,3 @@ if (this.isConnected() && this.sendBuffer.length > 0) { | ||
} | ||
/** @internal */ | ||
_sendHeartbeat() { | ||
@@ -343,2 +359,3 @@ var _a; | ||
} | ||
/** @internal */ | ||
_throttle(callback, eventsPerSecondLimit = this.eventsPerSecondLimitMs) { | ||
@@ -345,0 +362,0 @@ return () => { |
@@ -58,50 +58,4 @@ import { PresenceOpts, PresenceOnJoinCallback, PresenceOnLeaveCallback } from 'phoenix'; | ||
constructor(channel: RealtimeChannel, opts?: PresenceOpts); | ||
/** | ||
* Used to sync the list of presences on the server with the | ||
* client's state. | ||
* | ||
* An optional `onJoin` and `onLeave` callback can be provided to | ||
* react to changes in the client's local presences across | ||
* disconnects and reconnects with the server. | ||
*/ | ||
private static syncState; | ||
/** | ||
* Used to sync a diff of presence join and leave events from the | ||
* server, as they happen. | ||
* | ||
* Like `syncState`, `syncDiff` accepts optional `onJoin` and | ||
* `onLeave` callbacks to react to a user joining or leaving from a | ||
* device. | ||
*/ | ||
private static syncDiff; | ||
private static map; | ||
/** | ||
* Remove 'metas' key | ||
* Change 'phx_ref' to 'presence_ref' | ||
* Remove 'phx_ref' and 'phx_ref_prev' | ||
* | ||
* @example | ||
* // returns { | ||
* abc123: [ | ||
* { presence_ref: '2', user_id: 1 }, | ||
* { presence_ref: '3', user_id: 2 } | ||
* ] | ||
* } | ||
* RealtimePresence.transformState({ | ||
* abc123: { | ||
* metas: [ | ||
* { phx_ref: '2', phx_ref_prev: '1' user_id: 1 }, | ||
* { phx_ref: '3', user_id: 2 } | ||
* ] | ||
* } | ||
* }) | ||
*/ | ||
private static transformState; | ||
private static cloneDeep; | ||
private onJoin; | ||
private onLeave; | ||
private onSync; | ||
private inPendingSyncState; | ||
} | ||
export {}; | ||
//# sourceMappingURL=RealtimePresence.d.ts.map |
@@ -80,2 +80,4 @@ /* | ||
* disconnects and reconnects with the server. | ||
* | ||
* @internal | ||
*/ | ||
@@ -119,2 +121,4 @@ static syncState(currentState, newState, onJoin, onLeave) { | ||
* device. | ||
* | ||
* @internal | ||
*/ | ||
@@ -156,2 +160,3 @@ static syncDiff(state, diff, onJoin, onLeave) { | ||
} | ||
/** @internal */ | ||
static map(obj, func) { | ||
@@ -180,2 +185,4 @@ return Object.getOwnPropertyNames(obj).map((key) => func(key, obj[key])); | ||
* }) | ||
* | ||
* @internal | ||
*/ | ||
@@ -200,14 +207,19 @@ static transformState(state) { | ||
} | ||
/** @internal */ | ||
static cloneDeep(obj) { | ||
return JSON.parse(JSON.stringify(obj)); | ||
} | ||
/** @internal */ | ||
onJoin(callback) { | ||
this.caller.onJoin = callback; | ||
} | ||
/** @internal */ | ||
onLeave(callback) { | ||
this.caller.onLeave = callback; | ||
} | ||
/** @internal */ | ||
onSync(callback) { | ||
this.caller.onSync = callback; | ||
} | ||
/** @internal */ | ||
inPendingSyncState() { | ||
@@ -214,0 +226,0 @@ return !this.joinRef || this.joinRef !== this.channel._joinRef(); |
{ | ||
"name": "@supabase/realtime-js", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Listen to realtime updates to your PostgreSQL database", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -9,3 +9,7 @@ import RealtimeClient, { | ||
RealtimeChannelSendResponse, | ||
RealtimePostgresChangesFilter, | ||
RealtimePostgresChangesPayload, | ||
RealtimePostgresInsertPayload, | ||
RealtimePostgresUpdatePayload, | ||
RealtimePostgresDeletePayload, | ||
REALTIME_LISTEN_TYPES, | ||
@@ -30,3 +34,7 @@ REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, | ||
RealtimeMessage, | ||
RealtimePostgresChangesFilter, | ||
RealtimePostgresChangesPayload, | ||
RealtimePostgresInsertPayload, | ||
RealtimePostgresUpdatePayload, | ||
RealtimePostgresDeletePayload, | ||
RealtimePresenceJoinPayload, | ||
@@ -33,0 +41,0 @@ RealtimePresenceLeavePayload, |
@@ -1,1 +0,1 @@ | ||
export const version = '2.0.0' | ||
export const version = '2.1.0' |
@@ -27,15 +27,42 @@ import { CHANNEL_EVENTS, CHANNEL_STATES } from './lib/constants' | ||
export type RealtimePostgresChangesPayload<T extends { [key: string]: any }> = { | ||
type RealtimePostgresChangesPayloadBase = { | ||
schema: string | ||
table: string | ||
commit_timestamp: string | ||
eventType: | ||
| `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}` | ||
| `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}` | ||
| `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}` | ||
new: T | {} | ||
old: Partial<T> | {} | ||
errors: string[] | ||
} | ||
export type RealtimePostgresInsertPayload<T extends { [key: string]: any }> = | ||
RealtimePostgresChangesPayloadBase & { | ||
eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}` | ||
new: T | ||
old: {} | ||
} | ||
export type RealtimePostgresUpdatePayload<T extends { [key: string]: any }> = | ||
RealtimePostgresChangesPayloadBase & { | ||
eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}` | ||
new: T | ||
old: Partial<T> | ||
} | ||
export type RealtimePostgresDeletePayload<T extends { [key: string]: any }> = | ||
RealtimePostgresChangesPayloadBase & { | ||
eventType: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}` | ||
new: {} | ||
old: Partial<T> | ||
} | ||
export type RealtimePostgresChangesPayload<T extends { [key: string]: any }> = | ||
| RealtimePostgresInsertPayload<T> | ||
| RealtimePostgresUpdatePayload<T> | ||
| RealtimePostgresDeletePayload<T> | ||
export type RealtimePostgresChangesFilter<T extends string> = { | ||
event: T | ||
schema: string | ||
table?: string | ||
filter?: string | ||
} | ||
export type RealtimeChannelSendResponse = 'ok' | 'timed out' | 'rate limited' | ||
@@ -63,2 +90,7 @@ | ||
/** A channel is the basic building block of Realtime | ||
* and narrows the scope of data flow to subscribed clients. | ||
* You can think of a channel as a chatroom where participants are able to see who's online | ||
* and send and receive messages. | ||
**/ | ||
export default class RealtimeChannel { | ||
@@ -82,2 +114,3 @@ bindings: { | ||
constructor( | ||
/** Topic name can be any string. */ | ||
public topic: string, | ||
@@ -140,2 +173,3 @@ public params: RealtimeChannelOptions = { config: {} }, | ||
/** Subscribe registers your client with the server */ | ||
subscribe( | ||
@@ -284,2 +318,3 @@ callback?: (status: `${REALTIME_SUBSCRIBE_STATES}`, err?: Error) => void, | ||
/** Listen to messages. */ | ||
on( | ||
@@ -296,20 +331,35 @@ type: `${REALTIME_LISTEN_TYPES.BROADCAST}`, | ||
type: `${REALTIME_LISTEN_TYPES.PRESENCE}`, | ||
filter: { event: `${REALTIME_PRESENCE_LISTEN_EVENTS}` }, | ||
callback: ( | ||
payload: | ||
| RealtimePresenceJoinPayload | ||
| RealtimePresenceLeavePayload | ||
| undefined | ||
) => void | ||
filter: { event: `${REALTIME_PRESENCE_LISTEN_EVENTS.SYNC}` }, | ||
callback: () => void | ||
): RealtimeChannel | ||
on( | ||
type: `${REALTIME_LISTEN_TYPES.PRESENCE}`, | ||
filter: { event: `${REALTIME_PRESENCE_LISTEN_EVENTS.JOIN}` }, | ||
callback: (payload: RealtimePresenceJoinPayload) => void | ||
): RealtimeChannel | ||
on( | ||
type: `${REALTIME_LISTEN_TYPES.PRESENCE}`, | ||
filter: { event: `${REALTIME_PRESENCE_LISTEN_EVENTS.LEAVE}` }, | ||
callback: (payload: RealtimePresenceLeavePayload) => void | ||
): RealtimeChannel | ||
on<T extends { [key: string]: any }>( | ||
type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, | ||
filter: { | ||
event: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT}` | ||
schema: string | ||
table?: string | ||
filter?: string | ||
}, | ||
filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.ALL}`>, | ||
callback: (payload: RealtimePostgresChangesPayload<T>) => void | ||
): RealtimeChannel | ||
on<T extends { [key: string]: any }>( | ||
type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, | ||
filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}`>, | ||
callback: (payload: RealtimePostgresInsertPayload<T>) => void | ||
): RealtimeChannel | ||
on<T extends { [key: string]: any }>( | ||
type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, | ||
filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}`>, | ||
callback: (payload: RealtimePostgresUpdatePayload<T>) => void | ||
): RealtimeChannel | ||
on<T extends { [key: string]: any }>( | ||
type: `${REALTIME_LISTEN_TYPES.POSTGRES_CHANGES}`, | ||
filter: RealtimePostgresChangesFilter<`${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}`>, | ||
callback: (payload: RealtimePostgresDeletePayload<T>) => void | ||
): RealtimeChannel | ||
on( | ||
@@ -398,2 +448,3 @@ type: `${REALTIME_LISTEN_TYPES}`, | ||
/** @internal */ | ||
_push( | ||
@@ -423,2 +474,4 @@ event: string, | ||
* Must return the payload, modified or unmodified. | ||
* | ||
* @internal | ||
*/ | ||
@@ -429,2 +482,3 @@ _onMessage(_event: string, payload: any, _ref?: string) { | ||
/** @internal */ | ||
_isMember(topic: string): boolean { | ||
@@ -434,2 +488,3 @@ return this.topic === topic | ||
/** @internal */ | ||
_joinRef(): string { | ||
@@ -439,2 +494,3 @@ return this.joinPush.ref | ||
/** @internal */ | ||
_trigger(type: string, payload?: any, ref?: string) { | ||
@@ -512,11 +568,18 @@ const typeLower = type.toLocaleLowerCase() | ||
/** @internal */ | ||
_isClosed(): boolean { | ||
return this.state === CHANNEL_STATES.closed | ||
} | ||
/** @internal */ | ||
_isJoined(): boolean { | ||
return this.state === CHANNEL_STATES.joined | ||
} | ||
/** @internal */ | ||
_isJoining(): boolean { | ||
return this.state === CHANNEL_STATES.joining | ||
} | ||
/** @internal */ | ||
_isLeaving(): boolean { | ||
@@ -526,2 +589,3 @@ return this.state === CHANNEL_STATES.leaving | ||
/** @internal */ | ||
_replyEventName(ref: string): string { | ||
@@ -531,2 +595,3 @@ return `chan_reply_${ref}` | ||
/** @internal */ | ||
_on(type: string, filter: { [key: string]: any }, callback: Function) { | ||
@@ -550,2 +615,3 @@ const typeLower = type.toLocaleLowerCase() | ||
/** @internal */ | ||
_off(type: string, filter: { [key: string]: any }) { | ||
@@ -563,2 +629,3 @@ const typeLower = type.toLocaleLowerCase() | ||
/** @internal */ | ||
private static isEqual( | ||
@@ -581,2 +648,3 @@ obj1: { [key: string]: string }, | ||
/** @internal */ | ||
private _rejoinUntilConnected() { | ||
@@ -591,2 +659,4 @@ this.rejoinTimer.scheduleTimeout() | ||
* Registers a callback that will be executed when the channel closes. | ||
* | ||
* @internal | ||
*/ | ||
@@ -599,2 +669,4 @@ private _onClose(callback: Function) { | ||
* Registers a callback that will be executed when the channel encounteres an error. | ||
* | ||
* @internal | ||
*/ | ||
@@ -607,2 +679,4 @@ private _onError(callback: Function) { | ||
* Returns `true` if the socket is connected and the channel has been joined. | ||
* | ||
* @internal | ||
*/ | ||
@@ -613,2 +687,3 @@ private _canPush(): boolean { | ||
/** @internal */ | ||
private _rejoin(timeout = this.timeout): void { | ||
@@ -623,2 +698,3 @@ if (this._isLeaving()) { | ||
/** @internal */ | ||
private _getPayloadRecords(payload: any) { | ||
@@ -625,0 +701,0 @@ const records = { |
@@ -277,2 +277,4 @@ import { w3cwebsocket } from 'websocket' | ||
* Return the next message ref, accounting for overflows | ||
* | ||
* @internal | ||
*/ | ||
@@ -292,2 +294,4 @@ _makeRef(): string { | ||
* Unsubscribe from channels with the specified topic. | ||
* | ||
* @internal | ||
*/ | ||
@@ -308,2 +312,4 @@ _leaveOpenTopic(topic: string): void { | ||
* @param channel An open subscription. | ||
* | ||
* @internal | ||
*/ | ||
@@ -318,2 +324,4 @@ _remove(channel: RealtimeChannel) { | ||
* Returns the URL of the websocket. | ||
* | ||
* @internal | ||
*/ | ||
@@ -327,2 +335,3 @@ private _endPointURL(): string { | ||
/** @internal */ | ||
private _onConnMessage(rawMessage: { data: any }) { | ||
@@ -355,2 +364,3 @@ this.decode(rawMessage.data, (msg: RealtimeMessage) => { | ||
/** @internal */ | ||
private _onConnOpen() { | ||
@@ -368,2 +378,3 @@ this.log('transport', `connected to ${this._endPointURL()}`) | ||
/** @internal */ | ||
private _onConnClose(event: any) { | ||
@@ -377,2 +388,3 @@ this.log('transport', 'close', event) | ||
/** @internal */ | ||
private _onConnError(error: ErrorEvent) { | ||
@@ -384,2 +396,3 @@ this.log('transport', error.message) | ||
/** @internal */ | ||
private _triggerChanError() { | ||
@@ -391,2 +404,3 @@ this.channels.forEach((channel: RealtimeChannel) => | ||
/** @internal */ | ||
private _appendParams( | ||
@@ -405,2 +419,3 @@ url: string, | ||
/** @internal */ | ||
private _flushSendBuffer() { | ||
@@ -412,3 +427,3 @@ if (this.isConnected() && this.sendBuffer.length > 0) { | ||
} | ||
/** @internal */ | ||
private _sendHeartbeat() { | ||
@@ -437,2 +452,3 @@ if (!this.isConnected()) { | ||
/** @internal */ | ||
private _throttle( | ||
@@ -439,0 +455,0 @@ callback: Function, |
@@ -162,2 +162,4 @@ /* | ||
* disconnects and reconnects with the server. | ||
* | ||
* @internal | ||
*/ | ||
@@ -220,2 +222,4 @@ private static syncState( | ||
* device. | ||
* | ||
* @internal | ||
*/ | ||
@@ -281,2 +285,3 @@ private static syncDiff( | ||
/** @internal */ | ||
private static map<T = any>( | ||
@@ -309,2 +314,4 @@ obj: RealtimePresenceState, | ||
* }) | ||
* | ||
* @internal | ||
*/ | ||
@@ -336,2 +343,3 @@ private static transformState( | ||
/** @internal */ | ||
private static cloneDeep(obj: { [key: string]: any }) { | ||
@@ -341,2 +349,3 @@ return JSON.parse(JSON.stringify(obj)) | ||
/** @internal */ | ||
private onJoin(callback: PresenceOnJoinCallback): void { | ||
@@ -346,2 +355,3 @@ this.caller.onJoin = callback | ||
/** @internal */ | ||
private onLeave(callback: PresenceOnLeaveCallback): void { | ||
@@ -351,2 +361,3 @@ this.caller.onLeave = callback | ||
/** @internal */ | ||
private onSync(callback: () => void): void { | ||
@@ -356,2 +367,3 @@ this.caller.onSync = callback | ||
/** @internal */ | ||
private inPendingSyncState(): boolean { | ||
@@ -358,0 +370,0 @@ return !this.joinRef || this.joinRef !== this.channel._joinRef() |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
338125
5996