@depup/supabase__realtime-js 2.99.3-depup.0
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.
- package/README.md +32 -0
- package/changes.json +14 -0
- package/dist/main/RealtimeChannel.d.ts +370 -0
- package/dist/main/RealtimeChannel.d.ts.map +1 -0
- package/dist/main/RealtimeChannel.js +644 -0
- package/dist/main/RealtimeChannel.js.map +1 -0
- package/dist/main/RealtimeClient.d.ts +238 -0
- package/dist/main/RealtimeClient.d.ts.map +1 -0
- package/dist/main/RealtimeClient.js +870 -0
- package/dist/main/RealtimeClient.js.map +1 -0
- package/dist/main/RealtimePresence.d.ts +76 -0
- package/dist/main/RealtimePresence.d.ts.map +1 -0
- package/dist/main/RealtimePresence.js +237 -0
- package/dist/main/RealtimePresence.js.map +1 -0
- package/dist/main/index.d.ts +6 -0
- package/dist/main/index.d.ts.map +1 -0
- package/dist/main/index.js +18 -0
- package/dist/main/index.js.map +1 -0
- package/dist/main/lib/constants.d.ts +39 -0
- package/dist/main/lib/constants.d.ts.map +1 -0
- package/dist/main/lib/constants.js +48 -0
- package/dist/main/lib/constants.js.map +1 -0
- package/dist/main/lib/push.d.ts +48 -0
- package/dist/main/lib/push.d.ts.map +1 -0
- package/dist/main/lib/push.js +102 -0
- package/dist/main/lib/push.js.map +1 -0
- package/dist/main/lib/serializer.d.ts +33 -0
- package/dist/main/lib/serializer.d.ts.map +1 -0
- package/dist/main/lib/serializer.js +155 -0
- package/dist/main/lib/serializer.js.map +1 -0
- package/dist/main/lib/timer.d.ts +22 -0
- package/dist/main/lib/timer.d.ts.map +1 -0
- package/dist/main/lib/timer.js +39 -0
- package/dist/main/lib/timer.js.map +1 -0
- package/dist/main/lib/transformers.d.ts +109 -0
- package/dist/main/lib/transformers.d.ts.map +1 -0
- package/dist/main/lib/transformers.js +241 -0
- package/dist/main/lib/transformers.js.map +1 -0
- package/dist/main/lib/version.d.ts +2 -0
- package/dist/main/lib/version.d.ts.map +1 -0
- package/dist/main/lib/version.js +11 -0
- package/dist/main/lib/version.js.map +1 -0
- package/dist/main/lib/websocket-factory.d.ts +81 -0
- package/dist/main/lib/websocket-factory.d.ts.map +1 -0
- package/dist/main/lib/websocket-factory.js +131 -0
- package/dist/main/lib/websocket-factory.js.map +1 -0
- package/dist/module/RealtimeChannel.d.ts +370 -0
- package/dist/module/RealtimeChannel.d.ts.map +1 -0
- package/dist/module/RealtimeChannel.js +639 -0
- package/dist/module/RealtimeChannel.js.map +1 -0
- package/dist/module/RealtimeClient.d.ts +238 -0
- package/dist/module/RealtimeClient.d.ts.map +1 -0
- package/dist/module/RealtimeClient.js +866 -0
- package/dist/module/RealtimeClient.js.map +1 -0
- package/dist/module/RealtimePresence.d.ts +76 -0
- package/dist/module/RealtimePresence.d.ts.map +1 -0
- package/dist/module/RealtimePresence.js +233 -0
- package/dist/module/RealtimePresence.js.map +1 -0
- package/dist/module/index.d.ts +6 -0
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +6 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/lib/constants.d.ts +39 -0
- package/dist/module/lib/constants.d.ts.map +1 -0
- package/dist/module/lib/constants.js +45 -0
- package/dist/module/lib/constants.js.map +1 -0
- package/dist/module/lib/push.d.ts +48 -0
- package/dist/module/lib/push.d.ts.map +1 -0
- package/dist/module/lib/push.js +99 -0
- package/dist/module/lib/push.js.map +1 -0
- package/dist/module/lib/serializer.d.ts +33 -0
- package/dist/module/lib/serializer.d.ts.map +1 -0
- package/dist/module/lib/serializer.js +152 -0
- package/dist/module/lib/serializer.js.map +1 -0
- package/dist/module/lib/timer.d.ts +22 -0
- package/dist/module/lib/timer.d.ts.map +1 -0
- package/dist/module/lib/timer.js +36 -0
- package/dist/module/lib/timer.js.map +1 -0
- package/dist/module/lib/transformers.d.ts +109 -0
- package/dist/module/lib/transformers.d.ts.map +1 -0
- package/dist/module/lib/transformers.js +229 -0
- package/dist/module/lib/transformers.js.map +1 -0
- package/dist/module/lib/version.d.ts +2 -0
- package/dist/module/lib/version.d.ts.map +1 -0
- package/dist/module/lib/version.js +8 -0
- package/dist/module/lib/version.js.map +1 -0
- package/dist/module/lib/websocket-factory.d.ts +81 -0
- package/dist/module/lib/websocket-factory.d.ts.map +1 -0
- package/dist/module/lib/websocket-factory.js +127 -0
- package/dist/module/lib/websocket-factory.js.map +1 -0
- package/dist/tsconfig.module.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +85 -0
- package/src/RealtimeChannel.ts +1039 -0
- package/src/RealtimeClient.ts +1023 -0
- package/src/RealtimePresence.ts +346 -0
- package/src/index.ts +53 -0
- package/src/lib/constants.ts +49 -0
- package/src/lib/push.ts +121 -0
- package/src/lib/serializer.ts +203 -0
- package/src/lib/timer.ts +43 -0
- package/src/lib/transformers.ts +270 -0
- package/src/lib/version.ts +7 -0
- package/src/lib/websocket-factory.ts +192 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Helpers to convert the change Payload into native JS types.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.httpEndpointURL = exports.toTimestampString = exports.toArray = exports.toJson = exports.toNumber = exports.toBoolean = exports.convertCell = exports.convertColumn = exports.convertChangeData = exports.PostgresTypes = void 0;
|
|
7
|
+
// Adapted from epgsql (src/epgsql_binary.erl), this module licensed under
|
|
8
|
+
// 3-clause BSD found here: https://raw.githubusercontent.com/epgsql/epgsql/devel/LICENSE
|
|
9
|
+
var PostgresTypes;
|
|
10
|
+
(function (PostgresTypes) {
|
|
11
|
+
PostgresTypes["abstime"] = "abstime";
|
|
12
|
+
PostgresTypes["bool"] = "bool";
|
|
13
|
+
PostgresTypes["date"] = "date";
|
|
14
|
+
PostgresTypes["daterange"] = "daterange";
|
|
15
|
+
PostgresTypes["float4"] = "float4";
|
|
16
|
+
PostgresTypes["float8"] = "float8";
|
|
17
|
+
PostgresTypes["int2"] = "int2";
|
|
18
|
+
PostgresTypes["int4"] = "int4";
|
|
19
|
+
PostgresTypes["int4range"] = "int4range";
|
|
20
|
+
PostgresTypes["int8"] = "int8";
|
|
21
|
+
PostgresTypes["int8range"] = "int8range";
|
|
22
|
+
PostgresTypes["json"] = "json";
|
|
23
|
+
PostgresTypes["jsonb"] = "jsonb";
|
|
24
|
+
PostgresTypes["money"] = "money";
|
|
25
|
+
PostgresTypes["numeric"] = "numeric";
|
|
26
|
+
PostgresTypes["oid"] = "oid";
|
|
27
|
+
PostgresTypes["reltime"] = "reltime";
|
|
28
|
+
PostgresTypes["text"] = "text";
|
|
29
|
+
PostgresTypes["time"] = "time";
|
|
30
|
+
PostgresTypes["timestamp"] = "timestamp";
|
|
31
|
+
PostgresTypes["timestamptz"] = "timestamptz";
|
|
32
|
+
PostgresTypes["timetz"] = "timetz";
|
|
33
|
+
PostgresTypes["tsrange"] = "tsrange";
|
|
34
|
+
PostgresTypes["tstzrange"] = "tstzrange";
|
|
35
|
+
})(PostgresTypes || (exports.PostgresTypes = PostgresTypes = {}));
|
|
36
|
+
/**
|
|
37
|
+
* Takes an array of columns and an object of string values then converts each string value
|
|
38
|
+
* to its mapped type.
|
|
39
|
+
*
|
|
40
|
+
* @param {{name: String, type: String}[]} columns
|
|
41
|
+
* @param {Object} record
|
|
42
|
+
* @param {Object} options The map of various options that can be applied to the mapper
|
|
43
|
+
* @param {Array} options.skipTypes The array of types that should not be converted
|
|
44
|
+
*
|
|
45
|
+
* @example convertChangeData([{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], {first_name: 'Paul', age:'33'}, {})
|
|
46
|
+
* //=>{ first_name: 'Paul', age: 33 }
|
|
47
|
+
*/
|
|
48
|
+
const convertChangeData = (columns, record, options = {}) => {
|
|
49
|
+
var _a;
|
|
50
|
+
const skipTypes = (_a = options.skipTypes) !== null && _a !== void 0 ? _a : [];
|
|
51
|
+
if (!record) {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
return Object.keys(record).reduce((acc, rec_key) => {
|
|
55
|
+
acc[rec_key] = (0, exports.convertColumn)(rec_key, columns, record, skipTypes);
|
|
56
|
+
return acc;
|
|
57
|
+
}, {});
|
|
58
|
+
};
|
|
59
|
+
exports.convertChangeData = convertChangeData;
|
|
60
|
+
/**
|
|
61
|
+
* Converts the value of an individual column.
|
|
62
|
+
*
|
|
63
|
+
* @param {String} columnName The column that you want to convert
|
|
64
|
+
* @param {{name: String, type: String}[]} columns All of the columns
|
|
65
|
+
* @param {Object} record The map of string values
|
|
66
|
+
* @param {Array} skipTypes An array of types that should not be converted
|
|
67
|
+
* @return {object} Useless information
|
|
68
|
+
*
|
|
69
|
+
* @example convertColumn('age', [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], {first_name: 'Paul', age: '33'}, [])
|
|
70
|
+
* //=> 33
|
|
71
|
+
* @example convertColumn('age', [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], {first_name: 'Paul', age: '33'}, ['int4'])
|
|
72
|
+
* //=> "33"
|
|
73
|
+
*/
|
|
74
|
+
const convertColumn = (columnName, columns, record, skipTypes) => {
|
|
75
|
+
const column = columns.find((x) => x.name === columnName);
|
|
76
|
+
const colType = column === null || column === void 0 ? void 0 : column.type;
|
|
77
|
+
const value = record[columnName];
|
|
78
|
+
if (colType && !skipTypes.includes(colType)) {
|
|
79
|
+
return (0, exports.convertCell)(colType, value);
|
|
80
|
+
}
|
|
81
|
+
return noop(value);
|
|
82
|
+
};
|
|
83
|
+
exports.convertColumn = convertColumn;
|
|
84
|
+
/**
|
|
85
|
+
* If the value of the cell is `null`, returns null.
|
|
86
|
+
* Otherwise converts the string value to the correct type.
|
|
87
|
+
* @param {String} type A postgres column type
|
|
88
|
+
* @param {String} value The cell value
|
|
89
|
+
*
|
|
90
|
+
* @example convertCell('bool', 't')
|
|
91
|
+
* //=> true
|
|
92
|
+
* @example convertCell('int8', '10')
|
|
93
|
+
* //=> 10
|
|
94
|
+
* @example convertCell('_int4', '{1,2,3,4}')
|
|
95
|
+
* //=> [1,2,3,4]
|
|
96
|
+
*/
|
|
97
|
+
const convertCell = (type, value) => {
|
|
98
|
+
// if data type is an array
|
|
99
|
+
if (type.charAt(0) === '_') {
|
|
100
|
+
const dataType = type.slice(1, type.length);
|
|
101
|
+
return (0, exports.toArray)(value, dataType);
|
|
102
|
+
}
|
|
103
|
+
// If not null, convert to correct type.
|
|
104
|
+
switch (type) {
|
|
105
|
+
case PostgresTypes.bool:
|
|
106
|
+
return (0, exports.toBoolean)(value);
|
|
107
|
+
case PostgresTypes.float4:
|
|
108
|
+
case PostgresTypes.float8:
|
|
109
|
+
case PostgresTypes.int2:
|
|
110
|
+
case PostgresTypes.int4:
|
|
111
|
+
case PostgresTypes.int8:
|
|
112
|
+
case PostgresTypes.numeric:
|
|
113
|
+
case PostgresTypes.oid:
|
|
114
|
+
return (0, exports.toNumber)(value);
|
|
115
|
+
case PostgresTypes.json:
|
|
116
|
+
case PostgresTypes.jsonb:
|
|
117
|
+
return (0, exports.toJson)(value);
|
|
118
|
+
case PostgresTypes.timestamp:
|
|
119
|
+
return (0, exports.toTimestampString)(value); // Format to be consistent with PostgREST
|
|
120
|
+
case PostgresTypes.abstime: // To allow users to cast it based on Timezone
|
|
121
|
+
case PostgresTypes.date: // To allow users to cast it based on Timezone
|
|
122
|
+
case PostgresTypes.daterange:
|
|
123
|
+
case PostgresTypes.int4range:
|
|
124
|
+
case PostgresTypes.int8range:
|
|
125
|
+
case PostgresTypes.money:
|
|
126
|
+
case PostgresTypes.reltime: // To allow users to cast it based on Timezone
|
|
127
|
+
case PostgresTypes.text:
|
|
128
|
+
case PostgresTypes.time: // To allow users to cast it based on Timezone
|
|
129
|
+
case PostgresTypes.timestamptz: // To allow users to cast it based on Timezone
|
|
130
|
+
case PostgresTypes.timetz: // To allow users to cast it based on Timezone
|
|
131
|
+
case PostgresTypes.tsrange:
|
|
132
|
+
case PostgresTypes.tstzrange:
|
|
133
|
+
return noop(value);
|
|
134
|
+
default:
|
|
135
|
+
// Return the value for remaining types
|
|
136
|
+
return noop(value);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
exports.convertCell = convertCell;
|
|
140
|
+
const noop = (value) => {
|
|
141
|
+
return value;
|
|
142
|
+
};
|
|
143
|
+
const toBoolean = (value) => {
|
|
144
|
+
switch (value) {
|
|
145
|
+
case 't':
|
|
146
|
+
return true;
|
|
147
|
+
case 'f':
|
|
148
|
+
return false;
|
|
149
|
+
default:
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
exports.toBoolean = toBoolean;
|
|
154
|
+
const toNumber = (value) => {
|
|
155
|
+
if (typeof value === 'string') {
|
|
156
|
+
const parsedValue = parseFloat(value);
|
|
157
|
+
if (!Number.isNaN(parsedValue)) {
|
|
158
|
+
return parsedValue;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return value;
|
|
162
|
+
};
|
|
163
|
+
exports.toNumber = toNumber;
|
|
164
|
+
const toJson = (value) => {
|
|
165
|
+
if (typeof value === 'string') {
|
|
166
|
+
try {
|
|
167
|
+
return JSON.parse(value);
|
|
168
|
+
}
|
|
169
|
+
catch (_a) {
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return value;
|
|
174
|
+
};
|
|
175
|
+
exports.toJson = toJson;
|
|
176
|
+
/**
|
|
177
|
+
* Converts a Postgres Array into a native JS array
|
|
178
|
+
*
|
|
179
|
+
* @example toArray('{}', 'int4')
|
|
180
|
+
* //=> []
|
|
181
|
+
* @example toArray('{"[2021-01-01,2021-12-31)","(2021-01-01,2021-12-32]"}', 'daterange')
|
|
182
|
+
* //=> ['[2021-01-01,2021-12-31)', '(2021-01-01,2021-12-32]']
|
|
183
|
+
* @example toArray([1,2,3,4], 'int4')
|
|
184
|
+
* //=> [1,2,3,4]
|
|
185
|
+
*/
|
|
186
|
+
const toArray = (value, type) => {
|
|
187
|
+
if (typeof value !== 'string') {
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
const lastIdx = value.length - 1;
|
|
191
|
+
const closeBrace = value[lastIdx];
|
|
192
|
+
const openBrace = value[0];
|
|
193
|
+
// Confirm value is a Postgres array by checking curly brackets
|
|
194
|
+
if (openBrace === '{' && closeBrace === '}') {
|
|
195
|
+
let arr;
|
|
196
|
+
const valTrim = value.slice(1, lastIdx);
|
|
197
|
+
// TODO: find a better solution to separate Postgres array data
|
|
198
|
+
try {
|
|
199
|
+
arr = JSON.parse('[' + valTrim + ']');
|
|
200
|
+
}
|
|
201
|
+
catch (_) {
|
|
202
|
+
// WARNING: splitting on comma does not cover all edge cases
|
|
203
|
+
arr = valTrim ? valTrim.split(',') : [];
|
|
204
|
+
}
|
|
205
|
+
return arr.map((val) => (0, exports.convertCell)(type, val));
|
|
206
|
+
}
|
|
207
|
+
return value;
|
|
208
|
+
};
|
|
209
|
+
exports.toArray = toArray;
|
|
210
|
+
/**
|
|
211
|
+
* Fixes timestamp to be ISO-8601. Swaps the space between the date and time for a 'T'
|
|
212
|
+
* See https://github.com/supabase/supabase/issues/18
|
|
213
|
+
*
|
|
214
|
+
* @example toTimestampString('2019-09-10 00:00:00')
|
|
215
|
+
* //=> '2019-09-10T00:00:00'
|
|
216
|
+
*/
|
|
217
|
+
const toTimestampString = (value) => {
|
|
218
|
+
if (typeof value === 'string') {
|
|
219
|
+
return value.replace(' ', 'T');
|
|
220
|
+
}
|
|
221
|
+
return value;
|
|
222
|
+
};
|
|
223
|
+
exports.toTimestampString = toTimestampString;
|
|
224
|
+
const httpEndpointURL = (socketUrl) => {
|
|
225
|
+
const wsUrl = new URL(socketUrl);
|
|
226
|
+
wsUrl.protocol = wsUrl.protocol.replace(/^ws/i, 'http');
|
|
227
|
+
wsUrl.pathname = wsUrl.pathname
|
|
228
|
+
.replace(/\/+$/, '') // remove all trailing slashes
|
|
229
|
+
.replace(/\/socket\/websocket$/i, '') // remove the socket/websocket path
|
|
230
|
+
.replace(/\/socket$/i, '') // remove the socket path
|
|
231
|
+
.replace(/\/websocket$/i, ''); // remove the websocket path
|
|
232
|
+
if (wsUrl.pathname === '' || wsUrl.pathname === '/') {
|
|
233
|
+
wsUrl.pathname = '/api/broadcast';
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
wsUrl.pathname = wsUrl.pathname + '/api/broadcast';
|
|
237
|
+
}
|
|
238
|
+
return wsUrl.href;
|
|
239
|
+
};
|
|
240
|
+
exports.httpEndpointURL = httpEndpointURL;
|
|
241
|
+
//# 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,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,CAAA;IACvB,8BAAa,CAAA;IACb,gCAAe,CAAA;IACf,gCAAe,CAAA;IACf,oCAAmB,CAAA;IACnB,4BAAW,CAAA;IACX,oCAAmB,CAAA;IACnB,8BAAa,CAAA;IACb,8BAAa,CAAA;IACb,wCAAuB,CAAA;IACvB,4CAA2B,CAAA;IAC3B,kCAAiB,CAAA;IACjB,oCAAmB,CAAA;IACnB,wCAAuB,CAAA;AACzB,CAAC,EAzBW,aAAa,6BAAb,aAAa,QAyBxB;AAgBD;;;;;;;;;;;GAWG;AACI,MAAM,iBAAiB,GAAG,CAC/B,OAAgB,EAChB,MAAqB,EACrB,UAAoC,EAAE,EAC9B,EAAE;;IACV,MAAM,SAAS,GAAG,MAAA,OAAO,CAAC,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;AANY,QAAA,iBAAiB,qBAM7B;AAEM,MAAM,eAAe,GAAG,CAAC,SAAiB,EAAU,EAAE;IAC3D,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAA;IAEhC,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEvD,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ;SAC5B,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,8BAA8B;SAClD,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC,mCAAmC;SACxE,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,yBAAyB;SACnD,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAA,CAAC,4BAA4B;IAE5D,IAAI,KAAK,CAAC,QAAQ,KAAK,EAAE,IAAI,KAAK,CAAC,QAAQ,KAAK,GAAG,EAAE,CAAC;QACpD,KAAK,CAAC,QAAQ,GAAG,gBAAgB,CAAA;IACnC,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,GAAG,gBAAgB,CAAA;IACpD,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAA;AACnB,CAAC,CAAA;AAlBY,QAAA,eAAe,mBAkB3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO,WAAW,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.version = void 0;
|
|
4
|
+
// Generated automatically during releases by scripts/update-version-files.ts
|
|
5
|
+
// This file provides runtime access to the package version for:
|
|
6
|
+
// - HTTP request headers (e.g., X-Client-Info header for API requests)
|
|
7
|
+
// - Debugging and support (identifying which version is running)
|
|
8
|
+
// - Telemetry and logging (version reporting in errors/analytics)
|
|
9
|
+
// - Ensuring build artifacts match the published package version
|
|
10
|
+
exports.version = '2.99.3';
|
|
11
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":";;;AAAA,6EAA6E;AAC7E,gEAAgE;AAChE,uEAAuE;AACvE,iEAAiE;AACjE,kEAAkE;AAClE,iEAAiE;AACpD,QAAA,OAAO,GAAG,QAAQ,CAAA"}
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* Closes the socket, optionally providing a close code and reason.
|
|
11
|
+
*/
|
|
12
|
+
close(code?: number, reason?: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Sends data through the socket using the underlying implementation.
|
|
15
|
+
*/
|
|
16
|
+
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
|
17
|
+
onopen: ((this: any, ev: Event) => any) | null;
|
|
18
|
+
onmessage: ((this: any, ev: MessageEvent) => any) | null;
|
|
19
|
+
onclose: ((this: any, ev: CloseEvent) => any) | null;
|
|
20
|
+
onerror: ((this: any, ev: Event) => any) | null;
|
|
21
|
+
/**
|
|
22
|
+
* Registers an event listener on the socket (compatible with browser WebSocket API).
|
|
23
|
+
*/
|
|
24
|
+
addEventListener(type: string, listener: EventListener): void;
|
|
25
|
+
/**
|
|
26
|
+
* Removes a previously registered event listener.
|
|
27
|
+
*/
|
|
28
|
+
removeEventListener(type: string, listener: EventListener): void;
|
|
29
|
+
binaryType?: string;
|
|
30
|
+
bufferedAmount?: number;
|
|
31
|
+
extensions?: string;
|
|
32
|
+
dispatchEvent?: (event: Event) => boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface WebSocketEnvironment {
|
|
35
|
+
type: 'native' | 'ws' | 'cloudflare' | 'unsupported';
|
|
36
|
+
constructor?: any;
|
|
37
|
+
error?: string;
|
|
38
|
+
workaround?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Utilities for creating WebSocket instances across runtimes.
|
|
42
|
+
*/
|
|
43
|
+
export declare class WebSocketFactory {
|
|
44
|
+
/**
|
|
45
|
+
* Static-only utility – prevent instantiation.
|
|
46
|
+
*/
|
|
47
|
+
private constructor();
|
|
48
|
+
private static detectEnvironment;
|
|
49
|
+
/**
|
|
50
|
+
* Returns the best available WebSocket constructor for the current runtime.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const WS = WebSocketFactory.getWebSocketConstructor()
|
|
55
|
+
* const socket = new WS('wss://realtime.supabase.co/socket')
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
static getWebSocketConstructor(): typeof WebSocket;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a WebSocket using the detected constructor.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const socket = WebSocketFactory.createWebSocket('wss://realtime.supabase.co/socket')
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
static createWebSocket(url: string | URL, protocols?: string | string[]): WebSocketLike;
|
|
68
|
+
/**
|
|
69
|
+
* Detects whether the runtime can establish WebSocket connections.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* if (!WebSocketFactory.isWebSocketSupported()) {
|
|
74
|
+
* console.warn('Falling back to long polling')
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
static isWebSocketSupported(): boolean;
|
|
79
|
+
}
|
|
80
|
+
export default WebSocketFactory;
|
|
81
|
+
//# 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;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3C;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,GAAG,eAAe,GAAG,IAAI,CAAA;IAEnE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,CAAA;IAC9C,SAAS,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,YAAY,KAAK,GAAG,CAAC,GAAG,IAAI,CAAA;IACxD,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,UAAU,KAAK,GAAG,CAAC,GAAG,IAAI,CAAA;IACpD,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,CAAA;IAE/C;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAA;IAC7D;;OAEG;IACH,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAA;IAGhE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAA;CAC1C;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,YAAY,GAAG,aAAa,CAAA;IACpD,WAAW,CAAC,EAAE,GAAG,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAC3B;;OAEG;IACH,OAAO;IACP,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAmFhC;;;;;;;;OAQG;WACW,uBAAuB,IAAI,OAAO,SAAS;IAYzD;;;;;;;OAOG;WACW,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa;IAK9F;;;;;;;;;OASG;WACW,oBAAoB,IAAI,OAAO;CAQ9C;AAED,eAAe,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSocketFactory = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Utilities for creating WebSocket instances across runtimes.
|
|
6
|
+
*/
|
|
7
|
+
class WebSocketFactory {
|
|
8
|
+
/**
|
|
9
|
+
* Static-only utility – prevent instantiation.
|
|
10
|
+
*/
|
|
11
|
+
constructor() { }
|
|
12
|
+
static detectEnvironment() {
|
|
13
|
+
var _a;
|
|
14
|
+
if (typeof WebSocket !== 'undefined') {
|
|
15
|
+
return { type: 'native', constructor: WebSocket };
|
|
16
|
+
}
|
|
17
|
+
if (typeof globalThis !== 'undefined' && typeof globalThis.WebSocket !== 'undefined') {
|
|
18
|
+
return { type: 'native', constructor: globalThis.WebSocket };
|
|
19
|
+
}
|
|
20
|
+
if (typeof global !== 'undefined' && typeof global.WebSocket !== 'undefined') {
|
|
21
|
+
return { type: 'native', constructor: global.WebSocket };
|
|
22
|
+
}
|
|
23
|
+
if (typeof globalThis !== 'undefined' &&
|
|
24
|
+
typeof globalThis.WebSocketPair !== 'undefined' &&
|
|
25
|
+
typeof globalThis.WebSocket === 'undefined') {
|
|
26
|
+
return {
|
|
27
|
+
type: 'cloudflare',
|
|
28
|
+
error: 'Cloudflare Workers detected. WebSocket clients are not supported in Cloudflare Workers.',
|
|
29
|
+
workaround: 'Use Cloudflare Workers WebSocket API for server-side WebSocket handling, or deploy to a different runtime.',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if ((typeof globalThis !== 'undefined' && globalThis.EdgeRuntime) ||
|
|
33
|
+
(typeof navigator !== 'undefined' && ((_a = navigator.userAgent) === null || _a === void 0 ? void 0 : _a.includes('Vercel-Edge')))) {
|
|
34
|
+
return {
|
|
35
|
+
type: 'unsupported',
|
|
36
|
+
error: 'Edge runtime detected (Vercel Edge/Netlify Edge). WebSockets are not supported in edge functions.',
|
|
37
|
+
workaround: 'Use serverless functions or a different deployment target for WebSocket functionality.',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Use dynamic property access to avoid Next.js Edge Runtime static analysis warnings
|
|
41
|
+
const _process = globalThis['process'];
|
|
42
|
+
if (_process) {
|
|
43
|
+
const processVersions = _process['versions'];
|
|
44
|
+
if (processVersions && processVersions['node']) {
|
|
45
|
+
// Remove 'v' prefix if present and parse the major version
|
|
46
|
+
const versionString = processVersions['node'];
|
|
47
|
+
const nodeVersion = parseInt(versionString.replace(/^v/, '').split('.')[0]);
|
|
48
|
+
// Node.js 22+ should have native WebSocket
|
|
49
|
+
if (nodeVersion >= 22) {
|
|
50
|
+
// Check if native WebSocket is available (should be in Node.js 22+)
|
|
51
|
+
if (typeof globalThis.WebSocket !== 'undefined') {
|
|
52
|
+
return { type: 'native', constructor: globalThis.WebSocket };
|
|
53
|
+
}
|
|
54
|
+
// If not available, user needs to provide it
|
|
55
|
+
return {
|
|
56
|
+
type: 'unsupported',
|
|
57
|
+
error: `Node.js ${nodeVersion} detected but native WebSocket not found.`,
|
|
58
|
+
workaround: 'Provide a WebSocket implementation via the transport option.',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// Node.js < 22 doesn't have native WebSocket
|
|
62
|
+
return {
|
|
63
|
+
type: 'unsupported',
|
|
64
|
+
error: `Node.js ${nodeVersion} detected without native WebSocket support.`,
|
|
65
|
+
workaround: 'For Node.js < 22, install "ws" package and provide it via the transport option:\n' +
|
|
66
|
+
'import ws from "ws"\n' +
|
|
67
|
+
'new RealtimeClient(url, { transport: ws })',
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
type: 'unsupported',
|
|
73
|
+
error: 'Unknown JavaScript runtime without WebSocket support.',
|
|
74
|
+
workaround: "Ensure you're running in a supported environment (browser, Node.js, Deno) or provide a custom WebSocket implementation.",
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the best available WebSocket constructor for the current runtime.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const WS = WebSocketFactory.getWebSocketConstructor()
|
|
83
|
+
* const socket = new WS('wss://realtime.supabase.co/socket')
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
static getWebSocketConstructor() {
|
|
87
|
+
const env = this.detectEnvironment();
|
|
88
|
+
if (env.constructor) {
|
|
89
|
+
return env.constructor;
|
|
90
|
+
}
|
|
91
|
+
let errorMessage = env.error || 'WebSocket not supported in this environment.';
|
|
92
|
+
if (env.workaround) {
|
|
93
|
+
errorMessage += `\n\nSuggested solution: ${env.workaround}`;
|
|
94
|
+
}
|
|
95
|
+
throw new Error(errorMessage);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Creates a WebSocket using the detected constructor.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* const socket = WebSocketFactory.createWebSocket('wss://realtime.supabase.co/socket')
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
static createWebSocket(url, protocols) {
|
|
106
|
+
const WS = this.getWebSocketConstructor();
|
|
107
|
+
return new WS(url, protocols);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Detects whether the runtime can establish WebSocket connections.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* if (!WebSocketFactory.isWebSocketSupported()) {
|
|
115
|
+
* console.warn('Falling back to long polling')
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
static isWebSocketSupported() {
|
|
120
|
+
try {
|
|
121
|
+
const env = this.detectEnvironment();
|
|
122
|
+
return env.type === 'native' || env.type === 'ws';
|
|
123
|
+
}
|
|
124
|
+
catch (_a) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.WebSocketFactory = WebSocketFactory;
|
|
130
|
+
exports.default = WebSocketFactory;
|
|
131
|
+
//# sourceMappingURL=websocket-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-factory.js","sourceRoot":"","sources":["../../../src/lib/websocket-factory.ts"],"names":[],"mappings":";;;AA8CA;;GAEG;AACH,MAAa,gBAAgB;IAC3B;;OAEG;IACH,gBAAuB,CAAC;IAChB,MAAM,CAAC,iBAAiB;;QAC9B,IAAI,OAAO,SAAS,KAAK,WAAW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