@supabase/realtime-js 2.71.2-canary.3 → 2.71.2-canary.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/main/RealtimeChannel.d.ts +235 -0
  2. package/dist/main/RealtimeChannel.d.ts.map +1 -0
  3. package/dist/main/RealtimeChannel.js +576 -0
  4. package/dist/main/RealtimeChannel.js.map +1 -0
  5. package/dist/main/RealtimeClient.d.ts +196 -0
  6. package/dist/main/RealtimeClient.d.ts.map +1 -0
  7. package/dist/main/RealtimeClient.js +736 -0
  8. package/dist/main/RealtimeClient.js.map +1 -0
  9. package/dist/main/RealtimePresence.d.ts +68 -0
  10. package/dist/main/RealtimePresence.d.ts.map +1 -0
  11. package/dist/main/RealtimePresence.js +229 -0
  12. package/dist/main/RealtimePresence.js.map +1 -0
  13. package/dist/main/index.d.ts +6 -0
  14. package/dist/main/index.d.ts.map +1 -0
  15. package/dist/main/index.js +53 -0
  16. package/dist/main/index.js.map +1 -0
  17. package/dist/main/lib/constants.d.ts +37 -0
  18. package/dist/main/lib/constants.d.ts.map +1 -0
  19. package/dist/main/lib/constants.js +46 -0
  20. package/dist/main/lib/constants.js.map +1 -0
  21. package/dist/main/lib/push.d.ts +48 -0
  22. package/dist/main/lib/push.d.ts.map +1 -0
  23. package/dist/main/lib/push.js +102 -0
  24. package/dist/main/lib/push.js.map +1 -0
  25. package/dist/main/lib/serializer.d.ts +7 -0
  26. package/dist/main/lib/serializer.d.ts.map +1 -0
  27. package/dist/main/lib/serializer.js +36 -0
  28. package/dist/main/lib/serializer.js.map +1 -0
  29. package/dist/main/lib/timer.d.ts +22 -0
  30. package/dist/main/lib/timer.d.ts.map +1 -0
  31. package/dist/main/lib/timer.js +39 -0
  32. package/dist/main/lib/timer.js.map +1 -0
  33. package/dist/main/lib/transformers.d.ts +109 -0
  34. package/dist/main/lib/transformers.d.ts.map +1 -0
  35. package/dist/main/lib/transformers.js +229 -0
  36. package/dist/main/lib/transformers.js.map +1 -0
  37. package/dist/main/lib/version.d.ts +2 -0
  38. package/dist/main/lib/version.d.ts.map +1 -0
  39. package/dist/main/lib/version.js +5 -0
  40. package/dist/main/lib/version.js.map +1 -0
  41. package/dist/main/lib/websocket-factory.d.ts +35 -0
  42. package/dist/main/lib/websocket-factory.d.ts.map +1 -0
  43. package/dist/main/lib/websocket-factory.js +90 -0
  44. package/dist/main/lib/websocket-factory.js.map +1 -0
  45. package/dist/module/RealtimeChannel.d.ts +235 -0
  46. package/dist/module/RealtimeChannel.d.ts.map +1 -0
  47. package/dist/module/RealtimeChannel.js +536 -0
  48. package/dist/module/RealtimeChannel.js.map +1 -0
  49. package/dist/module/RealtimeClient.d.ts +196 -0
  50. package/dist/module/RealtimeClient.d.ts.map +1 -0
  51. package/dist/module/RealtimeClient.js +698 -0
  52. package/dist/module/RealtimeClient.js.map +1 -0
  53. package/dist/module/RealtimePresence.d.ts +68 -0
  54. package/dist/module/RealtimePresence.d.ts.map +1 -0
  55. package/dist/module/RealtimePresence.js +225 -0
  56. package/dist/module/RealtimePresence.js.map +1 -0
  57. package/dist/module/index.d.ts +6 -0
  58. package/dist/module/index.d.ts.map +1 -0
  59. package/dist/module/index.js +6 -0
  60. package/dist/module/index.js.map +1 -0
  61. package/dist/module/lib/constants.d.ts +37 -0
  62. package/dist/module/lib/constants.d.ts.map +1 -0
  63. package/dist/module/lib/constants.js +43 -0
  64. package/dist/module/lib/constants.js.map +1 -0
  65. package/dist/module/lib/push.d.ts +48 -0
  66. package/dist/module/lib/push.d.ts.map +1 -0
  67. package/dist/module/lib/push.js +99 -0
  68. package/dist/module/lib/push.js.map +1 -0
  69. package/dist/module/lib/serializer.d.ts +7 -0
  70. package/dist/module/lib/serializer.d.ts.map +1 -0
  71. package/dist/module/lib/serializer.js +33 -0
  72. package/dist/module/lib/serializer.js.map +1 -0
  73. package/dist/module/lib/timer.d.ts +22 -0
  74. package/dist/module/lib/timer.d.ts.map +1 -0
  75. package/dist/module/lib/timer.js +36 -0
  76. package/dist/module/lib/timer.js.map +1 -0
  77. package/dist/module/lib/transformers.d.ts +109 -0
  78. package/dist/module/lib/transformers.d.ts.map +1 -0
  79. package/dist/module/lib/transformers.js +217 -0
  80. package/dist/module/lib/transformers.js.map +1 -0
  81. package/dist/module/lib/version.d.ts +2 -0
  82. package/dist/module/lib/version.d.ts.map +1 -0
  83. package/dist/module/lib/version.js +2 -0
  84. package/dist/module/lib/version.js.map +1 -0
  85. package/dist/module/lib/websocket-factory.d.ts +35 -0
  86. package/dist/module/lib/websocket-factory.d.ts.map +1 -0
  87. package/dist/module/lib/websocket-factory.js +86 -0
  88. package/dist/module/lib/websocket-factory.js.map +1 -0
  89. package/package.json +1 -1
@@ -0,0 +1,33 @@
1
+ // This file draws heavily from https://github.com/phoenixframework/phoenix/commit/cf098e9cf7a44ee6479d31d911a97d3c7430c6fe
2
+ // License: https://github.com/phoenixframework/phoenix/blob/master/LICENSE.md
3
+ export default class Serializer {
4
+ constructor() {
5
+ this.HEADER_LENGTH = 1;
6
+ }
7
+ decode(rawPayload, callback) {
8
+ if (rawPayload.constructor === ArrayBuffer) {
9
+ return callback(this._binaryDecode(rawPayload));
10
+ }
11
+ if (typeof rawPayload === 'string') {
12
+ return callback(JSON.parse(rawPayload));
13
+ }
14
+ return callback({});
15
+ }
16
+ _binaryDecode(buffer) {
17
+ const view = new DataView(buffer);
18
+ const decoder = new TextDecoder();
19
+ return this._decodeBroadcast(buffer, view, decoder);
20
+ }
21
+ _decodeBroadcast(buffer, view, decoder) {
22
+ const topicSize = view.getUint8(1);
23
+ const eventSize = view.getUint8(2);
24
+ let offset = this.HEADER_LENGTH + 2;
25
+ const topic = decoder.decode(buffer.slice(offset, offset + topicSize));
26
+ offset = offset + topicSize;
27
+ const event = decoder.decode(buffer.slice(offset, offset + eventSize));
28
+ offset = offset + eventSize;
29
+ const data = JSON.parse(decoder.decode(buffer.slice(offset, buffer.byteLength)));
30
+ return { ref: null, topic: topic, event: event, payload: data };
31
+ }
32
+ }
33
+ //# sourceMappingURL=serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../../src/lib/serializer.ts"],"names":[],"mappings":"AAAA,2HAA2H;AAC3H,8EAA8E;AAE9E,MAAM,CAAC,OAAO,OAAO,UAAU;IAA/B;QACE,kBAAa,GAAG,CAAC,CAAA;IA0CnB,CAAC;IAxCC,MAAM,CAAC,UAAgC,EAAE,QAAkB;QACzD,IAAI,UAAU,CAAC,WAAW,KAAK,WAAW,EAAE,CAAC;YAC3C,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAA;QACjD,CAAC;QAED,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACnC,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA;QACzC,CAAC;QAED,OAAO,QAAQ,CAAC,EAAE,CAAC,CAAA;IACrB,CAAC;IAEO,aAAa,CAAC,MAAmB;QACvC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAA;QACjC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;QAEjC,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACrD,CAAC;IAEO,gBAAgB,CACtB,MAAmB,EACnB,IAAc,EACd,OAAoB;QAOpB,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;QAClC,IAAI,MAAM,GAAG,IAAI,CAAC,aAAa,GAAG,CAAC,CAAA;QACnC,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAA;QACtE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;QAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAA;QACtE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;QAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QAEhF,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IACjE,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Creates a timer that accepts a `timerCalc` function to perform calculated timeout retries, such as exponential backoff.
3
+ *
4
+ * @example
5
+ * let reconnectTimer = new Timer(() => this.connect(), function(tries){
6
+ * return [1000, 5000, 10000][tries - 1] || 10000
7
+ * })
8
+ * reconnectTimer.scheduleTimeout() // fires after 1000
9
+ * reconnectTimer.scheduleTimeout() // fires after 5000
10
+ * reconnectTimer.reset()
11
+ * reconnectTimer.scheduleTimeout() // fires after 1000
12
+ */
13
+ export default class Timer {
14
+ callback: Function;
15
+ timerCalc: Function;
16
+ timer: number | undefined;
17
+ tries: number;
18
+ constructor(callback: Function, timerCalc: Function);
19
+ reset(): void;
20
+ scheduleTimeout(): void;
21
+ }
22
+ //# sourceMappingURL=timer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../../../src/lib/timer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IAKf,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,QAAQ;IAL5B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAY;IACrC,KAAK,EAAE,MAAM,CAAI;gBAGR,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,QAAQ;IAM5B,KAAK;IAOL,eAAe;CAWhB"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Creates a timer that accepts a `timerCalc` function to perform calculated timeout retries, such as exponential backoff.
3
+ *
4
+ * @example
5
+ * let reconnectTimer = new Timer(() => this.connect(), function(tries){
6
+ * return [1000, 5000, 10000][tries - 1] || 10000
7
+ * })
8
+ * reconnectTimer.scheduleTimeout() // fires after 1000
9
+ * reconnectTimer.scheduleTimeout() // fires after 5000
10
+ * reconnectTimer.reset()
11
+ * reconnectTimer.scheduleTimeout() // fires after 1000
12
+ */
13
+ export default class Timer {
14
+ constructor(callback, timerCalc) {
15
+ this.callback = callback;
16
+ this.timerCalc = timerCalc;
17
+ this.timer = undefined;
18
+ this.tries = 0;
19
+ this.callback = callback;
20
+ this.timerCalc = timerCalc;
21
+ }
22
+ reset() {
23
+ this.tries = 0;
24
+ clearTimeout(this.timer);
25
+ this.timer = undefined;
26
+ }
27
+ // Cancels any previous scheduleTimeout and schedules callback
28
+ scheduleTimeout() {
29
+ clearTimeout(this.timer);
30
+ this.timer = setTimeout(() => {
31
+ this.tries = this.tries + 1;
32
+ this.callback();
33
+ }, this.timerCalc(this.tries + 1));
34
+ }
35
+ }
36
+ //# sourceMappingURL=timer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.js","sourceRoot":"","sources":["../../../src/lib/timer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IAIxB,YACS,QAAkB,EAClB,SAAmB;QADnB,aAAQ,GAAR,QAAQ,CAAU;QAClB,cAAS,GAAT,SAAS,CAAU;QAL5B,UAAK,GAAuB,SAAS,CAAA;QACrC,UAAK,GAAW,CAAC,CAAA;QAMf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;QACd,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACxB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;IACxB,CAAC;IAED,8DAA8D;IAC9D,eAAe;QACb,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAExB,IAAI,CAAC,KAAK,GAAQ,UAAU,CAC1B,GAAG,EAAE;YACH,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;YAC3B,IAAI,CAAC,QAAQ,EAAE,CAAA;QACjB,CAAC,EACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAC/B,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Helpers to convert the change Payload into native JS types.
3
+ */
4
+ export declare enum PostgresTypes {
5
+ abstime = "abstime",
6
+ bool = "bool",
7
+ date = "date",
8
+ daterange = "daterange",
9
+ float4 = "float4",
10
+ float8 = "float8",
11
+ int2 = "int2",
12
+ int4 = "int4",
13
+ int4range = "int4range",
14
+ int8 = "int8",
15
+ int8range = "int8range",
16
+ json = "json",
17
+ jsonb = "jsonb",
18
+ money = "money",
19
+ numeric = "numeric",
20
+ oid = "oid",
21
+ reltime = "reltime",
22
+ text = "text",
23
+ time = "time",
24
+ timestamp = "timestamp",
25
+ timestamptz = "timestamptz",
26
+ timetz = "timetz",
27
+ tsrange = "tsrange",
28
+ tstzrange = "tstzrange"
29
+ }
30
+ type Columns = {
31
+ name: string;
32
+ type: string;
33
+ flags?: string[];
34
+ type_modifier?: number;
35
+ }[];
36
+ type BaseValue = null | string | number | boolean;
37
+ type RecordValue = BaseValue | BaseValue[];
38
+ type Record = {
39
+ [key: string]: RecordValue;
40
+ };
41
+ /**
42
+ * Takes an array of columns and an object of string values then converts each string value
43
+ * to its mapped type.
44
+ *
45
+ * @param {{name: String, type: String}[]} columns
46
+ * @param {Object} record
47
+ * @param {Object} options The map of various options that can be applied to the mapper
48
+ * @param {Array} options.skipTypes The array of types that should not be converted
49
+ *
50
+ * @example convertChangeData([{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], {first_name: 'Paul', age:'33'}, {})
51
+ * //=>{ first_name: 'Paul', age: 33 }
52
+ */
53
+ export declare const convertChangeData: (columns: Columns, record: Record, options?: {
54
+ skipTypes?: string[];
55
+ }) => Record;
56
+ /**
57
+ * Converts the value of an individual column.
58
+ *
59
+ * @param {String} columnName The column that you want to convert
60
+ * @param {{name: String, type: String}[]} columns All of the columns
61
+ * @param {Object} record The map of string values
62
+ * @param {Array} skipTypes An array of types that should not be converted
63
+ * @return {object} Useless information
64
+ *
65
+ * @example convertColumn('age', [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], {first_name: 'Paul', age: '33'}, [])
66
+ * //=> 33
67
+ * @example convertColumn('age', [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], {first_name: 'Paul', age: '33'}, ['int4'])
68
+ * //=> "33"
69
+ */
70
+ export declare const convertColumn: (columnName: string, columns: Columns, record: Record, skipTypes: string[]) => RecordValue;
71
+ /**
72
+ * If the value of the cell is `null`, returns null.
73
+ * Otherwise converts the string value to the correct type.
74
+ * @param {String} type A postgres column type
75
+ * @param {String} value The cell value
76
+ *
77
+ * @example convertCell('bool', 't')
78
+ * //=> true
79
+ * @example convertCell('int8', '10')
80
+ * //=> 10
81
+ * @example convertCell('_int4', '{1,2,3,4}')
82
+ * //=> [1,2,3,4]
83
+ */
84
+ export declare const convertCell: (type: string, value: RecordValue) => RecordValue;
85
+ export declare const toBoolean: (value: RecordValue) => RecordValue;
86
+ export declare const toNumber: (value: RecordValue) => RecordValue;
87
+ export declare const toJson: (value: RecordValue) => RecordValue;
88
+ /**
89
+ * Converts a Postgres Array into a native JS array
90
+ *
91
+ * @example toArray('{}', 'int4')
92
+ * //=> []
93
+ * @example toArray('{"[2021-01-01,2021-12-31)","(2021-01-01,2021-12-32]"}', 'daterange')
94
+ * //=> ['[2021-01-01,2021-12-31)', '(2021-01-01,2021-12-32]']
95
+ * @example toArray([1,2,3,4], 'int4')
96
+ * //=> [1,2,3,4]
97
+ */
98
+ export declare const toArray: (value: RecordValue, type: string) => RecordValue;
99
+ /**
100
+ * Fixes timestamp to be ISO-8601. Swaps the space between the date and time for a 'T'
101
+ * See https://github.com/supabase/supabase/issues/18
102
+ *
103
+ * @example toTimestampString('2019-09-10 00:00:00')
104
+ * //=> '2019-09-10T00:00:00'
105
+ */
106
+ export declare const toTimestampString: (value: RecordValue) => RecordValue;
107
+ export declare const httpEndpointURL: (socketUrl: string) => string;
108
+ export {};
109
+ //# sourceMappingURL=transformers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../src/lib/transformers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,oBAAY,aAAa;IACvB,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,WAAW,gBAAgB;IAC3B,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,SAAS,cAAc;CACxB;AAED,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,EAAE,CAAA;AAEH,KAAK,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AACjD,KAAK,WAAW,GAAG,SAAS,GAAG,SAAS,EAAE,CAAA;AAE1C,KAAK,MAAM,GAAG;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAA;CAC3B,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,GAC5B,SAAS,OAAO,EAChB,QAAQ,MAAM,EACd,UAAS;IAAE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,KACrC,MAOF,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,GACxB,YAAY,MAAM,EAClB,SAAS,OAAO,EAChB,QAAQ,MAAM,EACd,WAAW,MAAM,EAAE,KAClB,WAUF,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,OAAO,WAAW,KAAG,WA0C9D,CAAA;AAKD,eAAO,MAAM,SAAS,GAAI,OAAO,WAAW,KAAG,WAS9C,CAAA;AACD,eAAO,MAAM,QAAQ,GAAI,OAAO,WAAW,KAAG,WAQ7C,CAAA;AACD,eAAO,MAAM,MAAM,GAAI,OAAO,WAAW,KAAG,WAU3C,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO,GAAI,OAAO,WAAW,EAAE,MAAM,MAAM,KAAG,WA0B1D,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,WAAW,KAAG,WAMtD,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,WAAW,MAAM,KAAG,MAKnD,CAAA"}
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Helpers to convert the change Payload into native JS types.
3
+ */
4
+ // Adapted from epgsql (src/epgsql_binary.erl), this module licensed under
5
+ // 3-clause BSD found here: https://raw.githubusercontent.com/epgsql/epgsql/devel/LICENSE
6
+ export var PostgresTypes;
7
+ (function (PostgresTypes) {
8
+ PostgresTypes["abstime"] = "abstime";
9
+ PostgresTypes["bool"] = "bool";
10
+ PostgresTypes["date"] = "date";
11
+ PostgresTypes["daterange"] = "daterange";
12
+ PostgresTypes["float4"] = "float4";
13
+ PostgresTypes["float8"] = "float8";
14
+ PostgresTypes["int2"] = "int2";
15
+ PostgresTypes["int4"] = "int4";
16
+ PostgresTypes["int4range"] = "int4range";
17
+ PostgresTypes["int8"] = "int8";
18
+ PostgresTypes["int8range"] = "int8range";
19
+ PostgresTypes["json"] = "json";
20
+ PostgresTypes["jsonb"] = "jsonb";
21
+ PostgresTypes["money"] = "money";
22
+ PostgresTypes["numeric"] = "numeric";
23
+ PostgresTypes["oid"] = "oid";
24
+ PostgresTypes["reltime"] = "reltime";
25
+ PostgresTypes["text"] = "text";
26
+ PostgresTypes["time"] = "time";
27
+ PostgresTypes["timestamp"] = "timestamp";
28
+ PostgresTypes["timestamptz"] = "timestamptz";
29
+ PostgresTypes["timetz"] = "timetz";
30
+ PostgresTypes["tsrange"] = "tsrange";
31
+ PostgresTypes["tstzrange"] = "tstzrange";
32
+ })(PostgresTypes || (PostgresTypes = {}));
33
+ /**
34
+ * Takes an array of columns and an object of string values then converts each string value
35
+ * to its mapped type.
36
+ *
37
+ * @param {{name: String, type: String}[]} columns
38
+ * @param {Object} record
39
+ * @param {Object} options The map of various options that can be applied to the mapper
40
+ * @param {Array} options.skipTypes The array of types that should not be converted
41
+ *
42
+ * @example convertChangeData([{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], {first_name: 'Paul', age:'33'}, {})
43
+ * //=>{ first_name: 'Paul', age: 33 }
44
+ */
45
+ export const convertChangeData = (columns, record, options = {}) => {
46
+ var _a;
47
+ const skipTypes = (_a = options.skipTypes) !== null && _a !== void 0 ? _a : [];
48
+ return Object.keys(record).reduce((acc, rec_key) => {
49
+ acc[rec_key] = convertColumn(rec_key, columns, record, skipTypes);
50
+ return acc;
51
+ }, {});
52
+ };
53
+ /**
54
+ * Converts the value of an individual column.
55
+ *
56
+ * @param {String} columnName The column that you want to convert
57
+ * @param {{name: String, type: String}[]} columns All of the columns
58
+ * @param {Object} record The map of string values
59
+ * @param {Array} skipTypes An array of types that should not be converted
60
+ * @return {object} Useless information
61
+ *
62
+ * @example convertColumn('age', [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], {first_name: 'Paul', age: '33'}, [])
63
+ * //=> 33
64
+ * @example convertColumn('age', [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], {first_name: 'Paul', age: '33'}, ['int4'])
65
+ * //=> "33"
66
+ */
67
+ export const convertColumn = (columnName, columns, record, skipTypes) => {
68
+ const column = columns.find((x) => x.name === columnName);
69
+ const colType = column === null || column === void 0 ? void 0 : column.type;
70
+ const value = record[columnName];
71
+ if (colType && !skipTypes.includes(colType)) {
72
+ return convertCell(colType, value);
73
+ }
74
+ return noop(value);
75
+ };
76
+ /**
77
+ * If the value of the cell is `null`, returns null.
78
+ * Otherwise converts the string value to the correct type.
79
+ * @param {String} type A postgres column type
80
+ * @param {String} value The cell value
81
+ *
82
+ * @example convertCell('bool', 't')
83
+ * //=> true
84
+ * @example convertCell('int8', '10')
85
+ * //=> 10
86
+ * @example convertCell('_int4', '{1,2,3,4}')
87
+ * //=> [1,2,3,4]
88
+ */
89
+ export const convertCell = (type, value) => {
90
+ // if data type is an array
91
+ if (type.charAt(0) === '_') {
92
+ const dataType = type.slice(1, type.length);
93
+ return toArray(value, dataType);
94
+ }
95
+ // If not null, convert to correct type.
96
+ switch (type) {
97
+ case PostgresTypes.bool:
98
+ return toBoolean(value);
99
+ case PostgresTypes.float4:
100
+ case PostgresTypes.float8:
101
+ case PostgresTypes.int2:
102
+ case PostgresTypes.int4:
103
+ case PostgresTypes.int8:
104
+ case PostgresTypes.numeric:
105
+ case PostgresTypes.oid:
106
+ return toNumber(value);
107
+ case PostgresTypes.json:
108
+ case PostgresTypes.jsonb:
109
+ return toJson(value);
110
+ case PostgresTypes.timestamp:
111
+ return toTimestampString(value); // Format to be consistent with PostgREST
112
+ case PostgresTypes.abstime: // To allow users to cast it based on Timezone
113
+ case PostgresTypes.date: // To allow users to cast it based on Timezone
114
+ case PostgresTypes.daterange:
115
+ case PostgresTypes.int4range:
116
+ case PostgresTypes.int8range:
117
+ case PostgresTypes.money:
118
+ case PostgresTypes.reltime: // To allow users to cast it based on Timezone
119
+ case PostgresTypes.text:
120
+ case PostgresTypes.time: // To allow users to cast it based on Timezone
121
+ case PostgresTypes.timestamptz: // To allow users to cast it based on Timezone
122
+ case PostgresTypes.timetz: // To allow users to cast it based on Timezone
123
+ case PostgresTypes.tsrange:
124
+ case PostgresTypes.tstzrange:
125
+ return noop(value);
126
+ default:
127
+ // Return the value for remaining types
128
+ return noop(value);
129
+ }
130
+ };
131
+ const noop = (value) => {
132
+ return value;
133
+ };
134
+ export const toBoolean = (value) => {
135
+ switch (value) {
136
+ case 't':
137
+ return true;
138
+ case 'f':
139
+ return false;
140
+ default:
141
+ return value;
142
+ }
143
+ };
144
+ export const toNumber = (value) => {
145
+ if (typeof value === 'string') {
146
+ const parsedValue = parseFloat(value);
147
+ if (!Number.isNaN(parsedValue)) {
148
+ return parsedValue;
149
+ }
150
+ }
151
+ return value;
152
+ };
153
+ export const toJson = (value) => {
154
+ if (typeof value === 'string') {
155
+ try {
156
+ return JSON.parse(value);
157
+ }
158
+ catch (error) {
159
+ console.log(`JSON parse error: ${error}`);
160
+ return value;
161
+ }
162
+ }
163
+ return value;
164
+ };
165
+ /**
166
+ * Converts a Postgres Array into a native JS array
167
+ *
168
+ * @example toArray('{}', 'int4')
169
+ * //=> []
170
+ * @example toArray('{"[2021-01-01,2021-12-31)","(2021-01-01,2021-12-32]"}', 'daterange')
171
+ * //=> ['[2021-01-01,2021-12-31)', '(2021-01-01,2021-12-32]']
172
+ * @example toArray([1,2,3,4], 'int4')
173
+ * //=> [1,2,3,4]
174
+ */
175
+ export const toArray = (value, type) => {
176
+ if (typeof value !== 'string') {
177
+ return value;
178
+ }
179
+ const lastIdx = value.length - 1;
180
+ const closeBrace = value[lastIdx];
181
+ const openBrace = value[0];
182
+ // Confirm value is a Postgres array by checking curly brackets
183
+ if (openBrace === '{' && closeBrace === '}') {
184
+ let arr;
185
+ const valTrim = value.slice(1, lastIdx);
186
+ // TODO: find a better solution to separate Postgres array data
187
+ try {
188
+ arr = JSON.parse('[' + valTrim + ']');
189
+ }
190
+ catch (_) {
191
+ // WARNING: splitting on comma does not cover all edge cases
192
+ arr = valTrim ? valTrim.split(',') : [];
193
+ }
194
+ return arr.map((val) => convertCell(type, val));
195
+ }
196
+ return value;
197
+ };
198
+ /**
199
+ * Fixes timestamp to be ISO-8601. Swaps the space between the date and time for a 'T'
200
+ * See https://github.com/supabase/supabase/issues/18
201
+ *
202
+ * @example toTimestampString('2019-09-10 00:00:00')
203
+ * //=> '2019-09-10T00:00:00'
204
+ */
205
+ export const toTimestampString = (value) => {
206
+ if (typeof value === 'string') {
207
+ return value.replace(' ', 'T');
208
+ }
209
+ return value;
210
+ };
211
+ export const httpEndpointURL = (socketUrl) => {
212
+ let url = socketUrl;
213
+ url = url.replace(/^ws/i, 'http');
214
+ url = url.replace(/(\/socket\/websocket|\/socket|\/websocket)\/?$/i, '');
215
+ return url.replace(/\/+$/, '') + '/api/broadcast';
216
+ };
217
+ //# sourceMappingURL=transformers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformers.js","sourceRoot":"","sources":["../../../src/lib/transformers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,0EAA0E;AAC1E,yFAAyF;AAEzF,MAAM,CAAN,IAAY,aAyBX;AAzBD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,8BAAa,CAAA;IACb,8BAAa,CAAA;IACb,wCAAuB,CAAA;IACvB,kCAAiB,CAAA;IACjB,kCAAiB,CAAA;IACjB,8BAAa,CAAA;IACb,8BAAa,CAAA;IACb,wCAAuB,CAAA;IACvB,8BAAa,CAAA;IACb,wCAAuB,C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G,CAAC,CAAC,CAAA;IAC5D,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAkB,EAAe,EAAE;IACnE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IAChC,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,SAAiB,EAAU,EAAE;IAC3D,IAAI,GAAG,GAAG,SAAS,CAAA;IACnB,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,iDAAiD,EAAE,EAAE,CAAC,CAAA;IACxE,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,gBAAgB,CAAA;AACnD,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const version = "0.0.0-automated";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,oBAAoB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export const version = '0.0.0-automated';
2
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,iBAAiB,CAAA"}
@@ -0,0 +1,35 @@
1
+ export interface WebSocketLike {
2
+ readonly CONNECTING: number;
3
+ readonly OPEN: number;
4
+ readonly CLOSING: number;
5
+ readonly CLOSED: number;
6
+ readonly readyState: number;
7
+ readonly url: string;
8
+ readonly protocol: string;
9
+ close(code?: number, reason?: string): void;
10
+ send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
11
+ onopen: ((this: any, ev: Event) => any) | null;
12
+ onmessage: ((this: any, ev: MessageEvent) => any) | null;
13
+ onclose: ((this: any, ev: CloseEvent) => any) | null;
14
+ onerror: ((this: any, ev: Event) => any) | null;
15
+ addEventListener(type: string, listener: EventListener): void;
16
+ removeEventListener(type: string, listener: EventListener): void;
17
+ binaryType?: string;
18
+ bufferedAmount?: number;
19
+ extensions?: string;
20
+ dispatchEvent?: (event: Event) => boolean;
21
+ }
22
+ export interface WebSocketEnvironment {
23
+ type: 'native' | 'ws' | 'cloudflare' | 'unsupported';
24
+ constructor?: any;
25
+ error?: string;
26
+ workaround?: string;
27
+ }
28
+ export declare class WebSocketFactory {
29
+ private static detectEnvironment;
30
+ static getWebSocketConstructor(): typeof WebSocket;
31
+ static createWebSocket(url: string | URL, protocols?: string | string[]): WebSocketLike;
32
+ static isWebSocketSupported(): boolean;
33
+ }
34
+ export default WebSocketFactory;
35
+ //# sourceMappingURL=websocket-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-factory.d.ts","sourceRoot":"","sources":["../../../src/lib/websocket-factory.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IAEzB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3C,IAAI,CAAC,IAAI,EAAE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MAAM,EAAE,GAAG,aAAa;WAKhF,oBAAoB,IAAI,OAAO;CAQ9C;AAED,eAAe,gBAAgB,CAAA"}
@@ -0,0 +1,86 @@
1
+ export class WebSocketFactory {
2
+ static detectEnvironment() {
3
+ var _a;
4
+ if (typeof WebSocket !== 'undefined') {
5
+ return { type: 'native', constructor: WebSocket };
6
+ }
7
+ if (typeof globalThis !== 'undefined' && typeof globalThis.WebSocket !== 'undefined') {
8
+ return { type: 'native', constructor: globalThis.WebSocket };
9
+ }
10
+ if (typeof global !== 'undefined' && typeof global.WebSocket !== 'undefined') {
11
+ return { type: 'native', constructor: global.WebSocket };
12
+ }
13
+ if (typeof globalThis !== 'undefined' &&
14
+ typeof globalThis.WebSocketPair !== 'undefined' &&
15
+ typeof globalThis.WebSocket === 'undefined') {
16
+ return {
17
+ type: 'cloudflare',
18
+ error: 'Cloudflare Workers detected. WebSocket clients are not supported in Cloudflare Workers.',
19
+ workaround: 'Use Cloudflare Workers WebSocket API for server-side WebSocket handling, or deploy to a different runtime.',
20
+ };
21
+ }
22
+ if ((typeof globalThis !== 'undefined' && globalThis.EdgeRuntime) ||
23
+ (typeof navigator !== 'undefined' && ((_a = navigator.userAgent) === null || _a === void 0 ? void 0 : _a.includes('Vercel-Edge')))) {
24
+ return {
25
+ type: 'unsupported',
26
+ error: 'Edge runtime detected (Vercel Edge/Netlify Edge). WebSockets are not supported in edge functions.',
27
+ workaround: 'Use serverless functions or a different deployment target for WebSocket functionality.',
28
+ };
29
+ }
30
+ if (typeof process !== 'undefined' && process.versions && process.versions.node) {
31
+ const nodeVersion = parseInt(process.versions.node.split('.')[0]);
32
+ // Node.js 22+ should have native WebSocket
33
+ if (nodeVersion >= 22) {
34
+ // Check if native WebSocket is available (should be in Node.js 22+)
35
+ if (typeof globalThis.WebSocket !== 'undefined') {
36
+ return { type: 'native', constructor: globalThis.WebSocket };
37
+ }
38
+ // If not available, user needs to provide it
39
+ return {
40
+ type: 'unsupported',
41
+ error: `Node.js ${nodeVersion} detected but native WebSocket not found.`,
42
+ workaround: 'Provide a WebSocket implementation via the transport option.',
43
+ };
44
+ }
45
+ // Node.js < 22 doesn't have native WebSocket
46
+ return {
47
+ type: 'unsupported',
48
+ error: `Node.js ${nodeVersion} detected without native WebSocket support.`,
49
+ workaround: 'For Node.js < 22, install "ws" package and provide it via the transport option:\n' +
50
+ 'import ws from "ws"\n' +
51
+ 'new RealtimeClient(url, { transport: ws })',
52
+ };
53
+ }
54
+ return {
55
+ type: 'unsupported',
56
+ error: 'Unknown JavaScript runtime without WebSocket support.',
57
+ workaround: "Ensure you're running in a supported environment (browser, Node.js, Deno) or provide a custom WebSocket implementation.",
58
+ };
59
+ }
60
+ static getWebSocketConstructor() {
61
+ const env = this.detectEnvironment();
62
+ if (env.constructor) {
63
+ return env.constructor;
64
+ }
65
+ let errorMessage = env.error || 'WebSocket not supported in this environment.';
66
+ if (env.workaround) {
67
+ errorMessage += `\n\nSuggested solution: ${env.workaround}`;
68
+ }
69
+ throw new Error(errorMessage);
70
+ }
71
+ static createWebSocket(url, protocols) {
72
+ const WS = this.getWebSocketConstructor();
73
+ return new WS(url, protocols);
74
+ }
75
+ static isWebSocketSupported() {
76
+ try {
77
+ const env = this.detectEnvironment();
78
+ return env.type === 'native' || env.type === 'ws';
79
+ }
80
+ catch (_a) {
81
+ return false;
82
+ }
83
+ }
84
+ }
85
+ export default WebSocketFactory;
86
+ //# sourceMappingURL=websocket-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-factory.js","sourceRoot":"","sources":["../../../src/lib/websocket-factory.ts"],"names":[],"mappings":"AAkCA,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAC,iBAAiB;;QAC9B,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE,CAAC;YACrC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,CAAA;QACnD,CAAC;QAED,IAAI,OAAO,UAAU,KAAK,WAAW,IAAI,OAAQ,UA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AAE,CAAA;YACpC,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,CAAA;QACnD,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;CACF;AAED,eAAe,gBAAgB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supabase/realtime-js",
3
- "version": "2.71.2-canary.3",
3
+ "version": "2.71.2-canary.6",
4
4
  "description": "Listen to realtime updates to your PostgreSQL database",
5
5
  "keywords": [
6
6
  "realtime",