The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Make amendments according to feedback
Angelicoed46049ee9d4
diff --git a/packages/realtime-js/src/Realtime.js b/packages/realtime-js/src/Realtime.jsindex a8540980d80..6f579f0da3c 100644--- a/packages/realtime-js/src/Realtime.js+++ b/packages/realtime-js/src/Realtime.js@@ -14,6 +14,14 @@ export default class Realtime {})}+ /**+ * Starts socket and all of its channels/ listeners+ *+ * @param {Array} listeners+ * @param {Object} listeners[n]+ * @param {String} listener.channel The name of channel+ * @param {Function} listener.callback The callback function to fire when the channel receives a change+ */start(listeners) {this.socket.connect()if (this.channel.state !== 'joined'){@@ -29,41 +37,49 @@ export default class Realtime {}}+ /**+ * Stops socket and all of its channels/ listeners+ */stop(){- this.listeners.forEach(({ messageName, messagae }) => {- this.channel.off(messageName, message)+ this.listeners.forEach(({ channel, callback }) => {+ this.channel.off(channel, callback)})this.socket.disconnect()}/**- * takes in an object with keys- * - messageName- * - messgage- * to:- * 1. add to this.listener- * 2. turn channel on- * @param {object} listener+ * Adds a listener to the socket and activates it+ *+ * @param {Object} listener+ * @param {String} listener.channel The name of channel+ * @param {Function} listener.callback The callback function to fire when the channel receives a change+ *+ * @example+ * addListener({channel: 'shout', callback: () => {}})*/addListener(listener){this.listeners.push(listener)- let { messageName, message } = listener+ let { channel, callback } = listener- this.channel.on(messageName, message)+ this.channel.on(channel, callback)}/**- * Takes in messageName string to:+ * Takes in String channel to:* 1. turn channel off* 2. remove specific listener from this.listener- * @param {string} messageName+ *+ * @param {String} channel+ *+ * @example+ * removeListener('shout')*/- removeListener(messageName){- this.channel.off(mesageName)+ removeListener(channel){+ this.channel.off(channel)let updatedListeners = this.listeners.filter(listener => {- let name = listener.messageName- return name !== messageName+ let channelName = listener.channel+ return channelName !== channel})this.listeners = updatedListeners}diff --git a/packages/realtime-js/src/mapper.js b/packages/realtime-js/src/mapper.jsindex da997180558..07118436c07 100644--- a/packages/realtime-js/src/mapper.js+++ b/packages/realtime-js/src/mapper.js@@ -39,11 +39,15 @@* to its mapped type* @param {{name: String, type: String}[]} columns* @param {Object} records+ * @param {Object} options The map of various options that can be applied to the mapper+ * @param {Array} options.skipTypes The array of types that should not be converted*/-export const dataConverter = (columns, records) => {+export const dataConverter = (columns, records, options = {}) => {let result = {}+ let skipTypes = typeof options.skipTypes !== 'undefined' ? options.skipTypes : []+Object.entries(records).map(([key, value]) => {- result[key] = convertColumn(key, columns, records)+ result[key] = convertColumn(key, columns, records, skipTypes)})return result}@@ -53,10 +57,13 @@ export const dataConverter = (columns, records) => {* @param {String} columnName The column that you want to convert* @param {{name: String, type: String}[]} columns All of the columns* @param {Object} records The map of string values+ * @param {Array} skipTypes An array of types that should not be converted*/-export const convertColumn = (columnName, columns, records) => {+export const convertColumn = (columnName, columns, records, skipTypes) => {+let column = columns.find(x => x.name == columnName)- return convertCell(column.type, records[columnName])+ if(skipTypes.includes(column.type)) return noop(records[columnName])+ else return convertCell(column.type, records[columnName])}/**@@ -80,7 +87,6 @@ export const convertCell = (type, stringValue) => {case 'cidr':return noop(stringValue)case 'date':- return noop(stringValue) // PostgREST uses stringreturn toDate(stringValue)case 'daterange':return toDateRange(stringValue)@@ -121,10 +127,8 @@ export const convertCell = (type, stringValue) => {case 'time':return noop(stringValue)case 'timestamp':- return noop(stringValue) // PostgREST uses stringreturn toDate(stringValue)case 'timestamptz':- return noop(stringValue) // PostgREST uses stringreturn toDate(stringValue)case 'timetz':return noop(stringValue)