@supabase/realtime-js
Advanced tools
Comparing version
@@ -48,11 +48,10 @@ "use strict"; | ||
*/ | ||
const convertChangeData = (columns, record, options = {}) => { | ||
exports.convertChangeData = (columns, record, options = {}) => { | ||
var _a; | ||
const skipTypes = (_a = options.skipTypes) !== null && _a !== void 0 ? _a : []; | ||
return Object.keys(record).reduce((acc, rec_key) => { | ||
acc[rec_key] = (0, exports.convertColumn)(rec_key, columns, record, skipTypes); | ||
acc[rec_key] = exports.convertColumn(rec_key, columns, record, skipTypes); | ||
return acc; | ||
}, {}); | ||
}; | ||
exports.convertChangeData = convertChangeData; | ||
/** | ||
@@ -72,3 +71,3 @@ * Converts the value of an individual column. | ||
*/ | ||
const convertColumn = (columnName, columns, record, skipTypes) => { | ||
exports.convertColumn = (columnName, columns, record, skipTypes) => { | ||
const column = columns.find((x) => x.name === columnName); | ||
@@ -78,7 +77,6 @@ const colType = column === null || column === void 0 ? void 0 : column.type; | ||
if (colType && !skipTypes.includes(colType)) { | ||
return (0, exports.convertCell)(colType, value); | ||
return exports.convertCell(colType, value); | ||
} | ||
return noop(value); | ||
}; | ||
exports.convertColumn = convertColumn; | ||
/** | ||
@@ -97,7 +95,7 @@ * If the value of the cell is `null`, returns null. | ||
*/ | ||
const convertCell = (type, value) => { | ||
exports.convertCell = (type, value) => { | ||
// if data type is an array | ||
if (type.charAt(0) === '_') { | ||
const dataType = type.slice(1, type.length); | ||
return (0, exports.toArray)(value, dataType); | ||
return exports.toArray(value, dataType); | ||
} | ||
@@ -107,3 +105,3 @@ // If not null, convert to correct type. | ||
case PostgresTypes.bool: | ||
return (0, exports.toBoolean)(value); | ||
return exports.toBoolean(value); | ||
case PostgresTypes.float4: | ||
@@ -116,8 +114,8 @@ case PostgresTypes.float8: | ||
case PostgresTypes.oid: | ||
return (0, exports.toNumber)(value); | ||
return exports.toNumber(value); | ||
case PostgresTypes.json: | ||
case PostgresTypes.jsonb: | ||
return (0, exports.toJson)(value); | ||
return exports.toJson(value); | ||
case PostgresTypes.timestamp: | ||
return (0, exports.toTimestampString)(value); // Format to be consistent with PostgREST | ||
return exports.toTimestampString(value); // Format to be consistent with PostgREST | ||
case PostgresTypes.abstime: // To allow users to cast it based on Timezone | ||
@@ -142,7 +140,6 @@ case PostgresTypes.date: // To allow users to cast it based on Timezone | ||
}; | ||
exports.convertCell = convertCell; | ||
const noop = (value) => { | ||
return value; | ||
}; | ||
const toBoolean = (value) => { | ||
exports.toBoolean = (value) => { | ||
switch (value) { | ||
@@ -157,4 +154,3 @@ case 't': | ||
}; | ||
exports.toBoolean = toBoolean; | ||
const toNumber = (value) => { | ||
exports.toNumber = (value) => { | ||
if (typeof value === 'string') { | ||
@@ -168,4 +164,3 @@ const parsedValue = parseFloat(value); | ||
}; | ||
exports.toNumber = toNumber; | ||
const toJson = (value) => { | ||
exports.toJson = (value) => { | ||
if (typeof value === 'string') { | ||
@@ -182,3 +177,2 @@ try { | ||
}; | ||
exports.toJson = toJson; | ||
/** | ||
@@ -194,3 +188,3 @@ * Converts a Postgres Array into a native JS array | ||
*/ | ||
const toArray = (value, type) => { | ||
exports.toArray = (value, type) => { | ||
if (typeof value !== 'string') { | ||
@@ -214,7 +208,6 @@ return value; | ||
} | ||
return arr.map((val) => (0, exports.convertCell)(type, val)); | ||
return arr.map((val) => exports.convertCell(type, val)); | ||
} | ||
return value; | ||
}; | ||
exports.toArray = toArray; | ||
/** | ||
@@ -227,3 +220,3 @@ * Fixes timestamp to be ISO-8601. Swaps the space between the date and time for a 'T' | ||
*/ | ||
const toTimestampString = (value) => { | ||
exports.toTimestampString = (value) => { | ||
if (typeof value === 'string') { | ||
@@ -234,3 +227,2 @@ return value.replace(' ', 'T'); | ||
}; | ||
exports.toTimestampString = toTimestampString; | ||
//# sourceMappingURL=transformers.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const version = "1.3.5"; | ||
export declare const version = "1.3.6"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
// generated by genversion | ||
exports.version = '1.3.5'; | ||
exports.version = '1.3.6'; | ||
//# sourceMappingURL=version.js.map |
@@ -127,3 +127,3 @@ import Timer from './lib/timer'; | ||
*/ | ||
connectionState(): "closed" | "connecting" | "open" | "closing"; | ||
connectionState(): "closed" | "open" | "closing" | "connecting"; | ||
/** | ||
@@ -163,3 +163,2 @@ * Retuns `true` is the connection is open. | ||
private _flushSendBuffer; | ||
private _resetHeartbeat; | ||
private _sendHeartbeat; | ||
@@ -166,0 +165,0 @@ } |
@@ -75,14 +75,11 @@ "use strict"; | ||
this.longpollerTimeout = options.longpollerTimeout; | ||
this.reconnectAfterMs = (options === null || options === void 0 ? void 0 : options.reconnectAfterMs) | ||
? options.reconnectAfterMs | ||
this.reconnectAfterMs = (options === null || options === void 0 ? void 0 : options.reconnectAfterMs) ? options.reconnectAfterMs | ||
: (tries) => { | ||
return [1000, 2000, 5000, 10000][tries - 1] || 10000; | ||
}; | ||
this.encode = (options === null || options === void 0 ? void 0 : options.encode) | ||
? options.encode | ||
this.encode = (options === null || options === void 0 ? void 0 : options.encode) ? options.encode | ||
: (payload, callback) => { | ||
return callback(JSON.stringify(payload)); | ||
}; | ||
this.decode = (options === null || options === void 0 ? void 0 : options.decode) | ||
? options.decode | ||
this.decode = (options === null || options === void 0 ? void 0 : options.decode) ? options.decode | ||
: this.serializer.decode.bind(this.serializer); | ||
@@ -239,8 +236,6 @@ this.reconnectTimer = new timer_1.default(() => __awaiter(this, void 0, void 0, function* () { | ||
let { topic, event, payload, ref } = msg; | ||
if (ref && ref === this.pendingHeartbeatRef) { | ||
if ((ref && ref === this.pendingHeartbeatRef) || | ||
event === (payload === null || payload === void 0 ? void 0 : payload.type)) { | ||
this.pendingHeartbeatRef = null; | ||
} | ||
else if (event === (payload === null || payload === void 0 ? void 0 : payload.type)) { | ||
this._resetHeartbeat(); | ||
} | ||
this.log('receive', `${payload.status || ''} ${topic} ${event} ${(ref && '(' + ref + ')') || ''}`, payload); | ||
@@ -302,3 +297,4 @@ this.channels | ||
this.reconnectTimer.reset(); | ||
this._resetHeartbeat(); | ||
this.heartbeatTimer && clearInterval(this.heartbeatTimer); | ||
this.heartbeatTimer = setInterval(() => this._sendHeartbeat(), this.heartbeatIntervalMs); | ||
this.stateChangeCallbacks.open.forEach((callback) => callback()); | ||
@@ -335,7 +331,2 @@ } | ||
} | ||
_resetHeartbeat() { | ||
this.pendingHeartbeatRef = null; | ||
this.heartbeatTimer && clearInterval(this.heartbeatTimer); | ||
this.heartbeatTimer = setInterval(() => this._sendHeartbeat(), this.heartbeatIntervalMs); | ||
} | ||
_sendHeartbeat() { | ||
@@ -342,0 +333,0 @@ var _a; |
@@ -1,2 +0,2 @@ | ||
export declare const version = "1.3.5"; | ||
export declare const version = "1.3.6"; | ||
//# sourceMappingURL=version.d.ts.map |
// generated by genversion | ||
export const version = '1.3.5'; | ||
export const version = '1.3.6'; | ||
//# sourceMappingURL=version.js.map |
@@ -127,3 +127,3 @@ import Timer from './lib/timer'; | ||
*/ | ||
connectionState(): "closed" | "connecting" | "open" | "closing"; | ||
connectionState(): "closed" | "open" | "closing" | "connecting"; | ||
/** | ||
@@ -163,3 +163,2 @@ * Retuns `true` is the connection is open. | ||
private _flushSendBuffer; | ||
private _resetHeartbeat; | ||
private _sendHeartbeat; | ||
@@ -166,0 +165,0 @@ } |
@@ -70,14 +70,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
this.longpollerTimeout = options.longpollerTimeout; | ||
this.reconnectAfterMs = (options === null || options === void 0 ? void 0 : options.reconnectAfterMs) | ||
? options.reconnectAfterMs | ||
this.reconnectAfterMs = (options === null || options === void 0 ? void 0 : options.reconnectAfterMs) ? options.reconnectAfterMs | ||
: (tries) => { | ||
return [1000, 2000, 5000, 10000][tries - 1] || 10000; | ||
}; | ||
this.encode = (options === null || options === void 0 ? void 0 : options.encode) | ||
? options.encode | ||
this.encode = (options === null || options === void 0 ? void 0 : options.encode) ? options.encode | ||
: (payload, callback) => { | ||
return callback(JSON.stringify(payload)); | ||
}; | ||
this.decode = (options === null || options === void 0 ? void 0 : options.decode) | ||
? options.decode | ||
this.decode = (options === null || options === void 0 ? void 0 : options.decode) ? options.decode | ||
: this.serializer.decode.bind(this.serializer); | ||
@@ -234,8 +231,6 @@ this.reconnectTimer = new Timer(() => __awaiter(this, void 0, void 0, function* () { | ||
let { topic, event, payload, ref } = msg; | ||
if (ref && ref === this.pendingHeartbeatRef) { | ||
if ((ref && ref === this.pendingHeartbeatRef) || | ||
event === (payload === null || payload === void 0 ? void 0 : payload.type)) { | ||
this.pendingHeartbeatRef = null; | ||
} | ||
else if (event === (payload === null || payload === void 0 ? void 0 : payload.type)) { | ||
this._resetHeartbeat(); | ||
} | ||
this.log('receive', `${payload.status || ''} ${topic} ${event} ${(ref && '(' + ref + ')') || ''}`, payload); | ||
@@ -297,3 +292,4 @@ this.channels | ||
this.reconnectTimer.reset(); | ||
this._resetHeartbeat(); | ||
this.heartbeatTimer && clearInterval(this.heartbeatTimer); | ||
this.heartbeatTimer = setInterval(() => this._sendHeartbeat(), this.heartbeatIntervalMs); | ||
this.stateChangeCallbacks.open.forEach((callback) => callback()); | ||
@@ -330,7 +326,2 @@ } | ||
} | ||
_resetHeartbeat() { | ||
this.pendingHeartbeatRef = null; | ||
this.heartbeatTimer && clearInterval(this.heartbeatTimer); | ||
this.heartbeatTimer = setInterval(() => this._sendHeartbeat(), this.heartbeatIntervalMs); | ||
} | ||
_sendHeartbeat() { | ||
@@ -337,0 +328,0 @@ var _a; |
{ | ||
"name": "@supabase/realtime-js", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"description": "Listen to realtime updates to your PostgreSQL database", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
// generated by genversion | ||
export const version = '1.3.5' | ||
export const version = '1.3.6' |
@@ -275,6 +275,8 @@ import { | ||
let { topic, event, payload, ref } = msg | ||
if (ref && ref === this.pendingHeartbeatRef) { | ||
if ( | ||
(ref && ref === this.pendingHeartbeatRef) || | ||
event === payload?.type | ||
) { | ||
this.pendingHeartbeatRef = null | ||
} else if (event === payload?.type) { | ||
this._resetHeartbeat() | ||
} | ||
@@ -357,3 +359,7 @@ | ||
this.reconnectTimer.reset() | ||
this._resetHeartbeat() | ||
this.heartbeatTimer && clearInterval(this.heartbeatTimer) | ||
this.heartbeatTimer = setInterval( | ||
() => this._sendHeartbeat(), | ||
this.heartbeatIntervalMs | ||
) | ||
this.stateChangeCallbacks.open.forEach((callback) => callback())! | ||
@@ -399,11 +405,2 @@ } | ||
private _resetHeartbeat() { | ||
this.pendingHeartbeatRef = null | ||
this.heartbeatTimer && clearInterval(this.heartbeatTimer) | ||
this.heartbeatTimer = setInterval( | ||
() => this._sendHeartbeat(), | ||
this.heartbeatIntervalMs | ||
) | ||
} | ||
private _sendHeartbeat() { | ||
@@ -410,0 +407,0 @@ if (!this.isConnected()) { |
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
215406
-0.66%3843
-0.8%